0.5.0
Loading...
Searching...
No Matches
Keys.hpp
Go to the documentation of this file.
1// This file is part of INSTINCT, the INS Toolkit for Integrated
2// Navigation Concepts and Training by the Institute of Navigation of
3// the University of Stuttgart, Germany.
4//
5// This Source Code Form is subject to the terms of the Mozilla Public
6// License, v. 2.0. If a copy of the MPL was not distributed with this
7// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
9/// @file Keys.hpp
10/// @brief Keys for the RTK algorithm for use inside the KeyedMatrices
11/// @author T. Topp (topp@ins.uni-stuttgart.de)
12/// @date 2023-12-21
13
14#pragma once
15
16#include <cstdint>
17#include <vector>
18#include <variant>
19#include <fmt/format.h>
20
23
24namespace NAV::RTK
25{
26
27namespace States
28{
29
30/// @brief State Keys of the Kalman filter
31enum KFStates : uint8_t
32{
33 PosX, ///< Position ECEF_X [m]
34 PosY, ///< Position ECEF_Y [m]
35 PosZ, ///< Position ECEF_Z [m]
36 VelX, ///< Velocity ECEF_X [m/s]
37 VelY, ///< Velocity ECEF_Y [m/s]
38 VelZ, ///< Velocity ECEF_Z [m/s]
39 KFStates_COUNT, ///< Count
40};
41/// @brief Double differenced N_br^1s = N_br^s - N_br^1 ambiguity [cycles] (one for each satellite signal, except for the pivot satellites)
43{
44 /// @brief Constructor
45 /// @param[in] satSigId Satellite Signal Id
47 /// @brief Equal comparison operator
48 /// @param rhs Right-hand side
49 bool operator==(const AmbiguityDD& rhs) const { return satSigId == rhs.satSigId; }
50 /// @brief Satellite Signal Id
52};
53
54/// Alias for the state key type
55using StateKeyType = std::variant<KFStates, AmbiguityDD>;
56/// @brief Vector with all position and velocity state keys
57inline static const std::vector<StateKeyType> PosVel = { KFStates::PosX, KFStates::PosY, KFStates::PosZ,
59/// @brief All position keys
60inline static const std::vector<StateKeyType> Pos = { KFStates::PosX, KFStates::PosY, KFStates::PosZ };
61/// @brief All velocity keys
62inline static const std::vector<StateKeyType> Vel = { KFStates::VelX, KFStates::VelY, KFStates::VelZ };
63
64} // namespace States
65
66namespace Meas
67{
68
69/// @brief Double differenced pseudorange measurement psr_br^1s [m] (one for each satellite signal, referenced to the pivot satellite)
70struct PsrDD
71{
72 /// @brief Equal comparison operator
73 /// @param rhs Right-hand side
74 bool operator==(const PsrDD& rhs) const { return satSigId == rhs.satSigId; }
75 /// @brief Satellite Signal Id
77};
78/// @brief Double differenced carrier-phase measurement phi_br^1s [m] (one for each satellite signal, referenced to the pivot satellite)
80{
81 /// @brief Equal comparison operator
82 /// @param rhs Right-hand side
83 bool operator==(const CarrierDD& rhs) const { return satSigId == rhs.satSigId; }
84 /// @brief Satellite Signal Id
86};
87/// @brief Double differenced range-rate (doppler) measurement d_br^1s [m/s] (one for each satellite signal, referenced to the pivot satellite)
89{
90 /// @brief Equal comparison operator
91 /// @param rhs Right-hand side
92 bool operator==(const DopplerDD& rhs) const { return satSigId == rhs.satSigId; }
93 /// @brief Satellite Signal Id
95};
96
97/// Alias for the measurement key type
98using MeasKeyTypes = std::variant<PsrDD, CarrierDD, DopplerDD, States::AmbiguityDD>;
99
100/// @brief Single Observation key
101template<typename ReceiverType>
103{
104 /// @brief Constructor
105 /// @param[in] satSigId Signal id
106 /// @param[in] recvType Receiver Type
107 /// @param[in] obsType Observation Type
110
111 SatSigId satSigId; ///< Signal id
112 ReceiverType recvType; ///< Receiver Type
113 GnssObs::ObservationType obsType; ///< Observation Type
114
115 /// @brief Equal comparison operator
116 /// @param rhs Right-hand side
117 bool operator==(const SingleObs<ReceiverType>& rhs) const
118 {
119 return satSigId == rhs.satSigId
120 && recvType == rhs.recvType
121 && obsType == rhs.obsType;
122 }
123};
124
125/// @brief Ambiguity Observation key
126template<typename ReceiverType>
127struct AmbObs
128{
129 /// @brief Constructor
130 /// @param[in] satSigId Signal id
131 /// @param[in] recvType Receiver Type
134
135 SatSigId satSigId; ///< Signal id
136 ReceiverType recvType; ///< Receiver Type
137
138 /// @brief Equal comparison operator
139 /// @param rhs Right-hand side
140 bool operator==(const AmbObs<ReceiverType>& rhs) const
141 {
142 return satSigId == rhs.satSigId && recvType == rhs.recvType;
143 }
144};
145
146} // namespace Meas
147
148} // namespace NAV::RTK
149
150namespace std
151{
152/// @brief Hash function (needed for unordered_map)
153template<>
154struct hash<NAV::RTK::States::AmbiguityDD>
155{
156 /// @brief Hash function
157 /// @param[in] ambDD Double differenced ambiguity
158 size_t operator()(const NAV::RTK::States::AmbiguityDD& ambDD) const
159 {
160 return NAV::RTK::States::KFStates_COUNT + std::hash<NAV::SatSigId>()(ambDD.satSigId);
161 }
162};
163/// @brief Hash function (needed for unordered_map)
164template<>
165struct hash<NAV::RTK::Meas::PsrDD>
166{
167 /// @brief Hash function
168 /// @param[in] psrDD Double differenced pseudorange
169 size_t operator()(const NAV::RTK::Meas::PsrDD& psrDD) const
170 {
171 return std::hash<NAV::SatSigId>()(psrDD.satSigId);
172 }
173};
174/// @brief Hash function (needed for unordered_map)
175template<>
176struct hash<NAV::RTK::Meas::CarrierDD>
177{
178 /// @brief Hash function
179 /// @param[in] cpDD Double differenced carrier-phase
180 size_t operator()(const NAV::RTK::Meas::CarrierDD& cpDD) const
181 {
182 return std::hash<NAV::SatSigId>()(cpDD.satSigId) << 12;
183 }
184};
185/// @brief Hash function (needed for unordered_map)
186template<>
187struct hash<NAV::RTK::Meas::DopplerDD>
188{
189 /// @brief Hash function
190 /// @param[in] dDD Double differenced doppler
191 size_t operator()(const NAV::RTK::Meas::DopplerDD& dDD) const
192 {
193 return std::hash<NAV::SatSigId>()(dDD.satSigId) << 24;
194 }
195};
196/// @brief Hash function (needed for unordered_map)
197template<typename ReceiverType>
198struct hash<NAV::RTK::Meas::SingleObs<ReceiverType>>
199{
200 /// @brief Hash function
201 /// @param[in] obs Single Observation
203 {
204 auto hash1 = std::hash<NAV::SatSigId>()(obs.satSigId);
205 auto hash2 = static_cast<size_t>(obs.obsType);
206 auto hash3 = static_cast<size_t>(obs.recvType);
207
208 return (hash1 << 4) | (hash2 << 2) | hash3;
209 }
210};
211/// @brief Hash function (needed for unordered_map)
212template<typename ReceiverType>
213struct hash<NAV::RTK::Meas::AmbObs<ReceiverType>>
214{
215 /// @brief Hash function
216 /// @param[in] obs Single Ambiguity Observation
218 {
219 auto hash1 = std::hash<NAV::SatSigId>()(obs.satSigId);
220 auto hash2 = static_cast<size_t>(obs.recvType);
221
222 return (hash1 << 2) | hash2;
223 }
224};
225} // namespace std
226
227#ifndef DOXYGEN_IGNORE
228
229/// @brief Formatter
230template<>
231struct fmt::formatter<NAV::RTK::States::KFStates> : fmt::formatter<const char*>
232{
233 /// @brief Defines how to format structs
234 /// @param[in] state Struct to format
235 /// @param[in, out] ctx Format context
236 /// @return Output iterator
237 template<typename FormatContext>
238 auto format(const NAV::RTK::States::KFStates& state, FormatContext& ctx) const
239 {
240 using namespace NAV::RTK::States; // NOLINT(google-build-using-namespace)
241
242 switch (state)
243 {
244 case PosX:
245 return fmt::formatter<const char*>::format("PosX", ctx);
246 case PosY:
247 return fmt::formatter<const char*>::format("PosY", ctx);
248 case PosZ:
249 return fmt::formatter<const char*>::format("PosZ", ctx);
250 case VelX:
251 return fmt::formatter<const char*>::format("VelX", ctx);
252 case VelY:
253 return fmt::formatter<const char*>::format("VelY", ctx);
254 case VelZ:
255 return fmt::formatter<const char*>::format("VelZ", ctx);
256 case KFStates_COUNT:
257 return fmt::formatter<const char*>::format("KFStates_COUNT", ctx);
258 }
259
260 return fmt::formatter<const char*>::format("ERROR", ctx);
261 }
262};
263
264/// @brief Formatter
265template<>
266struct fmt::formatter<NAV::RTK::States::AmbiguityDD> : fmt::formatter<std::string>
267{
268 /// @brief Defines how to format structs
269 /// @param[in] amb Struct to format
270 /// @param[in, out] ctx Format context
271 /// @return Output iterator
272 template<typename FormatContext>
273 auto format(const NAV::RTK::States::AmbiguityDD& amb, FormatContext& ctx) const
274 {
275 return fmt::formatter<std::string>::format(fmt::format("Amb({})", amb.satSigId), ctx);
276 }
277};
278
279/// @brief Formatter
280template<>
281struct fmt::formatter<NAV::RTK::Meas::PsrDD> : fmt::formatter<std::string>
282{
283 /// @brief Defines how to format structs
284 /// @param[in] psrDD Struct to format
285 /// @param[in, out] ctx Format context
286 /// @return Output iterator
287 template<typename FormatContext>
288 auto format(const NAV::RTK::Meas::PsrDD& psrDD, FormatContext& ctx) const
289 {
290 return fmt::formatter<std::string>::format(fmt::format("psrDD({})", psrDD.satSigId), ctx);
291 }
292};
293
294/// @brief Formatter
295template<>
296struct fmt::formatter<NAV::RTK::Meas::CarrierDD> : fmt::formatter<std::string>
297{
298 /// @brief Defines how to format structs
299 /// @param[in] phiDD Struct to format
300 /// @param[in, out] ctx Format context
301 /// @return Output iterator
302 template<typename FormatContext>
303 auto format(const NAV::RTK::Meas::CarrierDD& phiDD, FormatContext& ctx) const
304 {
305 return fmt::formatter<std::string>::format(fmt::format("phiDD({})", phiDD.satSigId), ctx);
306 }
307};
308
309/// @brief Formatter
310template<>
311struct fmt::formatter<NAV::RTK::Meas::DopplerDD> : fmt::formatter<std::string>
312{
313 /// @brief Defines how to format structs
314 /// @param[in] dDD Struct to format
315 /// @param[in, out] ctx Format context
316 /// @return Output iterator
317 template<typename FormatContext>
318 auto format(const NAV::RTK::Meas::DopplerDD& dDD, FormatContext& ctx) const
319 {
320 return fmt::formatter<std::string>::format(fmt::format("dopDD({})", dDD.satSigId), ctx);
321 }
322};
323
324/// @brief Formatter
325template<>
326struct fmt::formatter<NAV::RTK::States::StateKeyType> : fmt::formatter<std::string>
327{
328 /// @brief Defines how to format structs
329 /// @param[in] state Struct to format
330 /// @param[in, out] ctx Format context
331 /// @return Output iterator
332 template<typename FormatContext>
333 auto format(const NAV::RTK::States::StateKeyType& state, FormatContext& ctx) const
334 {
335 using namespace NAV::RTK::States; // NOLINT(google-build-using-namespace)
336
337 if (const auto* s = std::get_if<NAV::RTK::States::KFStates>(&state))
338 {
339 return fmt::formatter<std::string>::format(fmt::format("{}", *s), ctx);
340 }
341 if (const auto* amb = std::get_if<NAV::RTK::States::AmbiguityDD>(&state))
342 {
343 return fmt::formatter<std::string>::format(fmt::format("{}", *amb), ctx);
344 }
345
346 return fmt::formatter<std::string>::format("ERROR", ctx);
347 }
348};
349
350/// @brief Formatter
351template<>
352struct fmt::formatter<NAV::RTK::Meas::MeasKeyTypes> : fmt::formatter<std::string>
353{
354 /// @brief Defines how to format structs
355 /// @param[in] meas Struct to format
356 /// @param[in, out] ctx Format context
357 /// @return Output iterator
358 template<typename FormatContext>
359 auto format(const NAV::RTK::Meas::MeasKeyTypes& meas, FormatContext& ctx) const
360 {
361 if (const auto* psrDD = std::get_if<NAV::RTK::Meas::PsrDD>(&meas))
362 {
363 return fmt::formatter<std::string>::format(fmt::format("{}", *psrDD), ctx);
364 }
365 if (const auto* phiDD = std::get_if<NAV::RTK::Meas::CarrierDD>(&meas))
366 {
367 return fmt::formatter<std::string>::format(fmt::format("{}", *phiDD), ctx);
368 }
369 if (const auto* dDD = std::get_if<NAV::RTK::Meas::DopplerDD>(&meas))
370 {
371 return fmt::formatter<std::string>::format(fmt::format("{}", *dDD), ctx);
372 }
373 if (const auto* ambDD = std::get_if<NAV::RTK::States::AmbiguityDD>(&meas))
374 {
375 return fmt::formatter<std::string>::format(fmt::format("{}", *ambDD), ctx);
376 }
377
378 return fmt::formatter<std::string>::format("ERROR", ctx);
379 }
380};
381
382/// @brief Formatter
383template<typename ReceiverType>
384struct fmt::formatter<NAV::RTK::Meas::SingleObs<ReceiverType>> : fmt::formatter<std::string>
385{
386 /// @brief Defines how to format structs
387 /// @param[in] obs Struct to format
388 /// @param[in, out] ctx Format context
389 /// @return Output iterator
390 template<typename FormatContext>
391 auto format(const NAV::RTK::Meas::SingleObs<ReceiverType>& obs, FormatContext& ctx) const
392 {
393 return fmt::formatter<std::string>::format(fmt::format("obs({}_{:5}_{})", obs.obsType, obs.recvType, obs.satSigId), ctx);
394 }
395};
396
397/// @brief Formatter
398template<typename ReceiverType>
399struct fmt::formatter<NAV::RTK::Meas::AmbObs<ReceiverType>> : fmt::formatter<std::string>
400{
401 /// @brief Defines how to format structs
402 /// @param[in] obs Struct to format
403 /// @param[in, out] ctx Format context
404 /// @return Output iterator
405 template<typename FormatContext>
406 auto format(const NAV::RTK::Meas::AmbObs<ReceiverType>& obs, FormatContext& ctx) const
407 {
408 return fmt::formatter<std::string>::format(fmt::format("Amb({:5}_{})", obs.recvType, obs.satSigId), ctx);
409 }
410};
411
412#endif
GNSS Observation messages.
Structs identifying a unique satellite.
ObservationType
Observation types.
Definition GnssObs.hpp:37
std::variant< PsrDD, CarrierDD, DopplerDD, States::AmbiguityDD > MeasKeyTypes
Alias for the measurement key type.
Definition Keys.hpp:98
static const std::vector< StateKeyType > Vel
All velocity keys.
Definition Keys.hpp:62
KFStates
State Keys of the Kalman filter.
Definition Keys.hpp:32
@ VelX
Velocity ECEF_X [m/s].
Definition Keys.hpp:36
@ PosY
Position ECEF_Y [m].
Definition Keys.hpp:34
@ PosX
Position ECEF_X [m].
Definition Keys.hpp:33
@ VelZ
Velocity ECEF_Z [m/s].
Definition Keys.hpp:38
@ PosZ
Position ECEF_Z [m].
Definition Keys.hpp:35
@ KFStates_COUNT
Count.
Definition Keys.hpp:39
@ VelY
Velocity ECEF_Y [m/s].
Definition Keys.hpp:37
std::variant< KFStates, AmbiguityDD > StateKeyType
Alias for the state key type.
Definition Keys.hpp:55
static const std::vector< StateKeyType > Pos
All position keys.
Definition Keys.hpp:60
static const std::vector< StateKeyType > PosVel
Vector with all position and velocity state keys.
Definition Keys.hpp:57
Ambiguity Observation key.
Definition Keys.hpp:128
ReceiverType recvType
Receiver Type.
Definition Keys.hpp:136
SatSigId satSigId
Signal id.
Definition Keys.hpp:135
AmbObs(const SatSigId &satSigId, ReceiverType recvType)
Constructor.
Definition Keys.hpp:132
bool operator==(const AmbObs< ReceiverType > &rhs) const
Equal comparison operator.
Definition Keys.hpp:140
Double differenced carrier-phase measurement phi_br^1s [m] (one for each satellite signal,...
Definition Keys.hpp:80
SatSigId satSigId
Satellite Signal Id.
Definition Keys.hpp:85
bool operator==(const CarrierDD &rhs) const
Equal comparison operator.
Definition Keys.hpp:83
Double differenced range-rate (doppler) measurement d_br^1s [m/s] (one for each satellite signal,...
Definition Keys.hpp:89
bool operator==(const DopplerDD &rhs) const
Equal comparison operator.
Definition Keys.hpp:92
SatSigId satSigId
Satellite Signal Id.
Definition Keys.hpp:94
Double differenced pseudorange measurement psr_br^1s [m] (one for each satellite signal,...
Definition Keys.hpp:71
bool operator==(const PsrDD &rhs) const
Equal comparison operator.
Definition Keys.hpp:74
SatSigId satSigId
Satellite Signal Id.
Definition Keys.hpp:76
Single Observation key.
Definition Keys.hpp:103
bool operator==(const SingleObs< ReceiverType > &rhs) const
Equal comparison operator.
Definition Keys.hpp:117
GnssObs::ObservationType obsType
Observation Type.
Definition Keys.hpp:113
SingleObs(const SatSigId &satSigId, ReceiverType recvType, GnssObs::ObservationType obsType)
Constructor.
Definition Keys.hpp:108
ReceiverType recvType
Receiver Type.
Definition Keys.hpp:112
SatSigId satSigId
Signal id.
Definition Keys.hpp:111
Double differenced N_br^1s = N_br^s - N_br^1 ambiguity [cycles] (one for each satellite signal,...
Definition Keys.hpp:43
bool operator==(const AmbiguityDD &rhs) const
Equal comparison operator.
Definition Keys.hpp:49
SatSigId satSigId
Satellite Signal Id.
Definition Keys.hpp:51
AmbiguityDD(const SatSigId &satSigId)
Constructor.
Definition Keys.hpp:46
Identifies a satellite signal (satellite frequency and number)
size_t operator()(const NAV::RTK::Meas::AmbObs< ReceiverType > &obs) const
Hash function.
Definition Keys.hpp:217
size_t operator()(const NAV::RTK::Meas::CarrierDD &cpDD) const
Hash function.
Definition Keys.hpp:180
size_t operator()(const NAV::RTK::Meas::DopplerDD &dDD) const
Hash function.
Definition Keys.hpp:191
size_t operator()(const NAV::RTK::Meas::PsrDD &psrDD) const
Hash function.
Definition Keys.hpp:169
size_t operator()(const NAV::RTK::Meas::SingleObs< ReceiverType > &obs) const
Hash function.
Definition Keys.hpp:202
size_t operator()(const NAV::RTK::States::AmbiguityDD &ambDD) const
Hash function.
Definition Keys.hpp:158