Blog

Fusing GNSS, IMU and Wheel Odometry With robot_localization: A Working EKF Config

Tom Cosgrove,

Reading Room: The Fictionlab Blog

TL;DR: A reliable robot_localization ekf gnss imu setup on ROS 2 uses two EKF instances plus navsat_transform_node, the same topology as the dual EKF example shipped with the robot_localization package. The local EKF fuses wheel odometry and IMU into a continuous odom->base_link transform. The global EKF adds GNSS-derived odometry and publishes map->odom. This article walks through the YAML, the heading requirement that trips up most first attempts, covariance choices, launch wiring, the extra steps on a stock Leo Rover, and how to check that the fusion actually works, not just runs.

Why Is a Two-EKF Architecture the Right Answer for robot_localization EKF GNSS IMU Fusion?

Field robots need two things at once: a smooth, high-rate local pose that never jumps, and a drift-free global pose anchored to the Earth. A single filter cannot give both behaviours in one frame. If GNSS goes straight into the only EKF, every fix correction can shift the estimate, and controllers that use that frame receive discontinuous poses. The robot_localization ekf gnss imu pattern follows the REP-105 frame convention: odom is continuous but may drift, map is globally corrected but may jump.

The robot_localization package, originally written by Tom Moore, provides ekf_node, ukf_node and navsat_transform_node. The last one converts sensor_msgs/NavSatFix messages into a nav_msgs/Odometry message in the world frame of the filter. The setup described here runs two EKF nodes:

  • Local EKF (ekf_local): fuses wheel odometry and IMU angular velocity, world_frame: odom, publishes odom->base_link.
  • Global EKF (ekf_global): fuses the same inputs plus the GNSS odometry from navsat_transform_node and an Earth-referenced heading, world_frame: map, publishes map->odom.

This topology matches the official robot_localization GPS integration guide and works well on four-wheel differential-drive platforms like the Leo Rover, which turn by skidding their wheels, so wheel odometry alone drifts over long outdoor traverses.

What Sensors, Frames and Heading Do You Need for robot_localization EKF GNSS IMU Fusion?

Get the plumbing right before tuning anything. Wrong frames or units waste hours. The following inputs need to be available as ROS 2 topics:

  • Wheel odometry – nav_msgs/Odometry from the base controller, with header.frame_id set to odom, child_frame_id set to the robot base frame and twist covariance filled in.
  • IMU – sensor_msgs/Imu with at least angular velocity and linear acceleration, in a frame that has a static transform to the base frame in the URDF.
  • GNSS – sensor_msgs/NavSatFix from the receiver driver (for example a u-blox ZED-F9P based board), with position_covariance populated.
  • Earth-referenced heading – an orientation source whose yaw follows the ROS ENU convention (zero facing east, increasing counter-clockwise).

The last item is the most common reason a first attempt fails. navsat_transform_node uses the yaw from the message on its imu input to rotate GNSS positions into the filter’s world frame. If that yaw is only relative to the start pose, for example because the IMU has no magnetometer or the orientation is gyro-integrated, the GNSS track comes out rotated against the odometry. Typical heading sources are an IMU or AHRS with a calibrated magnetometer, a dual-antenna GNSS receiver, or a GNSS/INS unit that outputs fused orientation. When the heading is magnetic-north referenced, magnetic_declination_radians and yaw_offset correct it to ENU, as described in the navsat_transform_node documentation.

Verify TF completeness with ros2 run tf2_tools view_frames. The IMU and the GNSS antenna both need static transforms to the base frame. A missing or wrong antenna offset produces a position error that changes with vehicle heading.

Why Does Covariance Decide How the Filter Behaves?

An EKF weights each measurement by the inverse of its covariance. If the wheel odometry reports a variance close to zero, the filter trusts it almost absolutely and largely ignores everything else, which is a frequent failure in robot_localization ekf gnss imu setups. Starting points that are worth validating on the real robot:

  • Wheel odometry: use the covariance published by the base controller if it is realistic, and increase it for surfaces where the wheels slip.
  • IMU: derive angular velocity variance from the datasheet and observed noise at rest. Vibration, filtering and bias drift all change the effective value.
  • GNSS: an RTK-fixed solution with roughly 2 cm standard deviation corresponds to a variance of about 0.0004 m2, while a float or single-point solution is one to several orders of magnitude worse. Most receivers already report position_covariance; check that it reacts to fix quality rather than trusting it blindly.

What Does a Working robot_localization EKF GNSS IMU YAML Look Like?

The file below defines both filters and the navsat node, following the structure of dual_ekf_navsat_example.yaml from the robot_localization package. It is a planar (2D) template. The frame and topic names match a stock Leo Rover (see the next section); adjust them to your robot. Parameters that are not listed keep their package defaults, including process_noise_covariance.

