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)
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, each joint is clamped to [lower, upper] and
the velocity of any joint that hit a bound is zeroed (a fully inelastic stop). 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
|
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
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 | |