0.4.1
Loading...
Searching...
No Matches
UbloxGnssObsConverter.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
11#include <map>
12
13#include "util/Logger.hpp"
14
16namespace nm = NAV::NodeManager;
18
21
32
37
39{
40 return "UbloxGnssObsConverter";
41}
42
44{
45 return typeStatic();
46}
47
49{
50 return "Converter";
51}
52
54{
55 LOG_TRACE("{}: called", nameId());
56
57 _lastEpochObs.clear();
58
59 return true;
60}
61
63{
64 auto ubloxObs = std::static_pointer_cast<const UbloxObs>(queue.extract_front());
65
66 namespace ubx = vendor::ublox;
67
68 if (ubloxObs->msgClass == ubx::UBX_CLASS_RXM)
69 {
70 if (static_cast<ubx::UbxRxmMessages>(ubloxObs->msgId) == ubx::UbxRxmMessages::UBX_RXM_RAWX)
71 {
72 LOG_DATA("{}: Converting message at [{}]", nameId(), ubloxObs->insTime.toYMDHMS(GPST));
73 auto gnssObs = std::make_shared<GnssObs>();
74 gnssObs->insTime = ubloxObs->insTime;
75
76 const auto& ubxRxmRawx = std::get<ubx::UbxRxmRawx>(ubloxObs->data);
77
78 for (const auto& satSys : SatelliteSystem::GetAll())
79 {
80 std::map<SatSigId, GnssObs::ObservationData> sortedObsData;
81 for (const auto& data : ubxRxmRawx.data)
82 {
83 if (ubx::getSatSys(data.gnssId) != satSys) { continue; }
84
85 SatSigId satSigId(ubx::getCode(data.gnssId, data.sigId), data.svId);
86 LOG_DATA("{}: [{}][{}], prValid {}, cpValid {}, halfCycValid {}, subHalfSubtractedFromPhase {}, trkStat {}, observedLastEpoch {}",
87 nameId(), ubloxObs->insTime.toYMDHMS(GPST), satSigId, data.prValid(), data.cpValid(), data.halfCycValid(), data.subHalfSubtractedFromPhase(), data.trkStat,
88 _lastEpochObs.contains(satSigId));
89 GnssObs::ObservationData obsData(satSigId);
90 if (data.prValid())
91 {
92 if (data.prMes > 100'000'000) { return; } // Sometimes at the start of the ublox receiver, it reports absurd high numbers
94 .value = data.prMes,
95 .SSI = 0,
96 };
97 }
98 if (data.cpValid())
99 {
100 std::bitset<4> LLI;
101 LLI[0] = !_lastEpochObs.contains(satSigId);
102 LLI[1] = !data.halfCycValid();
104 .value = data.cpMes,
105 .SSI = 0,
106 .LLI = static_cast<uint8_t>(LLI.to_ulong()),
107 };
108 }
109 obsData.doppler = data.doMes;
110 obsData.CN0 = data.cno;
111
112 sortedObsData.insert(std::make_pair(satSigId, obsData));
113 gnssObs->satData(satSigId.toSatId()).frequencies |= satSigId.freq();
114 }
115 std::erase_if(_lastEpochObs, [&](const SatSigId& satSigId) { return satSigId.freq().getSatSys() == satSys; });
116 for (const auto& obsData : sortedObsData)
117 {
118 // LOG_DATA("{}: Adding [{}]", nameId(), obsData.second.satSigId);
119 gnssObs->data.push_back(obsData.second);
120 if (obsData.second.carrierPhase)
121 {
122 _lastEpochObs.insert(obsData.first);
123 }
124 }
125 }
126 if (gnssObs->data.empty()) { return; }
128 }
129 }
130}
Save/Load the Nodes.
GNSS Observation messages.
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
#define LOG_TRACE
Detailled info to trace the execution of the program. Should not be called on functions which receive...
Definition Logger.hpp:65
Manages all Nodes.
Convert UbloxObs into GnssObs.
ublox Observation Class
SatelliteSystem getSatSys() const
Get the satellite system for which this frequency is defined.
static std::string type()
Returns the type of the data class.
Definition GnssObs.hpp:150
TsDeque< std::shared_ptr< const NAV::NodeData > > NodeDataQueue
Node data queue type.
Definition Pin.hpp:707
Node(std::string name)
Constructor.
Definition Node.cpp:30
std::string nameId() const
Node name and id.
Definition Node.cpp:253
std::string name
Name of the Node.
Definition Node.hpp:395
void invokeCallbacks(size_t portIndex, const std::shared_ptr< const NodeData > &data)
Calls all registered callbacks on the specified output port.
Definition Node.cpp:180
bool _hasConfig
Flag if the config window should be shown.
Definition Node.hpp:413
auto extract_front()
Returns a copy of the first element in the container and removes it from the container.
Definition TsDeque.hpp:494
void receiveObs(InputPin::NodeDataQueue &queue, size_t pinIdx)
Data receive function.
static constexpr size_t OUTPUT_PORT_INDEX_GNSS_OBS
Flow.
bool initialize() override
Initialize the node.
static std::string category()
String representation of the Class Category.
~UbloxGnssObsConverter() override
Destructor.
UbloxGnssObsConverter()
Default constructor.
static std::string typeStatic()
String representation of the Class Type.
std::string type() const override
String representation of the Class Type.
std::unordered_set< SatSigId > _lastEpochObs
List of signals of the last epoch. To set the LLI flag.
static std::string type()
Returns the type of the data class.
Definition UbloxObs.hpp:30
OutputPin * CreateOutputPin(Node *node, const char *name, Pin::Type pinType, const std::vector< std::string > &dataIdentifier, OutputPin::PinData data=static_cast< void * >(nullptr), int idx=-1)
Create an Output Pin object.
InputPin * CreateInputPin(Node *node, const char *name, Pin::Type pinType, const std::vector< std::string > &dataIdentifier={}, InputPin::Callback callback=static_cast< InputPin::FlowFirableCallbackFunc >(nullptr), InputPin::FlowFirableCheckFunc firable=nullptr, int priority=0, int idx=-1)
Create an Input Pin object.
Code getCode(uint8_t gnssId, uint8_t sigId)
Get the GNSS code from gnssId and sigId.
SatelliteSystem getSatSys(uint8_t gnssId)
Get the GNSS Satellite System from gnssId.
@ UBX_CLASS_RXM
Receiver Manager Messages: Satellite Status, RTC Status.
UbxRxmMessages
The available RXM Messages.
@ GPST
GPS Time.
Stores the satellites observations.
Definition GnssObs.hpp:46
std::optional< Pseudorange > pseudorange
Pseudorange measurement [m].
Definition GnssObs.hpp:121
std::optional< CarrierPhase > carrierPhase
Carrier phase measurement [cycles].
Definition GnssObs.hpp:122
std::optional< double > CN0
Carrier-to-Noise density [dBHz].
Definition GnssObs.hpp:124
std::optional< double > doppler
Doppler measurement [Hz].
Definition GnssObs.hpp:123
@ Flow
NodeData Trigger.
Definition Pin.hpp:52
Identifies a satellite signal (satellite frequency and number)
Frequency freq() const
Returns the frequency of the satellite signal.
SatId toSatId() const
Returns a satellite identifier for the satellite signal.
static std::vector< SatelliteSystem > GetAll()
Returns a list with all possible satellite systems.