ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

[ROS2] robot_state_publisher + xacro + Python launch

asked 2020-09-15 10:48:19 -0600

Myzhar gravatar image

updated 2020-09-18 06:47:15 -0600

Hi all, the robot_state_publisher in ROS2 Eloquent wants an URDF file name as input parameter to publish static robot descriptions.

Is it possible to combine robot_state_publisher in a Python launch script using the description generated by XACRO as input?

Thank you Walter

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-09-18 06:33:04 -0600

tim-fan gravatar image

Hello, here's what I've got for this problem - it's a launch file which takes the path to a xacro file as an input argument.

On launch the xacro is converted to urdf (xml) and passed to the robot_state_publisher via the 'robot_description' parameter:

#!/usr/bin/env python3

from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.substitutions import LaunchConfiguration, Command
from launch_ros.actions import Node


def generate_launch_description():

    use_sim_time = LaunchConfiguration('use_sim_time', default='false')
    xacro_path = LaunchConfiguration('xacro_path', default=None)

    return LaunchDescription([
        DeclareLaunchArgument(
            'use_sim_time',
            default_value='false',
            description='Use simulation (Gazebo) clock if true'),
        DeclareLaunchArgument(
            'xacro_path',
            default_value=None,
            description='path to urdf.xacro file to publish'),

        Node(
            package='robot_state_publisher',
            executable='robot_state_publisher',
            name='robot_state_publisher',
            output='screen',
            parameters=[{
                'use_sim_time': use_sim_time,
                'robot_description':Command(['xacro',' ', xacro_path])
            }]),
    ])
edit flag offensive delete link more

Comments

Hi, I just noticed that i forgot to write "Eloquent". Your solution works for Foxy, in Eloquent robot_state_publisher doesn't use parameters... unless I missed something

Myzhar gravatar image Myzhar  ( 2020-09-18 06:46:35 -0600 )edit

Oh I see, yes this was tested in foxy. Maybe you could extend the 'Command' substitution to pipe the urdf to a temp file, and return the file name?

tim-fan gravatar image tim-fan  ( 2020-09-19 00:41:23 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2020-09-15 10:48:19 -0600

Seen: 2,864 times

Last updated: Sep 18 '20