Kinematics API
skelarm.kinematics
Provides functions for robot arm kinematics.
IKResult
dataclass
Outcome of a numerical inverse-kinematics solve.
Attributes:
| Name | Type | Description |
|---|---|---|
q |
NDArray[float64]
|
Final joint angles (radians), one per movable joint. |
position |
NDArray[float64]
|
Final endpoint position |
residual |
NDArray[float64]
|
Final residual |
residual_norm |
float
|
Euclidean norm of |
iterations |
int
|
Number of iterations performed. |
status |
str
|
Why the solver stopped: |
joint_limits_hit |
bool
|
Whether any proposed step was clamped to a joint limit. |
success |
bool
|
|
Source code in src/skelarm/kinematics.py
compute_coriolis_basis(skeleton)
Compute the centripetal/Coriolis acceleration basis of the endpoint.
The basis H is the 2 x num_joints matrix whose columns are the time
derivatives of the Jacobian columns,
.. math:: h_{x i} = -(\dot{y}n - \dot{y}), \qquad h_{y i} = \dot{x}n - \dot{x}.
Together with the Jacobian it gives the endpoint acceleration as
(xddot, yddot) = J qddot + H qdot. The per-joint columns are cached on
each movable link as link.hx / link.hy.
Notes
compute_forward_kinematics must have been run first so that the joint and
endpoint velocities are current.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skeleton
|
Skeleton
|
The Skeleton object with up-to-date forward kinematics. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
The |
Source code in src/skelarm/kinematics.py
compute_endpoint_acceleration(skeleton)
Compute the endpoint linear acceleration from the Jacobian and Coriolis basis.
Evaluates (xddot, yddot) = J qddot + H qdot using the current joint
velocities and accelerations. This offers an independent cross-check against
the acceleration propagated directly by compute_forward_kinematics
(stored on the tip link as ax / ay).
Notes
compute_forward_kinematics must have been run first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skeleton
|
Skeleton
|
The Skeleton object with up-to-date forward kinematics. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
The 2-element endpoint acceleration |
Source code in src/skelarm/kinematics.py
compute_endpoint_velocity(skeleton)
Compute the endpoint linear velocity from the Jacobian.
Evaluates (xdot, ydot) = J qdot using the current joint velocities. This
offers an independent cross-check against the velocity propagated directly by
compute_forward_kinematics (stored on the tip link as vx / vy).
Notes
compute_forward_kinematics must have been run first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skeleton
|
Skeleton
|
The Skeleton object with up-to-date forward kinematics. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
The 2-element endpoint velocity |
Source code in src/skelarm/kinematics.py
compute_forward_kinematics(skeleton)
Compute the forward kinematics for the given skeleton.
Updates the (x, y) positions of each link's end-effector (tip) and joints, as well as angular, joint-origin, tip, and COM velocities and accelerations.
The arm is rooted at the origin (0, 0). The fixed base link (links[0])
carries no joint motion, so it simply offsets the first joint to
(base_length, 0) with zero velocity and acceleration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skeleton
|
Skeleton
|
The Skeleton object containing the robot arm's links and joint angles. |
required |
Source code in src/skelarm/kinematics.py
compute_inverse_kinematics(skeleton, target, *, method='lm_sugihara', q0=None, max_iterations=100, position_tolerance=1e-06, step_tolerance=1e-09, damping=0.001, step_scale=1.0)
Solve endpoint position inverse kinematics by iterative refinement.
Starting from a seed pose, the solver repeatedly linearizes the endpoint
residual e = target - p(q) and takes a damped step until the residual is
within tolerance, the step stalls, or the iteration limit is reached. The
skeleton is driven to the final pose as a side effect. Each proposed step is
clamped to the joint limits, so the returned pose is always feasible.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skeleton
|
Skeleton
|
The arm to solve for. Its joint state is updated to the result pose. |
required |
target
|
NDArray[float64] | tuple[float, float]
|
Desired endpoint position |
required |
method
|
str
|
Step rule: |
'lm_sugihara'
|
q0
|
NDArray[float64] | None
|
Seed joint angles. Defaults to the skeleton's current pose. |
None
|
max_iterations
|
int
|
Maximum number of iterations. |
100
|
position_tolerance
|
float
|
Success threshold on the residual norm. |
1e-06
|
step_tolerance
|
float
|
Stalls when the (clamped) joint step norm falls to or below this value. |
1e-09
|
damping
|
float
|
Damping term passed to the step rule ( |
0.001
|
step_scale
|
float
|
Scale |
1.0
|
Returns:
| Type | Description |
|---|---|
IKResult
|
The final pose, endpoint, residual, iteration count, and status. |
Source code in src/skelarm/kinematics.py
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 | |
compute_jacobian(skeleton)
Compute the endpoint Jacobian relating joint and endpoint velocities.
The Jacobian J is the 2 x num_joints matrix that maps the joint
velocities to the linear velocity of the endpoint, (xdot, ydot) = J qdot.
Each column is obtained geometrically from the lever arm between the joint
and the endpoint,
.. math:: j_{x i} = -(y_n - y_{i-1}), \qquad j_{y i} = x_n - x_{i-1},
where :math:(x_n, y_n) is the endpoint and :math:(x_{i-1}, y_{i-1}) the
origin of joint :math:i. The per-joint columns are also cached on each
movable link as link.jx / link.jy.
Notes
compute_forward_kinematics must have been run first so that the joint and
endpoint positions are current.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skeleton
|
Skeleton
|
The Skeleton object with up-to-date forward kinematics. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
The |