Ask Your Question
2

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.

http://wiki.ros.org/xacro (5)

http://wiki.ros.org/roslaunch/XML#sub...

http://wiki.ros.org/roslaunch/XML/arg

Here is what I have right now.

robot.xacro

...
    <!--<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" />
...

robot.gazebo

...
 <gazebo>
  <plugin name="differential_drive_controller" filename="libgazebo_ros_diff_drive.so">
    <legacyMode>false</legacyMode>
    <alwaysOn>true</alwaysOn>
    <updateRate>100</updateRate>
    <leftJoint>left_wheel_hinge</leftJoint>
    <rightJoint>right_wheel_hinge</rightJoint>
    <wheelSeparation>${chassisWidth+wheelWidth}</wheelSeparation>
    <wheelDiameter>${2*wheelRadius}</wheelDiameter>
    <torque>20</torque>
    <!--<commandTopic>mybot/cmd_vel</commandTopic>-->
        <commandTopic>${ctopic}</commandTopic>
    <odometryTopic>mybot/odom_diffdrive</odometryTopic>
    <odometryFrame>odom</odometryFrame>
    <robotBaseFrame>footprint</robotBaseFrame>
  </plugin>
</gazebo>
...

robot.launch

...
  <!-- Load the URDF into the ROS Parameter Server -->
  <param name="robot_description"
     command="$(find xacro)/xacro.py '$(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"/>
...

Thanks

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

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="http://ros.org/wiki/xacro"
       name="mobile_claw">

  <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" />
    </joint>
  </xacro:if>
</robot>

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

<?xml version="1.0"?>
<launch>
  <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)"/>
</launch>

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

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

Seen: 1,619 times

Last updated: May 17 '18