CreOS SDK
The CreOS SDK allows you to interact with Avular robots
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
Loading...
Searching...
No Matches
gnss.hpp
1// Copyright (C) 2024 Avular Holding B.V. - All Rights Reserved
2// You may use this code under the terms of the Avular
3// Software End-User License Agreement.
4//
5// You should have received a copy of the Avular
6// Software End-User License Agreement license with
7// this file, or download it from: avular.com/eula
8//
9/*****************************************************************************
10 * Created on: 2024 July 08
11 * Author: Bram Tertoolen
12 *
13 * @file Message containing GNSS data of the robot
14 ****************************************************************************/
15#pragma once
16
17#include <array>
18#include <creos/robot_clock.hpp>
19#include <nlohmann/json.hpp>
20#include <string>
21
22#include "generic.hpp"
23
24namespace creos_messages {
25
34 double latitude = 0.0;
39 double longitude = 0.0;
44 double altitude = 0.0; // [m] NaN if no altitude is available
45
49 auto operator<=>(const GnssCoordinate& other) const = default;
50};
51
52NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(GnssCoordinate, latitude, longitude, altitude)
53
54
59 kInvalidCovariance = -1,
61 kApproximated = 1,
62 kDiagonalKnown = 2,
63 kKnown = 3
64 };
65
66 GnssCoordinate coordinate;
67 Matrixd<3, 3> covariance;
68 CovarianceType position_covariance_type = kInvalidCovariance;
69
73 auto operator<=>(const GnssPosition& other) const = default;
74};
75
76NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(GnssPosition, coordinate, covariance, position_covariance_type)
77
78
82
83 double heading = 0.0;
84 double heading_covariance = 0.0;
85
89 auto operator<=>(const GnssHeading& other) const = default;
90};
91
92NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(GnssHeading, heading, heading_covariance)
93
94
97struct Gnss {
98
99 struct Service {
100 bool gps : 1 = false;
101 bool glonass : 1 = false;
102 bool beidou : 1 = false;
103 bool galileo : 1 = false;
104
108 auto operator<=>(const Service& other) const = default;
109 };
110
112 kInvalidStatus = -2,
113 kNoAugmentationFix = -1,
114 kUnaugmentedFix = 0,
115 kSatelliteBasedAugmentation = 1,
116 kGroundBasedAugmentation = 2
117 };
118
120 kNoFix = -1,
121 k2DFix = 0,
122 k3DFix = 1,
123 kRTKFloat = 2,
124 kRTKFix = 3,
125 };
126
130 creos::RobotClock::time_point timestamp;
131
135 std::string frame_id;
136
140 Augmentation augmentation = Augmentation::kInvalidStatus;
141
146
151
156
160 FixStatus fix_status = FixStatus::kNoFix;
161
165 int satellites_visible = 0;
166
170 int satellites_used = 0;
171
175 auto operator<=>(const Gnss& other) const = default;
176};
177
178namespace detail {
179enum class GnssServiceFlags : uint32_t {
180 kNone = 0x0,
181 kGps = 0x1,
182 kGlonass = 0x2,
183 kBeidou = 0x4,
184 kGalileo = 0x8,
185};
186
187inline constexpr bool isSet(uint32_t flags, GnssServiceFlags flag) {
188 return (static_cast<uint32_t>(flag) & flags) != 0;
189}
190
191inline constexpr void addFlag(uint32_t& flags, GnssServiceFlags flag, bool value) {
192 if (value) {
193 flags |= static_cast<uint32_t>(flag);
194 }
195}
196
197} // namespace detail
198
199inline void to_json(nlohmann::json& j, const Gnss::Service& service) {
200 using namespace detail;
201
202 uint32_t flags = 0;
203 addFlag(flags, GnssServiceFlags::kGps, service.gps);
204 addFlag(flags, GnssServiceFlags::kGlonass, service.glonass);
205 addFlag(flags, GnssServiceFlags::kBeidou, service.beidou);
206 addFlag(flags, GnssServiceFlags::kGalileo, service.galileo);
207
208 j = flags;
209}
210
211inline void from_json(const nlohmann::json& j, Gnss::Service& service) {
212 using namespace detail;
213
214 uint32_t flags = j.get<uint32_t>();
215
216 service.gps = isSet(flags, GnssServiceFlags::kGps);
217 service.glonass = isSet(flags, GnssServiceFlags::kGlonass);
218 service.beidou = isSet(flags, GnssServiceFlags::kBeidou);
219 service.galileo = isSet(flags, GnssServiceFlags::kGalileo);
220}
221
222NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Gnss, timestamp, frame_id, augmentation, service, position, heading, fix_status,
223 satellites_visible, satellites_used)
224
225} // namespace creos_messages
Matrix template for a 2D array of type T.
Definition generic.hpp:115
The messages that are used in the communication between the agent and the client.
Definition accel.hpp:22
@ kUnknown
Unknown error.
Definition gnss.hpp:99
auto operator<=>(const Service &other) const =default
Compare two Service messages.
bool glonass
The GNSS sensor is connected to GLONASS satellites.
Definition gnss.hpp:101
bool beidou
The GNSS sensor is connected to Beidou satellites.
Definition gnss.hpp:102
bool gps
The GNSS sensor is connected to GPS satellites.
Definition gnss.hpp:100
bool galileo
The GNSS sensor is connected to Galileo satellites.
Definition gnss.hpp:103
A coordinate in the GNSS system.
Definition gnss.hpp:29
double altitude
altitude [m] NaN if no altitude is available
Definition gnss.hpp:44
double longitude
longitude [degrees] Positive values are east of the prime meridian, negative values are west of the p...
Definition gnss.hpp:39
double latitude
latitude [degrees] Positive values are north of the equator, negative values are south of the equator
Definition gnss.hpp:34
auto operator<=>(const GnssCoordinate &other) const =default
Compare two GnssCoordinate messages.
The heading of the GNSS sensor.
Definition gnss.hpp:81
auto operator<=>(const GnssHeading &other) const =default
Compare two GnssHeading messages.
The GNSS message contains the GNSS data of the robot.
Definition gnss.hpp:97
auto operator<=>(const Gnss &other) const =default
Compare two Gnss messages.
creos::RobotClock::time_point timestamp
Timestamp of when sensor data was created / measured.
Definition gnss.hpp:130
Augmentation
Definition gnss.hpp:111
Service service
The service of the GNSS sensor.
Definition gnss.hpp:145
FixStatus
Definition gnss.hpp:119
std::string frame_id
Frame id of the GNSS sensor.
Definition gnss.hpp:135
GnssHeading heading
The heading of the GNSS sensor.
Definition gnss.hpp:155
GnssPosition position
The position of the GNSS sensor.
Definition gnss.hpp:150
The GNSS message contains the GNSS data of the robot.
Definition gnss.hpp:57
auto operator<=>(const GnssPosition &other) const =default
Compare two GnssPosition messages.
CovarianceType
Definition gnss.hpp:58