Skeleton API
skelarm.skeleton
Defines the Link and Skeleton classes for the skelarm robot arm simulator.
Link
Represents a single link of the robot arm.
Source code in src/skelarm/skeleton.py
__init__(properties)
Initialize a Link object from LinkProp or a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
properties
|
LinkProp | dict[str, Any]
|
Either a LinkProp object or a dictionary containing link properties ('length', 'm', 'i', 'rgx', 'rgy', 'qmin', 'qmax'). |
required |
Source code in src/skelarm/skeleton.py
LinkProp
dataclass
Skeleton
Represents the entire robot arm (skeleton).
Source code in src/skelarm/skeleton.py
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 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 | |
base_length
property
Length of the fixed base (zeroth) link.
ddq
property
writable
Return current joint angular accelerations (one per movable link).
dq
property
writable
Return current joint angular velocities (one per movable link).
q
property
writable
Return current joint angles (one per movable link).
tau
property
writable
Return current joint torques (one per movable link).
__init__(link_props, base_length=0.0)
Initialize the Skeleton with a list of movable-link properties.
Following the reference notes, the arm is built around a fixed base
(zeroth) link of length base_length. It is stored as links[0] and
carries the first joint at (base_length, 0); the actuated links given
in link_props follow as links[1:]. A "2-link arm" therefore holds
three links in total: the base plus two movable links.
Forward kinematics is computed once at the end of construction, so the derived link states (positions, COM, ...) start out consistent with the initial pose.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
link_props
|
Sequence[LinkProp | dict[str, Any]]
|
A list of LinkProp objects or dictionaries, one for each movable link. |
required |
base_length
|
float
|
Length of the fixed base link, i.e. the offset from the origin to the first joint. Defaults to 0.0 (first joint at the origin). |
0.0
|
Source code in src/skelarm/skeleton.py
apply_initial_toml(file_path)
Apply the [initial] table from a TOML file to this skeleton.
Reads q (degrees) and optional dq (degrees/second) — one value per
joint — from the file's [initial] section and sets the joint state. This
lets a separate posture file be applied to an already-loaded robot. Joints
are left unchanged when q (or dq) is absent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str | Path
|
Path to a TOML file containing an |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/skelarm/skeleton.py
clone()
Return a new, independent Skeleton with the same geometry and state.
The clone duplicates the link geometry (its LinkProp objects are
separate) and copies the current joint state (q, dq, ddq,
tau); its derived link states are refreshed to match.
Returns:
| Type | Description |
|---|---|
Skeleton
|
A deep copy of this skeleton. |
Source code in src/skelarm/skeleton.py
copy_state_to(target)
Copy this skeleton's joint state onto an existing skeleton, in place.
Copies the joint angles, velocities, accelerations, and torques (q,
dq, ddq, tau) onto target and refreshes its derived link
states. target's geometry is left unchanged. Values are written
directly, so the state is reproduced exactly without limit clamping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
Skeleton
|
The skeleton to overwrite; it must have the same number of joints. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/skelarm/skeleton.py
from_config(data)
classmethod
Build a Skeleton from an already-parsed combined config mapping.
This is the dict-based core of :meth:from_toml: it reads the same
[skeleton] / [initial] schema (degrees) and applies the initial
pose. Rebuilding from the identical mapping reproduces the robot and pose
exactly, which underpins reproducible re-runs from an exported config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Mapping[str, Any]
|
A parsed combined config with an optional |
required |
Returns:
| Type | Description |
|---|---|
Skeleton
|
A new Skeleton posed at the configured initial state. |
Source code in src/skelarm/skeleton.py
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 | |
from_dict(data)
classmethod
Reconstruct a Skeleton from a :meth:to_dict mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict[str, Any]
|
A mapping with an optional |
required |
Returns:
| Type | Description |
|---|---|
Skeleton
|
A new Skeleton whose link positions match the zero pose. |
Source code in src/skelarm/skeleton.py
from_toml(file_path)
classmethod
Create a Skeleton from a TOML configuration file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str | Path
|
Path to the TOML file. |
required |
Returns:
| Type | Description |
|---|---|
Skeleton
|
A new Skeleton instance whose link positions are already consistent with the initial pose. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Notes
The canonical layout nests skeleton keys under a [skeleton] table,
with links given as [[skeleton.link]] and an optional
base_length. This lets a robot live alongside [initial] (and
future [task] / [controller]) sections in a single combined file
while still being loadable on its own. Legacy flat configs (top-level
base_length and [[link]]) remain supported as a fallback.
The initial state is a run condition, configured in a top-level
[initial] section with q (degrees) and optional dq
(degrees/second), one value per joint. [initial].q takes precedence
over the per-link q0 keys (a soft-deprecated fallback that defaults
each joint to zero when neither is given).
Each link's joint limits come from its limits = [min, max] (or
qmin / qmax) keys, in degrees. A link that omits them defaults to
[-180, 180] degrees. Limits are enforced: setting joint angles
clamps them into this range (with a warning), so an unspecified joint is
capped at one full revolution rather than left unbounded.
Source code in src/skelarm/skeleton.py
set_state(q=None, dq=None, ddq=None)
Set joint angles, velocities, and accelerations in one call.
Unlike assigning q, dq, and ddq separately (each of which
re-runs forward kinematics), this writes all provided values first and
refreshes the derived link states with a single forward-kinematics
pass. Arguments left as None keep their current values. q is
clamped to each joint's [qmin, qmax] limits (with a warning), like
the q setter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q
|
NDArray[float64] | None
|
Joint angles, one per movable link. |
None
|
dq
|
NDArray[float64] | None
|
Joint angular velocities, one per movable link. |
None
|
ddq
|
NDArray[float64] | None
|
Joint angular accelerations, one per movable link. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If any provided array does not hold one value per movable link. The skeleton is left unmodified in that case. |
Source code in src/skelarm/skeleton.py
to_dict()
Serialize the robot geometry to a plain, JSON/TOML-friendly dictionary.
Captures the fixed base_length and one entry per actuated link with the
native :class:LinkProp fields (lengths in meters, qmin / qmax in
radians), so :meth:from_dict reproduces the robot exactly. The joint state
(q / dq) is a separate run condition and is not included.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
|