0
$\begingroup$

Rosanswers logo

Hi there,

I've been using xacro.process_file(<file_name>)to convert from xacro to urdf, it works just fine. Now I have implemented a xacro argument in my file and I want to pass that from my launch file. It just doesn't get read with my current implementation.

XACRO:

<xacro:arg name="simulate_obstacles" default="true"/>
<xacro:if value="$(arg simulate_obstacles)">
  <...doing_something...>  
</xacro:if>

LAUNCH FILE:

doc = xacro.process_file(xacro_file, simulate_obstacles='false')

When running the xacro from the commandline I don't have any problem passing arguments. What am I doing wrong here? Or is there even a more simple way to use xacro in launch files in ROS2?

Thank you!

Working with eloquent.


Originally posted by relffok on ROS Answers with karma: 169 on 2020-04-17

Post score: 0

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

Hi, it seems like this fixes the issue:

doc = xacro.process_file(xacro_file, mappings={'simulate_obstacles' : 'false'}) 

In case there is or will be a better way to include xacro in ros2 launch files at some point, feel free to let me know!


Originally posted by relffok with karma: 169 on 2020-04-20

This answer was ACCEPTED on the original site

Post score: 5

$\endgroup$
0
$\begingroup$

You can add your own launch Substitution class - eg) https://github.com/Greenroom-Robotics/launch_ext/blob/main/launch_ext/substitutions/xacro.py#L17

This then allows you do do:

      state_publisher = Node(
        package="robot_state_publisher",
        executable="robot_state_publisher",
        parameters=[
            {
                "robot_description": Xacro(
                    file_path=JoinLaunchSubstitutions(
                        [
                            FindPackageShare("my_robot_description"),
                            "urdf",
                            "my_robot.urdf.xacro",
                        ]
                    ),
                    mappings={
                        "thing_to_substitute": "substitution_value",
                        "another_thing_to_substitute": LaunchConfiguration("another_thing_to_substitute"),
                    },
                )
            }
        ],
    )
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.