Difference between revisions of "Build a Robot"

From Lofaro Lab Wiki
Jump to: navigation, search
(Make a model)
Line 16: Line 16:
 
First create the model file
 
First create the model file
  
    <nowiki>gedit box.sdf</nowiki>
+
<syntaxhighlight lang="bash">gedit box.sdf</syntaxhighlight>
  
 
Copy the contents below into box.sdf
 
Copy the contents below into box.sdf
Line 71: Line 71:
 
'''Make a Mobile Robot'''
 
'''Make a Mobile Robot'''
 
1) Create directory for your models
 
1) Create directory for your models
    <nowiki> mkdir -p ~/.gazebo/models/my_robot </nowiki>
+
<syntaxhighlight lang="bash"> mkdir -p ~/.gazebo/models/my_robot </syntaxhighlight>
  
 
2) Create model.config file
 
2) Create model.config file
    <nowiki> gedit ~/.gazebo/models/my_robot/model.config</nowiki>
+
<syntaxhighlight lang="bash"> gedit ~/.gazebo/models/my_robot/model.config</syntaxhighlight>
  
 
3) Copy the following into the file
 
3) Copy the following into the file
    <nowiki><?xml version="1.0"?>
+
<syntaxhighlight lang="xml"><?xml version="1.0"?>
 
<model>
 
<model>
 
   <name>My Robot</name>
 
   <name>My Robot</name>
Line 91: Line 91:
 
     My awesome robot.
 
     My awesome robot.
 
   </description>
 
   </description>
</model></nowiki>
+
</model></syntaxhighlight>
  
 
4) Create a .sdf file
 
4) Create a .sdf file
    <nowiki>gedit ~/.gazebo/models/my_robot/model.sdf</nowiki>
+
<syntaxhighlight lang="bash">gedit ~/.gazebo/models/my_robot/model.sdf</syntaxhighlight>
  
 
5) Copy the following into the file
 
5) Copy the following into the file
     <nowiki><?xml version='1.0'?>
+
     <syntaxhighlight lang="xml"><?xml version='1.0'?>
 
<sdf version='1.4'>
 
<sdf version='1.4'>
 
   <model name="my_robot">
 
   <model name="my_robot">
 
   </model>
 
   </model>
</sdf></nowiki>
+
</sdf></syntaxhighlight>
  
 
Build the Model's Structure
 
Build the Model's Structure
Line 107: Line 107:
  
 
1) Make model static by adding the following under the line containing model name
 
1) Make model static by adding the following under the line containing model name
    <nowiki><static>true</static></nowiki>
+
<syntaxhighlight lang="bash"><static>true</static></syntaxhighlight>
  
 
2) Add base by adding the following right under the <static>true</static>
 
2) Add base by adding the following right under the <static>true</static>
    <nowiki> <link name='chassis'>
+
<syntaxhighlight lang="xml"> <link name='chassis'>
 
             <pose>0 0 .1 0 0 0</pose>
 
             <pose>0 0 .1 0 0 0</pose>
  
Line 128: Line 128:
 
               </geometry>
 
               </geometry>
 
             </visual>
 
             </visual>
           </link></nowiki>
+
           </link></syntaxhighlight>
  
 
3) Run Gazebo with model to make sure it is displayed correctly
 
3) Run Gazebo with model to make sure it is displayed correctly
  
 
4) Add caster by adding the following under part 2 (caster: sphere with no friction; substitute for wheel which has a joint)
 
4) Add caster by adding the following under part 2 (caster: sphere with no friction; substitute for wheel which has a joint)
    <nowiki><collision name='caster_collision'>
+
<syntaxhighlight lang="xml"><collision name='caster_collision'>
 
             <pose>-0.15 0 -0.05 0 0 0</pose>
 
             <pose>-0.15 0 -0.05 0 0 0</pose>
 
             <geometry>
 
             <geometry>
Line 160: Line 160:
 
               </sphere>
 
               </sphere>
 
             </geometry>
 
             </geometry>
           </visual></nowiki>
+
           </visual></syntaxhighlight>
  
 
5) Spawn it in Gazebo to make sure it displays correctly
 
5) Spawn it in Gazebo to make sure it displays correctly
Line 166: Line 166:
 
6) Add left wheel by adding the following under the lines containing geometry, visual, link
 
6) Add left wheel by adding the following under the lines containing geometry, visual, link
  
    <nowiki><link name="left_wheel">
