URDF Real Robot Step 2

Hello,

I have a quick question on the Real Robot Project Step 2 of the URDF for ROS2 course.

On the real Fastbot I am unclear if I need to use the joint state publisher - I thought not, but my wheels do not get transforms if I do not add a joint state publsher in my launch file:

After adding a joint state publisher in my launch file I do get transform data for my wheels, but they flicker into different positions:


I just need some guidance on if the joint state publisher is needed here and some pointers into things to look into. I thought maybe the flickering was due to multiple joint state publisher nodes running. I have my RobotDescription topic set to /fastbot_description as required in the test. Any tips would be greatly appreciated.

Below are my current state publisher and rviz launch files:

#!/usr/bin/env python3

import os

from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.substitutions import Command, LaunchConfiguration
from launch.conditions import IfCondition, UnlessCondition
from launch_ros.actions import Node

def generate_launch_description():
package_description = “ros2_urdf_project”
pkg_share = get_package_share_directory(package_description)

declare_use_sim_time = DeclareLaunchArgument(
    'use_sim_time', default_value='false',
    description='Use simulation time (true for Gazebo, false for real robot)')

use_sim_time = LaunchConfiguration('use_sim_time')

urdf_sim = os.path.join(pkg_share, 'urdf', 'fastbot_sim.urdf')
urdf_real = os.path.join(pkg_share, 'urdf', 'fastbot_real.urdf')

# Simulation: publishes to /robot_description (default topic)
robot_state_publisher_sim = Node(
    package='robot_state_publisher',
    executable='robot_state_publisher',
    name='robot_state_publisher_node',
    emulate_tty=True,
    parameters=[{
        'use_sim_time': use_sim_time,
        'robot_description': Command(['xacro ', urdf_sim]),
    }],
    output='screen',
    condition=IfCondition(use_sim_time),
)

# Real robot: remaps to /fastbot_description
robot_state_publisher_real = Node(
    package='robot_state_publisher',
    executable='robot_state_publisher',
    name='robot_state_publisher_node',
    emulate_tty=True,
    parameters=[{
        'use_sim_time': use_sim_time,
        'robot_description': Command(['xacro ', urdf_real]),
    }],
    remappings=[
        ('robot_description', 'fastbot_description'),
    ],
    output='screen',
    condition=UnlessCondition(use_sim_time),
)

# joint_state_publisher_real = Node(
#     package='joint_state_publisher',
#     executable='joint_state_publisher',
#     name='joint_state_publisher',
#     parameters=[{'use_sim_time': False}],
#     remappings=[
#         ('robot_description', 'fastbot_description'),
#     ],
#     condition=UnlessCondition(use_sim_time),
# )

return LaunchDescription([
    declare_use_sim_time,
    robot_state_publisher_sim,
    robot_state_publisher_real,
    # joint_state_publisher_real
])

#!/usr/bin/env python3

import os
from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.substitutions import LaunchConfiguration
from launch.conditions import IfCondition, UnlessCondition
from launch_ros.actions import Node

def generate_launch_description():

package_description = "ros2_urdf_project"
pkg_share = get_package_share_directory(package_description)

declare_use_sim_time = DeclareLaunchArgument(
    'use_sim_time', default_value='false',
    description='Use simulation time (true for Gazebo, false for real robot)')

use_sim_time = LaunchConfiguration('use_sim_time')

rviz_sim_config = os.path.join(pkg_share, 'rviz', 'fastbot_sim.rviz')
rviz_real_config = os.path.join(pkg_share, 'rviz', 'fastbot_real.rviz')

rviz_sim = Node(
    package='rviz2',
    executable='rviz2',
    output='screen',
    name='rviz_node',
    parameters=[{'use_sim_time': use_sim_time}],
    arguments=['-d', rviz_sim_config],
    condition=IfCondition(use_sim_time),
)

rviz_real = Node(
    package='rviz2',
    executable='rviz2',
    output='screen',
    name='rviz_node',
    parameters=[{'use_sim_time': use_sim_time}],
    arguments=['-d', rviz_real_config],
    condition=UnlessCondition(use_sim_time),
)

return LaunchDescription([
    declare_use_sim_time,
    rviz_sim,
    rviz_real,
])

Thanks :slight_smile:

Hi,

So in a Differential drive robot actually the state of teh joints of teh wheels is not really necessary for anything except for visualising that teh wheels are turning. You could add just a fixed joint to teh wheels and thats it.

If you want to use joint states, be sure that only ONE system is publishing there, otherwise you will see that flicker.

Just consider it

Thanks @duckfrost2 that’s helpful. I did think about adding the wheels as fixed but wasn’t sure if that’s how it should be done. My confusion I suppose is around the normal process for testing a real robot. Would you ever really want to publish joint states in a launch file like I’m doing here? That should all be done by the actual robot right? Which is why I get the flicker as I’m publishing joint states and the actual robot is too?

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.