Importing a Google 3D Warehouse Model (.skp) into Gazebo

From MIT PR2

Jump to: navigation, search

Tutorial

This tutorial gives step-by-step instructions for importing a .skp (Google warehouse format) into Gazebo. If you already have an .stl or other blender-importable file, skip down to "Scaling the mesh".

  1. Creating a .stl file:
    1. You need Google Sketchup to open the .skp. To get Google Sketchup running in Ubuntu:
      1. Download and install wine using these instructions
      2. Download and install Google Sketchup 8 using these instructions. The instructions say they are for Sketchup 7, but they also work for Sketchup 8. NOTE: I don't think you need wintricks so you can skip running the scripts.
    2. Download this plugin for Sketchup and follow the directions for installing it in Windows. Your "C directory" is in the .wine/drive_c/ folder in your home directory. Note that .wine is hidden so you either need to be able to view hidden files or just type in the path name.
    3. Use Sketchup to convert the .skp to .stl:
      1. Sketchup may be in Applications > Wine > Programs > Google SketchUp 7 > Google SketchUp, but it didn't put a link there for me. If you see that link, use it to open Sketchup. Otherwise, the executable is in ~/.wine/drive_c/Program Files/Google/Google SketchUp 8 named Sketchup.exe. Right click on it and open it using wine.
      2. Open your .skp in Sketchup and go to Tools > Export to DXF or STL. When it asks you what type of DXF to export, choose STL. You should now have an .stl version of the model.
  2. Scaling the mesh: Update: I now think you can simply scale the mesh in the URDF file. So this is useful if you want a smaller model but no longer essential. In addition, it's useful to show you the approximate size of your object.
    1. Download Blender using apt-get install blender
    2. Open your .stl in blender using File > Import > STL
    3. Change to Object Mode (it may already be there) using the tab key or by selecting it in the mode box.
    4. Press the "s" key to scale the object.
    5. Start typing in a number to scale by that fraction. For most meshes from the google 3D warehouse, a scaling of 0.01 to 0.05 will probably be about right. The "grid" in blender is a reasonable size so your object should not look huge against it.
    6. Save a .blend version of the scaled object using File > Save
    7. Export the scaled object using File > Export > STL
    8. Blender Documentation
  3. Importing the .stl into Gazebo:
    1. Download this urdf file.
    2. Edit the urdf file to just to point to your .stl. Note that you need to change it everywhere broom.stl is mentioned!
    3. Start the simulator.
    4. Use rosrun gazebo spawn_model -file <your_file>.urdf -urdf -model <any_name_you_want_for_object> <position of spawning> to spawn the object in simulation.
    5. Here is an example of launching the simulator with the object already spawned.
  4. Editing the URDF file
    1. The <collision> and <visual> sections of the urdf should always be the same or what you see in simulation will not match the physics. If your object doesn't seem solid, it is probably due to a discrepancy between these two sections.
    2. To scale an object, add a scale="xscale yscale zscale" argument after each mesh filename as shown in this urdf file.
    3. The units of the URDF are MKS.
    4. It's reasonably important to have moments of inertia that tally with your mass and to get your COM in approximately the correct place. These do appear to make a difference, although the actual value you put in for the mass doesn't seem to matter as much.
    5. If you want the object to respond to gravity, you must remove the <turnGravityOff>true</turnGravityOff> line from the urdf file.

Common Problems

Please edit this section as you find and fix problems!

Gazebo crashes when I try to spawn my object.

  • Your object is probably bigger than the world (not in terms of number of triangles in the mesh or file size - just actual object dimensions can be too big). If you try to import a broom larger than Jupiter, the simulator will crash. See "Scaling the mesh" for how to shrink your object using blender or Editing the URDF for how to scale it just in the URDF file.

I was able to import my object, but it isn't solid.

  • Firstly, make sure the physics is on. With the physics off, the collision checking doesn't work (or maybe just doesn't work as well). If it was off, turn it on and try again. If this doesn't fix your problem, check your urdf file. If your <visual> and <collision> sections do not match exactly (are you rotating/scaling the object in collision, but not vision?), the object won't appear to be solid since what you see does not match where the simulator thinks the object is.

My object just hangs in the air and does not fall.

  • Firstly, make sure the physics is on. If it was off, turn it on and try again. If it still hangs in the air, the gravity is probably turned off for this object. Check your urdf file for the line
    <turnGravityOff>true</turnGravityOff>
and delete it.

My object spawns, but is spinning madly in the air.

  • Your object is probably too large. When it hits the ground plane, it is bouncing into the air with a lot of momentum. Turn gravity off for just the object by adding
   <gazebo reference="<name_of_link>">
     <turnGravityOff>true</turnGravityOff>
   </gazebo>
to the urdf and re-import the object. Now the object just floats where you imported it. Spawn a PR2 or something you know is correctly sized and compare sizes. If your object is huge, use "Scaling the mesh" or "Editing the URDF" to shrink it. If everything seems ok, you probably have a collision during spawning. The simulator does not react well to that. Change your spawn point.

The robot is spinning madly in the air.

  • You hit the robot with your object when you imported it. If your object is too large or you've set the mass in the urdf really high, this can bounce the robot into the air. Use the answer to "My object spawns, but is spinning madly in the air" to check the size of your object. If it is reasonably sized, change your spawning point so that the object does not fall on the robot.

I want to spawn something directly in the robot's grasp or on a table but with gravity off. When I do this, the object flies away at the lightest touch.

  • Turn off the physics just while you are spawning the object. Once it is spawned, turn the physics back on. The object should stay where it was spawned.

Blender's UI is incomprehensible.

  • Not much we can do about this one. Along with the documentation, you could also try the wikibook. But the best thing to do is find someone who knows how to use it and make them teach you.

Links

Along with the pages I've linked to in the tutorial, I found these ROS tutorials extremely helpful for working with objects in the simulator:

Personal tools