0
$\begingroup$

Rosanswers logo

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?


Originally posted by Joe28965 on ROS Answers with karma: 1124 on 2020-01-08

Post score: 0


Original comments

Comment by marguedas on 2020-01-08:
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?

Comment by Joe28965 on 2020-01-09:
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>

Comment by Joe28965 on 2020-01-09:
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.

Comment by marguedas on 2020-01-10:
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?

Comment by Joe28965 on 2020-01-10:
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

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by Joe28965 with karma: 1124 on 2020-01-09

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by jdekarske on 2021-02-01:
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.

$\endgroup$

Your Answer

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