Da Vinci Firmware 1
Firmware for the DaVinci-M rocket avionics board.
Loading...
Searching...
No Matches
utilities.h File Reference

Provides low-level hardware drivers, sensor initialization routines, and various utility functions for the flight computer. More...

#include "bmp3.h"
#include "lsm6dso32_reg.h"
#include "main.h"
#include <stdbool.h>
#include <math.h>
#include "cmsis_os2.h"
Include dependency graph for utilities.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define AIR_DENSITY_KG_M3   1.293f
 
#define SPECIFIC_GAS_CONSTANT   287.0f
 

Enumerations

enum  OFFSET_TYPE { HWOFFSET = 0 , SWOFFSET = 1 , RESET_HWOFFSET = 2 }
 Specifies the type of offset compensation to be used. More...
 

Functions

int32_t imuP_write (void *handle, uint8_t reg_addr, const uint8_t *buf, uint16_t len)
 SPI write function for the primary IMU (LSM6DSO32).
 
int32_t imuP_read (void *handle, uint8_t reg_addr, uint8_t *buf, uint16_t len)
 SPI read function for the primary IMU (LSM6DSO32).
 
int8_t bmp390_P_write (uint8_t reg_addr, const uint8_t *buf, uint32_t len, void *intf_ptr)
 SPI write function for the primary Barometer (bmp390).
 
int8_t bmp390_P_read (uint8_t reg_addr, uint8_t *buf, uint32_t len, void *intf_ptr)
 SPI read function for the primary Barometer (bmp390).
 
int32_t imuB_write (void *handle, uint8_t reg_addr, const uint8_t *buf, uint16_t len)
 SPI write function for the backup IMU (LSM6DSO32).
 
int32_t imuB_read (void *handle, uint8_t reg_addr, uint8_t *buf, uint16_t len)
 SPI read function for the backup IMU (LSM6DSO32).
 
int8_t bmp390_B_write (uint8_t reg_addr, const uint8_t *buf, uint32_t len, void *intf_ptr)
 SPI write function for the backup Barometer (bmp390).
 
int8_t bmp390_B_read (uint8_t reg_addr, uint8_t *buf, uint32_t len, void *intf_ptr)
 SPI read function for the backup Barometer (bmp390).
 
int8_t init_imup (stmdev_ctx_t *imu, lsm6dso32_fs_xl_t acc_full_scale, lsm6dso32_fs_g_t gyro_full_scale, lsm6dso32_odr_xl_t acc_output_data_rate, lsm6dso32_odr_g_t gyro_output_data_rate)
 Initializes the primary IMU (LSM6DSO32).
 
int8_t init_bmp390_p (struct bmp3_dev *bmp390)
 Initializes the primary barometer (BMP390).
 
int8_t init_imuB (stmdev_ctx_t *imu, lsm6dso32_fs_xl_t acc_full_scale, lsm6dso32_fs_g_t gyro_full_scale, lsm6dso32_odr_xl_t acc_output_data_rate, lsm6dso32_odr_g_t gyro_output_data_rate)
 Initializes the backup IMU (LSM6DSO32).
 
int8_t init_bmp390_B (struct bmp3_dev *bmp390)
 Initializes the backup barometer (BMP390).
 
int8_t calibrateIMU (stmdev_ctx_t *imu, uint16_t iterationNum, OFFSET_TYPE type)
 Calibrates the IMU by calculating sensor offsets.
 
int32_t imuP_read_2 (void *handle, uint8_t reg_addr, uint8_t *buf, uint16_t len)
 SPI read function for the primary IMU (LSM6DSO32).
 
float_t readAltitude (float_t seaLevelPa, float_t seaLevelT, float_t currentPa)
 Calculates altitude based on the barometric formula.
 

Detailed Description

Provides low-level hardware drivers, sensor initialization routines, and various utility functions for the flight computer.

Author
Tommaso Gualtierotti & Francesco Abate
Date
2023-12-31

This file acts as a hardware abstraction layer (HAL) and utility library. It contains SPI communication wrappers for STMicroelectronics sensor drivers, high-level initialization and calibration routines for sensors, and common physics calculations needed by the flight software.

Definition in file utilities.h.

Macro Definition Documentation

◆ AIR_DENSITY_KG_M3

#define AIR_DENSITY_KG_M3   1.293f

Definition at line 50 of file utilities.h.

◆ SPECIFIC_GAS_CONSTANT

#define SPECIFIC_GAS_CONSTANT   287.0f

Definition at line 51 of file utilities.h.

Function Documentation

◆ readAltitude()

float_t readAltitude ( float_t  seaLevelPa,
float_t  seaLevelT,
float_t  currentPa 
)

Calculates altitude based on the barometric formula.

This function estimates the altitude in meters above sea level using the international barometric formula. It requires the current pressure, sea level pressure, and sea level temperature as inputs.

Parameters
[in]seaLevelPaThe reference pressure at sea level in Pascals (Pa).
[in]seaLevelTThe standard temperature at sea level in Kelvin (K).
[in]currentPaThe current atmospheric pressure measured by the sensor in Pascals (Pa).
Returns
The calculated altitude in meters (m).
Note
This calculation relies on several physical constants which must be defined elsewhere in the code:
  • GCONST: Standard gravity (~9.80665 m/s^2)
  • RAST: Specific gas constant for dry air (~287.058 J/(kg·K))
  • TAU: Standard temperature lapse rate (~0.0065 K/m)

Definition at line 780 of file utilities.c.

780 {
781 float_t altitude;
782
783
784 altitude = (seaLevelT/TAU)*(1-pow(currentPa/seaLevelPa,RAST*TAU/GCONST));
785
786 return altitude;
787}
#define TAU
Standard temperature lapse rate in K/m.
#define RAST
Specific gas constant for dry air in J/(kg·K).
#define GCONST
Standard gravity in m/s^2.
float_t altitude
Definition main.c:224

References altitude, GCONST, RAST, and TAU.

Referenced by StartSensor_Task().

Here is the caller graph for this function: