carla/Docs/walker_bone_control.md

141 lines
6.0 KiB
Markdown
Raw Normal View History

<h1>Walker Bone Control</h1>
In this tutorial we describe how to manually control and animate the
skeletons of walkers from the CARLA Python API. The reference of
all classes and methods available can be found at
[Python API reference](python_api.md).
!!! note
**This document assumes the user is familiar with the Python API**. <br>
The user should read the Python API tutorial before reading this document.
[Python API tutorial](python_api_tutorial.md).
### Walker skeleton structure
All walkers have the same skeleton hierarchy and bone names. Below is an image of the skeleton
hierarchy.
```
crl_root
└── crl_hips__C
├── crl_spine__C
│ └── crl_spine01__C
│ ├── ctrl_shoulder__L
│ │ └── crl_arm__L
│ │ └── crl_foreArm__L
│ │ └── crl_hand__L
│ │ ├── crl_handThumb__L
│ │ │ └── crl_handThumb01__L
│ │ │ └── crl_handThumb02__L
│ │ │ └── crl_handThumbEnd__L
│ │ ├── crl_handIndex__L
│ │ │ └── crl_handIndex01__L
│ │ │ └── crl_handIndex02__L
│ │ │ └── crl_handIndexEnd__L
│ │ ├── crl_handMiddle_L
│ │ │ └── crl_handMiddle01__L
│ │ │ └── crl_handMiddle02__L
│ │ │ └── crl_handMiddleEnd__L
│ │ ├── crl_handRing_L
│ │ │ └── crl_handRing01__L
│ │ │ └── crl_handRing02__L
│ │ │ └── crl_handRingEnd__L
│ │ └── crl_handPinky_L
│ │ └── crl_handPinky01__L
│ │ └── crl_handPinky02__L
│ │ └── crl_handPinkyEnd__L
│ ├── crl_neck__C
│ │ └── crl_Head__C
│ │ ├── crl_eye__L
│ │ └── crl_eye__R
│ └── crl_shoulder__R
│ └── crl_arm__R
│ └── crl_foreArm__R
│ └── crl_hand__R
│ ├── crl_handThumb__R
│ │ └── crl_handThumb01__R
│ │ └── crl_handThumb02__R
│ │ └── crl_handThumbEnd__R
│ ├── crl_handIndex__R
│ │ └── crl_handIndex01__R
│ │ └── crl_handIndex02__R
│ │ └── crl_handIndexEnd__R
│ ├── crl_handMiddle_R
│ │ └── crl_handMiddle01__R
│ │ └── crl_handMiddle02__R
│ │ └── crl_handMiddleEnd__R
│ ├── crl_handRing_R
│ │ └── crl_handRing01__R
│ │ └── crl_handRing02__R
│ │ └── crl_handRingEnd__R
│ └── crl_handPinky_R
│ └── crl_handPinky01__R
│ └── crl_handPinky02__R
│ └── crl_handPinkyEnd__R
├── crl_thigh__L
│ └── crl_leg__L
│ └── crl_foot__L
│ └── crl_toe__L
│ └── crl_toeEnd__L
└── crl_thigh__R
└── crl_leg__R
└── crl_foot__R
└── crl_toe__R
└── crl_toeEnd__R
```
### How to manually control a walker's bones
Following is a detailed step-by-step example of how to change the bone transforms of a walker
from the CARLA Python API
#### Connecting to the simulator
Import neccessary libraries used in this example
```py
import carla
import random
```
Initialize the carla client
```py
client = carla.Client('127.0.0.1', 2000)
client.set_timeout(2.0)
```
#### Spawning a walker
Spawn a random walker at one of the map's spawn points
```py
world = client.get_world()
blueprint = random.choice(self.world.get_blueprint_library().filter('walker.*'))
spawn_points = world.get_map().get_spawn_points()
spawn_point = random.choice(spawn_points) if spawn_points else carla.Transform()
world.try_spawn_actor(blueprint, spawn_point)
```
#### Controlling a walker's skeleton
A walker's skeleton can be modified by passing an instance of the WalkerBoneControl class
to the walker's apply_control function. The WalkerBoneControl class contains the transforms
of the bones to be modified. Its bone_transforms member is a list of tuples of value pairs
where the first value is the bone name and the second value is the bone transform. The
apply_control function can be called on every tick to animate a walker's skeleton. The
location and rotation of each transform is relative to its parent. Therefore when a
parent bone's transform is modified, the transforms of the child bones in model space
will also be changed relatively.
In the example below, the rotations of the walker's hands are set to be 90 degrees around
the forward axis and the locations are set to the origin.
```py
control = carla.WalkerBoneControl()
first_tuple = ('crl_hand__R', carla.Transform(rotation=carla.Rotation(roll=90)))
second_tuple = ('crl_hand__L', carla.Transform(rotation=carla.Rotation(roll=90)))
control.bone_transforms = [first_tuple, second_tuple]
world.player.apply_control(control)
```