Tutorials/intermediate/animated characters

Animated characters in Gazebo are special models based on captured human motion and allow the user to control the behavior of the model by scripting and controlling animation sequences. The SDF tag ` ` is used to specify animated characters. This page will offer some tips on how to use the Gazebo actors.


 * 1) Components of Actors ###

* **skin** element: This element specifies the Collada file which contains the mesh and skeleton data used to construct the actor. An actor must contain 1 skin element. * **animation** elements: An actor can have multiple animation resources to provide different behaviors. For example an actor can have animation resources for standing, walking and running that will be used to construct a complex behavior. An actor can contain 0 or more animation elements. * **script** element: The script element defines the behavior of the actor how the animation resources are going to be combined or whether the action of the actor is going to loop. An actor can contain 0 or 1 script element. * **trajectory** elements: This element represents an instance of an animation resource previously specified using an ` ` tag. This is used to sequence the actions loaded as resources. A script element can have 0 or more trajectory elements. When no trajectory tags are present the animation found in the skin file will be played back. * **waypoint** elements: Custom trajectories that replace the ones from the animation resource can be specified using waypoints. Each way point consists of a time stamp and a pose in the global coordinates. A trajectory can have 0 or more waypoint elements. When no way points are defined the trajectory from the original animation resource is used.


 * 1) Building an Actor ###

Gazebo uses Collada files containing animated models as resources for constructing actors. When you want to construct a model based on a mocap (captured motion) sequence (typically in a format like *.bvh), you will need to attach a mesh to the mocap skeleton and export the whole model in the Collada format. A good source for human character meshes is the Makehuman project. The process of attaching the mesh to the skeleton is called mesh skinning and involves assigning weights for the influences the skeleton bodies have on each mesh vertex. A tool that can be used for this is Blender and a good tutorial on how to do it can be found here.

. **Tip**: For better looking results when using looping animations, the animation data should be edited so that the end frame of the animation matches the first frame. This will ensure a smooth animation. . **Tip**: If the animation data is meant to be used with a custom trajectory rather than the one from the animation data, it is recommended to edit the animation data so that the model starts at origin facing along the positive X axis, and the animation translation (walking, running, etc.) is done along the X axis.

A couple of animation resource containing sequences are provided with Gazebo and can be used directly: * standing (stand.dae) * sit down (sit_down.dae) * sitting (sitting.dae) * stand up (stand_up.dae) * walk (walk.dae) * run (run.dae)


 * 1) Actor examples ###


 * Simple actor playing back one animation sequence**

The simplest actor you can create uses a Collada file to build the animated character model. Because no ` ` tag is present the animation contained in the ` ` file will be played back with looping.   

A script element can be used to control looping, auto and delayed start.


 * Combining multiple animation resources for complex actor behavior**

The following model files shows how multiple actions can be combined using a script to create a complex actor behavior. The actor defined by the following model file will stand for 10 seconds, sit down, sit, stand up, walk 5 meters in 10 seconds, run 5 meters in 5 seconds, moonwalk back to origin in 20 seconds and then repeat.              <waypoint time="10.0" pose="0 0 0 0 0 0"/> <trajectory id="1" type="sit_down"/> <trajectory id="2" type="sitting"/> <trajectory id="3" type="stand_up"/> <trajectory id="4" type="walking"> <waypoint time="0.0" pose="0 0 0 0 0 0"/> <waypoint time="10.0" pose="5 0 0 0 0 0"/> <trajectory id="5" type="running"> <waypoint time="0.0" pose="5 0 0 0 0 0"/> <waypoint time="5.0" pose="10 0 0 0 0 0"/> <trajectory id="6" type="moonwalking"> <waypoint time="0.0" pose="10 0 0 0 0 3.14159"/> <waypoint time="20.0" pose="0 0 0 0 0 3.14159"/>

