MBot Software Library  v1.0
An API documentation to mbot_firmware repository
imu.h
1 
10 #ifndef __MBOT_IMU_H__
11 #define __MBOT_IMU_H__
12 
13 #include <stdio.h>
14 #include <stdint.h>
15 #include <stdbool.h>
16 #include <pico/stdlib.h>
17 #include <hardware/i2c.h>
18 #include <mbot/defs/mbot_pins.h>
19 #include <mbot/defs/mbot_params.h>
20 
21 #include <mbot/imu/bhy_uc_driver.h>
25 #include <mbot/imu/bhy.h>
26 #include <mbot/imu/bhy_support.h>
27 
28 #define ACCEL_2_MS2 -0.000299387 //-(1 / 32767) * 9.81
29 #define GYRO_2_RADS 5.326484731e-07
30 #define MAG_2_UT 0.0625 // 16LSB/uT not certain about this value
31 #define QUAT_2_NORM 6.103515625e-05
32 #define RPY_2_RAD 0.00019174759848570515
33 
34 #define FIFO_SIZE 70
35 #define MAX_PACKET_LENGTH 18
36 #define OUT_BUFFER_SIZE 60
37 
38 typedef struct mbot_bhy_data_t{
41  float accel[3];
42  float gyro[3];
43  float mag[3];
44  float quat[4];
45  float rpy[3];
46  int16_t quat_qlty;
48 
51  int16_t raw_accel[3];
52  int16_t raw_gyro[3];
53  int16_t raw_mag[3];
54  int16_t raw_quat[4];
55  int16_t raw_rpy[3];
56  float accel_to_ms2;
57  float gyro_to_rads;
58  float mag_to_uT;
59  float quat_to_norm;
60  float rpy_to_rad;
63 
64 typedef struct mbot_bhy_config_t{
65  int8_t sample_rate; //12, 25, 50, 100, 200
66  int8_t accel_range; // 2, 4, 6, 8 g
67  int16_t gyro_range; // 125, 250, 500, 1000, 2000
68  int8_t enable_mag;
69  int8_t enable_rpy;
70  int8_t enable_quat;
72 
73 typedef struct bhy_calib_param_t
74 {
75  int16_t x_offset;
76  int16_t y_offset;
77  int16_t z_offset;
78  int16_t radius;
79  uint8_t accuracy;
81 
82 typedef enum {
83  BHI160_SAMPLE_RATE_12_5HZ = 12,
84  BHI160_SAMPLE_RATE_25HZ = 25,
85  BHI160_SAMPLE_RATE_50HZ = 50,
86  BHI160_SAMPLE_RATE_100HZ = 100,
87  BHI160_SAMPLE_RATE_200HZ = 200,
88 } BHI160_SampleRate;
89 
90 typedef enum {
91  BHI160_ACCEL_RANGE_2G = 2,
92  BHI160_ACCEL_RANGE_4G = 4,
93  BHI160_ACCEL_RANGE_8G = 8,
94  BHI160_ACCEL_RANGE_16G = 16
95 } BHI160_AccelRange;
96 
97 typedef enum {
98  BHI160_GYRO_RANGE_125_DPS = 125,
99  BHI160_GYRO_RANGE_250_DPS = 250,
100  BHI160_GYRO_RANGE_500_DPS = 500,
101  BHI160_GYRO_RANGE_1000_DPS = 1000,
102  BHI160_GYRO_RANGE_2000_DPS = 2000
103 } BHI160_GyroRange;
104 
105 int mbot_imu_init(mbot_bhy_data_t* data, mbot_bhy_config_t config);
106 void mbot_imu_print(mbot_bhy_data_t data);
107 mbot_bhy_config_t mbot_imu_default_config(void);
108 
109 
110 
111 #endif
BHY Sensor Driver Support Header File.
driver on MCU for bhy
headfile of driver on MCU for bhy
header file of bhy_uc_driver.c
header file of bhy_uc_driver.c
header file of bhy_uc_driver.c
Definition: imu.h:74
Definition: imu.h:64
Definition: imu.h:38
float mag_to_uT
conversion rate from raw gyroscope to uT
Definition: imu.h:58
float accel[3]
accelerometer (XYZ) in units of m/s^2
Definition: imu.h:41
float rpy_to_rad
conversion rate from raw RPY vector to radians
Definition: imu.h:60
float accel_to_ms2
conversion rate from raw accelerometer to m/s^2
Definition: imu.h:56
float gyro[3]
gyroscope (XYZ) in units of rad/s
Definition: imu.h:42
int16_t quat_qlty
quality estimate from Fuser Core
Definition: imu.h:46
int16_t raw_quat[4]
raw quaternion (WXYZ) from 16-bit ADC
Definition: imu.h:54
float quat[4]
normalized quaternion from Fuser Core
Definition: imu.h:44
int16_t raw_mag[3]
raw magnetometer (XYZ)from 16-bit ADC
Definition: imu.h:53
float mag[3]
magnetometer (XYZ) in units of uT
Definition: imu.h:43
float gyro_to_rads
conversion rate from raw gyroscope to rad/s
Definition: imu.h:57
int16_t raw_accel[3]
raw accelerometer (XYZ) from 16-bit ADC
Definition: imu.h:51
float rpy[3]
Roll(x) pitch(Y) yaw(Z) in radians from Fuser Core.
Definition: imu.h:45
float quat_to_norm
conversion rate from raw quaternion
Definition: imu.h:59
int16_t raw_rpy[3]
raw RPY vector (XYZ) Converted to -2^15 TO 2^15
Definition: imu.h:55
int16_t raw_gyro[3]
raw gyroscope (XYZ)from 16-bit ADC
Definition: imu.h:52