yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
MicroROS V2 Robot Car📖
01.Introduction
  • 0.Unboxing Video
  • 1. Readme Learning Route
  • 2. Must Read Before Use
  • 3. Introduction to MicroROS V2 Control Board
  • 4. Introduction to LiDAR
  • 5. Introduction to ESP32 Camera Module
  • 6. FAQ
  • 7. About Charging
02.Assembly course
  • Assembly Video
03.Preparation
  • 1. Quickly Start
  • 2. Write Firmware
  • 3. Install VM and Start System
  • 4. Configure VM and Connect Robot
  • 5. Connect to MicroROS Agent
04.Quick start control course
  • 1. VM Keyboard Remote Control
  • 2. VM Handle Remote Control
  • 3. USB Handle Control
05.Robot control course
  • 1. Robot Information Release
  • 2. Robot Keyboard Control
  • 3. Robot Handle Control
  • 4. Robot State Estimation
  • 5. Linear Speed Calibration
  • 6. Angular Velocity Calibration
  • 7. Robot URDF Model
06.Lidar course
  • 1. Precautions for LiDAR Mapping and Navigation
  • 2. Lidar Avoid
  • 3. Lidar Following
  • 4. Lidar Guard
  • 5. Lidar Patrol
  • 6. Gmapping Mapping
  • 7. Cartographer Mapping
  • 8. Cartographer Quickly Repositioning Navigation
  • 9. Slam Toolx Mapping
  • 10. Navigation2 Single Point Navigation
  • 11. Navigation2 Multi Point Navigation
  • 12. Ros Robot App Mapping And Navigation
07.Road network planning
  • 1. Introduction to Road Network Planning and Quick Start
  • 2. Build a Pose Map
  • 3. Road Network Annotation
  • 4. Planning and Navigation Between Road Networks
  • 5. Road Network Navigation in Any Pose
  • 6. Path Replanning
08.Vision basic course
OpenCV Image Processing
  • 1. Introduction to OpenCV Source CV
  • 2. Open Source CV Geometric Transformation
  • 3. Open Source CV Image Processing and Drawing Text Line Segments
  • 4. Open Source CV Image Beautification
09.Visual General Course (For Standard&Superior version)
4. Yolov11&26 Visual Recognition
  • 1. YOLO Environment Setup
  • 2. CLI Usage
  • 3. Object Detection
  • 4. Instance Segmentation
  • 5. Pose Estimation
  • 6. Image Classification
  • 7. Oriented Bounding Boxes Object Detection
  • 8. Model Prediction
1. ESP32 Visual Recognition Module Configuration
  • 1. Serial Port Configuration WiFi Instructions
  • 2. Use ESP32 Camera Module in Robot Car
  • 3. Servo PTZ Calibration
2. OpenCV Visual Recognition
  • 1. Human Pose Estimation
  • 2. Object Detection
  • 3. AR Vision
  • 4. QR Code
  • 5. Color Recognition
  • 6. Facial Recognition
  • 7. AprilTag Machine Code Recognition
3. Mediapipe Visual Recognition
  • 1. Hand Detection
  • 2. Pose Detection
  • 3. Holistic Detection
  • 4. Facial Detection
  • 5. Facial Recognition
  • 6. Facial Special Effects
  • 7. 3D Object Recognition
  • 8. Brush
  • 9. Gesture Recognition
  • 10. Palm Target Localization
  • 11. Fingertip Trajectory Recognition
10.Visual Advanced Course (Just for Standard version)
1. Visual Control
  • 1. QR Code Recognition Control Action
  • 2. AprilTag Control Car Action Group
  • 3. Gesture Control Car Action Group
  • 4. Visual Line Tracking
2. Visual Tracking
  • 1. Color Tracking
  • 2. Facial Tracking
  • 3. QR Code Tracking
  • 4. Object Recognition And Tracking
  • 5. Mediapipe Palm Tracking
  • 6. Mediapipe Gesture Tracking
  • 7. Mediapipe Human Pose Tracking
  • 8. KCF Object Tracking
  • 9. AprilTag Machine Code Tracking
