Sensors¶
The AURORA sensors library is merely an extension of the zephyr sensor driver api with helper functions, different sampling methods and specific workflows.
IMU¶
Interface for the inertial measurement unit (e.g. LSM6DSO32). Provides orientation (pitch and roll) and acceleration data.
-
ZBUS_CHAN_DECLARE(imu_data_chan)¶
ZBUS channel for IMU data.
-
int imu_poll(const struct device *dev, struct imu_data *out)¶
Take one IMU sample, publish it on the z-bus and hand it back.
In trigger mode the sample was already read off the sensor by the driver’s data-ready handler; this converts and publishes it. Returns -EAGAIN when no new sample has arrived since the last call, which is not an error: the caller is polling faster than the sensor produces.
- Parameters:
dev – Pointer to the IMU device. Ignored by the simulated sources.
out – Optional; receives a copy of the sample.
- Return values:
0 – on success.
-EAGAIN – in trigger mode when no new sample is waiting.
-errno – Negative errno on failure.
-
int imu_init(const struct device *dev)¶
Initialize the IMU.
Checks device readiness and, with CONFIG_IMU_TRIGGER, installs the library’s own data-ready handler.
A device that is present but cannot deliver that trigger reports -ENOTSUP: the device is usable, and the caller is expected to fall back to polling it with imu_poll() rather than treat the IMU as absent.
- Parameters:
dev – Pointer to the IMU device. Ignored by the simulated sources.
- Return values:
0 – on success.
-EINVAL – if
devis NULL.-ENODEV – if the device is not ready.
-ENOTSUP – if the device is ready but has no data-ready trigger.
-ENODATA – if a simulated source has no sample data.
-
int imu_sensor_value_to_acceleration(const struct imu_data *data, double *acc_out)¶
calculate the average acceleration from IMU sensor values in m/s^2.
- Parameters:
data – Pointer to the IMU sensor data
acc_out – Output for average acceleration in m/s^2. Must be valid pointer to a double.
- Return values:
0 – on success.
-EINVAL – if
dataoracc_outis NULL
-
int imu_sensor_value_to_orientation(const struct imu_data *data, double dt_s, const double gyro_bias[3], double *orientation)¶
Calculate the orientation (yaw, pitch, roll) from IMU sensor values.
Uses
CONFIG_IMU_UP_AXIS_*to remap the body frame so the configured up-axis aligns with world Z, making the result independent of IMU mounting orientation. The two remaining body axes are taken in cyclic order as the local forward (X) and lateral (Y) axes.Output convention (degrees):
orientation[0] = yaw (tilt of the forward axis from horizontal)
orientation[1] = pitch (tilt of the lateral axis from horizontal)
orientation[2] = roll (rotation about the up axis — the rocket’s long axis / flight path)
Yaw and pitch are derived from the accelerometer (gravity-dominated, meaningful only during quasi-static phases). Roll is unobservable from a static accelerometer reading because it is the rotation about the gravity vector itself; it is integrated from the gyroscope.
The caller owns the roll state:
orientation[2] is read on input as the previous roll angle, advanced bygyro_up* dt_s, and written back wrapped to [-180, 180] degrees. Passdt_s<= 0 to leave the roll value untouched (e.g. on the very first sample, before a dt is known).- Parameters:
data – Pointer to the IMU sensor data.
dt_s – Elapsed time in seconds since the previous call, used to integrate roll. Pass 0 to skip integration (yaw and pitch are still updated).
gyro_bias – Optional bias to subtract from the gyro reading before integration, in rad/s. Pass NULL to skip bias correction.
orientation – In/out: [yaw, pitch, roll] in degrees. Yaw and pitch are overwritten; roll is read and updated. Must be a valid pointer to a 3-element double array.
- Return values:
0 – on success.
-EINVAL – if
dataororientationis NULL.
-
IMU_NUM_AXES¶
Number of axes for IMU measurements.
-
struct imu_data¶
- #include <imu.h>
IMU measurement data structure.
carries the measurement data from the IMU, including accelerometer and gyroscope readings for the x, y, and z axes. This struct is used as a z-bus message payload for IMU data updates
Attitude¶
Gyro-integrated body-frame gravity tracker. Anchors the body-frame “up”
direction from a stationary accelerometer calibration window (typically
during SM_ARMED), then propagates the gravity vector through flight
using gyro measurements to project body-frame acceleration onto the
world vertical axis for the filter.
Mounting orientation is configured via the CONFIG_IMU_UP_AXIS_*
choice; calibration window length via CONFIG_IMU_CALIBRATION_SAMPLES.
-
int attitude_init(struct attitude *att)¶
Initialize (or reset) the attitude tracker.
Clears calibration sums, biases, and sets the body-frame gravity vector to the axis selected via
CONFIG_IMU_UP_AXIS_*, pointing opposite to “up” (i.e. in the direction gravity pulls the rocket).- Parameters:
att – Pointer to tracker state.
- Return values:
0 – on success.
-EINVAL – if
attis NULL.
-
int attitude_calibrate_sample(struct attitude *att, const double accel[3], const double gyro[3])¶
Add one IMU sample to the calibration accumulator.
Must only be called while the rocket is stationary.
- Parameters:
att – Pointer to tracker state.
accel – Body-frame accelerometer reading in m/s^2.
gyro – Body-frame gyroscope reading in rad/s.
- Return values:
0 – on success.
-EINVAL – if any pointer is NULL.
-EALREADY – if calibration has already been finalized.
-
int attitude_calibrate_converged(const struct attitude *att)¶
Query whether the calibration accumulator is ready to finish.
True once the running gyro-bias mean has stopped changing meaningfully between convergence checkpoints, or once a fixed multiple of
CONFIG_IMU_CALIBRATION_SAMPLESsamples have been accumulated (a safety ceiling), whichever comes first. Always false beforeCONFIG_IMU_CALIBRATION_SAMPLESsamples have been accumulated.- Parameters:
att – Pointer to tracker state.
- Return values:
1 – if ready to call attitude_calibrate_finish().
0 – if not yet ready.
-EINVAL – if
attis NULL.
-
int attitude_calibrate_finish(struct attitude *att)¶
Finalize calibration and seed the body-frame gravity vector.
Averages the accumulated samples to compute accelerometer bias, gyro bias, and gravity magnitude, then seeds
g_bfrom the Kconfig mounting axis. After this call attitude_is_calibrated returns non-zero.- Parameters:
att – Pointer to tracker state.
- Return values:
0 – on success.
-EINVAL – if
attis NULL.-ENODATA – if no samples have been accumulated.
-
int attitude_update(struct attitude *att, const double accel[3], const double gyro[3], double dt_s, double *accel_vert_out)¶
Propagate the gravity vector with a new IMU sample and project accelerometer into world vertical.
Subtracts biases, rotates the body-frame gravity vector by the gyro-integrated body rotation (small-angle Rodrigues), renormalizes, and returns the gravity-removed world-frame vertical acceleration (positive = up).
- Parameters:
att – Pointer to tracker state.
accel – Body-frame accelerometer reading in m/s^2.
gyro – Body-frame gyroscope reading in rad/s.
dt_s – Elapsed time in seconds since the previous update.
accel_vert_out – Output: world-frame vertical accel in m/s^2, gravity-removed (positive = up).
- Return values:
0 – on success.
-EINVAL – if any pointer is NULL or
dt_s<= 0.-ENODATA – if calibration has not been finalized.
-
int attitude_is_calibrated(const struct attitude *att)¶
Query whether calibration has been finalized.
- Parameters:
att – Pointer to tracker state.
- Return values:
1 – if calibrated, 0 if not, -EINVAL if
attis NULL.
-
ATTITUDE_NUM_AXES¶
Number of axes handled by the attitude tracker.
-
struct attitude¶
- #include <attitude.h>
Attitude tracker state.
Barometer¶
Interface for the barometric pressure sensor. Can compute altitude estimates from pressure readings.
-
ZBUS_CHAN_DECLARE(baro_data_chan)¶
ZBUS channel for baro data.
-
int baro_measure(const struct device *dev, struct baro_data *out)¶
Take one baro sample, publish it on the z-bus and hand it back.
In trigger mode the sample was already read off the sensor by the driver’s data-ready handler; this converts and publishes it. Returns -EAGAIN when no new sample has arrived since the last call, which is not an error: the caller is polling faster than the sensor produces.
- Parameters:
dev – Pointer to the barometric sensor device. Ignored by the simulated sources.
out – Optional; receives a copy of the sample.
- Return values:
0 – on success.
-EAGAIN – in trigger mode when no new sample is waiting.
-errno – Negative errno on failure.
-
int baro_init(const struct device *dev)¶
Initialize the barometric pressure sensor.
Checks device readiness and, with CONFIG_BARO_TRIGGER, installs the library’s own data-ready handler.
A device that is present but cannot deliver that trigger reports -ENOTSUP: the device is usable, and the caller is expected to fall back to polling it with baro_measure() rather than treat the barometer as absent.
- Parameters:
dev – Pointer to the barometric sensor device. Ignored by the simulated sources.
- Return values:
0 – on success.
-EINVAL – if
devis NULL.-ENODEV – if the device is not ready.
-ENOTSUP – if the device is ready but has no data-ready trigger.
-ENODATA – if a simulated source has no sample data.
-
int baro_set_reference(double ref_kpa)¶
Force the ground-level reference pressure to a known value.
Overrides the reference unconditionally, including one already being tracked. Calling this is not required for normal operation: baro_sensor_value_to_altitude establishes the reference from the first sample and keeps it on ambient by itself. It exists for callers that know the true pad pressure independently (an operator entering a QFE, a test fixture pinning a baseline).
The value does not stay pinned. While the vehicle is on the pad the next samples resume tracking from it, so a forced reference is a starting point, not a latch. To hold one exactly, set it once the vehicle is no longer on the pad.
- Parameters:
ref_kpa – Ground-level pressure in kilopascals.
- Return values:
0 – on success.
-EINVAL – if
ref_kpais not positive.
-
int baro_sensor_value_to_altitude(const struct sensor_value *press, double *altitude_out)¶
Convert a pressure reading to altitude AGL.
Uses the hypsometric formula (ISA troposphere model) against the ground reference pressure. The first call seeds that reference and subsequent calls keep it low-pass tracked onto ambient for as long as the vehicle is on the pad (see
BARO_REF_TRACK_TAU_MS), then freeze it at liftoff. So on the pad this reads ~0 m however far the sensor has drifted since power-on, and in flight it reads height above the pad.- Parameters:
press – Barometric pressure as sensor_value.
altitude_out – Altitude in meters above the reference level.
- Return values:
0 – on success.
-EINVAL – if
pressoraltitude_outis NULL.-EDOM – if the pressure or the resulting altitude is not usable.
-
struct baro_data¶
- #include <baro.h>
baro measurement data structure.
carries the measurement data from the baro including temperature and pressure readings. This struct is used as a z-bus message payload for baro data updates