Remarks: * Notice that some animation resources have the attribute interpolate_x set to true. This should be done for animations that involve the character translating to get better results with matching the simulated actor translation speed with the animation pose. If you turn it back to false, you will notice a sliding effect when the actor is walking or running. This is caused by the difference between the requested actor speed and the speed of the character in the resource file. * The trajectories for sitting down, sitting and standing up have no waypoints and no set duration. This means that the animation will be played back at the speed that it was recorded.


 * Using actors with curved trajectories**

Curved trajectories can also be used with the actor, even if the recorded motion is for translating on a straight line. Here is an example of actor model that walks on a circle with a radius of 1 m using an animation sequence of walking on a straight line:

<gazebo version="1.0"> <actor name="actor1" static="true"> <skin filename="sub_16.dae" scale="1.0"/> <animation name="walking" filename="walk.dae" scale="1.0" interpolate_x="true"/> <script loop="true" delay_start="0.0" auto_start="true"> <trajectory id="0" type="walking"> <waypoint time="0.0" pose="0 1 0 0 0 0"/> <waypoint time="0.5" pose="0.19509 0.980785 0 0 0 -0.19635"/> <waypoint time="1.0" pose="0.382683 0.92388 0 0 0 -0.392699"/> <waypoint time="1.5" pose="0.55557 0.83147 0 0 0 -0.589049"/> <waypoint time="2.0" pose="0.707107 0.707107 0 0 -0 -0.785398"/> <waypoint time="2.5" pose="0.83147 0.55557 0 0 0 -0.981748"/> <waypoint time="3.0" pose="0.92388 0.382683 0 0 0 -1.1781"/> <waypoint time="3.5" pose="0.980785 0.19509 0 0 0 -1.37445"/> <waypoint time="4.0" pose="1 0 0 0 0 -1.5708"/> <waypoint time="4.5" pose="0.980785 -0.19509 0 0 0 -1.76715"/> <waypoint time="5.0" pose="0.92388 -0.382683 0 0 0 -1.9635"/> <waypoint time="5.5" pose="0.83147 -0.55557 0 0 0 -2.15984"/> <waypoint time="6.0" pose="0.707107 -0.707107 0 0 0 -2.35619"/> <waypoint time="6.5" pose="0.55557 -0.83147 0 0 0 -2.55254"/> <waypoint time="7.5" pose="0.382683 -0.92388 0 0 0 -2.74889"/> <waypoint time="8.5" pose="0.19509 -0.980785 0 0 0 -2.94524"/> <waypoint time="9.5" pose="0 -1 0 0 0 -3.14159"/> <waypoint time="10.5" pose="-0.19509 -0.980785 0 0 0 -3.33794"/> <waypoint time="11.5" pose="-0.382683 -0.92388 0 0 0 -3.53429"/> <waypoint time="12.0" pose="-0.55557 -0.83147 0 0 0 -3.73064"/> <waypoint time="12.5" pose="-0.707107 -0.707107 0 0 0 -3.92699"/> <waypoint time="13.0" pose="-0.83147 -0.55557 0 0 0 -4.12334"/> <waypoint time="13.5" pose="-0.92388 -0.382683 0 0 0 -4.31969"/> <waypoint time="14.0" pose="-0.980785 -0.19509 0 0 0 -4.51604"/> <waypoint time="14.5" pose="-1 0 0 0 0 -4.71239"/> <waypoint time="15.0" pose="-0.980785 0.19509 0 0 0 -4.90874"/> <waypoint time="15.5" pose="-0.92388 0.382683 0 0 0 -5.10509"/> <waypoint time="16.0" pose="-0.83147 0.55557 0 0 0 -5.30144"/> <waypoint time="16.5" pose="-0.707107 0.707107 0 0 0 -5.49779"/> <waypoint time="17.0" pose="-0.55557 0.83147 0 0 0 -5.69414"/> <waypoint time="17.5" pose="-0.382683 0.92388 0 0 0 -5.89049"/> <waypoint time="18.0" pose="-0.19509 0.980785 0 0 0 -6.08684"/>