+
<syntaxhighlight lang="xml"><link name="left_wheel">
 
         <pose>0.1 0.13 0.1 0 1.5707 1.5707</pose>
 
         <pose>0.1 0.13 0.1 0 1.5707 1.5707</pose>
 
         <collision name="collision">
 
         <collision name="collision">
Line 184: Line 184:
 
           </geometry>
 
           </geometry>
 
         </visual>
 
         </visual>
       </link></nowiki>
+
       </link></syntaxhighlight>
  
 
7) Add a right wheel by copying the left wheel, by adding the following under the above lines
 
7) Add a right wheel by copying the left wheel, by adding the following under the above lines
    <nowiki><link name="right_wheel">
+
<syntaxhighlight lang="xml"><link name="right_wheel">
 
         <pose>0.1 -0.13 0.1 0 1.5707 1.5707</pose>
 
         <pose>0.1 -0.13 0.1 0 1.5707 1.5707</pose>
 
         <collision name="collision">
 
         <collision name="collision">
Line 205: Line 205:
 
           </geometry>
 
           </geometry>
 
         </visual>
 
         </visual>
       </link></nowiki>
+
       </link></syntaxhighlight>
  
 
8) Make the model dynamic by changing the <static> to false and add the following under lines from part 7  
 
8) Make the model dynamic by changing the <static> to false and add the following under lines from part 7  
    <nowiki>  <joint type="revolute" name="left_wheel_hinge">
+
<syntaxhighlight lang="xml">  <joint type="revolute" name="left_wheel_hinge">
 
         <pose>0 0 -0.03 0 0 0</pose>
 
         <pose>0 0 -0.03 0 0 0</pose>
 
         <child>left_wheel</child>
 
         <child>left_wheel</child>
Line 224: Line 224:
 
           <xyz>0 1 0</xyz>
 
           <xyz>0 1 0</xyz>
 
         </axis>
 
         </axis>
       </joint></nowiki>
+
       </joint></syntaxhighlight>
  
 
9) Follow steps 2,3 and 4 towards the bottom of the screen on this [http://gazebosim.org/tutorials?tut=build_robot&ver=1.9%2B&cat=build_robot link] to move the robot around with controllers for each joint
 
9) Follow steps 2,3 and 4 towards the bottom of the screen on this [http://gazebosim.org/tutorials?tut=build_robot&ver=1.9%2B&cat=build_robot link] to move the robot around with controllers for each joint
Line 233: Line 233:
 
1) Test the Mesh
 
1) Test the Mesh
 
Replace my_mesh.dae with your actual filename of the mesh you wish to test
 
Replace my_mesh.dae with your actual filename of the mesh you wish to test
    <nowiki><?xml version="1.0"?>
+
<syntaxhighlight lang="xml"><?xml version="1.0"?>
 
<sdf version="1.4">
 
<sdf version="1.4">
 
   <world name="default">
 
   <world name="default">
Line 254: Line 254:
 
     </model>
 
     </model>
 
   </world>
 
   </world>
</sdf></nowiki>
+
</sdf></syntaxhighlight>
  
 
launch Gazebo
 
launch Gazebo
    <nowiki>gazebo my_mesh.world</nowiki>
+
<syntaxhighlight lang="bash">gazebo my_mesh.world</syntaxhighlight>
  
 
'''Attach Meshes'''
 
'''Attach Meshes'''
  
 
1) Navigate to directly with model robot
 
1) Navigate to directly with model robot
    <nowiki>cd ~/.gazebo/models/my_robot</nowiki>
+
<syntaxhighlight lang="bash">cd ~/.gazebo/models/my_robot</syntaxhighlight>
  
 
2) Open model.sdf  
 
2) Open model.sdf  
    <nowiki>gedit ~/.gazebo/models/my_robot/model.sdf</nowiki>
+
<syntaxhighlight lang="bash">gedit ~/.gazebo/models/my_robot/model.sdf</syntaxhighlight>
  
 
3) Add mesh so that the visual with name=visual will now look like  
 
3) Add mesh so that the visual with name=visual will now look like  
    <nowiki><visual name='visual'>
+
<syntaxhighlight lang="xml"><visual name='visual'>
 
       <geometry>
 
       <geometry>
 
         <mesh>
 
         <mesh>
Line 274: Line 274:
 
         </mesh>
 
         </mesh>
 
       </geometry>
 
       </geometry>
     </visual></nowiki>