3. Visual Following
  • 1. Color Follow
  • 2. Face Follow
  • 3. QR Code Follow
  • 4. Mediapipe Palm Follow
  • 5. Mediapipe Gesture Follow
  • 6. Mediapipe Human Posture Follow
  • 7. AprilTag Machine Code Follow
  • 8. Object Follow
11.Visual Advanced Course (Just for Superior version)
1. Visual Control
  • 1. QR Code Recognition Control Action
  • 2. AprilTag Control Car Action Group
  • 3. Gesture Control Car Action Group
  • 4. Visual Line Tracking
2. Visual Tracking
  • 1. Color Tracking
  • 2. Facial Tracking
  • 3. QR Code Tracking
  • 4. YOLO Object Recognition and Tracking
  • 5. Mediapipe Palm Tracking
  • 6. Mediapipe Gesture Tracking
  • 7. Mediapipe Human Pose Tracking
  • 8. KCF Object Tracking
  • 9. AprilTag Machine Code Tracking
3. Visual Follow
  • 1. Color Follow
  • 2. Face Follow
  • 3. QR Code Follow
  • 4. Mediapipe Palm Follow
  • 5. Mediapipe Gesture Follow
  • 6. Mediapipe Human Pose Follow
  • 7. AprilTag Machine Code Follow
  • 8. Object Follow
12.AI Large Model Basic and Applications Course
1. AI Large Model Preparation
  • 1.AI Large Model Preparation
2. AI Large Model Basic Course
  • 1. AI Large Model Types and Principles
  • 2. RAG Retrieval Augmented and Training Samples
  • 3. Embodied Intelligent System Architecture
  • 4. Embodied Intelligence Core Source Code
3. AI Large Model Development
  • 1. Register Model Service Account
  • 2. Configure API KEY
  • 3. Dify Introduction
  • 4. Dify Basic Features
  • 5. RAG Knowledge Base Deployment
  • 6. AI Application Development Chatbot
  • 7. RAG Knowledge Base and Chatbot
  • 8. AI Agent Workflow
4. AI Large Model (Text Version)
  • 1. Semantic Understanding and Instruction Following
  • 2. Multimodal Visual Understanding
  • 3. Multimodal Visual Understanding + Basic Control
  • 4. Multimodal Visual Understanding + Object Following
  • 5. Multimodal Visual Understanding + Visual Line Following
  • 6. Multimodal Visual Understanding + SLAM Navigation
  • 7. Multimodal Visual Understanding + SLAM Navigation + Visual Line Following
  • 8. Multimodal Visual Understanding + SLAM Navigation + Object Following
  • 9. Intent Inference + Multimodal Visual Understanding + SLAM Navigation
13.Openclaw Basics Course
  • 1. Openclaw Introduction
  • 2. Openclaw Core Concepts
  • 3. Openclaw Api-Key Configuration
  • 4. Openclaw Switching Models
  • 5. Openclaw System Prompt
  • 6. Openclaw Common CLI Command
14. Openclaw Interaction Course
  • 1. Openclaw Webchat Interaction
  • 2. Openclaw Tui Interaction
  • 3. Openclaw Whatsapp Interaction
15.Openclaw Development Course
  • 1. Openclaw Robot Mcp Service Integration
  • 2. Robot CLI Command Tools
  • 3. Robot-Control Plugin Tools
  • 4. Openclaw Skills Development
  • 5. Openclaw Scheduled Tasks
  • 6. Openclaw Multi Agent System
  • 7. Openclaw Proactive Interaction
  • 8. Openclaw Vector Memory
16.Openclaw Embodied Intelligence Course
  • 1. OpenClaw Natural Interaction + Basic Control
  • 2. OpenClaw Natural Interaction + Slam Navigation
  • 3. OpenClaw Natural Interaction + Multimodal Visual Understand
  • 4. OpenClaw Natural Interaction + Multimodal Visual Understand + Slam Navigation + Visual Follow
  • 5. OpenClaw Natural Interaction + Multimodal Visual Understand + Slam Navigation + Visual Track
17.Multi-machine Course
  • 1. Multi Machine Handle Control
  • 2. Multi Machine Keyboard Control
  • 3. Multi Machine Navigation
