0.4.1
Loading...
Searching...
No Matches
Demo.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 Demo.hpp
10/// @brief Demo Node which demonstrates all capabilities
11/// @author T. Topp (topp@ins.uni-stuttgart.de)
12/// @date 2021-01-13
13
14#pragma once
15
17
18#include "util/Eigen.hpp"
19#include <array>
20#include <cstddef>
21#include <cstdint>
23
24namespace NAV
25{
26/// @brief Demonstrates the basic GUI functionality of nodes
27class Demo : public Node
28{
29 public:
30 /// @brief Default constructor
31 Demo();
32 /// @brief Destructor
33 ~Demo() override;
34 /// @brief Copy constructor
35 Demo(const Demo&) = delete;
36 /// @brief Move constructor
37 Demo(Demo&&) = delete;
38 /// @brief Copy assignment operator
39 Demo& operator=(const Demo&) = delete;
40 /// @brief Move assignment operator
41 Demo& operator=(Demo&&) = delete;
42
43 /// @brief String representation of the Class Type
44 [[nodiscard]] static std::string typeStatic();
45
46 /// @brief String representation of the Class Type
47 [[nodiscard]] std::string type() const override;
48
49 /// @brief String representation of the Class Category
50 [[nodiscard]] static std::string category();
51
52 /// @brief ImGui config window which is shown on double click
53 /// @attention Don't forget to set _hasConfig to true in the constructor of the node
54 void guiConfig() override;
55
56 /// @brief Saves the node into a json object
57 [[nodiscard]] json save() const override;
58
59 /// @brief Restores the node from a json object
60 /// @param[in] j Json object with the node state
61 void restore(const json& j) override;
62
63 /// @brief Resets the node. It is guaranteed that the node is initialized when this is called.
64 bool resetNode() override;
65
66 /// @brief Called when a new link is to be established
67 /// @param[in] startPin Pin where the link starts
68 /// @param[in] endPin Pin where the link ends
69 /// @return True if link is allowed, false if link is rejected
70 bool onCreateLink(OutputPin& startPin, InputPin& endPin) override;
71
72 /// @brief Called when a link was deleted
73 /// @param[in] startPin Pin where the link starts
74 /// @param[in] endPin Pin where the link ends
75 void afterDeleteLink(OutputPin& startPin, InputPin& endPin) override;
76
77 /// @brief Data struct transmitted over an output port
78 struct DemoData
79 {
80 std::array<int, 3> integer = { 12, -2, 2 }; ///< Integer inside the DemoData
81 bool boolean = false; ///< Boolean inside the DemoData
82 };
83
84 // private: // All this would be usually private. The Demo node however does not include private items to generate a complete Doxygen documentation
85
86 /// @brief Initialize the node
87 bool initialize() override;
88
89 /// @brief Deinitialize the node
90 void deinitialize() override;
91
92 /// Update the pins depending on the GUI
93 void updatePins();
94
95 /// Pin types used in this demo
96 enum class DemoPins : uint8_t
97 {
98 Delegate, ///< Delegate pins giving access to the complete connected node
99 Flow, ///< Flow pins transmitting data as timestamped shared pointers
100 Bool, ///< Booleans
101 Int, ///< Integer numbers
102 Float, ///< Float numbers
103 Double, ///< Double numbers
104 String, ///< Strings
105 Object, ///< Custom objects
106 Matrix, ///< Matrix objects
107 };
108
109 /// @brief Calculates the pin index for the given type
110 /// @param[in] pinType Pin type to use
111 /// @return Index of the pin (input and output pins have same indices)
112 std::optional<size_t> getPinIdx(DemoPins pinType) const;
113
114 /// @brief Receive callback on the Flow pin
115 /// @param[in] queue Queue with all the received data messages
116 /// @param[in] pinIdx Index of the pin the data is received on
117 void receiveData(InputPin::NodeDataQueue& queue, size_t pinIdx);
118
119 /// @brief Polls data from the file. This function is needed, if we have multiple output pins, polling data.
120 /// @note Not used in the node as only one output flow pin which does not need peeking and therefore utilizes the NAV::Demo::pollData() function
121 /// @param[in] peek Specifies if the data should be peeked (without moving the read cursor) or read
122 /// @return The read observation
123 [[nodiscard]] std::shared_ptr<const NodeData> peekPollData(bool peek = false);
124
125 /// @brief Polls data from the file
126 /// @return The read observation
127 [[nodiscard]] std::shared_ptr<const NodeData> pollData();
128
129 /// @brief Updates the output flow pin depending on the GUI selection
130 void updateOutputFlowPin();
131
132 /// Whether to have a file reader instead of a sensor output pin
134
135 /// Timer object to handle async data requests
137
138 /// @brief Function which performs the async data reading
139 /// @param[in] userData Pointer to the object
140 static void readSensorDataThread(void* userData);
141
142 /// @brief Output frequency for the simulated sensor data
144 /// @brief Counter how often data was received
146
147 /// Counter for data Reading
148 int _iPollData = 0;
149 /// Amount of Observations to be read
150 int _nPollData = 20;
151
152 bool _enableDelegate = false; ///< Switch to enable the delegate pin
153 bool _enableFlow = true; ///< Switch to enable the flow pin
154 bool _enableBool = false; ///< Switch to enable the bool pin
155 bool _enableInt = false; ///< Switch to enable the int pin
156 bool _enableFloat = false; ///< Switch to enable the float pin
157 bool _enableDouble = false; ///< Switch to enable the double pin
158 bool _enableString = false; ///< Switch to enable the string pin
159 bool _enableObject = false; ///< Switch to enable the object pin
160 bool _enableMatrix = false; ///< Switch to enable the matrix pin
161
162 bool _valueBool = true; ///< Value which is represented over the Bool pin
163 int _valueInt = -1; ///< Value which is represented over the Int pin
164 float _valueFloat = 65.4F; ///< Value which is represented over the Float pin
165 double _valueDouble = 1242.342; ///< Value which is represented over the Double pin
166 std::string _valueString = "Demo"; ///< Value which is represented over the String pin
167 DemoData _valueObject; ///< Value which is represented over the Object pin
168 Eigen::MatrixXd _valueMatrix = Eigen::MatrixXd::Identity(3, 3); ///< Value which is represented over the Matrix pin
169 size_t _stringUpdateCounter = 0; ///< Counter of how often the string was updated
170
171 /// @brief Function to call when the string is updated
172 /// @param[in] insTime Time the data was received
173 /// @param[in] pinIdx Index of the pin the data is received on
174 void stringUpdatedNotifyFunction(const InsTime& insTime, size_t pinIdx);
175};
176
177} // namespace NAV
Starts a Periodic Timer.
Vector space operations.
nlohmann::json json
json namespace
Node Class.
Manages a thread which calls a specified function at a specified interval.
bool _fileReaderInsteadSensor
Whether to have a file reader instead of a sensor output pin.
Definition Demo.hpp:133
int _iPollData
Counter for data Reading.
Definition Demo.hpp:148
bool _valueBool
Value which is represented over the Bool pin.
Definition Demo.hpp:162
bool _enableInt
Switch to enable the int pin.
Definition Demo.hpp:155
void afterDeleteLink(OutputPin &startPin, InputPin &endPin) override
Called when a link was deleted.
Definition Demo.cpp:676
bool onCreateLink(OutputPin &startPin, InputPin &endPin) override
Called when a new link is to be established.
Definition Demo.cpp:664
CallbackTimer _timer
Timer object to handle async data requests.
Definition Demo.hpp:136
Demo(Demo &&)=delete
Move constructor.
bool _enableFlow
Switch to enable the flow pin.
Definition Demo.hpp:153
int _receivedDataCnt
Counter how often data was received.
Definition Demo.hpp:145
bool _enableDouble
Switch to enable the double pin.
Definition Demo.hpp:157
std::optional< size_t > getPinIdx(DemoPins pinType) const
Calculates the pin index for the given type.
Definition Demo.cpp:586
bool _enableObject
Switch to enable the object pin.
Definition Demo.hpp:159
float _valueFloat
Value which is represented over the Float pin.
Definition Demo.hpp:164
bool _enableString
Switch to enable the string pin.
Definition Demo.hpp:158
bool initialize() override
Initialize the node.
Definition Demo.cpp:475
bool _enableFloat
Switch to enable the float pin.
Definition Demo.hpp:156
void updatePins()
Update the pins depending on the GUI.
Definition Demo.cpp:509
bool _enableBool
Switch to enable the bool pin.
Definition Demo.hpp:154
size_t _stringUpdateCounter
Counter of how often the string was updated.
Definition Demo.hpp:169
bool resetNode() override
Resets the node. It is guaranteed that the node is initialized when this is called.
Definition Demo.cpp:625
static void readSensorDataThread(void *userData)
Function which performs the async data reading.
Definition Demo.cpp:694
void stringUpdatedNotifyFunction(const InsTime &insTime, size_t pinIdx)
Function to call when the string is updated.
Definition Demo.cpp:782
void restore(const json &j) override
Restores the node from a json object.
Definition Demo.cpp:445
void updateOutputFlowPin()
Updates the output flow pin depending on the GUI selection.
Definition Demo.cpp:635
std::shared_ptr< const NodeData > peekPollData(bool peek=false)
Polls data from the file. This function is needed, if we have multiple output pins,...
Definition Demo.cpp:741
static std::string typeStatic()
String representation of the Class Type.
Definition Demo.cpp:98
int _valueInt
Value which is represented over the Int pin.
Definition Demo.hpp:163
Eigen::MatrixXd _valueMatrix
Value which is represented over the Matrix pin.
Definition Demo.hpp:168
Demo(const Demo &)=delete
Copy constructor.
Demo & operator=(const Demo &)=delete
Copy assignment operator.
void deinitialize() override
Deinitialize the node.
Definition Demo.cpp:496
int _nPollData
Amount of Observations to be read.
Definition Demo.hpp:150
std::shared_ptr< const NodeData > pollData()
Polls data from the file.
Definition Demo.cpp:766
bool _enableMatrix
Switch to enable the matrix pin.
Definition Demo.hpp:160
std::string type() const override
String representation of the Class Type.
Definition Demo.cpp:103
DemoPins
Pin types used in this demo.
Definition Demo.hpp:97
@ Int
Integer numbers.
Definition Demo.hpp:101
@ Float
Float numbers.
Definition Demo.hpp:102
@ Delegate
Delegate pins giving access to the complete connected node.
Definition Demo.hpp:98
@ String
Strings.
Definition Demo.hpp:104
@ Object
Custom objects.
Definition Demo.hpp:105
@ Bool
Booleans.
Definition Demo.hpp:100
@ Double
Double numbers.
Definition Demo.hpp:103
@ Flow
Flow pins transmitting data as timestamped shared pointers.
Definition Demo.hpp:99
@ Matrix
Matrix objects.
Definition Demo.hpp:106
int _outputFrequency
Output frequency for the simulated sensor data.
Definition Demo.hpp:143
void receiveData(InputPin::NodeDataQueue &queue, size_t pinIdx)
Receive callback on the Flow pin.
Definition Demo.cpp:686
std::string _valueString
Value which is represented over the String pin.
Definition Demo.hpp:166
static std::string category()
String representation of the Class Category.
Definition Demo.cpp:108
bool _enableDelegate
Switch to enable the delegate pin.
Definition Demo.hpp:152
void guiConfig() override
ImGui config window which is shown on double click.
Definition Demo.cpp:113
Demo()
Default constructor.
Definition Demo.cpp:75
json save() const override
Saves the node into a json object.
Definition Demo.cpp:416
DemoData _valueObject
Value which is represented over the Object pin.
Definition Demo.hpp:167
Demo & operator=(Demo &&)=delete
Move assignment operator.
double _valueDouble
Value which is represented over the Double pin.
Definition Demo.hpp:165
~Demo() override
Destructor.
Definition Demo.cpp:93
Input pins of nodes.
Definition Pin.hpp:491
TsDeque< std::shared_ptr< const NAV::NodeData > > NodeDataQueue
Node data queue type.
Definition Pin.hpp:707
The class is responsible for all time-related tasks.
Definition InsTime.hpp:710
Node(std::string name)
Constructor.
Definition Node.cpp:30
Output pins of nodes.
Definition Pin.hpp:338
Data struct transmitted over an output port.
Definition Demo.hpp:79
std::array< int, 3 > integer
Integer inside the DemoData.
Definition Demo.hpp:80