Mod Library
Sun Devil Rocketry's hardware agnostic utility library
Loading...
Searching...
No Matches
sensor.h File Reference

: Contains functions to interface between SDEC terminal commands and SDR sensor APIs More...

#include "stm32h7xx_hal.h"
#include "imu.h"
#include "gps.h"

Go to the source code of this file.

Classes

struct  _IMU_CONVERTED
 Physical-unit converted accel/gyro/mag data. More...
struct  _STATE_ESTIMATION
struct  _IMU_DATA
 Aggregate struct containing converted IMU data and state estimate. More...
struct  SENSOR_DATA
struct  _BARO_PRESET

Macros

#define SENSOR_DUMP_CODE   ( 0x01 )
#define NUM_SENSORS   ( 38 )
#define SENSOR_DATA_SIZE   ( 128 )

Typedefs

typedef struct _PRESET_DATA PRESET_DATA
typedef struct _IMU_CONVERTED IMU_CONVERTED
 Physical-unit converted accel/gyro/mag data.
typedef struct _STATE_ESTIMATION STATE_ESTIMATION
typedef struct _IMU_DATA IMU_DATA
 Aggregate struct containing converted IMU data and state estimate.
typedef struct SENSOR_DATA SENSOR_DATA
typedef struct _BARO_PRESET BARO_PRESET

Enumerations

enum  SENSOR_STATUS {
  SENSOR_OK = 0 , SENSOR_UNRECOGNIZED_OP , SENSOR_UNSUPPORTED_OP , SENSOR_IMU_FAIL ,
  SENSOR_PT_ERROR , SENSOR_TC_ERROR , SENSOR_LC_ERROR , SENSOR_ACCEL_ERROR ,
  SENSOR_GYRO_ERROR , SENSOR_MAG_ERROR , SENSOR_BARO_ERROR , SENSOR_USB_FAIL ,
  SENSOR_UNRECOGNIZED_SENSOR_ID , SENSOR_FAIL , SENSOR_IT_TIMEOUT
}
enum  MOUNT_ORIENTATION { MOUNT_ORIENTATION_IMU_INVERTED = -1 , MOUNT_ORIENTATION_IMU_NORMAL = 1 }

Functions

SENSOR_STATUS sensor_cmd_execute (uint8_t subcommand)
 Executes a sensor subcommand.
SENSOR_STATUS sensor_dump (SENSOR_DATA *sensor_data_ptr)
 Reads all sensors and fills the sensor data structure.
SENSOR_STATUS sensor_init (PRESET_DATA *preset_data)
 Initializes sensor timing, velocity, and attitude state.
MOUNT_ORIENTATION sensor_get_mount_orientation (void)
 Gets the configured flight-computer mount orientation.
void sensor_set_mount_orientation (MOUNT_ORIENTATION orientation)
 Sets the flight-computer mount orientation.
void sensor_reset_velo (void)
 Resets velocity values to prevent accumulation of drift.
SENSOR_STATUS sensor_body_state (const IMU_CONVERTED *imu_converted, STATE_ESTIMATION *state_estimate)
 Performs sensor fusion on converted IMU data to get body rate.
void sensor_axis_remap (float *x, float *y, float *z)
 Remaps sensor axes for the flight configuration.
void sensor_imu_velo (const IMU_CONVERTED *imu_converted, STATE_ESTIMATION *state_estimate)
 Calculates velocity from acceleration.
void sensor_conv_imu (IMU_CONVERTED *imu_converted, IMU_RAW *imu_raw)
 Converts raw IMU readouts into accelerometer, gyro, and magnetometer data.
float sensor_acc_conv (int16_t readout)
 Converts accelerometer readouts to meters per second squared.
float sensor_gyro_conv (int16_t readout)
 Converts gyro readouts to degrees per second.
void sensor_baro_alt (SENSOR_DATA *sensor_data_ptr)
 Calculates altitude from pressure readings.

Detailed Description

: Contains functions to interface between SDEC terminal commands and SDR sensor APIs

Copyright (c) 2025 Sun Devil Rocketry. All rights reserved.

This software is licensed under terms that can be found in the LICENSE file in the root directory of this software component. If no LICENSE file comes with this software, it is covered under the BSD-3-Clause.

https://opensource.org/license/bsd-3-clause

Typedef Documentation

◆ IMU_CONVERTED

typedef struct _IMU_CONVERTED IMU_CONVERTED

Physical-unit converted accel/gyro/mag data.

Note
Migrated from imu.h/imu_legacy.h to avoid recursive include issues

Function Documentation

◆ sensor_acc_conv()

float sensor_acc_conv ( int16_t readout)

Converts accelerometer readouts to meters per second squared.

Converts a raw accelerometer reading to meters per second squared.

Parameters
readoutRaw accelerometer readout.
Returns
Acceleration in meters per second squared.

Converts accelerometer readouts to meters per second squared.