18.MicroROS-V2 Control Board Development Environment
  • 1. Set Up the ESP32-IDF Development Environment
  • 2. ESP32-IDF Configuration Tool
  • 3. ESP Flash Tool Flashing Firmware
  • 4. Install ESP32 Microros Components
  • 5. Install And Start Microros Agent
19.MicroROS-V2 Control Board ESP32 Basic Course
  • 1. Led Light Up
  • 2. Button Function
  • 3. Drive Buzzer
  • 4. Oled
  • 5. Usb Host Function
  • 6. Serial Communication
  • 7. Battery Voltage Detection
  • 8. Drive Pwm Servo
  • 9. Drive Motors
  • 10. Read Motor Encoder Data
  • 11. Pid Motor Speed Control
  • 12. Robot Kinematics Analysis Theory
  • 13. Read Imu Data
  • 14. Read Lidar Data
  • 15. Flash Data Storage
  • 16. Custom Partition Table
  • 17. Bluetooth Communication
  • 18. Wifi Connection
  • 19. ESP32 Visual Recognition Module
20.MicroROS-V2 Control Board Micro_ros Basic Course
  • 1. Publish Topics
  • 2. Subscribe To Topics
  • 3. Multi Topic Subscription And Publishing
  • 4. Subscribe To Buzzer Topic
  • 5. Subscribe To Pwm Servo Topic
  • 6. Subscribe To Speed Control Topic
  • 7. Publish Odometry Topic
  • 8. Publish Imu Data Topic
  • 9. Publish Lidar Data Topic
21. Linux System Course
  • 1.Introduction to Linux system
  • 2.Ubuntu file system
  • 3.Ubuntu common commands
  • 4.Ubuntu common editors
  • 5.Ubuntu software operation commands
  • 6.Virtual machine installation
  • 7.SSH remote control
  • 8.VNC remote control
  • 9.Transfer files remotely
  • 10.Driver library and communication
  • 11.Static IP and hotspot mode
  • 12.Bind device ID
  • 13.Capacity expansion and resource allocation
  • 14.Update system software sources
  • 15.Set root user password
  • 16.sudo free password
  • 17.Connect to WiFi network
  • 18.View system version
  • 19.Customized service management
  • 20.Back up system image
22.Docker Course
  • 1.Docker overview and docker installation
  • 2.Common commands for docker image containers
  • 3.Docker images deeply understand and publish images
23.ROS Basic Course
  • 1.Introduction to ROS2
  • 2.ROS2 install Humble
  • 3.ROS2 development environment
  • 4.ROS2 workspace
  • 5.ROS2 function package
  • 6.ROS2 node
  • 7.ROS2 topic communication
  • 8.ROS2 service communication
  • 9.ROS2 action communication
  • 10.ROS2 custom interface message
  • 11.ROS2 parameter service case
  • 12.ROS2 meta-function package
  • 13.ROS2 distributed communication
  • 14.ROS2 DDS
  • 15.ROS2 time related API
  • 16.ROS2 common command tools
  • 17.ROS2 rviz2 use
  • 18.ROS2 rqt toolbox
  • 19.ROS2 Launch startup file configuration
  • 20.ROS2 recording and playback tool
  • 21.ROS2 URDF model
  • 22.ROS2 Gazebo simulation platform
  • 23.ROS2 TF2 coordinate transformation
Download
  • Mapping_APP(iOS_Android)
  • Code
  • Software_Tools
  • VM_System_File
  • 3D_Model_File
  • ESP32_Firmware
  • Dify LLM Base
  • Instruction_Manual
  • VMware
Download ZIP

Welcome to MicroROS V2 Robot Car repository

13. Read Imu Data

Reading IMU Data

I. Experiment Objective

Learn how to read the raw data of the QMI8658 six-axis inertial sensor (accelerometer + gyroscope) through the I2C bus on the ESP32-S3 platform, and solve it into Euler angles (roll, pitch, yaw). Also master the basic methods of sensor calibration, attitude fusion algorithms (AHRS), and attitude stability analysis.

II. Experiment Principle

1. Keywords

