Welcome to ROSMASTER A1 PRO repository
7.Robot EKF State Estimation
📊 Robot State Estimation
1. Course Introduction
Multi-sensor Extended Kalman Filter (EKF) fusion using IMU (Inertial Measurement Unit) and chassis motor encoder data to obtain high-precision filtered odometry, accurately estimating the spatial pose and motion state of the A1 Pro Ackermann robot.
🎯 Course Objectives
Understand the basic principles of EKF (Extended Kalman Filter) multi-sensor data fusion
Master the methods for launching the robot state estimation node and RViz visualization comparison
Deeply understand the characteristic differences between
/odom(fused filtered odometry) and/odom_raw(wheel odometry)Master the 15-dimensional state vector configuration rules for EKF fusion parameters (
odom0_configandimu0_config)
2. Prerequisites
2.1 Launch Chassis Driver and Visualization Model
Run the following command in the terminal to launch the chassis hardware driver (driver_node), IMU attitude solution (imu_attitude_converter), EKF filter node, and RViz visualization interface:
ros2 launch dofbot_pro_description display_A1pro.launch.py pose_source:=ekf
2.2 Launch Keyboard Control
Launch the keyboard control node in a new terminal for manually controlling the robot's movement:
xxxxxxxxxxros2 run yahboomcar_ctrl yahboom_keyboard
Important
When using keyboard control, keep the terminal in focused/selected state and set the input method to English mode.
3. Demonstration and Effect Comparison
Control the robot to move using the keyboard (recommended: trace a closed square loop), and observe the comparative performance of the two odometry trajectories in RViz:
/odom(EKF fused odometry): Fuses IMU attitude yaw angle with wheel odometry velocity. The trajectory is smooth during turns and acceleration/deceleration, without sideslip discontinuities, and has extremely strong drift resistance./odom_raw(raw wheel odometry): Calculated by the chassis driver node solely through midpoint integration of wheel velocities. Heading accumulates significant drift after wheel slippage or prolonged turning.

Tip
When the remote-controlled robot returns to the physical origin after completing a loop, you can clearly observe that /odom trajectory closure and pose coincidence are significantly better than /odom_raw.
4. Computation Graph and Data Flow
Use rqt_graph to view the data interaction relationships between nodes:
xxxxxxxxxxrqt_graph
4.1 Core Data Flow Diagram

4.2 Core responsibilities of Each Node
| Node Name | Package | Core Responsibilities and Function Description |
|---|---|---|
driver_node (Ackman_driver_A1P) | yahboomcar_bringup | Chassis integrated driver core. Communicates with MCU via serial port, publishes /odom_raw directly based on Ackermann trapezoidal midpoint integration, and publishes raw IMU /imu/data_raw and velocity feedback /vel_raw |
imu_attitude_converter | yahboomcar_bringup | Responsible for IMU attitude solution and coordinate system conversion, publishes /imu/data with standardized quaternion pose |
ekf_filter_node | robot_localization | Extended Kalman filter, fuses /odom_raw velocity with /imu/data heading angle, outputs high-precision /odom and broadcasts odom → base_footprint TF |
5. EKF Parameter Configuration Details
Configuration file path:
xxxxxxxxxx$HOME/yahboomcar_ros2_ws/yahboomcar_ws/src/yahboomcar_bringup/param/ekf_A1.yaml
5.1 Basic Filter Parameters
| Parameter Name | Default Value | Description |
|---|---|---|
frequency | 30.0 | EKF filter update frequency (Hz) |
two_d_mode | true | Enable 2D planar mode (automatically ignores Z-axis displacement, Pitch, and Roll) |
publish_tf | true | EKF publishes odom → base_footprint coordinate transform (TF) |
odom_frame | odom | Odometry global reference frame name |
base_link_frame | base_footprint | Robot chassis projected base frame name |
world_frame | odom | State estimation world reference frame |
5.2 Sensor Fusion Matrix (15-Dimensional State Vector)
EKF configures a 15-element boolean array for each sensor input, where each position corresponds to the following state vector:
xxxxxxxxxx[ X, Y, Z, Roll, Pitch, Yaw, Vx, Vy, Vz, Vroll, Vpitch, Vyaw, Ax, Ay, Az ]
1. Wheel Odometry Configuration (odom0: /odom_raw)
xxxxxxxxxxodom0/odom_rawodom0_configfalse false false false false false true true false false false true false false falseodom0_queue_size10odom0_differentialfalseodom0_relativefalseEnabled dimensions:
Vx(linear velocity),Vy(lateral velocity),Vyaw(angular velocity)Design Principles:
Ackermann non-holonomic kinematic constraint: Ackermann chassis theoretically has no sideslip lateral displacement. Enabling
Vymeasurement input (reported as 0 by the low-level) provides a strong sideslip suppression constraint to the filter.Avoid pose double accumulation: Only fuse linear velocity and angular velocity to avoid negative effects from cumulative drift of raw pose on the filter.
2. IMU Attitude Configuration (imu0: /imu/data)
xxxxxxxxxximu0/imu/dataimu0_configfalse false false false false true false false false false false false false false falseimu0_queue_size10imu0_differentialfalseimu0_relativetrueEnabled dimensions:
Yaw(yaw angle)Design Principles:
IMU gyroscope has extremely high high-frequency response speed for rotation angle measurement, and is completely unaffected by wheel slip or changes in ground traction. Use IMU's
Yawangle to correct wheel odometry heading drift in real-time.imu0_relative: trueensures that at node startup, the current initial heading direction is used as the $0$ reference point, avoiding sudden jumps caused by geomagnetic or uncalibrated absolute heading.
6. Source Code and Configuration File Reference
| Functional Module | Corresponding Path | Description |
|---|---|---|
| EKF Fusion Parameters | yahboomcar_ws/src/yahboomcar_bringup/param/ekf_A1.yaml | Kalman filter matrices, covariance, and sensor input configuration |
| Chassis Driver Parameters | yahboomcar_ws/src/yahboomcar_bringup/param/a1_driver.yaml | Odometry scale coefficients, covariance, and publish switches |
| Chassis Driver Launch | yahboomcar_ws/src/yahboomcar_bringup/launch/yahboomcar_bringup_A1_launch.py | Unified launch of low-level driver, IMU attitude conversion, and EKF node |
| Model Display Launch | dofbot_pro_ws/src/dofbot_pro_description/launch/display_A1pro.launch.py | Visualization launch file with RViz interaction and pose switching |
| Chassis Driver Source | yahboomcar_ws/src/yahboomcar_bringup/yahboomcar_bringup/Ackman_driver_A1P.py | Serial communication and trapezoidal midpoint dead-reckoning odometry publishing |
| Attitude Conversion Source | yahboomcar_ws/src/yahboomcar_bringup/yahboomcar_bringup/imu_attitude_converter.py | IMU filtered attitude solution and quaternion conversion publishing |