[foxy] Different results when using xacro from launch and command line

asked 2020-11-16 05:38:46 -0500

Alrevan gravatar image

Hello,

I have a .xacro file I want to convert to .urdf in order to launch a robot_state_publisher node with it.

If i use xacro in command line then launch the node with the resulting urdf file, everything works fine:

xacro path/to/xacro/suitee.xacro > out.urdf
ros2 run robot_state_publisher robot_state_publisher out.urdf

I have however created a launch file that consists of the following:

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


def generate_launch_description():
    use_sim_time = LaunchConfiguration('use_sim_time', default='false')
    suitee_xacro = os.path.join(get_package_share_directory('s_description'), 'urdf', 'suitee.xacro')

    return LaunchDescription([
        DeclareLaunchArgument(
            'use_sim_time',
            default_value='false',
            description='Use simulation (Gazebo) clock if true'),

        Node(
            package='robot_state_publisher',
            executable='robot_state_publisher',
            name='robot_state_publisher_robot',
            output='screen',
            parameters=[{
                'use_sim_time': use_sim_time,
                'robot_description': Command(['xacro', ' ', suitee_xacro])
            }]),
    ])

When I try to launch this file, I have the following error:

 yaml.scanner.ScannerError: while scanning for the next token
 found character '\t' that cannot start any token
  in "<unicode string>", line 47, column 1:
      <xacro:insert_block name="s ...
   ^

I dont know why this happens here and not when i convert xacro on command line, any insights on this ?

I can provide xacro file if needed.

edit retag flag offensive close merge delete

Comments

I encountered the same issue. With a similar launch setup, I used the xacro file found here.

I got an error:

 File "/usr/lib/python3/dist-packages/yaml/parser.py", line 171, in parse_document_start
    raise ParserError(None, None,
yaml.parser.ParserError: expected '<document start>', but found '<scalar>'
  in "<unicode string>", line 9, column 1:
    truck.
    ^
Task exception was never retrieved

The word "truck" is part of an XML comment block at the beginning of the file. Removing the comment avoids the error. Is there a better workaround? Why must the output of xacro be parsed as yaml?

acy gravatar image acy  ( 2021-01-07 00:59:58 -0500 )edit