inverse_kinematics
IK-based trajectory initialization.
Generates joint-space trajectory guesses by interpolating task-space poses (position + orientation) between keyframes and solving inverse kinematics at each node via damped least-squares. Combines linspace (position), slerp (orientation), and IK into a single initialization call.
Two solve modes are available:
-
Parallel (default): Solves all nodes independently via
jax.vmap. Each node starts from the sameangles_initseed. Avoids propagating bad local minima but may produce less coherent joint-space paths. -
Sequential: Solves nodes in order via
jax.lax.scan, seeding each node with the previous node's solution. Produces smoother trajectories when the seed is good, but a bad early solution can propagate.
Requires jaxlie: pip install openscvx[lie]
ik_interpolation(keyframes: Sequence[Pose], nodes: Sequence[int], screw_axes: np.ndarray, T_home: np.ndarray, *, angles_init: np.ndarray = None, angles_min: np.ndarray = None, angles_max: np.ndarray = None, sequential: bool = False, damping: float = 0.001, max_iter: int = 200, tol: float = 1e-06) -> np.ndarray
¶
Generate joint-angle trajectory guess via task-space interpolation and IK.
Interpolates end-effector poses between keyframes (linspace for position, slerp for orientation) and solves inverse kinematics at each trajectory node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
keyframes
|
Sequence[Pose]
|
Sequence of (position, quaternion_wxyz) tuples. Each position is array-like with shape (3,) and each quaternion is array-like with shape (4,) in [w, x, y, z] order. |
required |
nodes
|
Sequence[int]
|
Sequence of node indices where keyframes occur. Must be sorted in ascending order and have the same length as keyframes. The last node determines the output size (N = nodes[-1] + 1). |
required |
screw_axes
|
ndarray
|
(n_joints, 6) array of screw axes for Product of Exponentials. |
required |
T_home
|
ndarray
|
(4, 4) home configuration transform. |
required |
angles_init
|
ndarray
|
(n_joints,) initial joint angle guess. In parallel mode this seeds every node; in sequential mode it seeds only the first node. Defaults to zeros. |
None
|
angles_min
|
ndarray
|
(n_joints,) optional lower joint limits. |
None
|
angles_max
|
ndarray
|
(n_joints,) optional upper joint limits. |
None
|
sequential
|
bool
|
If True, solve nodes sequentially (each node seeded by the
previous solution). If False (default), solve all nodes in parallel
from the same |
False
|
damping
|
float
|
Damping factor for least-squares IK. |
0.001
|
max_iter
|
int
|
Maximum IK iterations per node. |
200
|
tol
|
float
|
IK convergence tolerance. |
1e-06
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray of shape (N, n_joints) containing joint angles at each node. |
Example
Initialize a 7-DOF arm trajectory reaching for a target::
import openscvx as ox
angle.guess = ox.init.ik_interpolation(
keyframes=[
([0.7, 0, 0.34], [1, 0, 0, 0]), # home pose
([0.3, 0.3, 0.5], [1, 0, 0, 0]), # target pose
],
nodes=[0, 49],
screw_axes=screw_axes,
T_home=T_home,
)
Source code in openscvx/init/inverse_kinematics.py
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 | |