Tutorials/1.3/intermediate/animate pose


 * 1) Tutorial: Animate Pose#

An animation engine built into Gazebo allows you to move models around the environment without relying on the physics engine. This may be desirable for character animation, or any situation where planned movement of a non-dynamic object is desired.

In this tutorial, we will keep it simple and animate a box on a plane.


 * 1) Setup ##

First create a work directory.

mkdir ~/gazebo_animate_pose cd ~/gazebo_animate_pose


 * 1) World File ##

This is the world we'll use for this tutorial. Notice that we defined our box model as `static`. This tells Gazebo not to simulate the model in the physics engine.

The world file will not run at this point because we have not yet compiled and installed the plugin specified in the world file.

Create a world file:

gedit ~/gazebo_animate_pose/animate_pose.world

Copy and past this xml code into it:

  model://ground_plane

 0 0 0.5 0 0 0                            1 1 1                             1 1 1              true  0 0 10 0 0 0            1.0 1.0 1.0 1             0 0 0 1                 20                 0.01                 0.8                 0.0             0.0 0.2 -8.0             true

Run this world file:

gazebo ~/gazebo_animate_pose/animate_pose.world

'''NOTE: This will produce an error on the command line about a missing plugin. This error can be safely ignored.'''

$ gazebo ~/gazebo_animate_pose/animate_pose.world Gazebo multi-robot simulator, version 1.3 Copyright (C) 2011 Nate Koenig, John Hsu, and contributors. Released under the Apache 2 License. http://gazebosim.org

Gazebo multi-robot simulator, version 1.3 Copyright (C) 2011 Nate Koenig, John Hsu, and contributors. Released under the Apache 2 License. http://gazebosim.org

Msg Waiting for master Msg Connected to gazebo master @ http://localhost:11345 Msg Waiting for master Msg Connected to gazebo master @ http://localhost:11345 Error [Plugin.hh:120] Failed to load plugin libanimate_pose.so: libanimate_pose.so: cannot open shared object file: No such file or directory


 * 1) Animation Plugin ###

The plugin must be attached to a model (as in the above world file). When it is loaded, the plugin will move its parent model 5 meters in the X direction, and apply a 180 degree rotation around the Z axis.

Create a plugin:

gedit ~/gazebo_animate_pose/animate_pose.cc

Copy and paste this code into it.


 * 1) include "common/CommonTypes.hh"
 * 2) include "common/Animation.hh"
 * 3) include "common/KeyFrame.hh"
 * 4) include "physics/Model.hh"
 * 5) include "gazebo.hh"

namespace gazebo { class AnimatePose : public ModelPlugin {   public: void Load(physics::ModelPtr _parent, sdf::ElementPtr /*_sdf*/) {     gazebo::common::PoseAnimationPtr anim(          new gazebo::common::PoseAnimation("test", 1000.0, true));

gazebo::common::PoseKeyFrame *key;

key = anim->CreateKeyFrame(0); key->SetTranslation(math::Vector3(0, 0, 0)); key->SetRotation(math::Quaternion(0, 0, 0));

key = anim->CreateKeyFrame(10.0); key->SetTranslation(math::Vector3(5, 0, 0)); key->SetRotation(math::Quaternion(0, 0, 1.5707));

_parent->SetAnimation(anim); } };

// Register this plugin with the simulator GZ_REGISTER_MODEL_PLUGIN(AnimatePose) }

Create a CMake script file:
 * 1) Build ##

gedit ~/gazebo_animate_pose/CMakeLists.txt

Copy this content into it:

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)

include (FindPkgConfig) if (PKG_CONFIG_FOUND) pkg_check_modules(GAZEBO gazebo) endif include_directories(${GAZEBO_INCLUDE_DIRS}) link_directories(${GAZEBO_LIBRARY_DIRS})

add_library(animate_pose SHARED animate_pose.cc) target_link_libraries(animate_pose ${GAZEBO_libraries})

Create a `build` directory and compile the plugin:

mkdir ~/gazebo_animate_pose/build cd ~/gazebo_animate_pose/build cmake .. make


 * 1) Run Tutorial ##

Add the current directory to the shared library path and run gazebo with the world we just created. Close down previous instances of gazebo if you haven't already. In a terminal

cd ~/gazebo_animate_pose/build export GAZEBO_PLUGIN_PATH=`pwd`:$GAZEBO_PLUGIN_PATH gazebo ~/gazebo_animate_pose/animate_pose.world

You should see the box moving forward and rotating.


 * 1) Things to try on your own##

1. Add another box to the world. 1. Make the first box move forward (along the x-axis) 1 meter and stop. 1. Once the first box has stopped moving, make the second box move 1 meter along the y-axis.

Tip: Try using the [`Model::SetAnimation`](http://gazebosim.org/api/1.3.0/classgazebo_1_1physics_1_1Entity.html#a1db1526d6f51f6c463036f4835e87232) callback function parameter to receive a callback when an animation is complete.

Next: Animate Joint