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

Xacro macro is not getting expanded/ substituted

asked 2022-06-28 13:03:49 -0500

dvy gravatar image

Hi,

I am using Ubuntu 20.04 focal with ROS noetic on amd64 (tried with arm64 as well) architecture. I have xacro file of husky robot by clearpath robotics from their official package and I am trying to add a ZED2 camera to the robot. I found ZED2's urdf from this package which works perfectly in their setup. I studied how the clearpath robotics has implemented arguments in xacro file to enable/ disable various sensors.

<!-- Intel Realsense camera related parameters or code-->
<xacro:arg name="realsense_enabled" default="$(optenv HUSKY_REALSENSE_ENABLED 0)" />
<xacro:arg name="realsense_xyz" default="$(optenv HUSKY_REALSENSE_XYZ 0 0.14 0)" />
<xacro:arg name="realsense_rpy" default="$(optenv HUSKY_REALSENSE_RPY 0 0 0)" />
<xacro:arg name="realsense_mount" default="$(optenv HUSKY_REALSENSE_MOUNT_FRAME sensor_arch_mount_link)" />

<xacro:include filename="$(find husky_description)/urdf/accessories/intel_realsense.urdf.xacro"/>

<!-- add the intel realsense to the sensor arch if needed -->
    <xacro:if value="$(arg realsense_enabled)">
        <link name="realsense_mountpoint"/>
        <joint name="realsense_mountpoint_joint" type="fixed">
        <origin xyz="$(arg realsense_xyz)" rpy="$(arg realsense_rpy)" />
        <parent link="$(arg realsense_mount)"/>
        <child link="realsense_mountpoint" />
        </joint>
        <xacro:intel_realsense_mount prefix="camera" topic="realsense" parent_link="realsense_mountpoint"/>
    </xacro:if>

I did something similar to add a ZED2 camera in the "husky.urdf.xacro" file

  <!-- Custom addition to xacro file to include ZED2 camera ; by Dev Vaibhav-->
  <xacro:arg name="zed2_enabled" default="$(optenv HUSKY_ZED2_ENABLED 1)" />
  <xacro:arg name="zed2_xyz" default="$(optenv HUSKY_ZED2_XYZ 0 0.14 0)" />
  <xacro:arg name="zed2_rpy" default="$(optenv HUSKY_ZED2_RPY 0 0 0)" />
  <xacro:arg name="zed2_mount" default="$(optenv HUSKY_ZED2_MOUNT_FRAME sensor_arch_mount_link)" />

  <xacro:include filename="$(find husky_description)/urdf/accessories/zed2.xacro"/>

  <xacro:property name="sensorbar_needed_zed2" value="$(arg zed2_enabled)" />

  <xacro:if value="${sensorbar_needed_realsense or sensorbar_user_enabled or sensorbar_needed_lidar or sensorbar_needed_zed2}">
    <xacro:sensor_arch prefix="" parent="top_plate_link" size="$(arg sensor_arch_height)">
        <origin xyz="$(optenv HUSKY_SENSOR_ARCH_OFFSET 0 0 0)" rpy="$(optenv HUSKY_SENSOR_ARCH_RPY 0 0 0)"/>
      </xacro:sensor_arch>
  </xacro:if>

  <!-- Custom addition to xacro file to include ZED2 camera ; by Dev Vaibhav-->
  <!-- add the zed2 to the sensor arch if needed -->
  <xacro:if value="$(arg zed2_enabled)">
    <link name="zed2_mountpoint"/>
    <joint name="zed2_mountpoint_joint" type="fixed">
      <origin xyz="$(arg zed2_xyz)" rpy="$(arg zed2_rpy)" />
      <parent link="$(arg zed2_mount)"/>
      <child link="zed2_mountpoint" />
    </joint>
    <xacro:zed2_mount prefix="" topic="zed2" parent_link="zed2_mountpoint"/>
  </xacro:if>

My "zed2.xacro" macro's look something like this. First is the parent macro <xacro:macro name="zed2_mount" params="prefix topic parent_link"> which I am calling through the line no. 256 in husky.urdf.xacro with no prefix; and inside that is the child macro <xacro:macro name="zed2" params="link_prefix:=${prefix} joint_prefix:=${prefix}"> With this code, I am trying to connect the ZED2 camera to robot with parent link as zed2_mountpoint (present on sensor arch on robot) and child link as zed2_camera_center (present on the sensor itself) but it is not working. I tried to visualize it in gazebo but I didn't see any ... (more)

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-06-30 19:43:12 -0500

Mike Scheutzow gravatar image

In the zed2.xacro file, you are defining macro "zed2" inside the definition of macro "zed2_mount". I wouldn't expect the xacro tool to handle a nested definition like you have created.

edit flag offensive delete link more

Comments

@Mike Scheutzow: I did so because "intel_realsense.urdf.xacro" also implemented nested xacro which is working fine. I also checked http://wiki.ros.org/xacro#Including_other_xacro_files where they say that "Macros may contain other macros. The outer macro will be expanded first, and then the inner macro will be expanded. For example:" Verbose debug output of rosrun xacro xacro --verbosity=4 husky.urdf.xacro > /home/ubuntu/Documents/debug.txt gives below relevant output which seems insufficient to me for debugging. Any ideas?

use zed2_mount: <xacro.Macro object at 0xffffbc5bcb80> (husky.urdf.xacro)
 set prefix:  (husky.urdf.xacro)
 set topic: zed2 (husky.urdf.xacro)
 set parent_link: zed2_mountpoint (husky.urdf.xacro)
 set baseline: 0.12 (husky.urdf.xacro)
 set zed2: <xacro.Macro object at 0xffffba8717f0> (husky.urdf.xacro)
 set zed2_gazebo: <xacro.Macro object at 0xffffba871820> (husky.urdf.xacro
dvy gravatar image dvy  ( 2022-07-01 09:00:20 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2022-06-28 12:52:29 -0500

Seen: 183 times

Last updated: Jun 30 '22