INSTINCT Code Coverage Report


Directory: src/
File: Navigation/GNSS/Positioning/ReceiverClock.hpp
Date: 2025-02-07 16:54:41
Exec Total Coverage
Lines: 14 23 60.9%
Functions: 4 6 66.7%
Branches: 13 38 34.2%

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 ReceiverClock.hpp
10 /// @brief Receiver Clock information
11 /// @author T. Topp (topp@ins.uni-stuttgart.de)
12 /// @date 2023-02-07
13
14 #pragma once
15
16 #include <algorithm>
17 #include <array>
18 #include <cstddef>
19 #include <cstdint>
20 #include <optional>
21 #include <vector>
22
23 #include "util/Container/UncertainValue.hpp"
24 #include "Navigation/GNSS/Core/SatelliteSystem.hpp"
25 #include "util/Logger.hpp"
26
27 namespace NAV
28 {
29
30 /// Receiver Clock information
31 struct ReceiverClock
32 {
33 /// @brief Constructor
34 /// @param[in] satelliteSystems Satellite systems to add
35 551 explicit ReceiverClock(std::vector<SatelliteSystem> satelliteSystems)
36 551 : satelliteSystems(std::move(satelliteSystems))
37 {
38
1/2
✓ Branch 2 taken 551 times.
✗ Branch 3 not taken.
551 bias.resize(this->satelliteSystems.size());
39
1/2
✓ Branch 2 taken 551 times.
✗ Branch 3 not taken.
551 biasStdDev.resize(this->satelliteSystems.size());
40
1/2
✓ Branch 2 taken 551 times.
✗ Branch 3 not taken.
551 drift.resize(this->satelliteSystems.size());
41
1/2
✓ Branch 2 taken 551 times.
✗ Branch 3 not taken.
551 driftStdDev.resize(this->satelliteSystems.size());
42 551 }
43
44 /// @brief Add a new system
45 /// @param[in] satSys Satellite System to add
46 void addSystem(SatelliteSystem satSys)
47 {
48 if (std::ranges::find(satelliteSystems, satSys) != satelliteSystems.end())
49 {
50 return;
51 }
52 satelliteSystems.push_back(satSys);
53 bias.emplace_back();
54 biasStdDev.emplace_back();
55 drift.emplace_back();
56 driftStdDev.emplace_back();
57 }
58
59 /// @brief Clear all the structures
60 void clear()
61 {
62 satelliteSystems.clear();
63 bias.clear();
64 biasStdDev.clear();
65 drift.clear();
66 driftStdDev.clear();
67 }
68
69 /// @brief Resets all structures to 0 (not removing them)
70 void reset()
71 {
72 std::ranges::for_each(bias, [](double& v) { v = 0; });
73 std::ranges::for_each(biasStdDev, [](double& v) { v = 0; });
74 std::ranges::for_each(drift, [](double& v) { v = 0; });
75 std::ranges::for_each(driftStdDev, [](double& v) { v = 0; });
76 }
77
78 /// @brief Get the bias for the given satellite system
79 /// @param[in] satSys Satellite system
80 /// @return The bias in [s] for the given satellite system. Or null if it is not found
81 83596 [[nodiscard]] const double* biasFor(SatelliteSystem satSys) const
82 {
83
3/6
✓ Branch 1 taken 83596 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 83596 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 83596 times.
✗ Branch 9 not taken.
83596 if (auto i = getIdx(satSys)) { return &bias.at(*i); }
84 return nullptr;
85 }
86 /// @brief Get the bias for the given satellite system
87 /// @param[in] satSys Satellite system
88 /// @return The bias in [s] for the given satellite system. Or null if it is not found
89 [[nodiscard]] double* biasFor(SatelliteSystem satSys)
90 {
91 if (auto i = getIdx(satSys)) { return &bias.at(*i); }
92 return nullptr;
93 }
94
95 /// @brief Get the bias StdDev for the given satellite system
96 /// @param[in] satSys Satellite system
97 /// @return The bias StdDev in [s] for the given satellite system. Or null if it is not found
98 [[nodiscard]] const double* biasStdDevFor(SatelliteSystem satSys) const
99 {
100 if (auto i = getIdx(satSys)) { return &biasStdDev.at(*i); }
101 return nullptr;
102 }
103 /// @brief Get the bias StdDev for the given satellite system
104 /// @param[in] satSys Satellite system
105 /// @return The bias StdDev in [s] for the given satellite system. Or null if it is not found
106 [[nodiscard]] double* biasStdDevFor(SatelliteSystem satSys)
107 {
108 if (auto i = getIdx(satSys)) { return &biasStdDev.at(*i); }
109 return nullptr;
110 }
111
112 /// @brief Get the drift for the given satellite system
113 /// @param[in] satSys Satellite system
114 /// @return The drift in [s/s] for the given satellite system. Or null if it is not found
115 81844 [[nodiscard]] const double* driftFor(SatelliteSystem satSys) const
116 {
117
3/6
✓ Branch 1 taken 81844 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 81844 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 81844 times.
✗ Branch 9 not taken.
81844 if (auto i = getIdx(satSys)) { return &drift.at(*i); }
118 return nullptr;
119 }
120 /// @brief Get the drift for the given satellite system
121 /// @param[in] satSys Satellite system
122 /// @return The drift in [s/s] for the given satellite system. Or null if it is not found
123 [[nodiscard]] double* driftFor(SatelliteSystem satSys)
124 {
125 if (auto i = getIdx(satSys)) { return &drift.at(*i); }
126 return nullptr;
127 }
128
129 /// @brief Get the drift StdDev for the given satellite system
130 /// @param[in] satSys Satellite system
131 /// @return The drift StdDev in [s/s] for the given satellite system. Or null if it is not found
132 [[nodiscard]] const double* driftStdDevFor(SatelliteSystem satSys) const
133 {
134 if (auto i = getIdx(satSys)) { return &driftStdDev.at(*i); }
135 return nullptr;
136 }
137 /// @brief Get the drift StdDev for the given satellite system
138 /// @param[in] satSys Satellite system
139 /// @return The drift StdDev in [s/s] for the given satellite system. Or null if it is not found
140 [[nodiscard]] double* driftStdDevFor(SatelliteSystem satSys)
141 {
142 if (auto i = getIdx(satSys)) { return &driftStdDev.at(*i); }
143 return nullptr;
144 }
145
146 /// @brief Get the index of the sat system
147 /// @param[in] satSys Satellite system
148 /// @return The index if it was in the list
149 167300 [[nodiscard]] std::optional<size_t> getIdx(SatelliteSystem satSys) const
150 {
151
1/2
✓ Branch 1 taken 167300 times.
✗ Branch 2 not taken.
167300 for (size_t i = 0; i < satelliteSystems.size(); i++)
152 {
153
2/4
✓ Branch 1 taken 167300 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 167300 times.
✗ Branch 5 not taken.
167300 if (satelliteSystems.at(i) == satSys) { return i; }
154 }
155 return std::nullopt;
156 }
157
158 /// Order of satellite systems
159 std::vector<SatelliteSystem> satelliteSystems;
160
161 /// Receiver clock biases for each satellite system [s]
162 std::vector<double> bias;
163 /// StdDev of the receiver clock biases for each satellite system [s]
164 std::vector<double> biasStdDev;
165 /// Receiver clock drifts for each satellite system [s/s]
166 std::vector<double> drift;
167 /// StdDev of the receiver clock drifts for each satellite system [s]
168 std::vector<double> driftStdDev;
169 };
170
171 } // namespace NAV
172