+
     </visual></syntaxhighlight>
  
 
4) Drag the My Robot model in the world
 
4) Drag the My Robot model in the world
  
 
5) Scale the visual by adding a scaling factor under the uri
 
5) Scale the visual by adding a scaling factor under the uri
    <nowiki><scale>0.9 0.5 0.5</scale></nowiki>
+
<syntaxhighlight lang="xml"><scale>0.9 0.5 0.5</scale></syntaxhighlight>
  
 
6) Raise the visual by adding under visual name = visual
 
6) Raise the visual by adding under visual name = visual
    <nowiki><pose>0 0 0.05 0 0 0</pose></nowiki>
+
<syntaxhighlight lang="xml"><pose>0 0 0.05 0 0 0</pose></syntaxhighlight>

Revision as of 21:50, 11 November 2014

Make a model

This tutorial is based off of the tutorial from this page. SDF models can be something as basic as simple shapes or as complex as intricate robots.

Components of SDF Models --Links, Collision, Visual, Inertial, Sensor, Joints, Plugins

Building a Model

1) Collect your meshes Simple shapes are provided in Gazebo (box, sphere, cylinder). Meshes are most commonly used to make your model look realistic. You can look for meshes in Google's 3D warehouse. Or you can create your own meshes using Blender / Sketchup. STL/Collada format is required for mesh files.

2) Make your model SDF file Start with something simple so that if you need to debug, it will be easier than debugging a model you are not familiar with.

First create the model file

gedit box.sdf

Copy the contents below into box.sdf

<sdf version="1.4">
<model name="my_model">
  <pose>0 0 0.5 0 0 0</pose>
  <static>true</static>
    <link name="link">
      <inertial>
        <mass>1.0</mass>
        <inertia> <!-- interias are tricky to compute -->
          <!-- http://answers.gazebosim.org/question/4372/the-inertia-matrix-explained/ -->
          <ixx>0.083</ixx>       <!-- for a box: ixx = 0.083 * mass * (y*y + z*z) -->
          <ixy>0.0</ixy>         <!-- for a box: ixy = 0 -->
          <ixz>0.0</ixz>         <!-- for a box: ixz = 0 -->
          <iyy>0.083</iyy>       <!-- for a box: iyy = 0.083 * mass * (x*x + z*z) -->
          <iyz>0.0</iyz>         <!-- for a box: iyz = 0 -->
          <izz>0.083</izz>       <!-- for a box: izz = 0.083 * mass * (x*x + y*y) -->
        </inertia>
      </inertial>
      <collision name="collision">
        <geometry>
          <box>
            <size>1 1 1</size>
          </box>
        </geometry>
      </collision>
      <visual name="visual">
        <geometry>
          <box>
            <size>1 1 1</size>
          </box>
        </geometry>
      </visual>
    </link>
  </model>
</sdf>

3) Add to model SDF file After each addition, load the model to make sure it is displayed correctly. In what order to add features (suggested, from gazebosim.org tutorials): 1.Add a link. 2.Set the collision element. 3.Set the visual element. 4.Set the inertial properties. 5.Go to #1 until all links have been added. 6.Add all joints (if any). 7.Add all plugins (if any)

Make a Mobile Robot 1) Create directory for your models

 mkdir -p ~/.gazebo/models/my_robot

2) Create model.config file

 gedit ~/.gazebo/models/my_robot/model.config

3) Copy the following into the file

<?xml version="1.0"?>
<model>
  <name>My Robot</name>
  <version>1.0</version>
  <sdf version='1.4'>model.sdf</sdf>
 
  <author>
   <name>My Name</name>
   <email>me@my.email</email>
  </author>
 
  <description>
    My awesome robot.
  </description>
</model>

4) Create a .sdf file

gedit ~/.gazebo/models/my_robot/model.sdf

5) Copy the following into the file

<?xml version='1.0'?>
<sdf version='1.4'>
  <model name="my_robot">
  </model>
</sdf>

Build the Model's Structure -- make changes to ~/.gazebo/models/my_robot/model.sdf

1) Make model static by adding the following under the line containing model name

<static>true</static>

