NDEVR
API Documentation
MadgwickSimulator.h
1#pragma once
2#include "DLLInfo.h"
3#include <NDEVR/Model.h>
4#include <NDEVR/GaussianRN.h>
5#include <NDEVR/MadgwickOrientationSensor.h>
6#include <NDEVR/ApplicationOption.h>
7#include <NDEVR/Resource.h>
8#include "IMUNoiseSimulator.h"
9namespace NDEVR
10{
11 class TranslatedString;
12 class PipeInfo;
13 class QTModelManager;
19 {
20 public:
23 fltp08 beta = 0.08;
26 Ray<3, fltp08> sensor_misalignment = Ray<3, fltp08>(0.0);
27 bool use_gyro = true;
28 bool use_accelerometer = true;
29 bool use_madgwick = true;
30 };
31
42
48 class HARDWARE_API MadgwickSimulator : public Device
49 {
50 public:
55 MadgwickSimulator(DesignObjectLookup* manager, const Model& model, LogPtr log);
57 static constexpr StringView TypeName() { return "madgwick_simulator"; }
68 virtual void update(Time time) override;
73 Ray<3, fltp08> gyroData(const Matrix<fltp08>& target_matrix, Matrix<fltp08>& last_gyro_matrix);
77 Ray<3, fltp08> accelerationData(const Matrix<fltp08>& target_matrix);
79 Ray<3, Angle<fltp08>> currentError() const;
82 void setMovement(const Vector<2, fltp08>& movement);
84 virtual TimeSpan updateInterval() const override;
88 void updateText(const TranslatedString& name, Model& model);
91 void setMadgwickOptions(const MadgwickOptions& options);
96 void setRecording(bool is_recording);
99 void saveStats(File file) const;
102 void readFile(const File& file);
104 void reset();
110 Model referenceModel() const { return getChild(0); }
112 Model referenceTransformModel() const { return getChild(0).getChild(0); }
121 public:
125 protected:
127 void init();
131 void setupChild(const TranslatedString& name, Model& model);
135 Time m_simulated_last_update_time = Constant<Time>::Invalid;
137 Time m_last_real_time = Constant<Time>::Invalid;
147 uint04 m_actual_data_location = Constant<uint04>::Invalid;
148 bool m_is_recording = false;
149 };
150}
The default object to store data of any type that should persist through sessions of the application.
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
A core class where all Design Objects including models, materials, and geometries are stored.
File file() const
Returns the file path associated with this design object as a File object.
Device(const Model &model, LogPtr log, QObject *parent=nullptr)
Constructs a Device from a Model with the given log and optional Qt parent.
Logic for reading or writing to a file as well as navigating filesystems or other common file operati...
Definition File.h:53
This class generates random bias and noise for modeling a 9-DoF IMU.
A light-weight wrapper that will be a no-op if there is not a valid log reference,...
Configuration options for the Madgwick orientation filter simulation.
fltp08 simulation_multiplier
Time multiplier for the simulation speed.
Ray< 3, fltp08 > sensor_misalignment
Simulated sensor misalignment per axis.
fltp08 gyro_input_range
Gyroscope input range in degrees per second.
fltp08 acceleration_multiplier
Multiplier for simulated acceleration.
bool use_accelerometer
Whether to include accelerometer data in the simulation.
bool use_gyro
Whether to include gyroscope data in the simulation.
bool use_madgwick
Whether to use the Madgwick filter for orientation.
fltp08 gyro_frequency
Gyroscope sampling frequency in Hz.
fltp08 beta
Madgwick filter gain parameter.
Used to calculate madgick orientation given sensor streams for gyro and optionally magnetometer(s) an...
static Resource< String > model_location
Resource for the model file location.
void setRecording(bool is_recording)
Enables or disables recording of simulation data.
Model referenceModel() const
Returns the reference model (first child).
TimeSpan m_gyro_td
Gyroscope time delta between samples.
MadgwickOrientationSensor * createOrientationSensor()
Creates and returns a new MadgwickOrientationSensor for this simulator.
void updateText(const TranslatedString &name, Model &model)
Updates the display text on a model with simulation information.
Time simulationStartTime() const
Returns the time when the simulation started.
void readFile(const File &file)
Reads simulation data from a file.
Vector< 3, fltp08 > m_axis_gyro_offset
Gyroscope axis offset for simulation.
Time m_last_text_update_time
Time of the last text display update.
const Buffer< SimulationDataPoint > & actualData() const
Returns the actual recorded data points.
MadgwickOptions madgwickOptions() const
Returns the current Madgwick simulation options.
Vector< 2, fltp08 > m_movement
Current user-input movement.
Buffer< SimulationDataPoint > m_actual_data_points
Buffer of actual recorded data points for playback.
static constexpr StringView TypeName()
Returns the type name identifier for this device.
void setMovement(const Vector< 2, fltp08 > &movement)
Sets the simulated movement input vector.
IMUNoiseSimulator & noiseModel()
Returns a mutable reference to the noise model used for simulation.
Matrix< fltp08 > m_last_gyro_matrix
The previous gyro orientation matrix.
void setActualDataPoints(const Buffer< SimulationDataPoint > &points)
Sets the actual data points used for playback mode.
MadgwickOrientationSensor * m_orientation_sensor
The orientation sensor processing simulated data.
void setMadgwickOptions(const MadgwickOptions &options)
Applies new Madgwick options to the simulation.
MadgwickOptions m_madgwick_options
Current simulation options.
MadgwickSimulator(DesignObjectLookup *manager, const Model &model, LogPtr log)
Constructs a MadgwickSimulator.
Model referenceTransformModel() const
Returns the reference transform model (first child of the reference model).
void saveStats(File file) const
Saves recorded simulation statistics to a file.
void init()
Initializes the simulator internals.
static ApplicationOption< fltp08 > gyro_noise
Default gyro noise level application option.
Time simulatedTime() const
Returns the current simulated time.
void setOrientationSensor(MadgwickOrientationSensor *sensor)
Sets the orientation sensor to use.
Ray< 3, fltp08 > gyroData(const Matrix< fltp08 > &target_matrix, Matrix< fltp08 > &last_gyro_matrix)
Computes simulated gyroscope data from the target orientation matrix.
virtual void update(Time time) override
Advances the simulation to the given time.
uint04 m_actual_data_location
Current index into the actual data buffer.
Time m_simulated_last_update_time
Simulated time of the last update.
void setupChild(const TranslatedString &name, Model &model)
Sets up a child model with the given name.
IMUNoiseSimulator m_noise_simulator
The noise simulator for adding realistic sensor noise.
Ray< 3, Angle< fltp08 > > currentError() const
Returns the current orientation error as Euler angles.
static ApplicationOption< fltp08 > accelerometer_noise
Default accelerometer noise level application option.
bool m_is_recording
Whether the simulation is currently recording data.
MadgwickOrientationSensor * orientationSensor()
Returns the orientation sensor used by this simulator.
Vector< 2, fltp08 > m_accelerated_movement
Current acceleration-derived movement.
void createCalculatedModel()
Creates the child model used to display the calculated orientation.
void reset()
Resets the simulation to its initial state.
Buffer< SimulationDataPoint > m_data_points
Buffer of simulated data points.
Time m_last_real_time
Real wall-clock time of the last update.
DesignObjectLookup * m_manager
Pointer to the design object lookup.
Ray< 3, fltp08 > accelerationData(const Matrix< fltp08 > &target_matrix)
Computes simulated accelerometer data from the target orientation matrix.
Vector< 3, fltp08 > m_axis_accelerometer_offset
Accelerometer axis offset for simulation.
virtual TimeSpan updateInterval() const override
Returns the update interval for the simulation.
Templated logic for doing matrix multiplication.
Definition Matrix.hpp:182
A core class that represents a node on model hierarchy.
Definition Model.h:292
Model getChild(uint04 child) const
Returns the child model at the given child slot index.
A wrapper around DesignObjectLookup that provides signal and slot functionality and adds rendering ca...
A core part of the engine, stores variables that can be listened to with ResourceListener which will ...
Definition Resource.h:42
The core String View class for the NDEVR API.
Definition StringView.h:58
Stores a time span, or difference between two times, with an optional start time.
Definition TimeSpan.h:46
Represents a timestamp with utilities for manipulation and conversion.
Definition Time.h:62
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
Definition Vector.hpp:62
The primary namespace for the NDEVR SDK.
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
double fltp08
Defines an alias representing an 8 byte floating-point number.
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved 'invali...
A single data point captured during Madgwick simulation, containing raw sensor data and the computed ...
Time time
The timestamp of this data point.
Ray< 3, fltp08 > raw_acceleromater
The raw accelerometer reading at this point.
Ray< 3, fltp08 > raw_gyro
The raw gyroscope reading at this point.
Vector< 4, fltp08 > madgwick_quaternion
The Madgwick-computed orientation quaternion.