NDEVR
API Documentation
IMUCalibrator.h
1#pragma once
2#include "DLLInfo.h"
3#include <NDEVR/Device.h>
4#include <NDEVR/Matrix.h>
5#include <NDEVR/Buffer.h>
6#include <NDEVR/INIInterface.h>
7#include <NDEVR/TranslatedString.h>
8#include <NDEVR/CalibrationData.h>
9#include <NDEVR/CalibrationPosition.h>
10#include <NDEVR/ApplicationResource.h>
11namespace NDEVR
12{
13 class CalibrationData;
14 class Model;
21 class HARDWARE_API IMUCalibrator : public Device, public INIInterface
22 {
23 Q_OBJECT
25 enum Status
26 {
27 e_idle
28 , e_rotate_to_position
29 , e_wait_to_stable
30 , e_collect_data
31 };
32 public:
36 IMUCalibrator(const UUID& id, const Model& model);
40 IMUCalibrator(const File& location, const Model& model);
42 bool isActive() const;
44 virtual fltp04 percent() const;
46 Status status() const;
54 void setStabilitySpan(const TimeSpan& span) { m_time_to_stable = span; }
59 void setMaxRotationThreshold(const Ray<3, fltp08>& rotation_threshold) { m_rotation_threshold = rotation_threshold;}
62 void setMaxAccelerometerThreshold(const Ray<3, fltp08>& rotation_threshold) { m_accelerometer_threshold = rotation_threshold; }
65 void setMaxNormalDeviation(const Ray<3, fltp08>& dev) { m_max_norm = dev; }
69 virtual TranslatedString message() const;
72 void setCalibrationData(const CalibrationData& data);
74 virtual String iconID() const;
79 void onReading(const Ray<3, fltp08>& accel, const Ray<3, fltp08>& gyro, Time t);
81 bool canCalibrate() const;
86 const Buffer<CalibrationPosition>& calibrationPositions() const { return m_calibration_positions; };
92 Ray<3, fltp08> expectedGravity() const;
95 virtual void getINI(INIFactory& factory) override;
103 virtual void finishCalibration();
105 uint04 stepIndex() const { return m_calibration_idx; }
107 Ray<3, fltp08> gravityTarget() const;
111 fltp08 stdDev(fltp08& mean_vector_length) const;
117 signals:
120 private:
121 CalibrationData m_calibration_data;
122 Matrix<fltp08> m_accelerometer_calibration = Constant<Matrix<fltp08>>::Invalid;
123 Buffer<std::pair<Time, Ray<3, fltp08>>> m_collected_gyro_data;
124 Buffer<CalibrationPosition> m_calibration_positions;
125 Ray<3, fltp08> m_gyro_bias = Ray<3, fltp08>(0.0);
126 Ray<3, fltp08> m_rotation_threshold = Ray<3, fltp08>(0.1);
127 Ray<3, fltp08> m_accelerometer_threshold = Ray<3, fltp08>(0.02);
128 Ray<3, fltp08> m_max_norm = Vector<3, fltp08>(0.5);
129 TimeSpan m_time_to_stable;
130 Time m_step_start_time = Constant<Time>::Invalid;
131 fltp04 m_percent = 1.0f;
132 uint04 m_samples_to_collect;
133 uint04 m_calibration_idx = 0;
134 uint04 m_valid_step_samples = 0U;
135 Status m_state = Status::e_idle;
136 Time m_calibration_time = Constant<Time>::Invalid;
137 bool m_is_moving = false;
138 bool m_is_in_norm = false;
139 };
140}
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
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
void stepFinishedSignal()
Emitted when a calibration step has been completed.
Matrix< fltp08 > accelerometerTransform() const
Returns the computed accelerometer calibration transform matrix.
void setMaxRotationThreshold(const Ray< 3, fltp08 > &rotation_threshold)
Sets the maximum rotation rate threshold for stability detection.
const Buffer< CalibrationPosition > & calibrationPositions() const
Returns the list of target calibration positions.
virtual void getINI(INIFactory &factory) override
Serializes calibration settings to an INI factory.
Vertex< 3, fltp08 > gyroBias() const
Returns the computed gyroscope bias from the calibration data.
IMUCalibrator(const File &location, const Model &model)
Constructs an IMUCalibrator loading calibration data from a file.
virtual fltp04 percent() const
Returns the completion percentage of the current calibration step.
Buffer< CalibrationReading > & accData()
Returns a mutable reference to the collected accelerometer calibration data.
static ApplicationOption< fltp08 > std_dev_filter
Standard deviation threshold for filtering readings.
bool isActive() const
Returns whether the calibration process is currently active.
static ApplicationOption< TimeSpan > default_stability_span
Default time the sensor must remain stable.
Buffer< std::pair< Time, Ray< 3, fltp08 > > > & gyroData()
Returns a mutable reference to the collected gyroscope data buffer.
void setCalibrationPositions(const Buffer< CalibrationPosition > &positions)
Sets the list of target calibration positions.
virtual String iconID() const
Returns the icon identifier for this calibrator device.
void cancelCalibration()
Cancels the calibration process and returns to idle state.
bool canCalibrate() const
Returns whether enough data has been collected to compute a calibration.
void finishStep()
Finishes the current calibration step and advances to the next position.
void onReading(const Ray< 3, fltp08 > &accel, const Ray< 3, fltp08 > &gyro, Time t)
Processes a new IMU reading during calibration.
void setMaxAccelerometerThreshold(const Ray< 3, fltp08 > &rotation_threshold)
Sets the maximum accelerometer threshold for stability detection.
Time calibrationTime() const
Returns the time when calibration started.
Ray< 3, fltp08 > expectedGravity() const
Returns the expected gravity vector for the current calibration position.
const Buffer< CalibrationReading > & accData() const
Returns a const reference to the collected accelerometer calibration data.
void setMaxNormalDeviation(const Ray< 3, fltp08 > &dev)
Sets the maximum allowed deviation from the expected gravity normal.
void setCalibrationData(const CalibrationData &data)
Sets the calibration data used for computing the transform.
void setStabilitySpan(const TimeSpan &span)
Sets the time the sensor must remain stable before data collection begins.
void setSamplesToCollect(uint04 samples)
Sets the number of samples to collect per calibration position.
virtual TranslatedString message() const
Returns a translated status message describing the current calibration state.
fltp08 stdDev(fltp08 &mean_vector_length) const
Computes the standard deviation of collected data at the current position.
virtual void finishCalibration()
Computes the final calibration transform from the collected data.
IMUCalibrator(const UUID &id, const Model &model)
Constructs an IMUCalibrator with the given UUID and Model.
void startCalibration()
Starts the calibration process from the beginning.
uint04 stepIndex() const
Returns the index of the current calibration step.
Ray< 3, fltp08 > gravityTarget() const
Returns the target gravity vector for the current calibration step.
static ApplicationOption< uint04 > default_sample_count
Default number of samples per calibration step.
Status status() const
Returns the current calibration state.
Contains methods for easily reading and writing to an INI file including efficient casting,...
Definition INIReader.h:107
INIInterface()
Constructs an INIInterface with no default INI file.
Templated logic for doing matrix multiplication.
Definition Matrix.hpp:182
A core class that represents a node on model hierarchy.
Definition Model.h:292
The core String class for the NDEVR API.
Definition String.h:95
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 universally unique identifier (UUID) is a 128-bit number used to identify information in computer s...
Definition UUID.h:61
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
Definition Vector.hpp:62
A point in N-dimensional space, used primarily for spatial location information.
Definition Vertex.hpp:44
The primary namespace for the NDEVR SDK.
float fltp04
Defines an alias representing a 4 byte floating-point number Bit layout is as follows: -Sign: 1 bit a...
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...