<?xml version="1.0"?>
<robot xmlns:xacro="http://www.ros.org/wiki/xacro">
  <xacro:macro name="square_wheel" params="name parent radius *origin">
    <link name="${name}_link">
      <inertial>
        <origin xyz="0 0 0" rpy="0 0 0"/>
        <mass value="1"/>
        <inertia ixx="0.2" ixy="0" ixz="0" iyy="0.2" iyz="0" izz="0.2"/>
      </inertial>
      <visual>
        <origin xyz="0 0 0" rpy="0 0 0"/>
        <geometry>
          <!-- use boxes for wheels, scale radius to account for "circumference" difference -->
          <box size="${wheel_radius*1.11} ${wheel_radius*1.11} ${wheel_radius*1.11} "/>
        </geometry>
      </visual>
      <collision>
        <origin xyz="0 0 0" rpy="0 0 0"/>
        <geometry>
          <box size="${wheel_radius*1.11} ${wheel_radius*1.11} ${wheel_radius*1.11} "/>
        </geometry>
      </collision>
    </link>

    <joint name="${name}_joint" type="continuous">
      <parent link="${parent}_link"/>
      <child link="${name}_link"/>
      <xacro:insert_block name="origin"/>
      <axis xyz="0 0 1"/>
    </joint>

    <!-- Transmission is important to link the joints and the controller -->
    <transmission name="${name}_joint_trans" type="SimpleTransmission">
      <actuator name="${name}_joint_motor"/>
      <joint name="${name}_joint"/>
      <mechanicalReduction>1</mechanicalReduction>
      <motorTorqueConstant>1</motorTorqueConstant>
    </transmission>

    <gazebo reference="${name}_link">
      <material>Gazebo/Red</material>
    </gazebo>
  </xacro:macro>
</robot>
