by Drew Owens
Open-source 15-DoF XL330 biped goose robot with Spine molecule PCB, 3D-printed chassis, and Isaac Lab to MuJoCo sim-to-real RL stack
main
Drew Owens
Publish Microgoose Rev A full-stack hardware, CAD, datasheet, and 7-stage RL stack
e843249
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
/*
* bmi270_min.h
* Minimal Bosch BMI270 6-axis IMU I2C driver for onboard torso IMU (0x68)
* and head sensor cable IMU (0x69) on STM32G431 I2C1 (PB6 SCL, PB7 SDA).
*/
#ifndef MICROGOOSE_BMI270_MIN_H
#define MICROGOOSE_BMI270_MIN_H
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
/* Bosch BMI270 Register Map */
#define BMI270_REG_CHIP_ID 0x00U
#define BMI270_REG_ERR_REG 0x02U
#define BMI270_REG_STATUS 0x03U
#define BMI270_REG_ACC_X_LSB 0x0CU /* 0x0C..0x11: Accel XYZ, 0x12..0x17: Gyro XYZ */
#define BMI270_REG_GYR_X_LSB 0x12U
#define BMI270_REG_INTERNAL_STATUS 0x21U
#define BMI270_REG_ACC_CONF 0x40U
#define BMI270_REG_ACC_RANGE 0x41U
#define BMI270_REG_GYR_CONF 0x42U
#define BMI270_REG_GYR_RANGE 0x43U
#define BMI270_REG_INIT_CTRL 0x59U
#define BMI270_REG_INIT_ADDR_0 0x5BU
#define BMI270_REG_INIT_DATA 0x5EU
#define BMI270_REG_PWR_CONF 0x7CU
#define BMI270_REG_PWR_CTRL 0x7DU
#define BMI270_REG_CMD 0x7EU
#define BMI270_CHIP_ID_EXPECTED 0x24U
#define BMI270_CMD_SOFTRESET 0xB6U
#define BMI270_INTERNAL_STATUS_INIT_OK 0x01U
/* Configuration values: 200 Hz ODR, normal filter, +/-4g accel, +/-1000 dps gyro */
#define BMI270_ACC_CONF_200HZ_NORM 0xA9U
#define BMI270_ACC_RANGE_4G 0x01U /* 8192 LSB/g */
#define BMI270_GYR_CONF_200HZ_NORM 0xE9U
#define BMI270_GYR_RANGE_1000DPS 0x01U /* 32.768 LSB/(deg/s) */
#define BMI270_PWR_CTRL_ACC_GYR_TEMP 0x0EU
typedef bool (*mg_i2c_read_fn)(uint8_t dev_addr, uint8_t reg_addr, uint8_t *buf, size_t len, void *ctx);
typedef bool (*mg_i2c_write_fn)(uint8_t dev_addr, uint8_t reg_addr, const uint8_t *buf, size_t len, void *ctx);
typedef struct {
uint8_t i2c_addr;
mg_i2c_read_fn i2c_read;
mg_i2c_write_fn i2c_write;
void *bus_ctx;
bool initialized;
float roll_rad;
float pitch_rad;
float yaw_rad;
} bmi270_dev_t;
typedef struct {
int16_t raw_acc[3];
int16_t raw_gyr[3];
int16_t accel_mg[3];
int16_t gyro_mrad_s[3];
float accel_m_s2[3];
float gyro_rad_s[3];
float projected_gravity[3];
} bmi270_sample_t;
/* Initialize BMI270 with optional config blob (pass NULL/0 when pre-loaded or simulated) */
bool bmi270_init(
bmi270_dev_t *dev,
uint8_t i2c_addr,
mg_i2c_read_fn read_fn,
mg_i2c_write_fn write_fn,
void *bus_ctx,
const uint8_t *config_blob,
size_t config_len
);
/* Convert a 12-byte little-endian burst (0x0C..0x17) into physical and fixed-point units */
void bmi270_convert_burst12(const uint8_t raw12[12], bmi270_sample_t *out);
/* Read a 12-byte burst over I2C and update complementary roll/pitch + projected gravity */
bool bmi270_read_sample(bmi270_dev_t *dev, float dt_sec, bmi270_sample_t *out);
#endif /* MICROGOOSE_BMI270_MIN_H */