### Local EKF: odom -> base_footprint, continuous, no GNSS
ekf_local:
ros__parameters:
frequency: 30.0
sensor_timeout: 0.1
two_d_mode: true # ground robot on roughly planar terrain
publish_tf: true
map_frame: map
odom_frame: odom
base_link_frame: base_footprint
world_frame: odom # local filter is anchored to odom

# Wheel odometry: forward velocity and yaw rate
odom0: /wheel_odom
odom0_config: [false, false, false,
false, false, false,
true, false, false,
false, false, true,
false, false, false]
odom0_differential: false
odom0_relative: false
odom0_queue_size: 10

# IMU: yaw rate only (orientation on this topic may be gyro-integrated)
imu0: /imu/data
imu0_config: [false, false, false,
false, false, false,
false, false, false,
false, false, true,
false, false, false]
imu0_differential: false
imu0_relative: false
imu0_queue_size: 10

### Global EKF: map -> odom, fuses GNSS and absolute heading
ekf_global:
ros__parameters:
frequency: 30.0
sensor_timeout: 0.1
two_d_mode: true
publish_tf: true
map_frame: map
odom_frame: odom
base_link_frame: base_footprint
world_frame: map # global filter is anchored to map

odom0: /wheel_odom
odom0_config: [false, false, false,
false, false, false,
true, false, false,
false, false, true,
false, false, false]
odom0_queue_size: 10

# GNSS position from navsat_transform_node
odom1: /odometry/gps
odom1_config: [true, true, false,
false, false, false,
false, false, false,
false, false, false,
false, false, false]
odom1_differential: false
odom1_queue_size: 10

imu0: /imu/data
imu0_config: [false, false, false,
false, false, false,
false, false, false,
false, false, true,
false, false, false]
imu0_queue_size: 10

# Earth-referenced heading (ENU), e.g. AHRS or dual-antenna GNSS
imu1: /heading/data
imu1_config: [false, false, false,
false, false, true,
false, false, false,
false, false, false,
false, false, false]
imu1_relative: false # must stay absolute for GNSS fusion
imu1_queue_size: 10

### navsat_transform: NavSatFix -> Odometry in the map frame
navsat_transform:
ros__parameters:
frequency: 30.0
delay: 3.0
magnetic_declination_radians: 0.0 # set only for magnetic-north referenced heading
yaw_offset: 0.0 # 0.0 when heading already reads 0 facing east
zero_altitude: true
publish_filtered_gps: true
use_odometry_yaw: false
wait_for_datum: false

Each _config vector follows the order X, Y, Z, roll, pitch, yaw, vX, vY, vZ, vRoll, vPitch, vYaw, aX, aY, aZ, as defined in the robot_localization configuration guide. Fuse only what a sensor actually measures well. Wheel Y velocity on a differential-drive robot, for example, is always zero by construction and adds no real information.

How Do You Run This robot_localization EKF GNSS IMU Setup on a Stock Leo Rover?

The Leo Rover ROS 2 stack (leo_robot-ros2, checked on the humble branch) already provides most inputs, but three details matter before adding robot_localization:

  • Topics and frames: wheel odometry is published on /wheel_odom with odom as frame and base_footprint as child frame. The filtered IMU is published on /imu/data.
  • Existing odom TF: the odom_filter node in leo_bringup broadcasts odom->base_footprint by default. Start leo_bringup.launch.xml with publish_odom_tf:=false, otherwise two nodes publish the same transform.
  • Heading: the stock imu_filter estimates orientation from gyroscope and accelerometer data, so its yaw is relative to the start pose. That is why the template fuses only yaw rate from /imu/data and expects an Earth-referenced heading on a separate topic. A GNSS/INS module such as the Fixposition Vision-RTK 2 integration is one way to get position and heading from one device.

For RTK hardware selection and wiring, see the guide on adding RTK GPS to a small mobile robot.

How Do You Launch the robot_localization EKF GNSS IMU Nodes?

navsat_transform_node waits until it has a GNSS fix, a heading on its imu input and filtered odometry before it computes the datum transform, so all three nodes can be started together. A minimal launch file, wired the same way as dual_ekf_navsat_example.launch.py in the package:

from launch import LaunchDescription
from launch_ros.actions import Node

def generate_launch_description():
params = '/path/to/ekf_dual.yaml'
return LaunchDescription([
Node(package='robot_localization', executable='ekf_node',
name='ekf_local', parameters=[params],
remappings=[('odometry/filtered', 'odometry/local')]),
Node(package='robot_localization', executable='ekf_node',
name='ekf_global', parameters=[params],
remappings=[('odometry/filtered', 'odometry/global')]),
Node(package='robot_localization', executable='navsat_transform_node',
name='navsat_transform', parameters=[params],
remappings=[
('imu', '/heading/data'),
('gps/fix', '/gps/fix'),
('odometry/filtered', 'odometry/global'),
]),
])

