ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

In case if you need a full code

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

    <!--INCLUDE FILES-->
<!--    <xacro:include filename="$(find description)/my_robot.gazebo" />-->

  <!-- Define robot constants -->
  <xacro:property name="base_width" value="0.2159"/>
  <xacro:property name="base_length" value="0.1524"/>
  <xacro:property name="base_height" value="0.10795"/>

  <xacro:property name="wheel_radius" value="0.0325"/>
  <xacro:property name="wheel_width" value="0.02"/>
  <xacro:property name="wheel_ygap" value="0.088"/>
  <xacro:property name="wheel_zoff" value="0.05"/>
  <xacro:property name="wheel_xoff" value="0.1"/>

  <xacro:property name="caster_xoff" value="0.14"/>

  <!-- Define some commonly used intertial properties  -->
  <xacro:macro name="box_inertia" params="m w h d">
    <inertial>
      <origin xyz="0 0 0" rpy="${pi/2} 0 ${pi/2}"/>
      <mass value="${m}"/>
      <inertia ixx="${(m/12) * (h*h + d*d)}" ixy="0.0" ixz="0.0" iyy="${(m/12) * (w*w + d*d)}" iyz="0.0" izz="${(m/12) * (w*w + h*h)}"/>
    </inertial>
  </xacro:macro>

  <xacro:macro name="cylinder_inertia" params="m r h">
    <inertial>
      <origin xyz="0 0 0" rpy="${pi/2} 0 0" />
      <mass value="${m}"/>
      <inertia ixx="${(m/12) * (3*r*r + h*h)}" ixy = "0" ixz = "0" iyy="${(m/12) * (3*r*r + h*h)}" iyz = "0" izz="${(m/2) * (r*r)}"/>
    </inertial>
  </xacro:macro>

 <!-- Robot Base -->
  <link name="base_link">
    <visual>
      <geometry>
    <box size="0.2159 0.1524 0.10795"/>
      </geometry>
      <material name="Cyan">
    <color rgba="0 1.0 1.0 1.0"/>
      </material>
    </visual>
    <collision>
    <geometry>
        <box size="0.2159 0.1524 0.10795"/>
      </geometry>
    </collision>

    <xacro:box_inertia m="15" w="0.2159" d="0.1524" h="0.10795"/>
  </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>


    <!-- Servos -->
    <link name ="head">
        <visual>
            <geometry>
                <cylinder radius="0.01" length="0.02"/>
            </geometry>
        <material name="white"/>
        </visual>
        <collision>
            <geometry>
                <cylinder radius="0.01" length="0.02"/>
            </geometry>
    </collision>

    <xacro:cylinder_inertia m="1" r="0.01" h="0.02"/>

    </link>

    <link name ="head2">
    <visual>
        <geometry>
            <cylinder radius="0.01" length="0.02"/>
        </geometry>
        <material name="Gray">
            <color rgba="0.5 0.5 0.5 1.0"/>
        </material>
    </visual>
    <collision>
    <geometry>
        <cylinder radius="0.01" length="0.02"/>
    </geometry>
    </collision>
    <xacro:cylinder_inertia m="0" r="0.01" h="0.02"/>
    </link>

    <!-- Wheels -->
  <xacro:macro name="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>
    <collision>
        <origin xyz="0 0 0" rpy="${pi/2} 0 0"/>
        <geometry>
            <cylinder radius="${wheel_radius}" length="${wheel_width}"/>
        </geometry>
    </collision>
    <xacro:cylinder_inertia m="0.5" r="0.01" h="0.02"/>
    </link>

      <joint name="${prefix}_joint" type="continuous">
      <parent link="base_link"/>
      <child link="${prefix}_link"/>
      <origin xyz="${x_reflect*wheel_xoff} ${y_reflect * (base_length/2 + wheel_width/2)} ${-wheel_zoff}" rpy="0 0 0"/>
      <axis xyz="0 1 0"/>
    </joint>
  </xacro:macro>

    <!-- Sensor -->
    <link name ="sensor">
    <visual>
        <geometry>
            <box size="0.02 0.04 0.01"/>
        </geometry>
        <material name="Royal Blue">
            <color rgba="83 51 237 1"/>
        </material>
    </visual>
    <collision>
        <geometry>
            <box size="0.02 0.04 0.01"/>
        </geometry>
        <material name="Royal Blue">
            <color rgba="83 51 237 1"/>
        </material>
    </collision>
    <xacro:box_inertia m="15" w="0.02" d="0.04" h="0.01"/>

    </link>

    <!--TEST    -->
