0
$\begingroup$

thisis my example xacro file and I need to change robot_namespace property's value

<?xml version="1.0"?>
<robot name="turtlebot3_waffle_pi_sim" xmlns:xacro="http://ros.org/wiki/xacro">

<xacro:property name="robot_namespace" value="robot1"/> 
  <plugin name="turtlebot3_waffle_pi_controller" filename="libgazebo_ros_diff_drive.so">
      <odometryTopic>${robot_namespace}/odom</odometryTopic>
  <odometryFrame>${robot_namespace}/odom</odometryFrame>

    </plugin>

</robot>

I am trying to format this file with xacro pathOfXacroFile robot_namespace:=robot2 but in the output it shows always the default value not the formatted one

$\endgroup$

1 Answer 1

0
$\begingroup$

You are trying to override the robot_namespace in the xacro file. For your scenario, you need to set the xacro property using a xacro argument (arg).

  • Modify your xacro file: Adding an arg means we enable the file to accept command line arguments. Let's make an arg for the robot_namespace.
<?xml version="1.0"?>

<robot name="turtlebot3_waffle_pi_sim" xmlns:xacro="http://ros.org/wiki/xacro">

  <!-- New arg to add with the same default -->
  <xacro:arg name="robot_namespace" default="robot1"/>
  <xacro:property name="robot_namespace" value="$(arg robot_namespace)"/> 
  
  <plugin name="turtlebot3_waffle_pi_controller" filename="libgazebo_ros_diff_drive.so">
      <odometryTopic>${robot_namespace}/odom</odometryTopic>
  <odometryFrame>${robot_namespace}/odom</odometryFrame>
  </plugin>
</robot>
  • Test with the same command in the question:
xacro pathOfXacroFile robot_namespace:=robot2

This will print the xacro file content with the required change. Hope this helps!

$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.