0.4.1
Loading...
Searching...
No Matches
GLONASSEphemeris.cpp
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
10#include <cstdint>
11
15
16#include "util/Logger.hpp"
17
18namespace NAV
19{
20
22 double tau_n, double gamma_n, bool health,
23 Eigen::Vector3d pos, Eigen::Vector3d vel, Eigen::Vector3d accelLuniSolar,
24 int8_t frequencyNumber)
26 tau_c(tau_c),
27 toc(toc),
28 tau_n(tau_n),
31 PZ90_pos(std::move(pos)),
32 PZ90_vel(std::move(vel)),
33 PZ90_accelLuniSolar(std::move(accelLuniSolar)),
35
36#ifdef TESTING
37
38GLONASSEphemeris::GLONASSEphemeris(int32_t year, int32_t month, int32_t day, int32_t hour, int32_t minute, double second,
39 double m_tau_n, double gamma_n, double /* messageFrameTime */,
40 double satPos_x, double satVel_x, double satAccel_x, double health,
41 double satPos_y, double satVel_y, double satAccel_y, double frequencyNumber,
42 double satPos_z, double satVel_z, double satAccel_z, double /* ageOfOperationInfo */,
43 double /* statusFlags */, double /* L1L2groupDelayDifference */, double /* URAI */, double /* healthFlags */,
44 double tau_c)
45 : SatNavData(SatNavData::GLONASSEphemeris, InsTime(year, month, day, hour, minute, second, UTC)),
46 tau_c(tau_c),
47 toc(refTime),
48 tau_n(-m_tau_n),
49 gamma_n(gamma_n),
50 health(static_cast<bool>(health)),
51 PZ90_pos(satPos_x * 1e3, satPos_y * 1e3, satPos_z * 1e3),
52 PZ90_vel(satVel_x * 1e3, satVel_y * 1e3, satVel_z * 1e3),
53 PZ90_accelLuniSolar(satAccel_x * 1e3, satAccel_y * 1e3, satAccel_z * 1e3),
54 frequencyNumber(static_cast<int8_t>(frequencyNumber))
55{}
56
57#endif
58
59Clock::Corrections GLONASSEphemeris::calcClockCorrections(const InsTime& recvTime, double dist, const Frequency& /* freq */) const
60{
61 LOG_DATA("Calc Sat Clock corrections at receiver time {}", recvTime.toGPSweekTow());
62 LOG_DATA(" toc {} (Time of clock)", toc.toGPSweekTow());
63
64 // Time at transmission
65 InsTime transTime = recvTime - std::chrono::duration<double>(dist / InsConst::C);
66
67 // SV clock time offset [s]
68 double dt_sv = -tau_n + gamma_n * static_cast<double>((transTime - toc).count());
69 LOG_DATA(" dt_sv {} [s] (SV clock time offset)", dt_sv);
70
71 transTime += std::chrono::duration<double>(dt_sv);
72 LOG_DATA(" transTime {} (Time at transmission)", transTime.toGPSweekTow());
73
74 return { .transmitTime = transTime, .bias = dt_sv, .drift = -gamma_n };
75}
76
78{
79 LOG_DATA("Calc Sat Position at transmit time {}", transTime.toGPSweekTow());
80 LOG_DATA(" toc {} (Time of clock)", toc.toGPSweekTow());
81
82 // Calculates the position and velocity derivative for the satellite position
83 // y State [x, y, z, v_x, v_y, v_z]^T
84 // c Constant values needed to calculate the derivatives
85 // Returns the derivative ∂/∂t [x, y, z, v_x, v_y, v_z]^T
86 auto calcPosVelDerivative = [](const Eigen::Matrix<double, 6, 1>& y, int /* z */, const Eigen::Vector3d& accelLuniSolar, double /* t */ = 0.0) {
87 // 0 1 2 3 4 5
88 // ∂/∂t [x, y, z, v_x, v_y, v_z]^T
89 Eigen::Matrix<double, 6, 1> y_dot = Eigen::Matrix<double, 6, 1>::Zero();
90
91 enum State : uint8_t
92 {
93 X,
94 Y,
95 Z,
96 VX,
97 VY,
98 VZ
99 };
100
101 double r = y.topRows<3>().norm();
102
103 double omega_ie2 = std::pow(InsConst::GLO::omega_ie, 2);
104
105 double a = 1.5 * InsConst::GLO::J2 * InsConst::GLO::MU * std::pow(InsConst::GLO::a, 2) / std::pow(r, 5);
106 double c = -InsConst::GLO::MU / std::pow(r, 3) - a * (1. - 5. * std::pow(y(Z), 2) / std::pow(r, 2));
107
108 y_dot.topRows<3>() = y.bottomRows<3>();
109 y_dot(3) = (c + omega_ie2) * y(X) + 2 * InsConst::GLO::omega_ie * y(VY) + accelLuniSolar.x();
110 y_dot(4) = (c + omega_ie2) * y(Y) - 2 * InsConst::GLO::omega_ie * y(VX) + accelLuniSolar.y();
111 y_dot(5) = (c - 2. * a) * y(Z) + accelLuniSolar.z();
112
113 return y_dot;
114 };
115
116 // State [x, y, z, v_x, v_y, v_z]^T
117 Eigen::Matrix<double, 6, 1> y;
118 y << PZ90_pos, PZ90_vel;
119
120 // Time to integrate in [s]
121 double dt = static_cast<double>((transTime - toc).count());
122 LOG_DATA(" dt {} [s] (Time to integrate)", dt);
123
124 while (std::abs(dt) > 1e-9)
125 {
126 double step = dt > 0 ? _h : -_h;
127 if (std::abs(dt) < _h)
128 {
129 step = dt;
130 }
131 LOG_DATA(" step {:0.2f}, pos {}, vel {}", step, y.topRows<3>().transpose(), y.bottomRows<3>().transpose());
132 ;
133 y = RungeKutta4(y, std::array<int, 4>{}, step, calcPosVelDerivative, PZ90_accelLuniSolar);
134 dt -= step;
135 }
136 LOG_DATA(" pos {}, vel {} (end state)", y.topRows<3>().transpose(), y.bottomRows<3>().transpose());
137
138 Eigen::Vector3d e_pos = Eigen::Vector3d::Zero();
139 Eigen::Vector3d e_vel = Eigen::Vector3d::Zero();
140 Eigen::Vector3d e_accel = Eigen::Vector3d::Zero();
141
142 if (calc & Calc_Position)
143 {
144 e_pos = y.topRows<3>(); // trafo::pz90toWGS84_pos(y.topRows<3>());
145 // LOG_DATA(" pos (WGS84) {}", e_pos.transpose());
146 }
147 if (calc & Calc_Velocity)
148 {
149 e_vel = y.bottomRows<3>(); // trafo::pz90toWGS84(y.bottomRows<3>(), y.topRows<3>());
150 // LOG_DATA(" vel (WGS84) {}", e_vel.transpose());
151 }
152 if (calc & Calc_Acceleration)
153 {
154 Eigen::Matrix<double, 6, 1> y_dot = calcPosVelDerivative(y, 0, PZ90_accelLuniSolar, 0.0);
155 e_accel = y_dot.bottomRows<3>(); // trafo::pz90toWGS84(y_dot.bottomRows<3>(), y.topRows<3>());
156 // LOG_DATA(" accel (WGS84) {}", e_accel.transpose());
157 }
158
159 return { .e_pos = e_pos,
160 .e_vel = e_vel,
161 .e_accel = e_accel };
162}
163
165{
166 return !health;
167}
168
170{
171 return 5 * 5;
172}
173
174} // namespace NAV
Holds all Constants.
Transformation collection.
Galileo Ephemeris information.
Utility class for logging to console and file.
#define LOG_DATA
All output which occurs repeatedly every time observations are received.
Definition Logger.hpp:29
Provides Numerical integration methods.
Frequency definition for different satellite systems.
Definition Frequency.hpp:59
Broadcasted ephemeris message data.
const bool health
Health.
const Eigen::Vector3d PZ90_vel
Velocity at reference time in PZ90 frame [m/s].
const double tau_c
Coefficient of linear polynomial of time system difference [s].
bool isHealthy() const final
Checks whether the signal is healthy.
const Eigen::Vector3d PZ90_accelLuniSolar
Accelerations due to lunar-solar gravitational perturbation in PZ90 frame [m/s^2].
const Eigen::Vector3d PZ90_pos
Position at reference time in PZ90 frame [m].
double calcSatellitePositionVariance() const final
Calculates the Variance of the satellite position in [m^2].
const double tau_n
SV clock bias [s].
PosVelAccel calcSatelliteData(const InsTime &transTime, Orbit::Calc calc) const final
Calculates position, velocity and acceleration of the satellite at transmission time.
static constexpr double _h
Integration step size in [s].
Corrections calcClockCorrections(const InsTime &recvTime, double dist, const Frequency &freq) const final
Calculates clock bias and drift of the satellite.
GLONASSEphemeris(const InsTime &toc, double tau_c, double tau_n, double gamma_n, bool health, Eigen::Vector3d pos, Eigen::Vector3d vel, Eigen::Vector3d accelLuniSolar, int8_t frequencyNumber)
Constructor.
const int8_t frequencyNumber
Frequency number (-7 ... +13) (-7 ...+6 (ICD 5.1))
const double gamma_n
SV relative frequency bias.
const InsTime toc
Toe Time of clock [s] (Reference time, ephemeris parameters)
static constexpr double J2
Second degree zonal coefficient of normal potential [-].
static constexpr double MU
Gravitational constant GLONASS [m³/s²].
static constexpr double a
Semi-major axis = equatorial radius.
static constexpr double omega_ie
Earth angular velocity GLONASS [rad/s].
static constexpr double C
Speed of light [m/s].
Definition Constants.hpp:34
The class is responsible for all time-related tasks.
Definition InsTime.hpp:710
constexpr InsTime_GPSweekTow toGPSweekTow(TimeSystem timesys=GPST) const
Converts this time object into a different format.
Definition InsTime.hpp:854
Calc
Calculation flags.
Definition Orbit.hpp:75
@ Calc_Position
Position calculation flag.
Definition Orbit.hpp:77
@ Calc_Velocity
Velocity calculation flag.
Definition Orbit.hpp:78
@ Calc_Acceleration
Acceleration calculation flag.
Definition Orbit.hpp:79
Satellite Navigation data (to calculate SatNavData and clock)
SatNavData(Type type, const InsTime &refTime)
Constructor.
@ GLONASSEphemeris
GLONASS Broadcast Ephemeris.
@ UTC
Coordinated Universal Time.
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
Y RungeKutta4(const Y &y_n, const std::array< Z, 4 > &z, const Scalar &h, const auto &f, const auto &constParam, const Scalar &t_n=0)
Runge-Kutta 4th order (explicit) .
Satellite clock corrections.
Definition Clock.hpp:28
Satellite Position, Velocity and Acceleration.
Definition Orbit.hpp:40