Skip to content

Bug in ROS 2: robot_state_publisher adds unintended leading slash '/' to frame IDs #1136

Description

@chendawe

Operating System:

Ubuntu 22.04

ROS version:

ROS 2: Humble

Turtlebot3 Model:

Waffle

Bug Description

The Problem

When frame_prefix is left as default (''), this expression evaluates to "/".
As a result, robot_state_publisher publishes frames like /base_link, /base_scan, /imu_link.
However, Gazebo's diff_drive plugin and SLAM (e.g., slam_toolbox) publish odom and map without the leading slash.
In ROS 2 tf2, base_link and /base_link are considered different frames, splitting the TF tree into two unconnected trees. This breaks Nav2 and autonomous exploration.

The Fix

This is a ROS 1 to ROS 2 migration artifact (ROS 1 tf ignored leading slashes).
It should be changed to only add the slash if a prefix is actually provided:

Steps to Reproduce

  1. Export the simulation environment:
    export TURTLEBOT3_MODEL=waffle
  2. Launch the Gazebo simulation:
    ros2 launch turtlebot3_gazebo turtlebot3_world.launch.py
  3. In a new terminal, launch SLAM (e.g., Cartographer):
    ros2 launch turtlebot3_cartographer cartographer.launch.py use_sim_time:=True
  4. In a new terminal, launch Nav2:
    ros2 launch nav2_bringup navigation_launch.py use_sim_time:=True params_file:=/opt/ros/humble/share/nav2_bringup/params/nav2_params.yaml
  5. Check the TF tree structure:
    ros2 run tf2_tools view_frames
  6. Open the generated frames.pdf (or run ros2 topic echo /tf_static --once).
    Expected behavior:
    The TF tree should be a single connected tree: map -> odom -> base_footprint -> base_link -> base_scan (without any leading slashes).
    Actual behavior:
    The TF tree is split into two unconnected trees:
  • Tree 1: map -> odom -> base_footprint
  • Tree 2: /base_footprint -> /base_link -> /base_scan -> etc.
    Nav2 throws TF_SELF_TRANSFORM errors and fails to navigate properly.

### Actual Behavior

_No response_

### What Have You Tried?

```shell
Got resolved by:
IN:
~/workspace/turtlebot3_ws/src/src/turtlebot3_simulations/turtlebot3_gazebo/launch/robot_state_publisher.launch.py
Replace 'frame_prefix' as :
'frame_prefix': PythonExpression(["'", frame_prefix, "/' if '", frame_prefix, "' else ''"]),

Relevant Logs / Terminal Output

Additional Information (Optional)

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions