AGX Dynamics 2.42.3.0
Loading...
Searching...
No Matches
IMUOutput.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16#pragma once
19
20#include <agx/Referenced.h>
21
22#include <limits>
23
24namespace agxSensor
25{
27
51 : public SystemNode
52 , public ISensorOutput
53 {
54 public:
55 enum Field : int32_t
56 {
112 SENSOR_MAX_X_F64 = (((1 << 30) - 3) / 3) * 3,
114 SENSOR_MAX_Y_F64 = SENSOR_MAX_X_F64 + 1,
116 SENSOR_MAX_Z_F64 = SENSOR_MAX_X_F64 + 2,
118 NUM_FIELDS
119 };
120
121 using FieldVector = std::vector<Field>;
122
123 public:
128 static size_t sizeOf(Field field);
129
134 static const char* getFieldName(Field field);
135
136 public:
140 IMUOutput() = default;
141
145 template <Field... field>
146 void build();
147
154
159 void setPaddingValue(const agx::Real& value);
160
165 virtual size_t getElementSize() const override;
166
170 virtual const BinaryOutputBuffer& getData() override;
171
179 virtual bool hasUnreadData(bool markAsRead = true) override;
180
184 bool contains(Field field) const;
185
192 size_t getOffset(Field field) const;
193
197 const FieldVector& getFields() const;
198
204
210
216
218
219 public:
220 virtual ~IMUOutput() = default;
221
222 virtual void result(const CallbackData& data) override;
223 virtual void cleanup() override;
224
226
228
229 private:
230 FieldVector m_fields {};
231 size_t m_elementSize {0u};
232 agx::Real m_paddingValue {std::numeric_limits<agx::Real>::signaling_NaN()};
233 bool m_hasUnreadData {false};
234 BinaryOutputBuffer m_output {};
235 };
236
237 template <IMUOutput::Field... field>
239 {
240 m_fields.clear();
241 m_elementSize = 0u;
242 (this->add(field), ...);
243 }
244
246
247#pragma pack(push, 1)
248 struct SixDoFValue
249 {
250 agx::Real x0, y0, z0;
251 agx::Real x1, y1, z1;
252
253 inline SixDoFValue() {}
254 inline SixDoFValue(const agx::Vec3& a, const agx::Vec3& b)
255 : x0(a.x())
256 , y0(a.y())
257 , z0(a.z())
258 , x1(b.x())
259 , y1(b.y())
260 , z1(b.z())
261 {
262 }
263 inline SixDoFValue(const SixDoFValue&) = default;
264 inline SixDoFValue& operator=(const SixDoFValue&) = default;
265
266 inline agx::Vec3 getTriplet(const size_t i) const noexcept
267 {
268 if (i == 0)
269 return agx::Vec3(x0, y0, z0);
270 else if (i == 1)
271 return agx::Vec3(x1, y1, z1);
272 else
273 return agx::Vec3();
274 }
275 };
276
277 struct NineDoFValue
278 {
279 agx::Real x0, y0, z0;
280 agx::Real x1, y1, z1;
281 agx::Real x2, y2, z2;
282
283 inline NineDoFValue() {}
284 inline NineDoFValue(const agx::Vec3& a, const agx::Vec3& b, const agx::Vec3& c)
285 : x0(a.x())
286 , y0(a.y())
287 , z0(a.z())
288 , x1(b.x())
289 , y1(b.y())
290 , z1(b.z())
291 , x2(c.x())
292 , y2(c.y())
293 , z2(c.z())
294 {
295 }
296 inline NineDoFValue(const NineDoFValue&) = default;
297 inline NineDoFValue& operator=(const NineDoFValue&) = default;
298
299 inline agx::Vec3 getTriplet(const size_t i) const noexcept
300 {
301 if (i == 0)
302 return agx::Vec3(x0, y0, z0);
303 else if (i == 1)
304 return agx::Vec3(x1, y1, z1);
305 else if (i == 2)
306 return agx::Vec3(x2, y2, z2);
307 else
308 return agx::Vec3();
309 }
310 };
311#pragma pack(pop)
312
313 class AGXSENSOR_EXPORT IMUOutputSixDoF : public IMUOutput
314 {
315 public:
316 IMUOutputSixDoF();
317 };
318
319 class AGXSENSOR_EXPORT IMUOutputNineDoF : public IMUOutput
320 {
321 public:
322 IMUOutputNineDoF();
323 };
324
326}
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#define AGXSTREAM_DECLARE_SERIALIZABLE(T)
Use this in a Serializable class to add the required methods Important: Use full namespace in the dec...
Definition: Serializable.h:207
#define AGXSENSOR_EXPORT
Buffer used for sensor output of a wide range of output element types.
IMU sensor output data where IMUOutput::Field is used to define the data available.
Definition: IMUOutput.h:53
virtual size_t getElementSize() const override
"Element size" is the summed data size of the currently added fields.
virtual bool hasUnreadData(bool markAsRead=true) override
std::vector< Field > FieldVector
Definition: IMUOutput.h:121
virtual const BinaryOutputBuffer & getData() override
static size_t sizeOf(Field field)
static const char * getFieldName(Field field)
void build()
Add one or more fields, build a matching data structure.
Definition: IMUOutput.h:238
agx::Vec3 computeMagnetometerCovariance() const
Compute the covariance of the magnetometer signal values for the magnetometer entry in the output.
IMUOutput()=default
Default constructor.
agx::Vec3 computeGyroscopeCovariance() const
Compute the covariance of the gyroscope signal values for the gyroscope entry in the output.
size_t getOffset(Field field) const
Offset in bytes of the first entry of field in the pack of fields.
const FieldVector & getFields() const
IMUOutput & add(Field field)
Add new field.
@ SENSOR_1_X_F64
1x 64-bit floating point x-axis output from the second sensor in the IMU.
Definition: IMUOutput.h:82
@ SENSOR_1_Y_F64
1x 64-bit floating point y-axis output from the second sensor in the IMU.
Definition: IMUOutput.h:84
@ ACCELEROMETER_Z_F64
1x 64-bit floating point accelerometer z-axis output.
Definition: IMUOutput.h:62
@ SENSOR_0_Z_F64
1x 64-bit floating point z-axis output from the first sensor in the IMU.
Definition: IMUOutput.h:80
@ GYROSCOPE_Y_F64
1x 64-bit floating point gyroscope y-axis output.
Definition: IMUOutput.h:66
@ MAGNETOMETER_Y_F64
1x 64-bit floating point magnetometer y-axis output.
Definition: IMUOutput.h:72
@ ACCELEROMETER_X_F64
1x 64-bit floating point accelerometer x-axis output.
Definition: IMUOutput.h:58
@ ACCELEROMETER_Y_F64
1x 64-bit floating point accelerometer y-axis output.
Definition: IMUOutput.h:60
@ SENSOR_0_Y_F64
1x 64-bit floating point y-axis output from the first sensor in the IMU.
Definition: IMUOutput.h:78
@ MAGNETOMETER_Z_F64
1x 64-bit floating point magnetometer z-axis output.
Definition: IMUOutput.h:74
@ SENSOR_1_Z_F64
1x 64-bit floating point z-axis output from the second sensor in the IMU.
Definition: IMUOutput.h:86
@ SENSOR_0_X_F64
1x 64-bit floating point x-axis output from the first sensor in the IMU.
Definition: IMUOutput.h:76
@ GYROSCOPE_X_F64
1x 64-bit floating point gyroscope x-axis output.
Definition: IMUOutput.h:64
@ MAGNETOMETER_X_F64
1x 64-bit floating point magnetometer x-axis output.
Definition: IMUOutput.h:70
@ GYROSCOPE_Z_F64
1x 64-bit floating point gyroscope z-axis output.
Definition: IMUOutput.h:68
bool contains(Field field) const
agx::Vec3 computeAccelerometerCovariance() const
Compute the covariance of the accelerometer signal values for the accelerometer entry in the output.
void setPaddingValue(const agx::Real &value)
Set value to use for padding when no underlying signal data can be found.
Common interface for sensor output data.
Definition: SensorOutput.h:27
System node is a separate step/operation in an execution tree representing a sensor (or such) in a se...
Definition: SystemNode.h:44
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:89
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:88
The agxSensor namespace contains components to model real-time sensors connected to the physics of AG...
Vec3T< Real > Vec3
The object holding 3 dimensional vectors and providing basic arithmetic.
Definition: agx/Vec3.h:36
double Real
Definition: Real.h:41