2#include <NDEVR/GenericOption.h>
3#include <NDEVR/BaseValues.h>
4#include <NDEVR/Random.h>
6#include <NDEVR/TimeSpan.h>
7#include <NDEVR/Angle.h>
8#include <NDEVR/AngleDefinitions.h>
9#include <NDEVR/Translator.h>
18 class HARDWARE_API IMUNoiseSimulator
89 m_last_accelerometer_update_time = Constant<Time>::Invalid;
90 m_last_gyro_update_time = Constant<Time>::Invalid;
91 m_last_magnetometer_update_time = Constant<Time>::Invalid;
99 for (
uint04 i = 0; i < 3; i++)
102 axis_name = axis_name.
toLower();
103 axis_name.replaceAll(
' ',
'_');
117 for (
uint04 i = 0; i < 3; i++)
120 axis_name = axis_name.
toLower();
121 axis_name.replaceAll(
' ',
'_');
141 return m_gyro_bias_dph;
147 m_gyro_bias_dph = bias;
254 m_last_gyro_update_time = Constant<Time>::Invalid;
280 m_last_accelerometer_update_time = Constant<Time>::Invalid;
289 settings[0].addOptionsToINI(gyro_factory);
299 settings[1].addOptionsToINI(acc_factory);
309 settings[0].addOptionsToINI(gyro_factory);
320 settings[1].addOptionsToINI(acc_factory);
325 : m_random_number_generator(
Time::SystemTime().getNanoSeconds() % 100000)
336 m_temperature = temperature;
426 if (
IsInvalid(m_last_gyro_update_time) || m_last_gyro_update_time - current_time >
TimeSpan(0.5))
429 for (
uint01 i = 0; i < 3; i++)
439 m_last_gyro_update_time = current_time;
442 fltp08 dt = (current_time - m_last_gyro_update_time).elapsedSeconds();
443 lib_assert(dt >= 0.0,
"bad dt?");
448 const fltp08 dt_hours = dt / 3600.0;
450 for (
uint01 i = 0; i < 3; i++)
454 m_gyro_bias_dph[i] += dt_hours * instability;
460 fltp08 noise_sample_std = noise_density_sample * dt_sqrt;
461 fltp08 single_axis_noise = m_random_number_generator.get() * noise_sample_std;
463 fltp08 rate_error = angular_rate[i] * m_current_gyro_scale_error[i];
464 fltp08 gyro_bias = m_gyro_bias_dph[i] * dt_hours;
466 angular_rate[i] += gyro_bias + single_axis_noise + rate_error;
468 m_last_gyro_update_time = current_time;
478 if (
IsInvalid(m_last_accelerometer_update_time) || m_last_accelerometer_update_time - current_time >
TimeSpan(0.5))
481 for (
uint01 i = 0; i < 3; i++)
495 m_last_accelerometer_update_time = current_time;
499 fltp08 dt = (current_time - m_last_accelerometer_update_time).elapsedSeconds();
500 lib_assert(dt >= 0.0,
"bad dt?");
504 for (
uint01 i = 0; i < 3; i++)
507 m_accel_bias[i] += 1.25 * m_current_accel_bias_instability[i] * m_random_number_generator.get();
512 fltp08 noise_sample_std = noise_density_sample_ug * dt_sqrt;
513 fltp08 single_axis_noise_ug = m_random_number_generator.get() * noise_sample_std;
515 gravity_vector[i] += (m_accel_bias[i] + single_axis_noise_ug) / 1000000.0;
517 m_last_accelerometer_update_time = current_time;
526 if (
IsInvalid(m_last_magnetometer_update_time))
528 for (
uint01 i = 0; i < 3; i++)
532 m_last_magnetometer_update_time = current_time;
536 const fltp08 dt = (current_time - m_last_magnetometer_update_time).elapsedSeconds();
539 for (
uint01 i = 0; i < 3; i++)
543 fltp08 noise_sample_std = noise_density_sample_ugauss * dt_sqrt;
544 fltp08 single_axis_noise_ugauss = m_random_number_generator.get() * noise_sample_std;
546 magnetic_vector[i] = magnetic_vector[i] + (
mag_bias_gauss[i]) + (single_axis_noise_ugauss / 1000000);
548 m_last_magnetometer_update_time = current_time;
557 Time m_last_gyro_update_time = Constant<Time>::Invalid;
558 Time m_last_accelerometer_update_time = Constant<Time>::Invalid;
559 Time m_last_magnetometer_update_time = Constant<Time>::Invalid;
560 fltp08 m_temperature = 30.0;
The equivelent of std::vector but with a bit more control.
void add(t_type &&object)
Adds object to the end of the buffer.
Logic for reading or writing to a file as well as navigating filesystems or other common file operati...
Used to generate a random number over a Gaussian distribution with templated setup parameters for ver...
Stores a groups of GenericOptions that can be used to group them.
t_type getValue(const TranslatedString &name) const
Retrieves the value of an option converted to the requested type, looked up by translated name.
void addOption(const TranslatedString &name, const t_type &value, bool is_editable=true)
Adds a new option to this group with the given name and typed value.
This class generates random bias and noise for modeling a 9-DoF IMU.
Vector< 3, fltp08 > gyro_noise_density_mean_dps_rt_hz
Gyro noise density average in deg/s/sqrt(Hz).
fltp08 gyro_vibration_noise_coef_std
Gyro vibration noise coefficient std dev.
fltp08 gyro_g_sensitivity
Gyro g-sensitivity coefficient.
Vector< 3, fltp08 > acc_scale_error_max_ppm
Accel scale factor error maximum in ppm.
void loadAccelerometerSettings(File file)
Loads accelerometer noise parameters from an INI file.
fltp08 max_mag_bias_offset_gauss
Maximum magnetometer bias offset in gauss.
fltp08 mag_bias_offset_mean_ugauss
Magnetometer turn-on bias offset mean in ugauss.
fltp08 mag_bias_offset_std_ugauss
Magnetometer turn-on bias offset std dev in ugauss.
Vector< 3, fltp08 > acc_scale_temperature_error_std_ppm
Accel scale temperature error std dev in ppm.
Vector< 3, fltp08 > accel_velocity_walk_mean
Accel velocity random walk mean.
fltp08 mag_noise_density_std_ugauss_rt_hz
Magnetometer noise density std dev in ugauss/sqrt(Hz).
Vector< 3, fltp08 > gyro_scale_temperature_error_std_ppm
Gyro scale temperature error std dev in ppm.
void addAccelerometerNoise(Vector< 3, fltp08 > &gravity_vector, const Time ¤t_time)
Adds noise to gravity_vector and updates bias to simulate a real-world accel using model: vector = ve...
Vector< 3, fltp08 > gyro_scale_error_mean_ppm
Gyro scale factor error mean in ppm.
void setVector(const GenericOptionGroup &group, Vector< 3, fltp08 > &vector, const StringView name)
Reads a 3D vector from three axis options in an option group.
Vector< 3, fltp08 > gyro_random_walk_mean
Gyro angular random walk mean.
Vector< 3, fltp08 > gyro_noise_density_max_dps_rt_hz
Gyro noise density maximum in deg/s/sqrt(Hz).
Vector< 3, fltp08 > gyro_bias_offset_mean_dph
Gyro turn-on bias average in deg/hr.
Vector< 3, fltp08 > acc_scale_error_std_ppm
Accel scale factor error std dev in ppm.
void setGyroBias(const Vector< 3, fltp08 > &bias)
Sets the current gyroscope bias.
Vector< 3, fltp08 > gyro_scale_temperature_error_mean_ppm
Gyro scale temperature error mean in ppm.
Vector< 3, fltp08 > accel_bias_temperature_mean_error
Accel bias temperature sensitivity mean in ug/sqrt(Hz).
Vector< 3, fltp08 > accel_noise_density_std_ug_rt_hz
Accel noise density std dev in ug/sqrt(Hz).
void loadGyroSettings(File file)
Loads gyroscope noise parameters from an INI file.
Vector< 3, fltp08 > accel_bias_temperature_std_error
Accel bias temperature sensitivity std dev in ug/sqrt(Hz).
fltp08 gyro_input_range
Gyroscope input range in degrees per second.
fltp08 gyro_vibration_rectification_mean
Gyro vibration rectification error mean.
Vector< 3, fltp08 > gyro_bias_offset_max_dph
Gyro turn-on bias maximum in deg/hr.
void addGyroNoise(Vector< 3, fltp08 > &angular_rate, const Time ¤t_time)
Adds noise to angular_rate and updates bias to simulate a real-world gyro using model: angular_rate =...
Vector< 3, fltp08 > acc_scale_temperature_error_mean_ppm
Accel scale temperature error mean in ppm.
Buffer< GenericOptionGroup > groups()
Builds and returns the gyroscope and accelerometer option groups for configuration.
Vector< 3, fltp08 > accel_bias_offset_std_ug
Accel turn-on bias std dev in ug.
Vector< 3, fltp08 > max_accel_noise_density_ug_rt_hz
Maximum accel noise density from OEM datasheet in ug/sqrt(Hz).
fltp08 gyro_vibration_rectification_std
Gyro vibration rectification error std dev.
Vector< 3, fltp08 > gyro_bias_instability_mean_dph
Gyro bias instability average in deg/hr.
fltp08 gyro_vibration_noise_coef_mean
Gyro vibration noise coefficient mean.
Vector< 3, fltp08 > acc_scale_error_mean_ppm
Accel scale factor error mean in ppm.
Vector< 3, fltp08 > accel_noise_density_max_ug_rt_hz
Accel noise density maximum in ug/sqrt(Hz).
Vector< 3, fltp08 > gyro_bias_offset_std_dph
Gyro turn-on bias std dev in deg/hr.
Vector< 3, fltp08 > max_accel_bias_ug
Maximum accel bias offset from OEM datasheet in ug.
Vector< 3, fltp08 > gyro_non_linearity_std_ppm
Gyro non-linearity std dev in ppm.
void saveAccelerometerSettings(File file)
Saves accelerometer noise parameters to an INI file.
fltp08 accel_dynamic_range
Accelerometer dynamic range in g.
Vector< 3, fltp08 > gyro_scale_error_max_ppm
Gyro scale factor error maximum in ppm.
Vector< 3, fltp08 > gyro_noise_density_std_dps_rt_hz
Gyro noise density std dev in deg/s/sqrt(Hz).
void addMagnetometerNoise(Vector< 3, fltp08 > &magnetic_vector, const Time ¤t_time)
Adds noise to gravity_vector to simulate a real-world magnetometer using model: vector = vector + noi...
void initializeMagBiasesMemsense()
Initializes magnetometer noise parameters based on Memsense datasheet values.
Vector< 3, fltp08 > gyro_bias_instability_std_dph
Gyro bias instability std dev in deg/hr.
void setTemperature(fltp08 temperature)
Sets the simulated temperature in Celsius, affecting temperature-dependent noise parameters.
void addVector(GenericOptionGroup &group, const Vector< 3, fltp08 > &vector, const StringView name)
Adds a 3D vector as three separate axis options to an option group.
Vector< 3, fltp08 > gyro_non_linearity_mean_ppm
Gyro non-linearity mean in ppm.
Vector< 3, fltp08 > gyro_non_linearity_max_ppm
Gyro non-linearity maximum in ppm.
fltp08 gyro_bias_temperature_std_error
Gyro bias temperature sensitivity std dev error.
void setGyroOptions(const GenericOptionGroup &gyro)
Applies gyroscope noise parameters from an option group.
Vector< 3, fltp08 > accel_velocity_walk_std
Accel velocity random walk std dev.
Vector< 3, fltp08 > acc_non_linearity_mean_ppm
Accel non-linearity mean in ppm.
void saveGyroSettings(File file)
Saves gyroscope noise parameters to an INI file.
void reset()
Resets the internal state, invalidating all last-update timestamps.
Vector< 3, fltp08 > acc_non_linearity_std_ppm
Accel non-linearity std dev in ppm.
Vector< 3, fltp08 > accelBias() const
Returns the current accelerometer bias per axis in ug.
Vector< 3, fltp08 > currentGyroBias() const
Returns the current gyroscope bias per axis in deg/hr.
void setAccelBias(const Vector< 3, fltp08 > &bias)
Sets the current accelerometer bias.
Vector< 3, fltp08 > accel_bias_offset_max_ug
Accel turn-on bias maximum in ug.
void initializeAccelBiasesMemsense()
Initializes accelerometer noise parameters based on Memsense datasheet values.
void setAccelerometerOptions(const GenericOptionGroup &accel)
Applies accelerometer noise parameters from an option group.
Vector< 3, fltp08 > accel_noise_density_mean_ug_rt_hz
Accel noise density average in ug/sqrt(Hz).
Vector< 3, fltp08 > accel_bias_instability_std_ug
Accel bias instability std dev in ug.
Vector< 3, fltp08 > mag_bias_gauss
Current magnetometer bias per axis in gauss.
fltp08 gyro_bias_temperature_mean_error
Gyro bias temperature sensitivity mean error.
Vector< 3, fltp08 > accel_bias_offset_mean_ug
Accel turn-on bias average in ug.
fltp08 mag_noise_density_mean_ugauss_rt_hz
Magnetometer noise density mean in ugauss/sqrt(Hz). Best guess from incomplete datasheet.
Vector< 3, fltp08 > gyro_random_walk_std
Gyro angular random walk std dev.
void initializeGyroBiasesMemsense()
Initializes gyroscope noise parameters based on Memsense datasheet values.
Vector< 3, fltp08 > accel_bias_instability_mean_ug
Accel bias instability average in ug.
Vector< 3, fltp08 > gyro_scale_error_std_ppm
Gyro scale factor error std dev in ppm.
Contains methods for easily reading and writing to an INI file including efficient casting,...
void writeToAsciiFile(File &file, bool include_end_comment=false)
Writes all registered options to an ASCII-formatted INI file.
void setPreserveOrder(bool preserve_order)
Sets whether to preserve the order in which options appear in the file.
void readAsciiFile(File &file)
Reads all options from an ASCII-formatted INI file.
The core String View class for the NDEVR API.
The core String class for the NDEVR API.
String & append(const StringView &string)
Appends a string to the back of this string.
StringAllocatingView toLower() const
changes all upper case characters into lower case characters.
String toTitleString() const
Formats the string to be a title, capitalizing important characters and replacing underscores with sp...
Stores a time span, or difference between two times, with an optional start time.
Represents a timestamp with utilities for manipulation and conversion.
static TranslatedString DirectString(const StringView &sub_string)
If a string does not have a translation (EG: reading from an already translated string) this operatio...
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
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.
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
static constexpr bool IsInvalid(const Angle< t_type > &value)
Checks whether the given Angle holds an invalid value.
@ file
The source file path associated with this object.
@ name
The display name of the object.
t_type sqrt(const t_type &value)
constexpr t_type clip(const t_type &value, const t_type &lower_bound, const t_type &upper_bound)
Clips the value given so that that the returned value falls between upper and lower bound.
constexpr t_to cast(const Angle< t_from > &value)
Casts an Angle from one backing type to another.
Stores a generic option of any type as well as some information about how the user might interact wit...