Inverse Kinematics
Differential IK
min sum_tasks || weight * (J v - v_des) ||^2 + (reg + lam) * ||v||^2 s.t. A v == b; G v <= h
i.e. - Minimimize the weighted task velocity error, plus regularization and damping terms for stability - Subject to a set of equality and inequality constraints
Note that since we use ElastiQP as our solver, inequality constraints are automatically (and efficiently) relaxed with an L1 penalty term. These constraints are held exactly when the problem is feasible, and only relaxed when the problem is infeasible*
*See the ElastiQP paper for more details, and more precise conditions on relaxation and when this occurs
Equality constraints are still held as hard constraints with ElastiQP, unless explicitly posed as an elastic equality. In this case, the equality is converted to a pair of opposing elastic inequalities.
DiffIKSolver
Differential IK with ElastiQP
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
robot
|
Robot
|
Robot model |
required |
tasks
|
Sequence[Task]
|
Tracking tasks |
required |
constraints
|
Sequence[InequalityConstraint | EqualityConstraint]
|
Constraints. Defaults to an empty tuple (unconstrained) |
()
|
regularization
|
ArrayLike
|
Tikhonov regularization on v, scalar or shape (nv,). Defaults to 1e-8 |
1e-08
|
damping
|
float
|
Levenberg-Marquardt damping, per unit of task cost. Defaults to 0.0 (no damping) |
0.0
|
solver_tol
|
float
|
QP solver tolerance. Defaults to 1e-5 |
1e-05
|
warm_start
|
bool
|
Whether to warm-start each QP from the previous solution. Defaults to True. |
True
|
Source code in frax/ik/solver.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 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 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 | |
cost(q, ref)
The cost of q: the QP objective at v = 0 (if the robot doesn't move), for the given reference data
Source code in frax/ik/solver.py
176 177 178 179 180 | |
solve(q, ref, qp_warm_start)
Solve the diff IK QP
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q
|
Array
|
Configuration, shape (nq,) |
required |
ref
|
Any
|
Per-step reference data (any pytree) |
required |
qp_warm_start
|
tuple[Array, Array, Array]
|
QP warm start (x, y, z) |
required |
Returns:
| Name | Type | Description |
|---|---|---|
v |
Array
|
Generalized velocity, shape (nv,) |
qp_warm_start |
tuple[Array, Array, Array]
|
QP solution (x, y, z), to warm-start the next QP |
info |
SolverInfo
|
Solver info, with the cost of q |
Source code in frax/ik/solver.py
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 | |
step(state, ref, dt)
One diff IK step
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
SolverState
|
Current state |
required |
ref
|
Any
|
Per-step reference data (any pytree) |
required |
dt
|
float
|
Timestep |
required |
Returns:
| Name | Type | Description |
|---|---|---|
state |
SolverState
|
New state |
v |
Array
|
Generalized velocity, shape (nv,) |
info |
SolverInfo
|
Solver info |
Source code in frax/ik/solver.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | |
converge(state, ref, max_iters, dt_max, tol)
Run differential IK until convergence
Note: This method should generally only be called as a component of a global IK pipeline, or at initialization of a solver. During online operation, or sequential calls in an offline pipeline, generally only a single diff IK step() should be taken.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
SolverState
|
Initial state |
required |
ref
|
Any
|
Reference data (any pytree) |
required |
max_iters
|
int
|
Maximum iterations |
required |
dt_max
|
float
|
Largest stepsize |
required |
tol
|
float
|
Convergence tolerance on max |v| |
required |
Returns:
| Name | Type | Description |
|---|---|---|
state |
SolverState
|
Converged state |
iters |
Array
|
Number of iterations |
Source code in frax/ik/solver.py
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 | |
Differential IK tasks
Notes: - Tasks operate on the velocity level, as opposed to a delta-q. - In general, a task has a least-squares structure || weight * (J v - v_des) ||^2
Task
Base differential IK task
Source code in frax/ik/tasks.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
linearize(q, ref)
Linearize the task about q
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q
|
Array
|
Configuration, shape (nq,) |
required |
ref
|
Any
|
Per-step reference data (any pytree) |
required |
Returns:
| Name | Type | Description |
|---|---|---|
J |
Array
|
Task Jacobian, shape (num_rows, nv) |
v_des |
Array
|
Desired task velocity, shape (num_rows,) |
weight |
Array
|
Per-row weight, shape (num_rows,) |
Source code in frax/ik/tasks.py
37 38 39 40 41 42 43 44 45 46 47 48 49 | |
ResidualTask
Bases: Task
Drive a residual e(q, ref) to zero, with a forward-mode autodiff Jacobian
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
robot
|
Robot
|
Robot model |
required |
residual_fn
|
Callable
|
(q, ref) -> e, shape (num_rows,) |
required |
num_rows
|
int
|
Residual dimension |
required |
gain
|
ArrayLike
|
Scalar or per-row gain (1/s) |
1.0
|
weight
|
ArrayLike
|
Scalar or per-row weight |
1.0
|
Source code in frax/ik/tasks.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
JointTask
Bases: Task
Track a joint-space task
Note: this is currently configured to only deal with actuated joints. For free-floating bases, use a FrameTask
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
robot
|
Robot
|
Robot model |
required |
idxs
|
ArrayLike
|
Indices into v to track |
required |
ref_key
|
str
|
Reference key for the targets, shape (len(idxs),) |
required |
gain
|
ArrayLike
|
Scalar or per-joint gain (1/s) |
1.0
|
weight
|
ArrayLike
|
Scalar or per-joint weight |
1.0
|
Source code in frax/ik/tasks.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
FrameTask
Bases: _PoseTask
Track world-frame positions and/or orientations of joint frames
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
robot
|
Robot
|
Robot model |
required |
joints
|
ArrayLike
|
Indices of the tracked joints, shape (n,) |
required |
gain_pos, gain_rot
|
ArrayLike
|
Scalar or per-frame gains (1/s) |
required |
weight_pos, weight_rot
|
ArrayLike
|
Scalar or per-frame weights |
required |
pos_key
|
str | None
|
Reference key for target positions, shape (n, 3). None to not track position |
'frame_pos'
|
rot_key
|
str | None
|
Reference key for target rotation matrices, shape (n, 3, 3). None to not track rotation |
'frame_rmat'
|
offsets
|
ArrayLike | None
|
Tracked frames in their joint frames, shape (4, 4) or (n, 4, 4). Defaults to None (identity) |
None
|
Source code in frax/ik/tasks.py
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 | |
EETask
Bases: _PoseTask
Track the world-frame position and/or orientation of a Manipulator's end
effector (including its ee_offset)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
robot
|
Manipulator
|
Manipulator model |
required |
gain_pos, gain_rot
|
float
|
Gains (1/s) |
required |
weight_pos, weight_rot
|
float
|
Weights |
required |
pos_key
|
str | None
|
Reference key for the target position, shape (3,). None to not track position |
'ee_pos'
|
rot_key
|
str | None
|
Reference key for the target rotation matrix, shape (3, 3). None to not track rotation |
'ee_rmat'
|
Source code in frax/ik/tasks.py
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 | |
IK constraints
Notes: - We use ElastiQP for our solver, which allows us to use efficient elastic inequality constraints, and hard equalities (where applicable) - Each inequality has an L1 relaxation with associated penalty w, typically left at a default high value like 1e6, though this can be tuned on a per-task basis. If this penalty is greater than the optimal dual multiplier for a feasible problem, the relaxation is exact - For tuning gains, ensure that gain * dt <= 1 to avoid overshoot - Since this solver operates on generalized velocities, all inequalities deal with v rather than a delta q. This is slightly different from other diff IK libraries like pink or mink
InequalityConstraint
Base (elastic) inequality constraint G v <= h
Source code in frax/ik/constraints.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
rows(q, ref)
Rows of G v <= h for this constraint, evaluated at q
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q
|
Array
|
Configuration, shape (nq,) |
required |
ref
|
Any
|
A pytree (such as a dict) containing problem data that is updated each step |
required |
Returns:
| Name | Type | Description |
|---|---|---|
G |
Array
|
Inequality matrix rows, shape (num_rows, nv) |
h |
Array
|
Inequality vector rows, shape (num_rows,) |
Source code in frax/ik/constraints.py
39 40 41 42 43 44 45 46 47 48 49 50 51 | |
EqualityConstraint
Base (hard) equality constraint Av = b
Generally, you should wrap any soft task terms that may not be feasible by construction in an ElasticEquality
Source code in frax/ik/constraints.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
rows(q, ref)
Rows of A v = b for this constraint, evaluated at q
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q
|
Array
|
Configuration, shape (nq,) |
required |
ref
|
Any
|
A pytree (such as a dict) containing problem data that is updated each step |
required |
Returns:
| Name | Type | Description |
|---|---|---|
A |
Array
|
Equality matrix rows, shape (num_rows, nv) |
b |
Array
|
Equality vector rows, shape (num_rows,) |
Source code in frax/ik/constraints.py
64 65 66 67 68 69 70 71 72 73 74 75 76 | |
JointLimits
Bases: InequalityConstraint
Joint position and velocity limits on the actuated joint velocities
max(v_min, gain * (q_min - q)) <= v <= min(v_max, gain * (q_max - q))
Limits default to "robot" to use the robot's own actuated joint position/ velocity limits, but you can also pass None (no limit) or an array of custom limits.
Currently, limits on floating bases are not implemented.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
robot
|
Robot
|
The frax robot model |
required |
q_min
|
ArrayLike | str | None
|
Lower position limits, shape (num_actuated,). Defaults to robot.actuated_joint_lower_limits |
'robot'
|
q_max
|
ArrayLike | str | None
|
Upper position limits, shape (num_actuated,). Defaults to robot.actuated_joint_upper_limits |
'robot'
|
v_max
|
ArrayLike | str | None
|
Upper velocity limits, shape (num_actuated,). Defaults to robot.actuated_joint_max_velocities |
'robot'
|
v_min
|
ArrayLike | str | None
|
Lower velocity limits, shape (num_actuated,). Defaults to -v_max |
'robot'
|
gain
|
float
|
CBF gain (1/s): how fast the position limits may be approached |
10.0
|
penalty
|
float
|
Relaxation penalty |
DEFAULT_PENALTY
|
Source code in frax/ik/constraints.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 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 | |
SelfCollisionConstraint
Bases: _SphereConstraint
Self-collision avoidance: h = robot.self_collision_distances(q) - margin
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
robot
|
Robot
|
Robot, with collision and self-collision data |
required |
max_rows
|
int | None
|
If set, keep only this many closest pairs per step |
None
|
gain
|
float
|
CBF gain (1/s) |
10.0
|
penalty
|
float
|
Relaxation penalty |
DEFAULT_PENALTY
|
margin
|
float
|
Additional safety margin between every collision pair |
0.0
|
Source code in frax/ik/constraints.py
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 | |
ObstacleConstraint
Bases: _SphereConstraint
Sphere obstacle avoidance: h = |p_i - c_k| - r_i - R_k - margin for each robot sphere i in sphere_idxs and obstacle k
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
robot
|
Robot
|
Robot, with collision data |
required |
obstacles
|
SphereObstacles
|
Obstacles. Their count K is fixed |
required |
sphere_idxs
|
ArrayLike | None
|
Robot collision spheres to check. Defaults to all |
None
|
ref_key
|
str | None
|
If set, ref[ref_key] replaces |
None
|
max_rows
|
int | None
|
If set, keep only this many closest pairs per step |
None
|
gain
|
float
|
CBF gain (1/s) |
10.0
|
penalty
|
float
|
Relaxation penalty |
DEFAULT_PENALTY
|
margin
|
float
|
Safety distance from every obstacle |
0.0
|
Source code in frax/ik/constraints.py
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 | |
FloorConstraint
Bases: _SphereConstraint
Floor at z = 0: h = z_i - r_i - margin for each robot sphere i in sphere_idxs
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
robot
|
Robot
|
Robot, with collision data |
required |
sphere_idxs
|
ArrayLike | None
|
Robot collision spheres to check. Defaults to all |
None
|
max_rows
|
int | None
|
If set, keep only this many lowest spheres per step |
None
|
gain
|
float
|
CBF gain (1/s) |
10.0
|
penalty
|
float
|
Relaxation penalty |
DEFAULT_PENALTY
|
margin
|
float
|
Height kept above the floor |
0.0
|
Source code in frax/ik/constraints.py
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 | |
BarrierConstraint
Bases: InequalityConstraint
CBF on a user-defined barrier h(q, ref) >= 0: dh/dq E(q) v >= -gain * h
The Jacobian is by forward-mode autodiff, so this suits a handful of rows
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
robot
|
Robot
|
Robot model |
required |
h_fn
|
Callable
|
(q, ref) -> h, shape (num_rows,) |
required |
num_rows
|
int
|
Number of barriers |
required |
gain
|
float
|
CBF gain (1/s) |
10.0
|
penalty
|
ArrayLike
|
Scalar or per-row relaxation penalty |
DEFAULT_PENALTY
|
Source code in frax/ik/constraints.py
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 | |
ResidualEquality
Bases: EqualityConstraint
Equality on a user-defined residual e(q, ref) = 0: de/dq E(q) v = -gain * e
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
robot
|
Robot
|
Robot model |
required |
residual_fn
|
Callable
|
(q, ref) -> e, shape (num_rows,) |
required |
num_rows
|
int
|
Residual dimension |
required |
gain
|
float
|
Gain (1/s) |
10.0
|
Source code in frax/ik/constraints.py
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 | |
ElasticEquality
Bases: InequalityConstraint
An equality A v = b, relaxed with an L1 penalty, as the inequalities A v <= b and -A v <= -b
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
equality
|
EqualityConstraint
|
The equality to relax |
required |
penalty
|
ArrayLike
|
Scalar or per-row relaxation penalty, shape (equality.num_rows,) |
DEFAULT_PENALTY
|
Source code in frax/ik/constraints.py
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 | |
Online and offline motion retargeting
Retargeter
Differential IK-based motion retargeter.
Given a sequence of frames, this class solves for the robot configurations q, based on the input DiffIKSolver
As opposed to just using a DiffIK solver, this adds logic for converging to an initial configuration on the first step, and processing a whole sequence in a single scan
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solver
|
DiffIKSolver
|
Diff IK solver |
required |
preprocess
|
Callable
|
Input frame -> the solver's reference |
required |
initial_q
|
Callable
|
First input frame -> initial guess for q |
required |
converge_max_iters
|
int
|
Max iterations to converge onto the first frame |
300
|
converge_dt
|
float | None
|
Largest convergence stepsize. Defaults to 1 / solver.max_gain (full Gauss-Newton step) |
None
|
converge_tol
|
float
|
Convergence tolerance on max |v| |
0.001
|
global_ik_init
|
GlobalIKSolver | None
|
If set, solves the first frame by global IK before converging, to avoid poor local solutions. |
None
|
global_ik_seed
|
int
|
Seed for the global IK samples |
0
|
Source code in frax/ik/retargeter.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
init(frame)
Converge onto the first frame
Returns:
| Name | Type | Description |
|---|---|---|
state |
SolverState
|
Converged state |
iters |
Array
|
Number of iterations |
Source code in frax/ik/retargeter.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
step(state, frame, dt)
Take one solver step towards an input frame
Source code in frax/ik/retargeter.py
84 85 86 87 88 89 | |
retarget_clip(frames, dt)
Retarget a full clip of input frames
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frames
|
Any
|
Input frames, with leading time axis T (any pytree) |
required |
dt
|
float
|
Time between frames |
required |
Returns:
| Name | Type | Description |
|---|---|---|
q |
Array
|
Configurations, shape (T, nq) |
infos |
SolverInfo
|
Per-step info, leading dim T - 1 |
init_iters |
Array
|
Iterations to converge onto the first frame |
Source code in frax/ik/retargeter.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
OfflineRetargeter
Retargets many clips, spread across devices. Clips are padded to a multiple of bucket frames, and compiled shapes are cached across calls
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
retargeter
|
Retargeter
|
Retargeter |
required |
dt
|
float
|
Time between frames |
required |
bucket
|
int
|
Padded clip lengths are multiples of this |
1024
|
devices
|
all | default | Sequence[Device]
|
Devices to spread the clips across. Defaults to "all" |
'all'
|
Source code in frax/ik/retargeter.py
122 123 124 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 | |
__call__(clips)
Retarget clips
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
clips
|
Sequence
|
Clips of input frames, each a pytree with leading time axis T. T may differ between clips |
required |
Returns:
| Type | Description |
|---|---|
list[ndarray]
|
list[np.ndarray]: Configurations, one array per clip, each shape (T, nq) with that clip's T |
Source code in frax/ik/retargeter.py
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 | |
OnlineRetargeter
Stateful retargeting wrapper for online operation.
Call compile() before any strict real-time operation to compile the performance-critical methods.
Source code in frax/ik/retargeter.py
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 | |
compile(example_frame)
Compile the init and step functions ahead of time
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
example_frame
|
Any
|
Example input frame (may be jax.ShapeDtypeStructs) |
required |
Source code in frax/ik/retargeter.py
207 208 209 210 211 212 213 214 215 | |
Global IK with multi-start SQP
Note: for continuous motion control, you should probably stick to differential IK. Global IK is useful for if instantaneous jumps are acceptable: for instance, finding a configuration that achieves a desired initial or goal pose, without worrying about continuity from your current state.
GlobalIKSolver
Multi-start SQP global IK solver
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solver
|
DiffIKSolver
|
Diff IK solver |
required |
num_samples
|
int
|
Number of starts, including q |
32
|
q_min, q_max
|
ArrayLike | robot
|
Sampling range for the actuated joints. Default to "robot", for the robot's joint limits, narrowed to those of any JointLimits constraints in the solver |
required |
max_iters
|
int
|
Max convergence iterations per start |
200
|
dt_max
|
float | None
|
Largest convergence stepsize. Defaults to 1 / solver.max_gain |
None
|
tol
|
float
|
Convergence tolerance on max |v| |
0.0001
|
cost_tol
|
float | None
|
Cost tolerance for acceptable solutions. If this term is set, then we return the closest sampled solution that is within cost_tol of the lowest cost. Defaults to None (select the lowest cost regardless of how far the solution is in configuration space) |
None
|
devices
|
all | default | Sequence[Device]
|
Devices to parallelize the samples across. Defaults to "default" (JAX's default device). |
'default'
|
Source code in frax/ik/global_ik.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 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 | |
solve(q, ref, key)
Solve global IK
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q
|
Array
|
Current configuration, shape (nq,) |
required |
ref
|
Any
|
Reference data (any pytree) |
required |
key
|
Array
|
PRNG key for the samples |
required |
Returns:
| Name | Type | Description |
|---|---|---|
GlobalIKResult |
GlobalIKResult
|
Result |
Source code in frax/ik/global_ik.py
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 | |
sample_configurations(robot, q, key, num_samples, q_min='robot', q_max='robot')
Sample configurations for global IK
The actuated joints are sampled uniformly. The floating base stays at q's: it has no joint limits to sample within, and is usually pinned by a task
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
robot
|
Robot
|
Robot model |
required |
q
|
Array
|
Nominal configuration, shape (nq,). This is also included as the first sample |
required |
key
|
Array
|
PRNG key |
required |
num_samples
|
int
|
Number of samples, including q |
required |
q_min
|
ArrayLike | robot
|
Lower joint bounds, shape (num_actuated,). Defaults to "robot", for robot.actuated_joint_lower_limits |
'robot'
|
q_max
|
ArrayLike | robot
|
Upper joint bounds, shape (num_actuated,). Defaults to "robot", for robot.actuated_joint_upper_limits |
'robot'
|
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
Sampled configurations, shape (num_samples, nq) |
Source code in frax/ik/global_ik.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
IK and motion utilities
load_bvh(filepath, to_world=None, scale=0.01)
Global bone poses from a BVH file
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str | Path
|
BVH file |
required |
to_world
|
ArrayLike | None
|
Rotation from the BVH frame to the world, shape (3, 3). Defaults to identity |
None
|
scale
|
float
|
BVH length unit (m). Defaults to cm |
0.01
|
Returns:
| Name | Type | Description |
|---|---|---|
poses |
ndarray
|
Poses [position, WXYZ quaternion], shape (T, B, 7) |
names |
list[str]
|
The B bone names |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any frame has NaNs |
Source code in frax/ik/utils.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
smooth_poses(poses, dt, sigma_pos=0.0, sigma_rot=0.0)
Zero-phase Gaussian smoothing of a clip of poses along time, for offline retargeting
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
poses
|
ArrayLike
|
Poses [position, WXYZ quaternion], shape (T, ..., 7) |
required |
dt
|
float
|
Time between poses |
required |
sigma_pos
|
float
|
Position kernel standard deviation (s). 0 to not smooth |
0.0
|
sigma_rot
|
float
|
Rotation kernel standard deviation (s). 0 to not smooth |
0.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Smoothed poses, shape (T, ..., 7) |
Source code in frax/ik/utils.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
resample_poses(poses, fps_in, fps_out)
Resample a clip of poses to a new frame rate
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
poses
|
ArrayLike
|
Poses [position, WXYZ quaternion], shape (T, ..., 7) |
required |
fps_in
|
float
|
Frame rate of poses |
required |
fps_out
|
float
|
Frame rate to resample to |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Resampled poses, shape (T_out, ..., 7), with T_out = floor((T - 1) * fps_out / fps_in) + 1 |
Source code in frax/ik/utils.py
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 | |
save_motion(path, robot, q, fps)
Save a motion as an .npz file with fields q (float32), fps, and the actuated joint_names
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Output file (.npz) |
required |
robot
|
Robot
|
Robot model |
required |
q
|
ArrayLike
|
Configurations, shape (T, nq) |
required |
fps
|
float
|
Frame rate |
required |
Source code in frax/ik/utils.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |