Behavior library
robot.behavior_library
Reusable behaviors.
A behavior is a short, named routine that drives both the face and the
body. The library ships a few ready-made ones (Greeting, Thinking,
Listening, Sleeping, Excited) and provides the building blocks
(:class:BehaviorStep) so the user can compose their own.
Behaviors
robot.behavior_library.behavior
Behavior primitives.
A :class:Behavior is a recipe: a list of steps to run, where each
step is either a face action, a body-language request, or a wait.
The runner walks the steps in order (some can be parallel) and returns
when the last step is done.
Behaviors are declarative - they describe what to do, not how. The runner decides how to schedule the steps against the face engine and the body-language engine.
__all__ = ['Behavior', 'BehaviorRunner', 'BehaviorStep', 'BodyStep', 'FaceStep', 'WaitStep', 'body', 'excited', 'face', 'greeting', 'listening', 'sleeping', 'surprised', 'thinking', 'wait']
module-attribute
_log = get_logger('behavior_library.behavior')
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)
Behavior
dataclass
A named sequence of steps.
Source code in src/robot/behavior_library/behavior.py
name
instance-attribute
steps = ()
class-attribute
instance-attribute
__init__(name, steps=())
BehaviorRunner
Run :class:Behavior objects against a face + body engine.
Source code in src/robot/behavior_library/behavior.py
body = body
instance-attribute
clock = clock
instance-attribute
face = face
instance-attribute
__init__(face, body, clock)
run(behavior)
async
BehaviorStep
dataclass
One entry in a behavior's recipe.
A step is one of:
* :class:FaceStep - call a method on the :class:FaceAnimator.
* :class:BodyStep - perform a :class:BodyRequest on the body.
* :class:WaitStep - sleep.
Source code in src/robot/behavior_library/behavior.py
body = None
class-attribute
instance-attribute
face = None
class-attribute
instance-attribute
kind
instance-attribute
name
instance-attribute
wait = None
class-attribute
instance-attribute
__init__(name, kind, face=None, body=None, wait=None)
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
BodyStep
dataclass
Clock
Bases: Protocol
Minimal time abstraction.
Source code in src/robot/utils/clock.py
monotonic()
now()
FaceAnimator
dataclass
Drive a single circular face display at 30 FPS.
Source code in src/robot/face/animator.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 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 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 | |
DEFAULT_FPS = 30
class-attribute
bus = None
class-attribute
instance-attribute
clock
instance-attribute
current
property
display
instance-attribute
emotions
instance-attribute
fps = DEFAULT_FPS
class-attribute
instance-attribute
frame_count
property
height = 240
class-attribute
instance-attribute
is_running
property
renderer
instance-attribute
theme
instance-attribute
width = 240
class-attribute
instance-attribute
__init__(renderer, display, clock, emotions, theme, fps=DEFAULT_FPS, bus=None, width=240, height=240)
__post_init__()
Source code in src/robot/face/animator.py
bounce()
double_blink()
drift(amplitude=0.1, speed=0.6)
eyebrow_raise(amount=0.6)
Source code in src/robot/face/animator.py
look(x, y, duration_s=0.25)
look_center(duration_s=0.25)
look_down(duration_s=0.25)
look_left(duration_s=0.25)
look_right(duration_s=0.25)
look_up(duration_s=0.25)
mouth_open(duration_s=0.3)
reset()
Source code in src/robot/face/animator.py
run_forever()
async
Source code in src/robot/face/animator.py
set_emotion(name, intensity=1.0)
Animate to the given emotion over ~0.3s.
Calling this method clears any running speaking and thinking animations (they are interruptible). The wake animation is not cleared -- it plays to completion.
Source code in src/robot/face/animator.py
set_speaking_animation(animation)
Set (or clear) the speaking animation that drives mouth shapes.
set_thinking_animation(animation)
Set (or clear) the thinking animation that drives gaze shifts.
set_wake_animation(animation)
smile_grow()
Animate the mouth from NEUTRAL to SMILE over 0.4s.
Source code in src/robot/face/animator.py
step(drift=True)
Advance one frame and push to the display.
The rendering pipeline applies overrides in priority order:
- Eye drift + blink state (from :class:
EyeAnimator). - Thinking animation gaze override.
- Timeline-based emotion interpolation.
- Speaking animation mouth override.
- Wake animation full override (highest priority).
Source code in src/robot/face/animator.py
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 | |
stop()
FaceStep
dataclass
A face command: method(*args, duration_s=...).
Source code in src/robot/behavior_library/behavior.py
args = ()
class-attribute
instance-attribute
kwargs = field(default_factory=dict)
class-attribute
instance-attribute
method
instance-attribute
__init__(method, args=(), kwargs=dict())
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
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)
WaitStep
dataclass
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
_maybe_await(value)
async
body(request)
excited()
Wider eyes, quick blink, bounce, small arm movement.
Source code in src/robot/behavior_library/behavior.py
face(method, *args, **kwargs)
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
greeting()
Smile, blink, raise arms, tilt head.
Source code in src/robot/behavior_library/behavior.py
listening()
Eyes focused, head tilted slightly, arms relaxed.
Source code in src/robot/behavior_library/behavior.py
sleeping()
Eyelids close, breathing animation, head lowers, arms rest.
Source code in src/robot/behavior_library/behavior.py
surprised()
Wide eyes, open mouth, small jump.
thinking()
Look up, brows furrowed, subtle head movement.