2) Add base by adding the following right under the <static>true</static>

 <link name='chassis'>
            <pose>0 0 .1 0 0 0</pose>
 
            <collision name='collision'>
              <geometry>
                <box>
                  <size>.4 .2 .1</size>
                </box>
              </geometry>
            </collision>
 
            <visual name='visual'>
              <geometry>
                <box>
                  <size>.4 .2 .1</size>
                </box>
              </geometry>
            </visual>
          </link>

3) Run Gazebo with model to make sure it is displayed correctly

4) Add caster by adding the following under part 2 (caster: sphere with no friction; substitute for wheel which has a joint)

<collision name='caster_collision'>
            <pose>-0.15 0 -0.05 0 0 0</pose>
            <geometry>
                <sphere>
                <radius>.05</radius>
              </sphere>
            </geometry>
 
            <surface>
              <friction>
                <ode>
                  <mu>0</mu>
                  <mu2>0</mu2>
                  <slip1>1.0</slip1>
                  <slip2>1.0</slip2>
                </ode>
              </friction>
            </surface>
          </collision>
 
          <visual name='caster_visual'>
            <pose>-0.15 0 -0.05 0 0 0</pose>
            <geometry>
              <sphere>
                <radius>.05</radius>
              </sphere>
            </geometry>
          </visual>

5) Spawn it in Gazebo to make sure it displays correctly

6) Add left wheel by adding the following under the lines containing geometry, visual, link

<link name="left_wheel">
        <pose>0.1 0.13 0.1 0 1.5707 1.5707</pose>
        <collision name="collision">
          <geometry>
            <cylinder>
              <radius>.1</radius>
              <length>.05</length>
            </cylinder>
          </geometry>
        </collision>
        <visual name="visual">
          <geometry>
            <cylinder>
              <radius>.1</radius>
              <length>.05</length>
            </cylinder>
          </geometry>
        </visual>
      </link>

7) Add a right wheel by copying the left wheel, by adding the following under the above lines

<link name="right_wheel">
        <pose>0.1 -0.13 0.1 0 1.5707 1.5707</pose>
        <collision name="collision">
          <geometry>
            <cylinder>
              <radius>.1</radius>
              <length>.05</length>
            </cylinder>
          </geometry>
        </collision>
        <visual name="visual">
          <geometry>
            <cylinder>
              <radius>.1</radius>
              <length>.05</length>
            </cylinder>
          </geometry>
        </visual>
      </link>

8) Make the model dynamic by changing the <static> to false and add the following under lines from part 7

  <joint type="revolute" name="left_wheel_hinge">
        <pose>0 0 -0.03 0 0 0</pose>
        <child>left_wheel</child>
        <parent>chassis</parent>
        <axis>
          <xyz>0 1 0</xyz>
        </axis>
      </joint>
 
      <joint type="revolute" name="right_wheel_hinge">
        <pose>0 0 0.03 0 0 0</pose>
        <child>right_wheel</child>
        <parent>chassis</parent>
        <axis>
          <xyz>0 1 0</xyz>
        </axis>
      </joint>

9) Follow steps 2,3 and 4 towards the bottom of the screen on this link to move the robot around with controllers for each joint

Import Meshes 'Reduce Complexity, Center the mesh, Scale the mesh'

1) Test the Mesh Replace my_mesh.dae with your actual filename of the mesh you wish to test

<?xml version="1.0"?>
<sdf version="1.4">
  <world name="default">
    <include>
      <uri>model://ground_plane</uri>
    </include>
    <include>
      <uri>model://sun</uri>
    </include>
    <model name="my_mesh">
      <pose>0 0 0  0 0 0</pose>
      <static>true</static>
      <link name="body">
        <visual name="visual">
          <geometry>
            <mesh><uri>file://my_mesh.dae</uri></mesh>
          </geometry>
        </visual>
      </link>
    </model>
  </world>
</sdf>

launch Gazebo

gazebo my_mesh.world

Attach Meshes

1) Navigate to directly with model robot

cd ~/.gazebo/models/my_robot

2) Open model.sdf

gedit ~/.gazebo/models/my_robot/model.sdf

3) Add mesh so that the visual with name=visual will now look like

<visual name='visual'>
      <geometry>
        <mesh>
          <uri>model://pioneer2dx/meshes/chassis.dae</uri>
        </mesh>
      </geometry>
    </visual>

4) Drag the My Robot model in the world

5) Scale the visual by adding a scaling factor under the uri

<scale>0.9 0.5 0.5</scale>

6) Raise the visual by adding under visual name = visual

<pose>0 0 0.05 0 0 0</pose>