KeywordExplanation
IMU (Inertial Measurement Unit)A sensor module that integrates an accelerometer and a gyroscope. The accelerometer measures three-axis acceleration (including the gravity component), and the gyroscope measures three-axis angular velocity. The QMI8658 is a six-axis IMU that does not include a magnetometer.
AccelerometerMeasures the acceleration on three axes (unit m/s²). At rest, it detects the direction of gravity (vertically downward) and is used to determine the pitch angle and roll angle. In this experiment, the default range is ±8g and the sensitivity is 1<<13.
GyroscopeMeasures the angular velocity on three axes (unit rad/s). Integration yields the angle change. In this experiment, the default range is ±1024 dps and the sensitivity is 32. At startup, the zero offset must be calibrated to reduce temperature drift.
AHRS (Attitude and Heading Reference System)An attitude solving algorithm that fuses accelerometer and gyroscope data. This experiment uses the open-source Fusion library, which performs six-axis fusion (no magnetometer), outputs quaternions, and converts them to Euler angles. Uses the North-West-Up (NWU) coordinate convention.
Quaternion / Euler angleA quaternion (q0,q1,q2,q3) is a mathematical representation of attitude with no gimbal-lock problem. Euler angles (roll, pitch, yaw) convert the quaternion into intuitive angle values. Since there is no magnetometer, yaw drifts over time.

2. Technical Architecture

The program adopts a layered driver structure: I2C master driver → QMI8658 sensor driver (platform adaptation layer) → attitude fusion encapsulation layer (Fusion AHRS library) → attitude stability analyzer.

main/main.c
    └── imu_attitude_fusion_init() / update_imu_data() / imu_attitude_fusion_update()
         └── components/imu_attitude_fusion/     Attitude fusion encapsulation layer
              ├── components/qmi8658b/          QMI8658 sensor driver (register read/write, data conversion)
              │    └── components/qmi8658b_port_esp32/  ESP32 platform adaptation (binding I2C callbacks)
              │         └── components/i2c_master/      I2C master driver (SCL:GPIO39, SDA:GPIO40)
              └── components/Fusion/                   Third-party AHRS algorithm library
         └── components/attitude_stability_analyzer/    Attitude stability analyzer (window statistics)

The main loop runs every 10ms: read sensor data → subtract the gyroscope zero offset → perform AHRS fusion → get Euler angles → perform a stability analysis once per second.

III. Experiment Steps

1. Hardware Preparation

HardwareRequirement
MicroROS-V2 control board✅ Required
USB data cable (Type-C)✅ Required

2. Prerequisites

  1. Set up the ESP32-IDF development environment

  2. Connect the MicroROS-V2 control board to the computer via USB

  3. Place the control board horizontally and still so that the gyroscope can be calibrated at startup

3. Compile and Flash

​x

cd ~/esp/base_samples/read_imu
source ~/esp/esp-idf/export.sh
idf.py build flash monitor

To exit the monitor: press Ctrl + ].

4. Stopping Method

In the terminal, press Ctrl+] to exit the serial monitor.

IV. Experiment Result

After flashing and running the program, you can see the following output in the serial monitor terminal:

xxxxxxxxxx
hello yahboom
I (1002) IMU_MAIN: Nice to meet you!
I (1012) I2C_MASTER: Init I2C master:SCL->GPIO39, SDA->GPIO40
qmi8658 slave = 0x6b WhoAmI = 0x05
...
I (6012) IMU_MAIN: Calibration complete, starting stability analysis
I (6012) IMU_MAIN: First ok Euler angles: roll = 0.52, pitch = -0.83, yaw = 0.02
I (6022) IMU_MAIN: Euler angles: roll = 0.53, pitch = -0.84, yaw = 0.05
I (6032) IMU_MAIN: Euler angles: roll = 0.51, pitch = -0.82, yaw = -0.01
  • The first 5 seconds are the calibration phase, during which no Euler angles are output

  • After calibration is complete, roll (roll angle), pitch (pitch angle), and yaw (yaw angle) are output every 10ms

  • When the control board is horizontal and still, roll and pitch fluctuate around 0° (usually within ±1°), and yaw represents the current heading angle, which is close to 0° by default after a reset/reboot

  • Slowly tilt or rotate the control board, and the Euler angles will change accordingly

V. Program Analysis

