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

xacro arg not working in lauch file

asked 2020-01-08 08:24:29 -0500

Joe28965 gravatar image

I'm using ros kinetic and I'm trying to get an argument via the launch file in my xacro file. I've done some reading and found that this can be done by adding the following lines to a xacro file

<xacro:arg name="laser_topic" default="scan"/>
<xacro:property name="lidar_topic" value="$(arg laser_topic)"/>

This would mean I could add the argument laser_topic when I launch. The strange part is, if I do:

rosrun xacro xacro --inorder myrobot.xacro laser_topic:=scan_topic

or

rosrun xacro xacro --inorder myrobot.xacro laser_topic:=scan_topic > myrobot.urdf

It will actually use the correct topic, namely scan_topic. However, if I try it via a launch file, using the following piece of code to create the urdf and spawn my robot in Gazebo:

  <param name="robot_description" command="$(find xacro)/xacro --inorder '$(find project)/urdf/myrobot.xacro' laser_topic:=scan_topic"/> 

  <!-- 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 myrobot -param robot_description"/>

It keeps the old topic scan, not the new one scan_topic. What am I doing wrong?

edit retag flag offensive close merge delete

Comments

If you rosparam get /robot_description, do you have the result you expect (scan_topic) or the old topic ?

How is this property used in the xacro file?

marguedas gravatar image marguedas  ( 2020-01-08 17:02:59 -0500 )edit

The property is used like this:

<laser_scanner parent="base_link" topic="${lidar_topic}"/>

which then calls a xacro:macro:

  <xacro:macro name="laser_scanner" params="parent topic">

    <xacro:sick_tim551 name="${laser_name}" ros_topic="${topic}"/>

    <joint name="${laser_name}_mount_joint" type="fixed">
      <parent link="${parent}"/>
      <child link="${laser_name}_mount_link"/>
      <origin xyz="${base_length/2 - laser_distance_x} 0 ${base_height/2}" rpy="0 0 0"/>
    </joint>

  </xacro:macro>

and the xacro:sick_tim551 has this part:

<plugin name="gazebo_ros_${name}_controller" filename="libgazebo_ros_laser.so">
  <alwaysOn>true</alwaysOn>
  <updateRate>${update_rate}</updateRate>
  <topicName>${ros_topic}</topicName>
  <frameName>${link}</frameName>
</plugin>
Joe28965 gravatar image Joe28965  ( 2020-01-09 02:28:51 -0500 )edit

if I use rosparam get /robot_description I get <topicName>scan</topicName> meaning that it used the default value assigned to the argument.

I expect it to use (scan_topic) since I added the line laser_topic:=scan_topic to my robot description parameter.

Joe28965 gravatar image Joe28965  ( 2020-01-09 02:31:46 -0500 )edit

I tried this with a simple example but couldnt reproduce the error. Can you try to simplify the example on your side to pin down where things went wrong?

marguedas gravatar image marguedas  ( 2020-01-10 04:51:41 -0500 )edit

it turned out that I accidentally called the line

<param name="robot_description" command="$(find xacro)/xacro --inorder '$(find project)/urdf/myrobot.xacro'/>

somewhere else too. This meant the parameter got overwritten. Once I renamed it, it worked flawlessly. It went wrong between me and the keyboard, as they say. Thank you very much for your help though, it allowed me to better pin down the issue

Joe28965 gravatar image Joe28965  ( 2020-01-10 06:37:13 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-01-09 03:34:11 -0500

Joe28965 gravatar image

I found my mistake, turns out somewhere three launch files the parameter robot_description was used again. This time without the laser_topic:=scan_topic so the default scan was used again.

Renamed the parameter to my_robot_description and my problem is solved.

edit flag offensive delete link more

Comments

YES, this was frustrating to debug, thank you! If you are using MoveIt! setup assistant, move_group.launch and planning_context.launch have default args that may get in the way.

jdekarske gravatar image jdekarske  ( 2021-02-01 19:23:00 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2020-01-08 08:24:29 -0500

Seen: 658 times

Last updated: Jan 09 '20