0.4.1
Loading...
Searching...
No Matches
Navio2Sensor.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 Navio2Sensor.hpp
10/// @brief Navio2 Sensors
11/// @author T. Topp (topp@ins.uni-stuttgart.de)
12/// @date 2020-07-13
13
14#pragma once
15
17
18#if !__APPLE__ && !defined(WIN32) && !defined(_WIN32) && !defined(__WIN32)
19 #include "Navio/Common/InertialSensor.h"
20#endif
21
23#include <chrono>
24
25namespace NAV
26{
27/// Navio2Sensor Sensor Class
28class Navio2Sensor : public Imu
29{
30 public:
31 /// @brief Default constructor
33 /// @brief Destructor
34 ~Navio2Sensor() override;
35 /// @brief Copy constructor
36 Navio2Sensor(const Navio2Sensor&) = delete;
37 /// @brief Move constructor
39 /// @brief Copy assignment operator
41 /// @brief Move assignment operator
43
44 /// @brief String representation of the Class Type
45 [[nodiscard]] static std::string typeStatic();
46
47 /// @brief String representation of the Class Type
48 [[nodiscard]] std::string type() const override;
49
50 /// @brief String representation of the Class Category
51 [[nodiscard]] static std::string category();
52
53 /// @brief ImGui config window which is shown on double click
54 /// @attention Don't forget to set _hasConfig to true in the constructor of the node
55 void guiConfig() override;
56
57 /// @brief Saves the node into a json object
58 [[nodiscard]] json save() const override;
59
60 /// @brief Restores the node from a json object
61 /// @param[in] j Json object with the node state
62 void restore(const json& j) override;
63
64 /// @brief Resets the node. It is guaranteed that the node is initialized when this is called.
65 bool resetNode() override;
66
67 private:
68 constexpr static size_t OUTPUT_PORT_INDEX_IMU_OBS = 0; ///< @brief Flow (ImuObs)
69
70 /// @brief Initialize the node
71 bool initialize() override;
72
73 /// @brief Deinitialize the node
74 void deinitialize() override;
75
76 /// Enumeration of IMUs on the Navio2
77 enum ImuType : uint8_t
78 {
79 /// MPU9250
81 /// LSM9DS1
83 };
84
85#if !__APPLE__ && !defined(WIN32) && !defined(_WIN32) && !defined(__WIN32)
86 /// Sensor object
87 std::unique_ptr<InertialSensor> _sensor;
88#endif
89
90 /// The Imu type
92
93 /// OutputFrequency to calculate rateDivisor field.
95
96 /// Timer object to handle async data requests
98 /// Start Time to calculate the TimeSinceStartup
99 std::chrono::time_point<std::chrono::steady_clock> _startTime;
100
101 /// Accelerometer X data, which are read into by the sensor
102 float _ax{};
103 /// Accelerometer Y data, which are read into by the sensor
104 float _ay{};
105 /// Accelerometer Z data, which are read into by the sensor
106 float _az{};
107 /// Gyroscope X data, which are read into by the sensor
108 float _gx{};
109 /// Gyroscope Y data, which are read into by the sensor
110 float _gy{};
111 /// Gyroscope Z data, which are read into by the sensor
112 float _gz{};
113 /// Magnetometer X data, which are read into by the sensor
114 float _mx{};
115 /// Magnetometer Y data, which are read into by the sensor
116 float _my{};
117 /// Magnetometer Z data, which are read into by the sensor
118 float _mz{};
119
120 /// @brief Function which performs the async data reading
121 /// @param[in, out] userData Pointer to the Navio2Sensor object
122 static void readImuThread(void* userData);
123};
124
125} // namespace NAV
Starts a Periodic Timer.
nlohmann::json json
json namespace
Abstract IMU Class.
Manages a thread which calls a specified function at a specified interval.
Imu(const Imu &)=delete
Copy constructor.
CallbackTimer _timer
Timer object to handle async data requests.
bool initialize() override
Initialize the node.
float _ay
Accelerometer Y data, which are read into by the sensor.
float _az
Accelerometer Z data, which are read into by the sensor.
static void readImuThread(void *userData)
Function which performs the async data reading.
std::string type() const override
String representation of the Class Type.
static std::string typeStatic()
String representation of the Class Type.
Navio2Sensor()
Default constructor.
float _ax
Accelerometer X data, which are read into by the sensor.
void guiConfig() override
ImGui config window which is shown on double click.
bool resetNode() override
Resets the node. It is guaranteed that the node is initialized when this is called.
json save() const override
Saves the node into a json object.
ImuType
Enumeration of IMUs on the Navio2.
float _mx
Magnetometer X data, which are read into by the sensor.
~Navio2Sensor() override
Destructor.
static constexpr size_t OUTPUT_PORT_INDEX_IMU_OBS
Flow (ImuObs)
void restore(const json &j) override
Restores the node from a json object.
float _my
Magnetometer Y data, which are read into by the sensor.
int _outputFrequency
OutputFrequency to calculate rateDivisor field.
Navio2Sensor(Navio2Sensor &&)=delete
Move constructor.
float _gy
Gyroscope Y data, which are read into by the sensor.
float _gz
Gyroscope Z data, which are read into by the sensor.
std::chrono::time_point< std::chrono::steady_clock > _startTime
Start Time to calculate the TimeSinceStartup.
static std::string category()
String representation of the Class Category.
Navio2Sensor & operator=(Navio2Sensor &&)=delete
Move assignment operator.
ImuType _imuType
The Imu type.
Navio2Sensor & operator=(const Navio2Sensor &)=delete
Copy assignment operator.
Navio2Sensor(const Navio2Sensor &)=delete
Copy constructor.
void deinitialize() override
Deinitialize the node.
std::unique_ptr< InertialSensor > _sensor
Sensor object.
float _gx
Gyroscope X data, which are read into by the sensor.
float _mz
Magnetometer Z data, which are read into by the sensor.