Source code paths:

  • Firmware source: ~/esp/base_samples/read_imu/main/main.c

  • Attitude fusion: ~/esp/base_samples/read_imu/components/imu_attitude_fusion/imu_attitude_fusion.h, imu_attitude_fusion.c

  • I2C driver: ~/esp/base_samples/read_imu/components/i2c_master/i2c_master.h, i2c_master.c

  • QMI8658 driver: ~/esp/base_samples/read_imu/components/qmi8658b/qmi8658b.h, qmi8658b.c

1. Directory Structure

xxxxxxxxxx
read_imu/
├── CMakeLists.txt
├── main/
│   ├── CMakeLists.txt
│   └── main.c
└── components/
    ├── qmi8658b/                      # QMI8658 sensor driver
    │   ├── qmi8658b.h
    │   └── qmi8658b.c
    ├── qmi8658b_port_esp32/           # ESP32 platform adaptation layer
    │   ├── qmi8658b_port_esp32.h
    │   └── qmi8658b_port_esp32.c
    ├── i2c_master/                    # I2C master driver
    │   ├── i2c_master.h
    │   └── i2c_master.c
    ├── imu_attitude_fusion/           # Attitude fusion encapsulation layer
    │   ├── imu_attitude_fusion.h
    │   └── imu_attitude_fusion.c
    ├── Fusion/                        # Third-party AHRS fusion algorithm library
    │   ├── Fusion.h
    │   ├── FusionAhrs.h / .c
    │   ├── FusionBias.h / .c
    │   ├── FusionMath.h
    │   ├── FusionEuler.h
    │   └── ...
    └── attitude_stability_analyzer/   # Attitude stability analyzer
        ├── attitude_stability_analyzer.h
        └── attitude_stability_analyzer.c

2. Main Program Logic

main/main.c implements the IMU data reading and attitude solving flow:

  1. Call imu_attitude_fusion_init() to initialize the I2C, the QMI8658 sensor, and the Fusion algorithm library

  2. Call fusion_param_setting() to set the sample rate (100Hz) and the gyroscope range (1024 dps)

  3. Call calibrate_gyro_startup_bias() to perform gyroscope startup bias calibration (sampling 300 times to calculate the average)

  4. Initialize the attitude stability analyzer (window size 300 samples)

  5. Main loop:

    • Wait for a 5-second calibration time; calibrate_time_counter increments until it reaches CALIBRATION_WAIT_TIME_MS(5000ms)/ 10 = 500 times

    • After calibration, set calibrate_ok_flag to 1 and start displaying Euler angles

    • Read sensor data every 10ms and update the AHRS fusion

    • Perform a stability analysis calculation once per second

Key configuration constants:

xxxxxxxxxx
#define FUSION_SAMPLE_RATE_HZ     (100.0f)   // Sample rate 100Hz
#define FUSION_GYRO_RANGE_DPS     (1024.0f)  // Gyroscope range ±1024 dps
#define ANALYZER_WINDOW_SIZE      (300U)     // Stability analysis window of 300 samples
#define CALIBRATION_WAIT_TIME_MS  (5000U)    // Calibration wait time 5 seconds

3. Key Components

I2C master driver

Files: components/i2c_master/i2c_master.h, components/i2c_master/i2c_master.c

Pin configuration:

Parameter definition file: ~/esp/base_samples/read_imu/components/i2c_master/i2c_master.h

SignalGPIODescription
SCLGPIO39I2C clock line
SDAGPIO40I2C data line

Parameter configuration:

  • I2C master number: 0 (I2C_MASTER_NUM = 0)

  • Communication frequency: 400 KHz (standard fast mode)

  • Timeout: 1000ms

Core functions:

  • I2C_Master_Init() — Initializes the I2C master, configures the SCL/SDA pins, and installs the driver

  • I2C_Master_Read(uint8_t addr, uint8_t reg, uint16_t len, uint8_t* data) — Reads multi-byte data from the register of the specified device address

  • I2C_Master_Write_Byte(uint8_t addr, uint8_t reg, uint8_t data) — Writes a single byte of data to the register of the specified device address

QMI8658 sensor driver

Files: components/qmi8658b/qmi8658b.h, components/qmi8658b/qmi8658b.c

The QMI8658 is a six-axis inertial measurement unit (IMU) that integrates a three-axis accelerometer and a three-axis gyroscope.