Parameters
readoutRaw accelerometer readout.
Returns
Acceleration in meters per second squared.

◆ sensor_axis_remap()

void sensor_axis_remap ( float * x,
float * y,
float * z )

Remaps sensor axes for the flight configuration.

Remaps sensor axes according to the flight-computer mounting orientation.

Parameters
xX-axis value to remap.
yY-axis value to remap.
zZ-axis value to remap.

Remaps sensor axes for the flight configuration.

Parameters
xX-axis value to remap.
yY-axis value to remap.
zZ-axis value to remap.

◆ sensor_baro_alt()

void sensor_baro_alt ( SENSOR_DATA * sen_data)

Calculates altitude from pressure readings.

Calculates altitude from the current barometric pressure and temperature.

Parameters
sensor_data_ptrSensor data structure to update.

Calculates altitude from pressure readings.

Parameters
sen_dataSensor data structure to update.

◆ sensor_body_state()

SENSOR_STATUS sensor_body_state ( const IMU_CONVERTED * imu_converted,
STATE_ESTIMATION * state_estimate )

Performs sensor fusion on converted IMU data to get body rate.

Integrates gyro data to update the estimated body attitude and rate.

Parameters
imu_convertedConverted IMU data.
state_estimateState estimate to update.

Performs sensor fusion on converted IMU data to get body rate.

Parameters
imu_convertedConverted IMU data.
state_estimateState estimate to update.

◆ sensor_cmd_execute()

SENSOR_STATUS sensor_cmd_execute ( uint8_t subcommand)

Executes a sensor subcommand.

Executes a sensor subcommand and transmits the requested readings.

Parameters
subcommandSensor subcommand code.
Returns
Sensor operation status.

Executes a sensor subcommand.

Parameters
subcommandSensor subcommand code.
Returns
Sensor operation status.

◆ sensor_conv_imu()

void sensor_conv_imu ( IMU_CONVERTED * imu_converted,
IMU_RAW * imu_raw )

Converts raw IMU readouts into accelerometer, gyro, and magnetometer data.

Converts raw IMU readings into calibrated, remapped sensor data.

Parameters
imu_convertedConverted IMU data to fill.
imu_rawRaw IMU readouts.

Converts raw IMU readouts into accelerometer, gyro, and magnetometer data.

Parameters
imu_convertedConverted IMU data to fill.
imu_rawRaw IMU readouts.

◆ sensor_dump()

SENSOR_STATUS sensor_dump ( SENSOR_DATA * sensor_data_ptr)

Reads all sensors and fills the sensor data structure.

Reads the available sensors and fills the sensor data structure.

Parameters
sensor_data_ptrPointer to the sensor data structure to fill.
Returns
Sensor operation status.

Reads all sensors and fills the sensor data structure.

Parameters
sensor_data_ptrPointer to the sensor data structure to fill.
Returns
Sensor operation status.

◆ sensor_get_mount_orientation()

MOUNT_ORIENTATION sensor_get_mount_orientation ( void )

Gets the configured flight-computer mount orientation.

Get the mount orientation.

Returns
The configured mount orientation.

Gets the configured flight-computer mount orientation.

Returns
The configured mount orientation

◆ sensor_gyro_conv()

float sensor_gyro_conv ( int16_t readout)

Converts gyro readouts to degrees per second.

Converts a raw gyro reading to degrees per second.

Parameters
readoutRaw gyro readout.
Returns
Angular rate in degrees per second.

Converts gyro readouts to degrees per second.

Parameters
readoutRaw gyro readout.
Returns
Angular rate in degrees per second.

◆ sensor_imu_velo()

void sensor_imu_velo ( const IMU_CONVERTED * imu_converted,
STATE_ESTIMATION * state_estimate )

Calculates velocity from acceleration.

Calculates velocity from converted accelerometer measurements.

Parameters
imu_convertedConverted IMU data.
state_estimateState estimate to update.

Calculates velocity from acceleration.

Parameters
imu_convertedConverted IMU data.
state_estimateState estimate to update.

◆ sensor_init()

SENSOR_STATUS sensor_init ( PRESET_DATA * preset_data)

Initializes sensor timing, velocity, and attitude state.

Initializes sensor timing and resets velocity state.

Parameters
preset_dataPointer to the preset calibration data.

Initializes sensor timing, velocity, and attitude state.

Parameters
preset_dataPointer to the preset calibration data.

◆ sensor_reset_velo()

void sensor_reset_velo ( void )

Resets velocity values to prevent accumulation of drift.

Resets accumulated velocity values to prevent drift.

Resets velocity values to prevent accumulation of drift.

◆ sensor_set_mount_orientation()

void sensor_set_mount_orientation ( MOUNT_ORIENTATION orientation)

Sets the flight-computer mount orientation.

Set the mount orientation.

Parameters
orientationMount orientation to use for axis remapping.

Sets the flight-computer mount orientation.

Parameters
orientationThe new mount orientation