Monday, May 4, 2020

Gazebo: make an animated box using a separate model file(s)

The Gazebo tutorial at shows how to make a box actor rotate around the vertical axis using only a world file. I wanted to use create a separate actor model and include it in the world file so I don't have to repeat the code. After fiddling around, I managed to figure out the procedure to do it. This post summarizes the steps.

Create an actor model
  1. In the user's home directory ~/.gazebo/models/, create a model folder, e.g. animated_box

    $ cd ~/.gazebo/models/
    $ mkdir -p animated_box/materials/scripts
    $ mkdir -p animated_box/materials/textures

  2. Change directory into the animated_box folder.

    $ cd animated_box

  3. Using a text editor, create a model.config file. Type in the following:
    <?xml version="1.0" encoding="utf-8"?>
     <name>Animated Box</name>
     <sdf version="1.4">model.sdf</sdf>
     <description>My animated box</description>

  4. Using a text editor, create a model.sdf file. Type in the following:

    Note: instead of the model tag, use the actor tag.
    <?xml version="1.0" encoding="utf-8"?>
    <sdf version="1.4">
     <actor name="animated_box">
       <link name="link">
        <visual name="visual">
           <size>0.2 0.2 0.2</size>
        <trajectory id="0" type="square">
          <pose>-1 -1 1 0 0 0</pose>
          <pose>-1 1 1 0 0 0</pose>
          <pose>1 1 1 0 0 0</pose>
          <pose>1 -1 1 0 0 0</pose>
          <pose>-1 -1 1 0 0 0</pose>

Create and run the world file
  1.  Using a text editor, create a world file, e.g. Type in the following commands:
    <?xml version="1.0" ?>
    <sdf version="1.3">
     <world name="default">

    Note: the previously created animated_box model is included as a model.

  2. Run the world file.

    $ gazebo

    Gazebo opens and an animated box is shown circling the z axis.