Ubuntu Linux for Robotics · Lesson 73 of 96
Sensor fusion with an EKF
robot_localization: fusing wheel odometry and an IMU into one estimate.
Estimated time · 60–90 min
Learning goals
What you will understand
- Explain sensor fusion with an ekf in your own words
- Use it in a small workstation example
- Verify the result instead of assuming it worked
Understand the idea first
The mental model
An Extended Kalman Filter (EKF) combines noisy sensors into one estimate. robot_localization's ekf_node fuses wheel odometry, an IMU and other sources and publishes a filtered odometry and the odom → base_link transform. Each sensor gets a 15-value boolean list in the parameter file that says which variables (x, y, z, roll, pitch, yaw, their velocities and accelerations) to use from it.
Use each sensor for what it does well: wheel odometry for velocity, the IMU for yaw rate. Do not feed the same information twice. Check the result by driving a known path and comparing it with the raw odometry, and tune the process noise if the filter reacts too slowly or too noisily.
Guided lesson
Work through these steps
- 1.
Open a terminal and record the current state before changing anything.
- 2.
Read the sensor fusion with an ekf commands and predict what each one does.
- 3.
Run the commands one at a time and compare each output with your prediction.
- 4.
Write the commands that worked in a setup note you can repeat later.
Worked example
Read it before you run it
sudo apt install ros-lyrical-robot-localization
# Install the EKF node.
ekf_filter_node:
# Node section in the YAML file.
ros__parameters:
# ROS parameters.
frequency: 30.0
# Filter update rate in Hz.
odom0: /wheel/odom
# First input: wheel odometry.
odom0_config: [false,false,false, false,false,false, true,true,false, false,false,true, false,false,false]
# Use vx, vy and yaw rate from the wheels.
imu0: /imu
# Second input: the IMU.
imu0_config: [false,false,false, false,false,true, false,false,false, false,false,true, false,false,false]
# Use yaw and yaw rate from the IMU.What the example is doing
- 1.Lines without sudo only inspect or change files you own; sudo authorizes a system-wide change.
- 2.Read command output before moving to the next line. Stop if names, versions, disks, or paths differ from the lesson.
- 3.Comments beginning with # explain safety checks and are not executed by the shell.
Watch it run · Sensor view
See what this code does
The terminal types this lesson's practice solution and runs it. The scene shows the kind of robot behaviour that code drives. It plays by itself and loops.
Demo for Sensor fusion with an EKF. Expected result: The filtered odometry appears on /odometry/filtered
Practice code
Now type it yourself
Open a terminal, run the starter line by line (or save it as practice.sh and run bash practice.sh), and replace every TODO with your own command.
# TODO: start ekf_node from robot_localization named ekf_filter_node with the parameter file ekf.yamlExpected output
The filtered odometry appears on /odometry/filteredStuck? Show the full solution (try it yourself first)
ros2 run robot_localization ekf_node --ros-args --params-file ekf.yaml -r __node:=ekf_filter_nodeExpected result
How you know it worked
- Each command completes without an unexplained error.
- Your notes contain the command, the important output, and what it proves.
Practical exercise
Apply the lesson
Fuse wheel odometry and an IMU with an EKF, drive a 2 m square, and compare the final error of raw odometry with the filtered result.
Before you continue
- You recorded the starting state
- Every command and output is understood
- The change can be repeated from your notes
If something goes wrong
Check ownership and permissions first. Do not add sudo unless the command changes a documented system location.
Check spelling, Ubuntu version, enabled repositories, and whether the previous installation command succeeded.