In ROS 2, navsat_transform_node subscribes to imu, gps/fix and odometry/filtered, and publishes odometry/gps (plus gps/filtered when publish_filtered_gps is enabled). The node names in the launch file must match the top-level keys in the YAML, otherwise the parameters are silently not applied. Following the package example, the navsat node reads the global filter output, which it uses to place the GNSS datum in the map frame.

How Do You Verify That robot_localization EKF GNSS IMU Fusion Actually Works?

A running node is not a working filter. These checks are worth doing before the output is used for navigation or field research:

  1. TF tree: ros2 run tf2_tools view_frames should show map -> odom -> base_footprint, with exactly one broadcaster per edge.
  2. Continuity: drive a straight line and plot /odometry/local. The trajectory should be smooth, with no jumps when GNSS fixes arrive.
  3. Heading alignment: drive a straight line of a few tens of metres and compare /gps/filtered (or /odometry/gps) with /odometry/global in RViz2. If the GNSS track is rotated relative to the odometry track, the heading source, yaw_offset or declination is wrong.
  4. Return-to-start test: drive a loop and stop at the start point. The local pose usually shows accumulated drift; the global pose should return close to the start, within the GNSS accuracy achievable at that site.
  5. Covariance sanity: ros2 topic echo /odometry/global --field pose.covariance. The X and Y terms should stay finite and grow during GNSS outages, then shrink when good fixes return.
  6. Outage behaviour: block or filter out GNSS fixes for a short period. The global EKF should keep dead reckoning on wheel odometry and IMU, and map->odom should converge again once valid fixes come back.

Recording all inputs with ros2 bag record during these tests makes it possible to replay the same drive offline while tuning covariances.

When Should You Deviate From This robot_localization EKF GNSS IMU Template?

The configuration above assumes a planar outdoor UGV with a separate absolute heading source and a single GNSS position input. It needs changes in these cases:

  • Uneven or steep terrain: set two_d_mode: false and fuse roll, pitch and Z where sensors provide them, accepting a larger state to tune.
  • Visual or LiDAR odometry available: add it as another odomN input to the local EKF. It helps during wheel-slip events where wheel odometry is unreliable.
  • Magnetometer-based heading near steel structures: magnetic disturbances can bias yaw by a large margin, so a dual-antenna GNSS heading is usually more robust in industrial or construction sites.
  • Indoor-outdoor transitions: forward only valid NavSatFix messages (status at least STATUS_FIX and covariance below an application-specific threshold) so that poor fixes do not pull the global estimate.

These variations are common in field deployments for agriculture, inspection and environmental monitoring, covered in Fictionlab’s research applications.

What Are the Most Common Questions About robot_localization EKF GNSS IMU Setups?

Do you need two EKF instances, or can one filter fuse GPS directly?

A single EKF can fuse GNSS, but then its output frame is globally corrected and can jump when fixes arrive. Two filters keep the continuous odom->base_link transform required by REP-105 and isolate global corrections in map->odom.

Why is the global pose rotated or drifting despite GNSS fusion?

The most common causes are a heading that is not Earth-referenced, a wrong yaw_offset or declination, unrealistic GNSS covariance, or a missing antenna transform. Comparing the GNSS track with the odometry track on a straight drive usually shows which one it is.

What frequency should the EKF run at?

The frequency parameter sets how often the filter publishes its estimate; measurements are processed as they arrive. Choose a rate that matches what the controller needs and what the CPU can sustain. The package example uses 30 Hz.

What happens during GPS outages under trees or between buildings?

The global EKF continues with wheel odometry and IMU only, so its uncertainty grows. How fast it drifts depends on odometry calibration, terrain, slip and IMU quality, so it is best measured on the actual robot rather than assumed.

Can this configuration be used with Nav2?

Yes, as long as the TF tree is consistent. Nav2 uses map as the global frame and odom as the local frame, and the odometry topic configured in Nav2 can point to /odometry/local.

Does two_d_mode discard useful IMU data?

It removes Z, roll and pitch from the estimate, which reduces noise on flat ground. If the robot pitches or rolls significantly, or terrain geometry matters for the application, disable it.

How do you tune process_noise_covariance without guessing?

Start from the package defaults, drive a known trajectory and compare the estimate with reference data where possible. If the filter reacts too slowly to credible measurements, increase process noise on the affected state; if it is jittery, decrease it. Change one diagonal entry at a time and replay the same bag file for each change.

How Can Fictionlab Help With a Field-Ready Localization Stack?

A working robot_localization ekf gnss imu configuration is the base of an outdoor autonomy stack, but every platform, sensor set and site shifts the tuning. For teams integrating GNSS-based localization on a custom UGV, Fictionlab’s engineering team supports integration projects through custom robotics services, from sensor selection to field testing.


Read more