Body-language reference
robot.body_language
Body Language Engine - high-level servo choreography.
The :class:BodyLanguageEngine consumes requests like
:class:LookLeft, :class:HeadNod, :class:Wave, :class:Celebrate,
:class:ArmsRelax and translates them into coordinated servo
motions on the four-servo chassis. It is the only component that
talks to the :class:ServoController for expressive motion.
The engine never knows about emotions directly. The EmotionEngine
emits a :class:BodyLanguageHint (head-tilt + arm-pose) which the
body-language engine interprets.
Requests
robot.body_language.requests
Body language request types.
A request is a high-level intent the body-language engine knows how
to perform. Each request knows how to translate itself into a
:class:ServoTimeline (a list of concurrent + sequential servo
animations).
CENTER = 90.0
module-attribute
DEFAULT_CALIBRATION = {SERVO_HEAD_PAN: ServoCalibration(SERVO_HEAD_PAN, 30.0, 150.0, 90.0), SERVO_HEAD_TILT: ServoCalibration(SERVO_HEAD_TILT, 45.0, 135.0, 90.0), SERVO_LEFT_ARM: ServoCalibration(SERVO_LEFT_ARM, 20.0, 160.0, 90.0), SERVO_RIGHT_ARM: ServoCalibration(SERVO_RIGHT_ARM, 20.0, 160.0, 90.0)}
module-attribute
MAX = 160.0
module-attribute
MIN = 20.0
module-attribute
SERVO_HEAD_PAN = 'pan'
module-attribute
SERVO_HEAD_TILT = 'tilt'
module-attribute
SERVO_LEFT_ARM = 'left_arm'
module-attribute
SERVO_RIGHT_ARM = 'right_arm'
module-attribute
__all__ = ['DEFAULT_CALIBRATION', 'SERVO_HEAD_PAN', 'SERVO_HEAD_TILT', 'SERVO_LEFT_ARM', 'SERVO_RIGHT_ARM', 'ArmsOpen', 'ArmsRelax', 'BodyRequest', 'Celebrate', 'Greet', 'HeadNod', 'HeadTiltRequest', 'LookLeft', 'LookRight', 'ServoCalibration', 'ServoFrame', 'Shrug', 'Wave']
module-attribute
ArmsOpen
dataclass
Bases: _BaseRequest
Source code in src/robot/body_language/requests.py
amount = 20.0
class-attribute
instance-attribute
duration_s = 0.5
class-attribute
instance-attribute
name = 'arms_open'
class-attribute
instance-attribute
__init__(name='arms_open', amount=20.0, duration_s=0.5)
frames()
Source code in src/robot/body_language/requests.py
ArmsRelax
dataclass
Bases: _BaseRequest
Source code in src/robot/body_language/requests.py
duration_s = 0.5
class-attribute
instance-attribute
name = 'arms_relax'
class-attribute
instance-attribute
__init__(name='arms_relax', duration_s=0.5)
BodyRequest
Bases: Protocol
A high-level body-language request.
Source code in src/robot/body_language/requests.py
name
property
frames()
Source code in src/robot/body_language/requests.py
Celebrate
dataclass
Bases: _BaseRequest
Source code in src/robot/body_language/requests.py
duration_s = 0.6
class-attribute
instance-attribute
name = 'celebrate'
class-attribute
instance-attribute
__init__(name='celebrate', duration_s=0.6)
frames()
Source code in src/robot/body_language/requests.py
Greet
dataclass
Bases: _BaseRequest
Source code in src/robot/body_language/requests.py
duration_s = 0.8
class-attribute
instance-attribute
name = 'greet'
class-attribute
instance-attribute
__init__(name='greet', duration_s=0.8)
frames()
Source code in src/robot/body_language/requests.py
HeadNod
dataclass
Bases: _BaseRequest
Source code in src/robot/body_language/requests.py
amplitude = 15.0
class-attribute
instance-attribute
duration_s = 0.5
class-attribute
instance-attribute
name = 'head_nod'
class-attribute
instance-attribute
__init__(name='head_nod', amplitude=15.0, duration_s=0.5)
frames()
Source code in src/robot/body_language/requests.py
HeadTiltRequest
dataclass
Bases: _BaseRequest
Source code in src/robot/body_language/requests.py
amount = 15.0
class-attribute
instance-attribute
direction = 'left'
class-attribute
instance-attribute
duration_s = 0.4
class-attribute
instance-attribute
name = 'head_tilt'
class-attribute
instance-attribute
__init__(name='head_tilt', direction='left', amount=15.0, duration_s=0.4)
frames()
LookLeft
dataclass
Bases: _BaseRequest
Source code in src/robot/body_language/requests.py
amount = 30.0
class-attribute
instance-attribute
duration_s = 0.3
class-attribute
instance-attribute
name = 'look_left'
class-attribute
instance-attribute
__init__(name='look_left', amount=30.0, duration_s=0.3)
LookRight
dataclass
Bases: _BaseRequest
Source code in src/robot/body_language/requests.py
amount = 30.0
class-attribute
instance-attribute
duration_s = 0.3
class-attribute
instance-attribute
name = 'look_right'
class-attribute
instance-attribute
__init__(name='look_right', amount=30.0, duration_s=0.3)
ServoCalibration
dataclass
Per-servo calibration (limits, centre, sign).
Source code in src/robot/body_language/requests.py
center_angle
instance-attribute
inverted = False
class-attribute
instance-attribute
max_angle
instance-attribute
min_angle
instance-attribute
name
instance-attribute
__init__(name, min_angle, max_angle, center_angle, inverted=False)
clamp(angle)
from_normalised(value)
Source code in src/robot/body_language/requests.py
normalised(angle)
Return a value in [-1, 1] relative to the servo range.
Source code in src/robot/body_language/requests.py
ServoFrame
dataclass
A target angle for every named servo at one instant.
Source code in src/robot/body_language/requests.py
duration_s = 0.4
class-attribute
instance-attribute
targets = field(default_factory=dict)
class-attribute
instance-attribute
__init__(targets=dict(), duration_s=0.4)
Shrug
dataclass
Bases: _BaseRequest
Source code in src/robot/body_language/requests.py
duration_s = 0.5
class-attribute
instance-attribute
name = 'shrug'
class-attribute
instance-attribute
__init__(name='shrug', duration_s=0.5)
frames()
Source code in src/robot/body_language/requests.py
Wave
dataclass
Bases: _BaseRequest
Source code in src/robot/body_language/requests.py
amplitude = 30.0
class-attribute
instance-attribute
duration_s = 1.0
class-attribute
instance-attribute
name = 'wave'
class-attribute
instance-attribute
__init__(name='wave', amplitude=30.0, duration_s=1.0)
frames()
Source code in src/robot/body_language/requests.py
_BaseRequest
dataclass
Source code in src/robot/body_language/requests.py
_arms(center, left, right, dur=0.4)
Source code in src/robot/body_language/requests.py
_head(center, pan, tilt, dur=0.4)
Source code in src/robot/body_language/requests.py
Engine
robot.body_language.engine
The :class:BodyLanguageEngine - plays body-language requests on the servos.
The engine owns the :class:ServoController and a per-servo
:class:ServoCalibration. To perform a request it:
- Asks the request for a list of :class:
ServoFrameobjects. - Plays each frame sequentially, interpolating every servo's angle
over the frame's
duration_swith a smoothstep easing. - Returns the new angles so the simulation overlay can read them.
DEFAULT_CALIBRATION = {SERVO_HEAD_PAN: ServoCalibration(SERVO_HEAD_PAN, 30.0, 150.0, 90.0), SERVO_HEAD_TILT: ServoCalibration(SERVO_HEAD_TILT, 45.0, 135.0, 90.0), SERVO_LEFT_ARM: ServoCalibration(SERVO_LEFT_ARM, 20.0, 160.0, 90.0), SERVO_RIGHT_ARM: ServoCalibration(SERVO_RIGHT_ARM, 20.0, 160.0, 90.0)}
module-attribute
__all__ = ['BodyLanguageEngine', 'Pose', 'hint_to_pose']
module-attribute
_log = get_logger('body_language.engine')
module-attribute
ArmPose
Bases: Enum
Discrete arm-pose hints.
Source code in src/robot/face/model.py
DOWN = 'down'
class-attribute
instance-attribute
OPEN = 'open'
class-attribute
instance-attribute
POINT = 'point'
class-attribute
instance-attribute
RELAXED = 'relaxed'
class-attribute
instance-attribute
SHRUG = 'shrug'
class-attribute
instance-attribute
WAVING = 'waving'
class-attribute
instance-attribute
WIDE = 'wide'
class-attribute
instance-attribute
BodyLanguageEngine
dataclass
Drive the four servos with high-level body-language requests.
Source code in src/robot/body_language/engine.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | |
calibration = field(default_factory=lambda: dict(DEFAULT_CALIBRATION))
class-attribute
instance-attribute
clock
instance-attribute
servo_controller
instance-attribute
__init__(servo_controller, clock, calibration=(lambda: dict(DEFAULT_CALIBRATION))())
apply_hint(hint)
Translate a :class:BodyLanguageHint into a Pose (no servo moves).
perform(request)
async
Play a request on the servos.
Source code in src/robot/body_language/engine.py
perform_sync(request)
play_frames(frames)
async
set_calibration(calibration)
BodyRequest
Bases: Protocol
A high-level body-language request.
Source code in src/robot/body_language/requests.py
name
property
frames()
Source code in src/robot/body_language/requests.py
Clock
Bases: Protocol
Minimal time abstraction.
Source code in src/robot/utils/clock.py
monotonic()
now()
HeadTilt
Bases: Enum
Discrete head-tilt hints the body-language engine understands.
Source code in src/robot/face/model.py
CURIOUS = 'curious'
class-attribute
instance-attribute
EXCITED = 'excited'
class-attribute
instance-attribute
NEUTRAL = 'neutral'
class-attribute
instance-attribute
SAD = 'sad'
class-attribute
instance-attribute
SLEEPY = 'sleepy'
class-attribute
instance-attribute
THINKING = 'thinking'
class-attribute
instance-attribute
Pose
dataclass
A snapshot of every servo's target angle.
Source code in src/robot/body_language/engine.py
Servo
Bases: Protocol
A single addressable servo channel.
Source code in src/robot/interfaces/servo.py
angle
property
Current angle in degrees.
name
property
Logical name of the servo (e.g. "head_pan").
move_to(angle, duration_s=0.4)
async
ServoCalibration
dataclass
Per-servo calibration (limits, centre, sign).
Source code in src/robot/body_language/requests.py
center_angle
instance-attribute
inverted = False
class-attribute
instance-attribute
max_angle
instance-attribute
min_angle
instance-attribute
name
instance-attribute
__init__(name, min_angle, max_angle, center_angle, inverted=False)
clamp(angle)
from_normalised(value)
Source code in src/robot/body_language/requests.py
normalised(angle)
Return a value in [-1, 1] relative to the servo range.
Source code in src/robot/body_language/requests.py
ServoController
Bases: Protocol
A controller that owns a collection of :class:Servo channels.
A controller is selected at application boot by the
:class:~robot.hardware.servos.factory.ServoControllerFactory based on
the value of config.servo.backend. The rest of the application only
ever depends on this interface.
Source code in src/robot/interfaces/servo.py
backend_name
property
Human-readable backend identifier (e.g. "gpio", "pca9685").
all()
close()
async
get(name)
ServoFrame
dataclass
A target angle for every named servo at one instant.
Source code in src/robot/body_language/requests.py
duration_s = 0.4
class-attribute
instance-attribute
targets = field(default_factory=dict)
class-attribute
instance-attribute
__init__(targets=dict(), duration_s=0.4)
get_logger(name)
Return a bound logger for the given module name.
The name is prefixed with robot. if it doesn't already start with it,
so log records naturally form a hierarchy. The name is also bound into
the event context as logger_name so :func:_capture_to_ring_buffer
can record it; :func:_strip_logger_name removes it before rendering so
the stdout JSON output stays unchanged.
Source code in src/robot/logging.py
hint_to_pose(hint)
Translate a :class:BodyLanguageHint into a static :class:Pose.
The result represents a resting pose - the body-language engine applies it as a base, and transient requests (Wave, Celebrate, …) layer on top.