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

Pass parameters to xacro from launch file, or otherwise

asked 2018-02-15 20:45:43 -0500

horseatinweeds gravatar image

Is there an example anywhere of how to actually pass a value from a launch file to the xacro files? I found a number of things here and there, but nothing clear as to what you need to do in the launch file and then how to get and use the value in the xacro. I'm just trying to spawn two robots in a single world with a couple different parameters.

I'm using kinetic. I've examined these bits of documentation but I can't figure out how to weave them together. I've experimented with enough that it would be clutter to include. (5)

Here is what I have right now.


    <!--<xacro:property name="ctopic" value="/mybot/property/cmd_vel" />-->
    <xacro:property name="ctopic" value="$(arg argCTopic)" />

  <xacro:include filename="$(find mybot_description)/urdf/robot.gazebo" />


  <plugin name="differential_drive_controller" filename="">


  <!-- Load the URDF into the ROS Parameter Server -->
  <param name="robot_description"
     command="$(find xacro)/ '$(find mybot_description)/urdf/robot.xacro' argCTopic:=/mybot/one/cmd_vel" />

  <!-- Run a python script to the send a service call to gazebo_ros to spawn a URDF robot -->
  <node name="urdf_spawner" pkg="gazebo_ros" type="spawn_model" respawn="false" output="screen"
    args="-urdf -model mybot -param robot_description"/>


edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2018-05-17 11:41:48 -0500

raequin gravatar image

updated 2018-05-17 13:29:19 -0500

Here's a working example of loading a mobile base model either with or without a gripper. Use xacro:arg in the xacro file.

<?xml version="1.0"?>
<robot xmlns:xacro=""

  <xacro:arg name="with_gripper" default="true" />

  <!-- model descriptions -->
  <!-- mobile base description -->
  <xacro:include filename="$(find mobile_manipulator)/models/mobile_base/mobile_base.urdf.xacro"/>

  <!-- gripper -->
  <xacro:if value="$(arg with_gripper)">
    <xacro:include filename="$(find mobile_manipulator)/models/gripper_fake/gripper_fake.urdf.xacro"/>

    <joint name="gripper_to_mount" type="fixed">
      <origin xyz=".15 0 .205" rpy="0 0 0" />
      <parent link="chassis" />
      <child link="gripper_center" />

A value for with_gripper can be passed from the launch file (here the value is itself an arg).

<?xml version="1.0"?>
  <arg name="is_using_gripper" default="true" />

  <!-- Load the mobile-arm description on the parameter server -->
  <param name="robot_description" command="$(find xacro)/xacro --inorder
                       '$(find mobile_manipulator)/models/mobile_manipulator/mobile_manipulator.urdf.xacro'
                       with_gripper:=$(arg is_using_gripper)"/>

Finally, the value can be passed to the launch file when it's called from terminal.

roslaunch -v mobile_manipulator mobile_manipulator.launch is_using_gripper:=false
edit flag offensive delete link more

Question Tools



Asked: 2018-02-15 20:45:43 -0500

Seen: 10,718 times

Last updated: May 17 '18