I'm trying to make a .xacro file for a UR5e robot, that allows choosing the gripper at launch, which means choosing different macros inside of it and I'm doing it based on the answer here. The setup is based on the ur moveit config so launching the robot goes like this:
- You launch
robot_setup.launch
- which launches
planning_execution.launch
- which then launches
planning_context.launch
- from which the robot.xacro is read as a
<param...
I want to change a parameter at robot_setup.launch
and have it change a parameter in the .xacro
.
Snippet of the xacro code:
<xacro:arg name="gripper_type" default="other"/>
<xacro:property name="gripper_type" value="$(arg gripper_type)" />
<!-- instantiating arm and gripper -->
<xacro:if value="${gripper_type == 'robotiq'}">
<xacro:robotiq_arg2f_140 prefix="${arm_prefix}"/>
</xacro:if>
<xacro:if value="${gripper_type == 'other'}">
<xacro:vacuum_gripper_definition prefix="${arm_prefix}" gripper_adjustment="0.00"/>
</xacro:if>
So I'm trying to pass gripper_type
from the robot_setup.launch
all the way through the mentioned files, to change it in the .xacro
, but in the end, the default value in the .xacro
stays unchanged, so what am I doing wrong?
Snippet from setup.launch
:
<arg name="gripper_type" default="other" />
<include file="$(find moveit_config)/launch/planning_execution.launch">
<arg name="gripper_type" value="$(arg gripper_type)" />
</include>
Snippet from planning_execution.launch
:
<arg name="gripper_type"/>
<include file="$(find moveit_config)/launch/planning_context.launch" >
<arg name="load_robot_description" value="true"/>
<arg name="gripper_type" value="$(arg gripper_type)"/>
</include>
Snippet from planning_context.launch
:
<arg name="gripper_type"/>
<param if="$(arg load_robot_description)" name="$(arg robot_description)" command="xacro '$(find robot_config)/urdf/.xacro' gripper_type:=$(arg gripper_type)"/>
Originally posted by sniegs on ROS Answers with karma: 65 on 2022-03-10
Post score: 0
Original comments
Comment by tryan on 2022-03-11:
What command are you using to run setup.launch
?
Comment by Mike Scheutzow on 2022-03-12:
I deleted my answer: passing user args to xacro using a syntax like n:=42
is supported in melodic.
Comment by sniegs on 2022-03-13:
@tryan I run it with roslaunch
, if it's of some importance, the roscore is on a second computer and they are connected through rosmaster, perhaps I needed to restart the whole roscore for the changes to take effect?
Comment by tryan on 2022-03-13:
It shouldn't matter where the master is running. I see that your xacro file defaults to "other," and that is also the default in setup.launch
. What command are you using that you expect to get a different value for gripper_type
?
Comment by sniegs on 2022-03-14:
@tryan gripper_type is the variable I've added in xacro. It has values "other" and "robotiq". I wasn't able to launch it without setting a default in both the setup.launch
and xacro. The command for launching would be roslaunch package setup.launch gripper_type:=robotiq
or other
, depending on the situation
Comment by Mike Scheutzow on 2022-04-27:\
Have you tried using the new syntax
<xacro:arg ...>
and<xacro:include ...>
?It's not clear to me that you can redefine an xacro:arg, or pass it "into" an included file. If xacro app reads the text content of the named file and interprets it in the parent's context, then the xacro:arg defined in the parent would be used to expand the content of the included file.
Comment by Mike Scheutzow on 2022-04-27:
Ugh. I got confused between include in launch file and include in the xacro file. I will look at the issue again.
Comment by Mike Scheutzow on 2022-04-28:
Based on what you provided above, my experiments show the xacro:property
being set to the expected value. Do you get the desired urdf if you directly run xacro from the command line?