A ROS2-based implementation of Extended Kalman Filter (EKF) localization built from scratch in C++, following the formulation in Probabilistic Robotics.
The system performs real-time sensor fusion between odometry and simulated noisy GPS measurements in Gazebo.
A demonstration of the robot moving in a straight line while EKF localization runs in real-time.
[
Legend:
- π΅ Odometry: Smooth but prone to drift
- π΄ Fake GPS: Noisy measurements
- π’ EKF: Fused estimate combining prediction and correction
- The fake GPS shows high variance due to simulated noise.
- Odometry provides smooth motion estimates but can accumulate error.
- The EKF combines both sources to produce a filtered trajectory.
In this straight-line experiment, the EKF tracks the motion while mitigating measurement noise, demonstrating effective sensor fusion.
This project implements a full EKF pipeline for mobile robot localization:
- Prediction from wheel odometry (
/odom) - Correction from simulated noisy GPS (
/fake_gps) - Fused estimate published as
/ekf/odom
The system is tested on a TurtleBot3 in Gazebo, demonstrating real-time state estimation under noisy conditions.
ΞΌΜβ = g(uβ, ΞΌβββ)
Ξ£Μβ = Gβ Ξ£βββ Gβα΅ + Rβ
Kβ = Ξ£β Hβα΅ (Hβ Ξ£β Hβα΅ + Qβ)β»ΒΉ
ΞΌβ = ΞΌβ + Kβ(zβ - zΜβ)
+----------------+
| /odom |
| (wheel data) |
+--------+-------+
|
v
[Prediction]
|
v
+---------+
| EKF |
+---------+
^
|
[Update]
|
+--------+--------+
| /fake_gps |
| (noisy sensor) |
+-----------------+
|
v
/ekf/odom (output)
ekf_localization_ros2/
βββ include/
β βββ ekf_localization_ros2/
β βββ ekf.hpp
βββ src/
β βββ ekf.cpp
β βββ ekf_node.cpp
β βββ fake_gps_node.cpp
βββ CMakeLists.txt
βββ package.xml
- ROS2 Humble
- TurtleBot3 packages
- Gazebo
Install dependencies:
sudo apt install ros-humble-turtlebot3* ros-humble-gazebo-ros-pkgscd ~/ekf
source /opt/ros/humble/setup.bash
colcon buildsource /opt/ros/humble/setup.bash
export TURTLEBOT3_MODEL=burger
ros2 launch turtlebot3_gazebo turtlebot3_world.launch.pysource ~/ekf/install/setup.bash
ros2 run ekf_localization_ros2 fake_gps_nodesource ~/ekf/install/setup.bash
ros2 run ekf_localization_ros2 ekf_nodesource /opt/ros/humble/setup.bash
export TURTLEBOT3_MODEL=burger
ros2 run turtlebot3_teleop teleop_keyboardros2 topic echo /odom --field pose.pose.positionros2 topic echo /fake_gpsros2 topic echo /ekf/odom --field pose.pose.position| Topic | Behavior |
|---|---|
/odom |
smooth but may drift |
/fake_gps |
noisy, jittery |
/ekf/odom |
smooth and corrected |
Example:
/odom β smooth trajectory
/fake_gps β noisy jumps
/ekf/odom β filtered estimate (best of both)
- EKF implemented from scratch (no external localization packages)
- Book-aligned notation (ΞΌ, Ξ£, R, Q)
- Modular ROS2 node architecture
- Simulated sensor noise for realistic testing
- Real-time operation in Gazebo
- RMSE evaluation against ground truth
- Comparison with
robot_localization - Sensor dropout handling
- Multi-sensor fusion (IMU, LiDAR)
- ROS2 Nav2 integration
The EKF combines:
- Odometry β smooth but drifting
- GPS β noisy but unbiased
