Robotics StackExchange | Archived questions

How to call macro with *origin and default params

I am working on a xacro model and attempting to call a macro in a different xacro file, the contents of which are just below:

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

    <!-- LIDAR -->
    <xacro:macro name="VLP16" params="*origin parent:=base_link name:=velodyne topic:=/velodyne_points hz:=10 lasers:=16 samples:=1875 collision_range:=0.3 min_range:=0.9 max_range:=130.0 noise:=0.008 min_angle:=-${M_PI} max_angle:=${M_PI} gpu:=false">

        <joint name="${name}_base_mount_joint" type="fixed">
            <xacro:insert_block name="origin" />
            <parent link="${parent}"/>
            <child link="${name}_base_link"/>
        </joint>

        <link name="${name}_base_link">
            <inertial>
                <mass value="0.83"/>
                <origin xyz="0 0 0.03585"/>
                <inertia ixx="${(0.83 * (3.0*0.0516*0.0516 + 0.0717*0.0717)) / 12.0}" ixy="0" ixz="0" iyy="${(0.83 * (3.0*0.0516*0.0516 + 0.0717*0.0717)) / 12.0}" iyz="0" izz="${0.5 * 0.83 * (0.0516*0.0516)}"/>
            </inertial>
            <visual>
                <geometry>
                    <mesh filename="package://velodyne_description/meshes/VLP16_base_1.dae" />
                </geometry>
            </visual>
            <visual>
                <geometry>
                    <mesh filename="package://velodyne_description/meshes/VLP16_base_2.dae" />
                </geometry>
            </visual>
            <collision>
                <origin rpy="0 0 0" xyz="0 0 0.03585"/>
                <geometry>
                    <cylinder radius="0.0516" length="0.0717"/>
                </geometry>
            </collision>
        </link>
        .    
        .
        .
        .
    </xacro:macro>
</robot>

That xacro code creates a lidar and I copied it from the velodyn-simulator package into my own.

My problem is I'm having difficulty calling the macro from my xacro file. The parameters are all default values and unlikely to change so I set them as xacro properties so I can call the xacro without parameter. So, I added the following in at the beging of the xacro and removed all the params after the xacro name :

<xacro:property name="M_PI" value="3.1415926535897931" />
<xacro:property name="parent" value="chasis"/>
<xacro:property name="name" value="velodyne"/>
<xacro:property name="topic" value="/velodyne_points"/>
<xacro:property name="hz" value="10"/>
<xacro:property name="lasers" value="16"/>
<xacro:property name="samples" value="1875"/>
<xacro:property name="collision_range" value="0.3"/>
<xacro:property name="min_range" value="0.9"/>
<xacro:property name="max_range" value="130.0"/>
<xacro:property name="noise" value="0.008"/>
<xacro:property name="min_angle" value="-${M_PI}"/>
<xacro:property name="max_angle" value="${M_PI}"/>
<xacro:property name="gpu" value="false"/>

Then in my xacro file, I use <xacro:VLP16 /> in my attempt to call the xacro but I get an error saying :

Not enough blocks when instantiating macro: VLP16 (/home/sisko/catkinws/src/sweepbot/urdf/macros.xacro) in file: /home/sisko/catkinws/src/sweepbot/urdf/cleaner.xacro RLException: Invalid tag: Cannot load command parameter [robotdescription]: command [['/opt/ros/melodic/lib/xacro/xacro', '/home/sisko/catkinws/src/sweep_bot/urdf/cleaner.xacro']] returned with code [2].

Param xml is The traceback for the exception was written to the log file

It is my guess that the missing block is **origin* but I don't know what to pass to the macro for that parameter..

Whatever the issue is, I've exhausted my guesses and would appreciate some help.

Asked by sisko on 2020-12-11 22:27:57 UTC

Comments

Answers

You might want to take a look at the xacro wiki page, specifically point 7. The origin parameter is a block parameter and can be used like this:

<xacro:VLP16>  
  <origin xyz="1 2 3" rpy="0 0 0" />  
</xacro:VLP16>

You can find a corresponding <xacro:insert_block name="origin" /> tag in your xacro file.

One additional thing: Declaring properties will not actually pass them to the macro. Depending on your macro complexity it might still be nice to have them as properties, but you need to pass them on explicitly:

<xacro:VLP16 parent=${parent} name=${name} ...>  
  <origin xyz="1 2 3" rpy="0 0 0" />  
</xacro:VLP16>

In that case you might want to rename your properties for clarity, e.g. by giving them a sensor-specific prefix.

As a further note, you don't need the name=robot_name in the <robot> tag of your vlp16 xacro file if you don't plan on using it "by itself".

Asked by RobertWilbrandt on 2020-12-13 15:32:15 UTC

Comments