0.4.1
Loading...
Searching...
No Matches
Observation.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 Observation.hpp
10/// @brief Observation data used for calculations
11/// @author T. Topp (topp@ins.uni-stuttgart.de)
12/// @date 2023-12-20
13
14#pragma once
15
16#include <cstdint>
17#include <memory>
18#include <set>
19#include <unordered_map>
20#include <unordered_set>
21#include <utility>
22
29
31
33#include "util/Eigen.hpp"
34#include "util/Logger.hpp"
35
36namespace NAV
37{
38
39/// Observation storage type
41{
42 /// @brief Receiver specific observation of the signal
44 {
45 /// @brief Destructor
46 ~SignalObservation() = default;
47 /// @brief Copy constructor
48 /// @param other The other object
50 : _navData(other._navData), _freqNum(other._freqNum)
51 {
52 for (const auto& [index, obs] : other.recvObs)
53 {
54 recvObs.insert(std::make_pair(index, std::make_shared<ReceiverSpecificData>(*obs)));
55 }
56 }
57 /// @brief Copy assignment operator
58 /// @param other The other object
60 {
61 if (this == &other) { return *this; } // Guard self assignment
62
63 for (const auto& [index, obs] : other.recvObs)
64 {
65 recvObs.insert(std::make_pair(index, std::make_shared<ReceiverSpecificData>(*obs)));
66 }
67 _navData = other._navData;
68 _freqNum = other._freqNum;
69
70 return *this;
71 }
72 /// @brief Move constructor
73 /// @param other The other object
75 : recvObs(std::move(other.recvObs)), _navData(std::move(other._navData)), _freqNum(other._freqNum) {}
76 /// @brief Move assignment operator
77 /// @param other The other object
79 {
80 if (this == &other) { return *this; } // Guard self assignment
81
82 recvObs = std::move(other.recvObs);
83 _navData = std::move(other._navData);
84 _freqNum = other._freqNum;
85
86 return *this;
87 }
88
89 /// Receiver specific data
91 {
92 /// Observations
94 {
95 double estimate = 0.0; ///< Estimate (psr [m], carrier [m], range-rate [m/s])
96 double measurement = 0.0; ///< Measurement (psr [m], carrier [m], range-rate [m/s])
97 double measVar = 0.0; ///< Variance of the measurement (psr [m^2], carrier [m^2], range-rate [m^2/s^2])
98 };
99
100 /// @brief Constructor
101 /// @param[in] gnssObs GNSS observation
102 /// @param[in] obsIdx GNSS observation index for this measurement
103 /// @param[in] e_satPos Satellite position in e frame
104 /// @param[in] e_satVel Satellite velocity in e frame
105 /// @param[in] satClock Satellite clock information
106 ReceiverSpecificData(std::shared_ptr<const GnssObs> gnssObs,
107 size_t obsIdx,
108 Eigen::Vector3d e_satPos,
109 Eigen::Vector3d e_satVel,
111 : _gnssObs(std::move(gnssObs)),
112 _obsIdx(obsIdx),
116
117 /// Receiver observation of the signal
119
120 /// @brief Returns the observation data
121 [[nodiscard]] const GnssObs::ObservationData& gnssObsData() const { return _gnssObs->data.at(_obsIdx); }
122 /// @brief Satellite position in ECEF frame coordinates [m]
123 [[nodiscard]] const Eigen::Vector3d& e_satPos() const { return _e_satPos; }
124 /// @brief Satellite velocity in ECEF frame coordinates [m/s]
125 [[nodiscard]] const Eigen::Vector3d& e_satVel() const { return _e_satVel; }
126 /// @brief Position Line-of-sight unit vector in ECEF frame coordinates
127 /// @param[in] e_recPos Receiver position in e frame
128 [[nodiscard]] Eigen::Vector3d e_pLOS(const Eigen::Vector3d& e_recPos) const
129 {
130 return e_calcLineOfSightUnitVector(e_recPos, _e_satPos);
131 }
132 /// @brief Velocity Line-of-sight unit vector in ECEF frame coordinates
133 /// @param[in] e_recPos Receiver position in e frame
134 /// @param[in] e_recVel Receiver velocity in e frame
135 [[nodiscard]] Eigen::Vector3d e_vLOS(const Eigen::Vector3d& e_recPos,
136 const Eigen::Vector3d& e_recVel) const
137 {
138 return (_e_satVel - e_recVel) / (_e_satPos - e_recPos).norm();
139 }
140 /// @brief Satellite Elevation [rad]
141 /// @param[in] e_recPos Receiver position in e frame
142 /// @param[in] lla_recPos Receiver position in lla frame
143 [[nodiscard]] double satElevation(const Eigen::Vector3d& e_recPos,
144 const Eigen::Vector3d& lla_recPos) const
145 {
146 Eigen::Vector3d n_lineOfSightUnitVector = trafo::n_Quat_e(lla_recPos(0), lla_recPos(1))
147 * e_pLOS(e_recPos);
148 return calcSatElevation(n_lineOfSightUnitVector);
149 }
150 /// @brief Satellite Azimuth [rad]
151 /// @param[in] e_recPos Receiver position in e frame
152 /// @param[in] lla_recPos Receiver position in lla frame
153 [[nodiscard]] double satAzimuth(const Eigen::Vector3d& e_recPos,
154 const Eigen::Vector3d& lla_recPos) const
155 {
156 Eigen::Vector3d n_lineOfSightUnitVector = trafo::n_Quat_e(lla_recPos(0), lla_recPos(1))
157 * e_pLOS(e_recPos);
158 return calcSatAzimuth(n_lineOfSightUnitVector);
159 }
160 /// @brief Satellite clock information
161 [[nodiscard]] const Clock::Corrections& satClock() const { return _satClock; }
162
163 /// @brief Terms used in the calculation
165 {
166 double rho_r_s = 0.0; ///< Receiver-Satellite Range [m]
167 ZenithDelay tropoZenithDelay; ///< Troposphere delay
168 double dpsr_T_r_s = 0.0; ///< Estimated troposphere propagation error [m]
169 double dpsr_I_r_s = 0.0; ///< Estimated ionosphere propagation error [m]
170 double dpsr_ie_r_s = 0.0; ///< Sagnac correction [m]
171 };
172 CalcTerms terms; ///< Sub terms used in the calculation
173
174 private:
175 std::shared_ptr<const GnssObs> _gnssObs = nullptr; ///< GNSS observation
176 size_t _obsIdx = 0; ///< Gnss observation data index
177 Eigen::Vector3d _e_satPos; ///< Satellite position in ECEF frame coordinates [m] (has to be calculated per signal because of TGD)
178 Eigen::Vector3d _e_satVel; ///< Satellite velocity in ECEF frame coordinates [m/s]
179 Clock::Corrections _satClock; ///< Satellite clock information
180 };
181
182 /// @brief Constructor
183 /// @param[in] navData Satellite Navigation data
184 /// @param[in] freqNum Frequency number. Only used for GLONASS G1 and G2
185 SignalObservation(std::shared_ptr<SatNavData> navData,
186 int8_t freqNum)
188 _freqNum(freqNum) {}
189
190 /// @brief Receiver specific data
191 ///
192 /// This is a shared_ptr so that e.g. the FGO can hold on to it over multiple epochs
193 std::unordered_map<size_t, std::shared_ptr<ReceiverSpecificData>> recvObs;
194
195 /// @brief Satellite Navigation data
196 [[nodiscard]] const std::shared_ptr<const SatNavData>& navData() const { return _navData; }
197 /// @brief Frequency number. Only used for GLONASS G1 and G2
198 [[nodiscard]] int8_t freqNum() const { return _freqNum; }
199
200 private:
201 std::shared_ptr<const SatNavData> _navData = nullptr; ///< Satellite Navigation data
202 int8_t _freqNum = -128; ///< Frequency number. Only used for GLONASS G1 and G2
203 };
204
205 unordered_map<SatSigId, SignalObservation> signals; ///< Observations and calculated data for each signal
206
207 std::unordered_set<size_t> receivers; ///< Receivers included
208 std::set<SatelliteSystem> systems; ///< Satellite systems used
209 std::unordered_set<SatId> satellites; ///< Satellites used
210 std::array<size_t, GnssObs::ObservationType_COUNT> nObservables{}; ///< Number of observables
211 std::array<size_t, GnssObs::ObservationType_COUNT> nObservablesUniqueSatellite{}; ///< Number of observables (counted once for each satellite)
212
213 /// @brief Counts how many observations for the specified signal ant type exist
214 /// @param[in] satSigId Signal identifier
215 /// @param[in] obsType Observation type
216 size_t countObservations(const SatSigId& satSigId, const GnssObs::ObservationType& obsType) const;
217
218 /// @brief Calculates/Recalculates the number of observables
219 /// @param[in] nameId Name and Id of the calling node for logging purposes
220 void recalcObservableCounts(const std::string& nameId);
221
222 /// @brief Remove the signal from the observations
223 /// @param[in] satSigId Signal identifier
224 /// @param[in] nameId Name and Id of the calling node for logging purposes
225 /// @return True if something was removed
226 bool removeSignal(const SatSigId& satSigId, const std::string& nameId);
227
228 /// @brief Remove the signal from the observations
229 /// @param[in] satSigId Signal identifier
230 /// @param[in] obsType Observation type
231 /// @param[in] nameId Name and Id of the calling node for logging purposes
232 /// @return True if something was removed
233 bool removeSignal(const SatSigId& satSigId, const GnssObs::ObservationType& obsType, const std::string& nameId);
234
235 /// @brief Remove all signals of the satellite
236 /// @param[in] satId Satellite identifier
237 /// @param[in] nameId Name and Id of the calling node for logging purposes
238 /// @return True if something was removed
239 bool removeSatellite(const SatId& satId, const std::string& nameId);
240
241 /// @brief Remove all measurements for the provided code and observation type
242 /// @param[in] code Code
243 /// @param[in] obsType Observation type
244 /// @param[in] nameId Name and Id of the calling node for logging purposes
245 /// @return True if something was removed
246 bool removeMeasurementsFor(const Code& code, const GnssObs::ObservationType& obsType, const std::string& nameId);
247
248 /// @brief Remove all measurements for the provided observation type
249 /// @param[in] obsType Observation type
250 /// @param[in] nameId Name and Id of the calling node for logging purposes
251 /// @return True if something was removed
252 bool removeObsType(const GnssObs::ObservationType& obsType, const std::string& nameId);
253};
254
255} // namespace NAV
Transformation collection.
Vector space operations.
GNSS helper functions.
GNSS Observation messages.
Utility class for logging to console and file.
Satellite Navigation data (to calculate SatNavData and clock)
Structs identifying a unique satellite.
Unordered map wrapper.
ankerl::unordered_dense::map< Key, T > unordered_map
Unordered map type.
Zenith hydrostatic and wet delay.
Enumerate for GNSS Codes.
Definition Code.hpp:89
ObservationType
Observation types.
Definition GnssObs.hpp:37
Eigen::Quaternion< Scalar > n_Quat_e(const Scalar &latitude, const Scalar &longitude)
Quaternion for rotations from Earth-fixed to navigation frame.
Derived::Scalar calcSatElevation(const Eigen::MatrixBase< Derived > &n_lineOfSightUnitVector)
Calculates the elevation of the satellite from the antenna.
Definition Functions.hpp:43
void move(std::vector< T > &v, size_t sourceIdx, size_t targetIdx)
Moves an element within a vector to a new position.
Definition Vector.hpp:27
Derived::Scalar calcSatAzimuth(const Eigen::MatrixBase< Derived > &n_lineOfSightUnitVector)
Calculates the azimuth of the satellite from the antenna.
Definition Functions.hpp:54
Eigen::Vector3< typename DerivedA::Scalar > e_calcLineOfSightUnitVector(const Eigen::MatrixBase< DerivedA > &e_posAnt, const Eigen::MatrixBase< DerivedB > &e_posSat)
Calculates the line-of-sight unit vector from the user antenna to the satellite.
Definition Functions.hpp:31
Satellite clock corrections.
Definition Clock.hpp:28
Stores the satellites observations.
Definition GnssObs.hpp:46
double dpsr_T_r_s
Estimated troposphere propagation error [m].
double dpsr_I_r_s
Estimated ionosphere propagation error [m].
double measVar
Variance of the measurement (psr [m^2], carrier [m^2], range-rate [m^2/s^2])
double measurement
Measurement (psr [m], carrier [m], range-rate [m/s])
double estimate
Estimate (psr [m], carrier [m], range-rate [m/s])
Eigen::Vector3d _e_satPos
Satellite position in ECEF frame coordinates [m] (has to be calculated per signal because of TGD)
std::shared_ptr< const GnssObs > _gnssObs
GNSS observation.
ReceiverSpecificData(std::shared_ptr< const GnssObs > gnssObs, size_t obsIdx, Eigen::Vector3d e_satPos, Eigen::Vector3d e_satVel, Clock::Corrections satClock)
Constructor.
const Eigen::Vector3d & e_satVel() const
Satellite velocity in ECEF frame coordinates [m/s].
Eigen::Vector3d _e_satVel
Satellite velocity in ECEF frame coordinates [m/s].
const Clock::Corrections & satClock() const
Satellite clock information.
Eigen::Vector3d e_pLOS(const Eigen::Vector3d &e_recPos) const
Position Line-of-sight unit vector in ECEF frame coordinates.
CalcTerms terms
Sub terms used in the calculation.
Eigen::Vector3d e_vLOS(const Eigen::Vector3d &e_recPos, const Eigen::Vector3d &e_recVel) const
Velocity Line-of-sight unit vector in ECEF frame coordinates.
double satElevation(const Eigen::Vector3d &e_recPos, const Eigen::Vector3d &lla_recPos) const
Satellite Elevation [rad].
Clock::Corrections _satClock
Satellite clock information.
const Eigen::Vector3d & e_satPos() const
Satellite position in ECEF frame coordinates [m].
double satAzimuth(const Eigen::Vector3d &e_recPos, const Eigen::Vector3d &lla_recPos) const
Satellite Azimuth [rad].
const GnssObs::ObservationData & gnssObsData() const
Returns the observation data.
unordered_map< GnssObs::ObservationType, Observation > obs
Receiver observation of the signal.
SignalObservation(const SignalObservation &other)
Copy constructor.
int8_t _freqNum
Frequency number. Only used for GLONASS G1 and G2.
int8_t freqNum() const
Frequency number. Only used for GLONASS G1 and G2.
SignalObservation(SignalObservation &&other) noexcept
Move constructor.
SignalObservation & operator=(const SignalObservation &other)
Copy assignment operator.
std::shared_ptr< const SatNavData > _navData
Satellite Navigation data.
std::unordered_map< size_t, std::shared_ptr< ReceiverSpecificData > > recvObs
Receiver specific data.
SignalObservation & operator=(SignalObservation &&other) noexcept
Move assignment operator.
const std::shared_ptr< const SatNavData > & navData() const
Satellite Navigation data.
~SignalObservation()=default
Destructor.
SignalObservation(std::shared_ptr< SatNavData > navData, int8_t freqNum)
Constructor.
Observation storage type.
size_t countObservations(const SatSigId &satSigId, const GnssObs::ObservationType &obsType) const
Counts how many observations for the specified signal ant type exist.
bool removeSignal(const SatSigId &satSigId, const std::string &nameId)
Remove the signal from the observations.
std::set< SatelliteSystem > systems
Satellite systems used.
bool removeMeasurementsFor(const Code &code, const GnssObs::ObservationType &obsType, const std::string &nameId)
Remove all measurements for the provided code and observation type.
std::array< size_t, GnssObs::ObservationType_COUNT > nObservables
Number of observables.
void recalcObservableCounts(const std::string &nameId)
Calculates/Recalculates the number of observables.
bool removeSatellite(const SatId &satId, const std::string &nameId)
Remove all signals of the satellite.
std::unordered_set< SatId > satellites
Satellites used.
std::array< size_t, GnssObs::ObservationType_COUNT > nObservablesUniqueSatellite
Number of observables (counted once for each satellite)
unordered_map< SatSigId, SignalObservation > signals
Observations and calculated data for each signal.
bool removeObsType(const GnssObs::ObservationType &obsType, const std::string &nameId)
Remove all measurements for the provided observation type.
std::unordered_set< size_t > receivers
Receivers included.
Identifies a satellite (satellite system and number)
Identifies a satellite signal (satellite frequency and number)
Zenith delays and mapping factors.