Line | Branch | Exec | Source |
---|---|---|---|
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 GnssNavInfo.hpp | ||
10 | /// @brief Navigation message information | ||
11 | /// @author T. Topp (topp@ins.uni-stuttgart.de) | ||
12 | /// @date 2022-04-21 | ||
13 | |||
14 | #pragma once | ||
15 | |||
16 | #include <unordered_map> | ||
17 | #include <utility> | ||
18 | |||
19 | #include "Navigation/GNSS/Core/SatelliteIdentifier.hpp" | ||
20 | #include "Navigation/GNSS/Core/SatelliteSystem.hpp" | ||
21 | #include "Navigation/Atmosphere/Ionosphere/IonosphericCorrections.hpp" | ||
22 | #include "Navigation/GNSS/Satellite/Satellite.hpp" | ||
23 | #include "util/Container/Pair.hpp" | ||
24 | #include "util/Logger.hpp" | ||
25 | |||
26 | namespace NAV | ||
27 | { | ||
28 | /// GNSS Navigation message information | ||
29 | class GnssNavInfo | ||
30 | { | ||
31 | public: | ||
32 | /// @brief Returns the type of the data class | ||
33 | /// @return The data type | ||
34 | 790 | [[nodiscard]] static std::string type() | |
35 | { | ||
36 |
1/2✓ Branch 1 taken 790 times.
✗ Branch 2 not taken.
|
1580 | return "GnssNavInfo"; |
37 | } | ||
38 | |||
39 | /// @brief Calculates position, velocity and acceleration of the satellite at transmission time | ||
40 | /// @param[in] satId Satellite identifier | ||
41 | /// @param[in] transTime Transmit time of the signal | ||
42 | [[nodiscard]] Orbit::Pos calcSatellitePos(const SatId& satId, const InsTime& transTime) const | ||
43 | { | ||
44 | return m_satellites.at(satId).calcSatellitePos(transTime); | ||
45 | } | ||
46 | /// @brief Calculates position, velocity and acceleration of the satellite at transmission time | ||
47 | /// @param[in] satId Satellite identifier | ||
48 | /// @param[in] transTime Transmit time of the signal | ||
49 | [[nodiscard]] Orbit::PosVel calcSatellitePosVel(const SatId& satId, const InsTime& transTime) const | ||
50 | { | ||
51 | return m_satellites.at(satId).calcSatellitePosVel(transTime); | ||
52 | } | ||
53 | /// @brief Calculates position, velocity and acceleration of the satellite at transmission time | ||
54 | /// @param[in] satId Satellite identifier | ||
55 | /// @param[in] transTime Transmit time of the signal | ||
56 | [[nodiscard]] Orbit::PosVelAccel calcSatellitePosVelAccel(const SatId& satId, const InsTime& transTime) const | ||
57 | { | ||
58 | return m_satellites.at(satId).calcSatellitePosVelAccel(transTime); | ||
59 | } | ||
60 | |||
61 | /// @brief Calculates clock bias and drift of the satellite | ||
62 | /// @param[in] satId Satellite identifier | ||
63 | /// @param[in] recvTime Receiver time of the signal | ||
64 | /// @param[in] dist Distance between receiver and satellite (normally the pseudorange) [m] | ||
65 | /// @param[in] freq Signal Frequency | ||
66 | [[nodiscard]] Clock::Corrections calcSatelliteClockCorrections(const SatId& satId, const InsTime& recvTime, double dist, const Frequency& freq) const | ||
67 | { | ||
68 | return m_satellites.at(satId).calcClockCorrections(recvTime, dist, freq); | ||
69 | } | ||
70 | |||
71 | /// @brief Calculates the Variance of the satellite position in [m] | ||
72 | /// @param[in] satId Satellite identifier | ||
73 | /// @param[in] recvTime Receiver time to calculate the satellite position for | ||
74 | [[nodiscard]] double calcSatellitePositionVariance(const SatId& satId, const InsTime& recvTime) const | ||
75 | { | ||
76 | return m_satellites.at(satId).calcSatellitePositionVariance(recvTime); | ||
77 | } | ||
78 | |||
79 | /// @brief Checks whether the signal is healthy | ||
80 | /// @param[in] satId Satellite identifier | ||
81 | /// @param[in] recvTime Receive time for the data lookup | ||
82 | [[nodiscard]] bool isHealthy(const SatId& satId, const InsTime& recvTime) const | ||
83 | { | ||
84 | return m_satellites.at(satId).isHealthy(recvTime); | ||
85 | } | ||
86 | |||
87 | /// @brief Adds the provided satellite navigation data to the satellite | ||
88 | /// @param[in] satId Satellite identifier | ||
89 | /// @param[in] satNavData Satellite Navigation Data to add | ||
90 | 8291 | void addSatelliteNavData(const SatId& satId, const std::shared_ptr<SatNavData>& satNavData) | |
91 | { | ||
92 | 8291 | m_satellites[satId].addSatNavData(satNavData); | |
93 | 8289 | } | |
94 | |||
95 | /// @brief Checks whether the satellite is included in the internal data | ||
96 | /// @param[in] satId Satellite identifier | ||
97 | /// @param[in] recvTime Receive time for the data lookup | ||
98 | 58194 | [[nodiscard]] std::shared_ptr<NAV::SatNavData> searchNavigationData(const SatId& satId, const InsTime& recvTime) const | |
99 | { | ||
100 |
2/4✓ Branch 1 taken 58194 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 58194 times.
|
58194 | if (!m_satellites.contains(satId)) { return nullptr; } |
101 | |||
102 |
2/4✓ Branch 1 taken 58194 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 58194 times.
✗ Branch 5 not taken.
|
58194 | auto satNavData = m_satellites.at(satId).searchNavigationData(recvTime); |
103 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 58194 times.
|
58194 | if (satNavData == nullptr) |
104 | { | ||
105 | [[maybe_unused]] auto printNavData = [&]() { | ||
106 | std::string ret; | ||
107 | for (const auto& navData : m_satellites.at(satId).getNavigationData()) | ||
108 | { | ||
109 | ret += fmt::format("[{} - diff {:.0f}s], ", navData->refTime.toYMDHMS(GPST), | ||
110 | static_cast<double>(std::abs((navData->refTime - recvTime).count()))); | ||
111 | } | ||
112 | return ret.substr(0, ret.length() - 2); | ||
113 | ✗ | }; | |
114 | |||
115 | LOG_TRACE("[{}][{}]: No navigation data found. Available data are at time: {}", satId, recvTime.toYMDHMS(GPST), printNavData()); | ||
116 | } | ||
117 | |||
118 | 58194 | return satNavData; | |
119 | 58194 | } | |
120 | |||
121 | /// @brief Returns the amount of satellites contained in this message | ||
122 | ✗ | [[nodiscard]] size_t nSatellites() const | |
123 | { | ||
124 | ✗ | return m_satellites.size(); | |
125 | } | ||
126 | |||
127 | /// @brief Get the satellites | ||
128 | /// @return Reference to the internal satellites map | ||
129 | 1645 | const auto& satellites() const | |
130 | { | ||
131 | 1645 | return m_satellites; | |
132 | } | ||
133 | |||
134 | /// @brief Resets the data by clearing the member variables | ||
135 | 57 | void reset() | |
136 | { | ||
137 | 57 | satelliteSystems = SatSys_None; | |
138 | 57 | ionosphericCorrections.clear(); | |
139 | 57 | timeSysCorr.clear(); | |
140 | 57 | m_satellites.clear(); | |
141 | 57 | } | |
142 | |||
143 | /// @brief Satellite Systems available | ||
144 | SatelliteSystem satelliteSystems = SatSys_None; | ||
145 | |||
146 | /// @brief Ionospheric correction values | ||
147 | IonosphericCorrections ionosphericCorrections; | ||
148 | |||
149 | /// @brief Time system correction parameters | ||
150 | struct TimeSystemCorrections | ||
151 | { | ||
152 | double a0 = std::nan(""); ///< a0 / tau_c Coefficient of linear polynomial [s] Δt = a0 + a1 * (t - t_ref) | ||
153 | double a1 = std::nan(""); ///< a1 Coefficient of linear polynomial [s/s] | ||
154 | // TODO: Add a2 value | ||
155 | }; | ||
156 | |||
157 | /// Time system correction parameters. Difference between GNSS system time and UTC or other time systems | ||
158 | std::unordered_map<std::pair<TimeSystem, TimeSystem>, TimeSystemCorrections> timeSysCorr; | ||
159 | |||
160 | private: | ||
161 | /// Map of satellites containing the navigation message data | ||
162 | std::unordered_map<SatId, Satellite> m_satellites; | ||
163 | }; | ||
164 | |||
165 | } // namespace NAV | ||
166 |