[ROS2] robot_state_publisher + xacro + Python launch
Hi all, the robotstatepublisher in ROS2 Eloquent wants an URDF file name as input parameter to publish static robot descriptions.
Is it possible to combine robotstatepublisher in a Python launch script using the description generated by XACRO as input?
Thank you Walter
Asked by Myzhar on 2020-09-15 10:48:19 UTC
Answers
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])
}]),
])
Asked by tim-fan on 2020-09-18 06:33:04 UTC
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
Asked by Myzhar on 2020-09-18 06:46:35 UTC
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?
Asked by tim-fan on 2020-09-19 00:41:23 UTC
Comments