blimputils.gyroscope
gyroscope.py
Module for the Bosch-Sensortec BMI270 gyroscope. This file provides the class Gyroscope for interacting with the gyroscope functionality of the BMI270 sensor via I2C.
- class blimputils.gyroscope.Gyroscope(i2c_addr=104)
Bases:
object
Bosch BMI270 sensor class for gyroscope data.
Provides methods to initialize, configure, and read data from the BMI270 sensor’s gyroscope using I2C communication.
- Parameters:
i2c_addr (int, optional) – The I2C address of the BMI270 sensor. Defaults to
I2C_PRIM_ADDR
.- Raises:
RuntimeError – If the I2C bus is not found.
- read_register(register_address) int
Read a byte from the specified register address.
- Parameters:
register_address (int) – The address of the register to read from.
- Returns:
The byte value read from the register.
- Return type:
int
- write_register(register_address, byte_data) None
Write a byte to the specified register address.
- Parameters:
register_address (int) – The address of the register to write to.
byte_data (int) – The byte value to write to the register.
- load_config_file() None
Load the configuration file to the BMI270 sensor.
This initializes the sensor. If already initialized, it prints a message. Otherwise, it performs the initialization sequence.
- set_mode(mode='performance') None
Set the power mode of the BMI270 sensor.
Configures accelerometer and gyroscope for different power modes. This method primarily affects gyroscope settings relevant to this class.
- Parameters:
mode (str, optional) – The desired power mode. Defaults to “performance”.
- Options mode:
"low_power"
: Low power mode."normal"
: Normal mode."performance"
: Performance mode.
- print_read_register(register_address, output_format='bin') None
Read and print the value of a register in binary or hexadecimal format.
- Parameters:
register_address (int) – The address of the register to read.
output_format (str, optional) – The format for printing the register value. Defaults to
BINARY
.
- Options output_format:
BINARY
: Print in binary format.HEXADECIMAL
: Print in hexadecimal format.
- print_write_register(register_address, byte_data, output_format='bin') None
Write to a register and print its value before and after the write.
- Parameters:
register_address (int) – The address of the register to write to.
byte_data (int) – The byte value to write.
output_format (str, optional) – The format for printing the register value. Defaults to
BINARY
.
- Options output_format:
BINARY
: Print in binary format.HEXADECIMAL
: Print in hexadecimal format.
- enable_aux() None
Enable the auxiliary sensor interface (AUX_IF).
- disable_aux() None
Disable the auxiliary sensor interface (AUX_IF).
- enable_gyr() None
Enable the gyroscope.
- disable_gyr() None
Disable the gyroscope.
- enable_temp() None
Enable the temperature sensor.
- disable_temp() None
Disable the temperature sensor.
- enable_fifo_header() None
Enable the FIFO header.
- disable_fifo_header() None
Disable the FIFO header.
Note: ODR of all enabled sensors needs to be identical when FIFO header is disabled.
- enable_data_streaming() None
Enable data streaming mode.
In this mode, data will not be stored in FIFO.
- disable_data_streaming() None
Disable data streaming mode.
In this mode, data will be stored in FIFO.
- enable_gyr_noise_perf() None
Enable gyroscope noise performance (performance optimized).
- disable_gyr_noise_perf() None
Disable gyroscope noise performance (power optimized).
- enable_gyr_filter_perf() None
Enable gyroscope filter performance (performance optimized).
- disable_gyr_filter_perf() None
Disable gyroscope filter performance (power optimized).
- set_gyr_range(range=0) None
Set the gyroscope measurement range.
- Parameters:
range (int, optional) – The desired gyroscope range. Defaults to
GYR_RANGE_2000
.- Options range:
GYR_RANGE_2000
: ±2000 dps (degrees per second)GYR_RANGE_1000
: ±1000 dpsGYR_RANGE_500
: ±500 dpsGYR_RANGE_250
: ±250 dpsGYR_RANGE_125
: ±125 dps
- set_gyr_odr(odr=9) None
Set the gyroscope Output Data Rate (ODR).
- Parameters:
odr (int, optional) – The desired gyroscope ODR. Defaults to
GYR_ODR_200
(200 Hz).- Options odr:
GYR_ODR_3200
: 3200 HzGYR_ODR_1600
: 1600 HzGYR_ODR_800
: 800 HzGYR_ODR_400
: 400 HzGYR_ODR_200
: 200 HzGYR_ODR_100
: 100 HzGYR_ODR_50
: 50 HzGYR_ODR_25
: 25 Hz
- set_gyr_bwp(bwp=2) None
Set the gyroscope Bandwidth Parameter (BWP).
- Parameters:
bwp (int, optional) – The desired gyroscope BWP. Defaults to
GYR_BWP_NORMAL
.- Options bwp:
GYR_BWP_OSR4
: OSR4 filterGYR_BWP_OSR2
: OSR2 filterGYR_BWP_NORMAL
: Normal filter
- get_sensor_time() int
Get the sensor’s internal timestamp.
- Returns:
The 24-bit sensor timestamp.
- Return type:
int
- get_raw_gyr_data() ndarray
Get raw gyroscope data (X, Y, Z).
Reads LSB and MSB for each axis and combines them.
- Returns:
A NumPy array containing raw [X, Y, Z] gyroscope values as int16.
- Return type:
np.ndarray
- get_raw_temp_data() int
Get raw temperature data from the sensor.
Reads LSB and MSB for temperature and converts to a signed 16-bit integer.
- Returns:
The raw temperature value as a signed 16-bit integer.
- Return type:
int
- get_xyz() ndarray
Get calibrated gyroscope data (X, Y, Z) in rad/s.
Reads raw gyroscope data and converts it to physical units (rad/s) based on the current gyroscope range.
- Returns:
A NumPy array containing calibrated [X, Y, Z] angular velocity in rad/s.
- Return type:
np.ndarray
- get_x() float
Get the calibrated gyroscope data for the X-axis in rad/s.
- Returns:
The X-axis angular velocity in rad/s.
- Return type:
float
- get_y() float
Get the calibrated gyroscope data for the Y-axis in rad/s.
- Returns:
The Y-axis angular velocity in rad/s.
- Return type:
float
- get_z() float
Get the calibrated gyroscope data for the Z-axis in rad/s.
- Returns:
The Z-axis angular velocity in rad/s.
- Return type:
float
- get_t() float
Get the temperature in degrees Celsius.
Reads raw temperature data and converts it to °C using a fixed formula.
- Returns:
The temperature in degrees Celsius.
- Return type:
float