Use xacro:macro as parent & another xacro:macro as child for a xacro:macro

asked 2022-12-02 08:01:41 -0500

Is_that_so gravatar image

updated 2022-12-02 08:05:34 -0500

Connect (continuous) front car wheel to a (revolute) axel to steer a single car wheel. Not looking to get fancy.

I do you call xacro's within each other to make more xacro's? I'm missing some simple logic and haven't found a solution.

Also using Humble on 22.04.

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

  <!-- Define robot constants -->
  <xacro:property name="base_width" value="0.073"/>
  <xacro:property name="base_length" value="0.142"/>
  <xacro:property name="base_height" value="0.024"/>

  <xacro:property name="wheel_radius" value="0.0135"/>
  <xacro:property name="wheel_width" value="0.011"/>
  <xacro:property name="wheel_ygap" value="0.00002"/>
  <xacro:property name="wheel_zoff" value="0.006"/>
  <xacro:property name="wheel_xoff" value="0.045"/>

  <!-- Robot Base -->
  <link name="base_link">
    <visual>
      <geometry>
        <box size="${base_length} ${base_width} ${base_height}"/>
      </geometry>
      <material name="Cyan">
        <color rgba="0 1.0 1.0 1.0"/>
      </material>
    </visual>
  </link>

  <!-- Robot Footprint -->
  <link name="base_footprint"/>

  <joint name="base_joint" type="fixed">
    <parent link="base_link"/>
    <child link="base_footprint"/>
    <origin xyz="0.0 0.0 ${-(wheel_radius+wheel_zoff)}" rpy="0 0 0"/>
  </joint>

<!-- Front Axles -->
<!-- Revolute to mimic steering for each front wheel. -->
  <xacro:macro name="fr_axle" params="prefix x_reflect y_reflect">
    <link name="${prefix}_link">
      <visual>
        <origin xyz="0 0 0" rpy="$0 0 0"/>
        <geometry>
            <cylinder radius="${wheel_radius}" length="${wheel_width}"/>
        </geometry>
        <material name="Gray">
          <color rgba="0.5 0.5 0.5 1.0"/>
        </material>
      </visual>
    </link>

    <joint name="${prefix}_joint" type="revolute">
      <parent link="base_link"/>
      <child link="${prefix}_link"/>
      <origin xyz="${x_reflect*wheel_xoff} ${y_reflect*(base_width/2+wheel_ygap)} ${-wheel_zoff}" rpy="0 0 0"/>
      <axis xyz="0 0 1"/>
      <limit lower="-0.575959" upper="0.575959" effort="12.2" velocity="2.0"/>
      <!-- Heads up that I haven't wrapped my head ^^ around effort and velocity ^^  -->
    </joint>
  </xacro:macro>

  <!-- Steering axles needed for front wheels -->
  <!-- I just want to connect each wheel to it's own axle because it seems like less trouble. -->
  <xacro:fr_axle prefix="axle_l" x_reflect="1" y_reflect="1" />
  <xacro:fr_axle prefix="axle_r" x_reflect="1" y_reflect="-1" />

<!-- Front wheels-->
<!-- Continuous spin to mimic front car wheels. -->
  <xacro:macro name="f_wheel" params="prefix x_reflect y_reflect">
    <link name="${prefix}_link">
      <visual>
        <origin xyz="0 0 0" rpy="${pi/2} 0 0"/>
        <geometry>
            <cylinder radius="${wheel_radius}" length="${wheel_width}"/>
        </geometry>
        <material name="Gray">
          <color rgba="0.5 0.5 0.5 1.0"/>
        </material>
      </visual>
    </link>

    <joint name="${prefix}_joint" type="continuous">
      <parent link="base_link"/>
      <child link="${prefix}_link"/>
      <origin xyz="${x_reflect*wheel_xoff} ${y_reflect*(base_width/2+wheel_ygap)} ${-wheel_zoff}" rpy="0 0 0"/>
      <axis xyz="0 1 ...
(more)
edit retag flag offensive close merge delete

Comments

It's not clear what question you are asking. If you are trying to debug your xacro file, have you tried using the xacro command line to expand it to a urdf file to verify that the urdf is what you want?

Mike Scheutzow gravatar image Mike Scheutzow  ( 2022-12-03 07:26:32 -0500 )edit

I'm trying to connect the continuous joint made in xacro:macro name="f_wheel" to a revolute joint made in xacro:macro name="fr_axle". The f_wheel joint parent link should be the child of the fr_axlechild link but considering the fr_axle is called as <xacro:fr_axle prefix="axle_l" x_reflect="1" y_reflect="1" /> for the right side and another for the left I need to some how call it a different way in order to become the parent link for f_wheel. How do I call the prefix="axle_l" as a parent?

Is_that_so gravatar image Is_that_so  ( 2022-12-05 06:13:35 -0500 )edit

Other people have already solved this. Have you done a web search for ackermann urdf?

Also, if it were me and I was running into trouble, I'd just write straight-forward urdf and not try to be clever with xacro.

Mike Scheutzow gravatar image Mike Scheutzow  ( 2022-12-05 07:42:37 -0500 )edit

I have and this works with ROS humble. I usually run into problems in Gazebo after changing the car size but I'll work around it. Thanks!

Is_that_so gravatar image Is_that_so  ( 2022-12-05 09:00:52 -0500 )edit