<!--        <link name="lidar_link">-->
<!--          <inertial>-->
<!--            <origin xyz="0 0 0" rpy="0 0 0"/>-->
<!--            <mass value="0.125"/>-->
<!--            <inertia ixx="0.001"  ixy="0"  ixz="0" iyy="0.001" iyz="0" izz="0.001" />-->
<!--          </inertial>-->

<!--          <collision>-->
<!--            <origin xyz="0 0 0" rpy="0 0 0"/>-->
<!--            <geometry>-->
<!--               <cylinder radius="0.0508" length="0.055"/>-->
<!--            </geometry>-->
<!--          </collision>-->

<!--          <visual>-->
<!--            <origin xyz="0 0 0" rpy="0 0 0"/>-->
<!--            <geometry>-->
<!--               <cylinder radius="0.0508" length="0.055"/>-->
<!--            </geometry>-->
<!--          </visual>-->
<!--        </link>-->



    <gazebo reference="sensor">
      <sensor type="ray" name="TeraRanger">
          <pose>0 0 0 0 0 0</pose>
          <visualize>true</visualize>
          <update_rate>50</update_rate>
          <ray>
             <scan>
                <horizontal>
                   <samples>10</samples>
                   <resolution>1</resolution>
                   <min_angle>-0.14835</min_angle>
                   <max_angle>0.14835</max_angle>
                </horizontal>
                <vertical>
                   <samples>10</samples>
                   <resolution>1</resolution>
                   <min_angle>-0.14835</min_angle>
                   <max_angle>0.14835</max_angle>
                </vertical>
             </scan>
             <range>
                <min>0.01</min>
                <max>2</max>
                <resolution>0.02</resolution>
             </range>
          </ray>
          <plugin filename="libgazebo_ros_range.so" name="gazebo_ros_range">
             <gaussianNoise>0.005</gaussianNoise>
             <alwaysOn>true</alwaysOn>
             <updateRate>50</updateRate>
             <topicName>sensor/ir_front</topicName>
             <frameName>base_ir_front</frameName>
             <radiation>INFRARED</radiation>
             <fov>0.2967</fov>
          </plugin>
       </sensor>
       </gazebo>

    <joint name="head_attach" type="revolute">
    <origin xyz="0.090 0 0.064" rpy="0 0 0"/>
    <parent link="base_link"/>
    <child link="head"/>
    <limit effort="10.0" lower="-1.51" upper="1.51" velocity="30"/>
    <dynamics damping="0.0" friction="0.0"/>
    <axis xyz="0 0 1"/>
    </joint>

    <joint name="head_attach2" type="revolute">
    <origin xyz="0 0 0.02" rpy="0 1.6 0"/>
    <parent link="head"/>
    <child link="head2"/>
    <limit effort="1000.0" lower="-1.51" upper="1.51" velocity="30"/>
    <dynamics damping="0.0" friction="0.0"/>
    <axis xyz="0 0 1"/>
    </joint>

<!--    <joint name="boards" type="fixed">-->
<!--        <origin xyz="0.02 0 -0.02"/>-->
<!--        <parent link="head2"/>-->
<!--        <child link="lidar_link"/>-->
<!--        <limit effort="1000.0" lower="-15" upper="15" velocity="30"/>-->
<!--        <dynamics damping="0.0" friction="0.0"/>-->
<!--    </joint>-->

     <joint name="ultrasonic" type="fixed">
    <axis xyz="0 1 0" />
    <origin rpy="0 0 0" xyz="0.02 0 0" />
    <parent link="head2"/>
    <child link="sensor"/>
     </joint>






<!--  <xacro:wheel prefix="drivewhl_rl" x_reflect="-1" y_reflect="1" />-->
<!--  <xacro:wheel prefix="drivewhl_rr" x_reflect="-1" y_reflect="-1" />-->
<!--  <xacro:wheel prefix="drivewhl_fl" x_reflect="1" y_reflect="1" />-->
<!--  <xacro:wheel prefix="drivewhl_fr" x_reflect="1" y_reflect="-1" />-->


</robot>