Device information:

  • I2C slave device address: 0x6b (ADDR_L) or 0x6a (ADDR_H)

  • WhoAmI register value: 0x05

  • Reset register: Qmi8658Register_Reset = 96, writing 0xB0 triggers a soft reset

Register map (partial, key registers):

RegisterAddressDescription
WhoAmI0x00Chip ID (should be 0x05)
Ctrl10x02Interrupt and clock configuration
Ctrl20x03Accelerometer configuration (range + ODR)
Ctrl30x04Gyroscope configuration (range + ODR)
Ctrl70x08Sensor enable control
Ax_L ~ Az_H0x35~0x3AAccelerometer raw data (6 bytes)
Gx_L ~ Gz_H0x3B~0x40Gyroscope raw data (6 bytes)
Status00x2EData ready status

Accelerometer ranges:

Enum ValueRangeSensitivity
Qmi8658AccRange_2g±2g1<<14
Qmi8658AccRange_4g±4g1<<13
Qmi8658AccRange_8g±8g1<<12 (default)
Qmi8658AccRange_16g±16g1<<11

Gyroscope ranges:

Enum ValueRangeSensitivity
Qmi8658GyrRange_16dps±16 dps2048
Qmi8658GyrRange_32dps±32 dps1024
Qmi8658GyrRange_64dps±64 dps512
Qmi8658GyrRange_128dps±128 dps256
Qmi8658GyrRange_256dps±256 dps128
Qmi8658GyrRange_512dps±512 dps64
Qmi8658GyrRange_1024dps±1024 dps32 (default)
Qmi8658GyrRange_2048dps±2048 dps16

Default configuration:

  • Accelerometer: ±8g, 250Hz ODR

  • Gyroscope: ±1024 dps, 250Hz ODR

  • Synchronous sampling mode (QMI8658_SYNC_SAMPLE_MODE)

Core functions:

  • qmi8658_init() — Initializes the sensor, detects the chip ID, performs a soft reset, performs one-time calibration, and configures registers

  • qmi8658_read_xyz(float acc[3], float gyro[3]) — Reads accelerometer (m/s²) and gyroscope (rad/s) data

  • qmi8658_soft_reset() — Soft-resets the sensor

  • qmi8658_axis_convert(float data_a[3], float data_g[3], int layout) — Axis direction remapping (supports 24 layouts)

Data reading flow:

Internal implementation of qmi8658_read_sensor_data():

  1. Read 12 bytes consecutively starting from register Ax_L (0x35)

  2. Extract 6 signed 16-bit raw values (acc_x/y/z, gyro_x/y/z)

  3. Convert the raw values to physical units:

    • Accelerometer: acc = raw * 9.807 / ssvt_a (unit m/s²)

    • Gyroscope: gyro = raw * π / (ssvt_g * 180) (unit rad/s)

  4. Perform axis remapping (layout = 0, i.e., X=X, Y=Y, Z=Z)

  5. If static calibration is enabled, subtract the zero offset

ESP32 platform adaptation layer

Files: components/qmi8658b_port_esp32/qmi8658b_port_esp32.h, components/qmi8658b_port_esp32/qmi8658b_port_esp32.c

Binds the bus interface callbacks of the QMI8658 driver to the ESP32 I2C driver:

xxxxxxxxxx
qmi8658_bus_io_t bus_io = {
    .write_reg = qmi8658_esp32_write_reg,   // Calls I2C_Master_Write_Byte
    .read_reg  = qmi8658_esp32_read_reg,    // Calls I2C_Master_Read
    .delay_ms  = qmi8658_esp32_delay_ms,    // Calls vTaskDelay
    .delay_us  = qmi8658_esp32_delay_us,    // Calls esp_rom_delay_us
};

Attitude fusion layer

Files: components/imu_attitude_fusion/imu_attitude_fusion.h, components/imu_attitude_fusion/imu_attitude_fusion.c

Based on the open-source Fusion AHRS algorithm library, it implements six-axis attitude solving without a magnetometer (pitch, roll, yaw).

Initialization flow:

xxxxxxxxxx
uint8_t imu_attitude_fusion_init(FusionAhrs* fusion, FusionBias* bias)
{
    I2C_Master_Init();
    ESP_ERROR_CHECK(qmi8658_esp32_port_register());
    if (!qmi8658_init()) return 0;
    FusionBiasInitialise(bias);
    FusionAhrsInitialise(fusion);
    return 1;
}

Algorithm parameter setting:

xxxxxxxxxx
void fusion_param_setting(FusionAhrs* fusion, FusionBias* bias,
                          float sample_rate_hz, float gyro_range_dps)
{
    FusionBiasSettings bias_settings = {
        .sampleRate = sample_rate_hz,          // 100 Hz
        .stationaryThreshold = 3.0f,           // Stationary threshold
        .stationaryPeriod = 3.0f,              // Stationary determination period (seconds)
    };
    FusionBiasSetSettings(bias, &bias_settings);

    FusionAhrsSettings ahrs_settings = {
        .convention = FusionConventionNwu,     // North-West-Up coordinate system
        .gain = 0.5f,                          // Fusion gain
        .gyroscopeRange = gyro_range_dps,      // 1024 dps
        .accelerationRejection = 10.0f,        // Acceleration disturbance rejection
        .magneticRejection = 0.0f,             // No magnetometer
        .recoveryTriggerPeriod = 5.0f * sample_rate_hz,
    };
    FusionAhrsSetSettings(fusion, &ahrs_settings);
}

Gyroscope startup bias calibration:

calibrate_gyro_startup_bias() collects 300 gyroscope samples at startup and averages them as the static zero offset. Each subsequent call to update_imu_data() automatically subtracts this offset to reduce the effect of gyroscope temperature drift.

Core functions:

  • update_imu_data(FusionVector *acc, FusionVector *gyro) — Reads sensor data, converts it to g and dps units, and subtracts the startup offset

  • imu_attitude_fusion_update() — Performs AHRS fusion, inputs the corrected gyroscope and accelerometer data, and updates the attitude

  • imu_attitude_fusion_get_quaternion() — Gets the current quaternion

  • imu_attitude_fusion_get_euler() — Converts the quaternion to Euler angles (roll, pitch, yaw, in degrees)

Attitude stability analyzer

Files: components/attitude_stability_analyzer/attitude_stability_analyzer.h, components/attitude_stability_analyzer/attitude_stability_analyzer.c

Used to evaluate the stability of the attitude angles over a period of time, calculating statistical metrics such as mean, standard deviation, min/max, and drift rate.

Data structure:

xxxxxxxxxx
typedef struct {
    float roll_buffer[300];      // Roll history ring buffer
    float pitch_buffer[300];     // Pitch history data
    float yaw_buffer[300];       // Yaw history data
    float time_buffer[300];      // Timestamp history
    size_t window_size;          // Window size (max 300)
    size_t count;                // Current sample count
    size_t head;                 // Ring buffer head pointer
} attitude_stability_analyzer_t;

Output metrics:

xxxxxxxxxx
typedef struct {
    axis_stability_metrics_t roll;    // Roll statistics
    axis_stability_metrics_t pitch;   // Pitch statistics
    axis_stability_metrics_t yaw;     // Yaw statistics
    size_t sample_count;
    float window_duration_s;          // Window duration (seconds)
    bool valid;
} attitude_stability_result_t;

The statistical metrics for each axis include: mean, stddev (standard deviation), min, max, range, drift_rate_deg_per_sec (drift rate per second), drift_rate_deg_per_min (drift rate per minute), and cumulative_drift_deg (cumulative drift).

VI. Common Problems

ProblemCauseSolution
No IMU dataAbnormal I2C connection or sensor initialization failureCheck whether GPIO39/40 are loose and confirm that the sensor WhoAmI is 0x05
roll/pitch is not 0The control board is not placed horizontally or the sensor installation has deviationPlace the control board on a horizontal desk, or modify the axis mapping layout
Large Euler angle fluctuationAcceleration disturbance or inappropriate algorithm gainCheck the gain parameter (default 0.5) and reduce it appropriately
yaw drifts continuouslyThe gyroscope zero offset is not fully eliminatedIncrease the calibration sample count (sample_count default 300) or extend the calibration wait time
Robot Kinematics Analysis Theory
Read Lidar Data

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文