<?xml version="1.0"?>
<sdf version="1.7" 
  xmlns:xacro="http://www.ros.org/wiki/xacro">

  <xacro:macro name="pendulum" params="name mass length radius color *pose *dynamics">
    <model name="${name}">
      <xacro:insert_block name="pose"/>
      <frame name="base_link">
      <pose>0 0 0 0 0 0</pose>
      </frame>
      <joint name="joint" type="revolute">
        <parent>world</parent>
        <child>rod</child>
        <pose relative_to="base_link">0 0 0 0 0 0</pose>
        <axis>
          <xyz>1 0 0</xyz>
          <xacro:insert_block name="dynamics" />
          <limit>
            <lower>-1e+16</lower>
            <upper>1e+16</upper>
          </limit>
        </axis>
      </joint>
      <link name="rod">
        <pose relative_to="base_link">0 0 ${-length/2} 0 0 0</pose>
        <inertial>
          <pose>0 0 ${-length/2} 0 0 0</pose>
          <mass>${mass}</mass>
          <inertia>
            <ixx>${1/3 * mass * length * length}</ixx>
            <ixy>0</ixy>
            <ixz>0</ixz>
            <iyy>${1/3 * mass * length * length}</iyy>
            <iyz>0</iyz>
            <izz>${1/3 * mass * length * length}</izz>
          </inertia>
        </inertial>
        <collision name="rod_collision">
          <pose>0 0 0 0 0 0</pose>
          <geometry>
            <cylinder>
              <length>${length}</length>
              <radius>${radius}</radius>
            </cylinder>
          </geometry>
          <surface>
            <contact>
              <ode>
                <kp>1e+06</kp>
                <kd>1</kd>
              </ode>
            </contact>
            <friction>
              <ode>
                <mu>1</mu>
                <mu2>1</mu2>
              </ode>
            </friction>
          </surface>
        </collision>
        <visual name="rod_visual">
          <pose>0 0 0 0 0 0</pose>
          <geometry>
            <cylinder>
              <length>${length}</length>
              <radius>${radius}</radius>
            </cylinder>
          </geometry>
          <material>
            <ambient>${color}</ambient>
            <diffuse>${color}</diffuse>
            <specular> 0.01 0.01 0.01 1.0</specular>
          </material>
        </visual>
        <gravity>1</gravity>
        <velocity_decay/>
      </link>
    </model>
  </xacro:macro>
</sdf>