Dynamics API
skelarm.dynamics
Provides functions for robot arm dynamics.
compute_coriolis_gravity_vector(skeleton, grav_vec=None)
Compute the bias vector h(q, dq).
The returned vector includes Coriolis, optional gravity, and any external forces stored on the skeleton's links.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skeleton
|
Skeleton
|
The Skeleton object. |
required |
grav_vec
|
NDArray[float64] | None
|
The gravity vector. Defaults to zero (planar motion). |
None
|
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
The N-dimensional bias vector h. |
Source code in src/skelarm/dynamics.py
compute_forward_dynamics(skeleton, tau, grav_vec=None)
Compute joint accelerations ddq given torques.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skeleton
|
Skeleton
|
The Skeleton object. |
required |
tau
|
NDArray[float64]
|
Joint torques. |
required |
grav_vec
|
NDArray[float64] | None
|
The gravity vector. Defaults to zero (planar motion). |
None
|
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
Joint accelerations ddq. |
Source code in src/skelarm/dynamics.py
compute_inverse_dynamics(skeleton, grav_vec=None)
Compute the inverse dynamics of the robot arm using the Recursive Newton-Euler algorithm.
Updates the tau (joint torque) for each link in the skeleton.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skeleton
|
Skeleton
|
The Skeleton object containing the robot arm's links and their states. |
required |
grav_vec
|
NDArray[float64] | None
|
A 2D gravity vector. Defaults to zero (planar motion). |
None
|
Source code in src/skelarm/dynamics.py
compute_kinetic_energy(skeleton)
Compute the total kinetic energy of the robot arm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skeleton
|
Skeleton
|
The Skeleton object with link velocities (w, v, vc) computed. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The total kinetic energy. |
Source code in src/skelarm/dynamics.py
compute_kinetic_energy_rate(skeleton, tau, grav_vec=None)
Compute the rate of change of kinetic energy (dKE/dt).
dKE/dt = dq^T * tau_applied. In the context of the dynamics equation Mddq + h = tau, dKE/dt should be dq^T * (Mddq + h). This must equal dq^T * tau_applied.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skeleton
|
Skeleton
|
The Skeleton object with current q and dq. |
required |
tau
|
NDArray[float64]
|
The N-dimensional vector of joint torques. |
required |
grav_vec
|
NDArray[float64] | None
|
The gravity vector. Defaults to zero (planar motion). |
None
|
Returns:
| Type | Description |
|---|---|
float
|
The rate of change of kinetic energy. |
Source code in src/skelarm/dynamics.py
compute_mass_matrix(skeleton, _grav_vec=None)
Compute the mass matrix M(q) for the robot arm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skeleton
|
Skeleton
|
The Skeleton object. |
required |
_grav_vec
|
NDArray[float64] | None
|
Ignored; the mass matrix is computed with zero gravity. |
None
|
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
The N x N mass matrix. |
Source code in src/skelarm/dynamics.py
integrate_with_limits(skeleton, tau, dt, lower=None, upper=None, grav_vec=None, *, stops='projected')
Advance one semi-implicit Euler step under tau, optionally with joint limits.
Computes ddq with :func:compute_forward_dynamics, integrates velocity then
position (symplectic Euler), writes the new q / dq directly onto the links
(bypassing the clamping setter), and refreshes forward kinematics. The skeleton is
updated in place.
When lower / upper are given, they are hard stops, of one of two models:
"projected"(the default): each joint is clamped to[lower, upper]and the velocity of any joint that hit a bound is zeroed. This is a simple projection, not an impact model: the other joints keep their velocities, and they keep accelerating as if the stopped joint were free, so the total kinetic energy is not guaranteed to drop (with coupled inertias it can rise, at the impact and while a joint is pressed into its stop)."locked": a stop holds the joint pressed into it, with whatever torque it takes to keep it there, and lets it go once that torque would have to pull it; the other joints move as if the held joints were welded, so a stop does no work. A joint that reaches its stop stops as in a plastic impact: the other joints keep their momentum, and the kinetic energy drops. Away from the stops, the step is the projected one to the bit.
Both None (the default) integrates without joint limits, so the limits
then apply only to the kinematics setters and inverse kinematics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skeleton
|
Skeleton
|
The arm to advance; its current |
required |
tau
|
NDArray[float64]
|
Applied joint torque. |
required |
dt
|
float
|
Integration step (seconds). |
required |
lower
|
NDArray[float64] | None
|
Per-joint angle limits (radians). Both |
None
|
upper
|
NDArray[float64] | None
|
Per-joint angle limits (radians). Both |
None
|
grav_vec
|
NDArray[float64] | None
|
Gravity vector; defaults to zero (planar motion). |
None
|
stops
|
('projected', 'locked')
|
The model of the hard stops (see above); ignored without limits. |
"projected"
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/skelarm/dynamics.py
simulate_robot(initial_skeleton, time_span, control_torques_func, grav_vec=None, dt=0.01, rtol=1e-06, atol=1e-08)
Simulate robot dynamics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
initial_skeleton
|
Skeleton
|
The initial Skeleton state (q, dq). |
required |
time_span
|
tuple[float, float]
|
A tuple (start_time, end_time) for the simulation. |
required |
control_torques_func
|
Callable[[float, Skeleton], NDArray[float64]]
|
A callable |
required |
grav_vec
|
NDArray[float64] | None
|
The gravity vector. Defaults to zero (planar motion). |
None
|
dt
|
float
|
Time step for the simulation, used for output points. |
0.01
|
rtol
|
float
|
Relative tolerance for the ODE solver. |
1e-06
|
atol
|
float
|
Absolute tolerance for the ODE solver. |
1e-08
|
Returns:
| Type | Description |
|---|---|
tuple[NDArray[float64], NDArray[float64], NDArray[float64]]
|
A tuple (times, q_trajectory, dq_trajectory) of NumPy arrays. |
Source code in src/skelarm/dynamics.py
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 | |