Ask Your Question
0

xacro arg not working in lauch file

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

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 imagemarguedas ( 2020-01-08 17:02:59 -0600 )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 imageJoe28965 ( 2020-01-09 02:28:51 -0600 )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 imageJoe28965 ( 2020-01-09 02:31:46 -0600 )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 imagemarguedas ( 2020-01-10 04:51:41 -0600 )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 imageJoe28965 ( 2020-01-10 06:37:13 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

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

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

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: 2020-01-08 08:24:29 -0600

Seen: 14 times

Last updated: Jan 09