[ros2] Launch file arguments, subsititutions, xacro and node parameters
Hi all,
I am having a "fight" with launch-file argument in ROS2 for a few days already. The scenario is the following:
- Set parameter when calling launch file.
- Use it as argument for xacro file holding robot description.
- Use the output of processed file (URDF) as parameters for a node.
I managed to find a solution for the first two steps, but now I have an issue with the third one. The example launch file is:
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.substitutions import Command, LaunchConfiguration, PathJoinSubstitution
from launch_ros.actions import Node
def generate_launch_description():
declared_arguments = []
declared_arguments.append(DeclareLaunchArgument(
'robot_param',
description='Some xacro robot param.'))
robot_param = LaunchConfiguration('robot_param')
robot_description_content = Command([
PathJoinSubstitution([get_package_prefix('xacro'), 'bin', 'xacro']),
' ',
PathJoinSubstitution([get_package_share_directory('ur_description'), 'urdf', 'ur.xacro']),
' ',
'robot_param:=', robot_param,
])
robot_description = {'robot_description': robot_description_content}
robot_state_pub_node = Node(
package='robot_state_publisher',
executable='robot_state_publisher',
output='screen',
parameters=[robot_description]
)
The Issue here is that "robot_description_content" is a string, and it cannot be used directly by the node. Only file paths are allowed. On the other hand, I cannot wrap this into a parameter map. Then I get a mapping issue.
What is the proper way to use this? Am I missing something with substitutions?