Sensors#
A simple and flexible way to use sensors in your projects. The sensors module provides a set of classes to handle the most common sensors used in attitude estimation algorithms.
The class Sensors already includes the implementation of the most
common sensors used in attitude estimation algorithms.
- class ahrs.utils.sensors.Sensors(quaternions: QuaternionArray = None, num_samples: int = 500, freq: float = 100.0, **kwargs)#
Generate synthetic sensor data of a hypothetical strapdown inertial navigation system.
It generates data of a 9-DOF IMU (3-axis gyroscopes, 3-axis accelerometers, and 3-axis magnetometers) from a given array of orientations as quaternions.
The accelerometer data is given as m/s^2, the gyroscope data as rad/s, and the magnetometer data as nT.
If no quaternions are provided, it generates random angular positions and computes the corresponding quaternions.
The sensor data can be accessed as attributes of the object. For example, the gyroscope data can be accessed as
sensors.gyroscopes.Simulating N observations, the most used attributes are:
gyroscopes: N-by-3 array with gyroscope data, as rad/s.accelerometers: N-by-3 array with accelerometer data, as m/s^2.magnetometers: N-by-3 array with magnetometer data, as nT.quaternions: N-by-4 array with orientations as quaternions.rotations: N-by-3-by-3 array with orientations as 3x3 Rotation matrices.angular_positions: N-by-3 array with orientations as Euler angles (roll, pitch, yaw.)ang_vel: N-by-3 array with angular velocities around the X-, Y-, and Z-axes. Obtained from differentiation of the orientations.frequency: Sampling frequency of the data, in Hz.
- Parameters:
quaternions (ahrs.QuaternionArray, default: None) – Array of orientations as quaternions.
num_samples (int, default: 500) – Number of samples to generate.
freq (float, default: 100.0) – Sampling frequency, in Hz, of the data.
in_degrees (bool, default: False) – If True, the gyroscope data is generated in degrees per second. Otherwise in radians per second.
normalized_mag (bool, default: False) – If True, the magnetometer data is normalized to unit norm.
reference_gravitational_vector (np.ndarray, default: None) – Reference gravitational vector. If None, it uses the default reference gravitational vector of
ahrs.utils.WGS().reference_magnetic_vector (np.ndarray, default: None) – Reference magnetic vector. If None, it uses the default reference magnetic vector of
ahrs.utils.WMM().gyr_noise (float) – Standard deviation of the gyroscope noise. If None given, it is generated from a normal distribution with zero mean. It is then scaled to be in the same units as the gyroscope data.
acc_noise (float) – Standard deviation of the accelerometer noise. If None given, it is generated from a normal distribution with zero mean. It is then scaled to be in the same units as the accelerometer data.
mag_noise (float) – Standard deviation of the magnetometer noise. If None given, it is generated from a normal distribution with zero mean. It is then scaled to be in the same units as the magnetometer data.
rng (np.random.Generator, default: np.random.default_rng(42)) – Random number generator to use. If not given, it uses the default random number generator with seed 42.
Examples
>>> sensors = Sensors(num_samples=1000) >>> sensors.gyroscopes.shape (1000, 3) >>> sensors.accelerometers.shape (1000, 3) >>> sensors.magnetometers.shape (1000, 3) >>> sensors.quaternions.shape (1000, 4)