Ask Your Question

How to call macro with *origin and default params

asked 2020-12-11 21:27:57 -0600

sisko gravatar image

updated 2021-04-24 02:53:38 -0600

miura gravatar image

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="" 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"/>

        <link name="${name}_base_link">
                <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)}"/>
                    <mesh filename="package://velodyne_description/meshes/VLP16_base_1.dae" />
                    <mesh filename="package://velodyne_description/meshes/VLP16_base_2.dae" />
                <origin rpy="0 0 0" xyz="0 0 0.03585"/>
                    <cylinder radius="0.0516" length="0.0717"/>

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/catkin_ws/src/sweep_bot/urdf/macros.xacro) in file: /home/sisko/catkin_ws/src/sweep_bot/urdf/cleaner.xacro RLException: Invalid tag: Cannot load command parameter [robot_description]: command [['/opt/ros/melodic/lib/xacro/xacro', '/home/sisko/catkin_ws/src/sweep_bot/urdf/cleaner.xacro']] returned with code [2].

Param xml is The traceback for the exception was written to the ...

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2020-12-13 14:32:15 -0600

RobertWilbrandt gravatar image

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:

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

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" />  

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".

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2020-12-11 21:27:57 -0600

Seen: 350 times

Last updated: Dec 13 '20