newton.ik.IKObjective#
- class newton.ik.IKObjective[source]#
Bases:
object
Abstract base class for inverse kinematics objectives.
- Subclasses must implement the following methods:
residual_dim(): Returns the number of residuals (constraints) this objective contributes.
compute_residuals(body_q, joint_q, model, residuals, start_idx): Computes the residuals for this objective.
compute_jacobian_autodiff(tape, model, jacobian, start_idx, dq_dof): Computes the Jacobian using autodiff.
- Optional methods for analytic Jacobian support:
supports_analytic(): Returns True if analytic Jacobian is supported, otherwise False.
compute_jacobian_analytic(body_q, joint_q, model, jacobian, joint_S_s, start_idx): Computes the analytic Jacobian if supported.
- Device and buffer management:
bind_device(device): Binds the objective to a specific device.
init_buffers(model, jacobian_mode): Initializes any buffers required for Jacobian computation.
Notes
The interface is designed for batch processing of multiple IK problems in parallel.
Each subclass may store per-problem data (e.g., targets) as device arrays.
- bind_device(device)#
Binds the objective to a specific device (e.g., CUDA or CPU).
- Parameters:
device (wp.Device) – The device to bind to.
- compute_jacobian_analytic(body_q, joint_q, model, jacobian, joint_S_s, start_idx)#
Computes the analytic Jacobian for this objective, if supported.
- Parameters:
body_q (wp.array2d(dtype=wp.transform)) – Array of body transforms for each problem.
joint_q (wp.array2d(dtype=wp.float)) – Array of joint coordinates for each problem.
model (newton.Model) – The kinematic model.
jacobian (wp.array3d(dtype=wp.float)) – Output array for the Jacobian.
joint_S_s (wp.array2d(dtype=wp.spatial_vector)) – Motion subspace matrices.
start_idx (int) – Starting index in the Jacobian for this objective.
- compute_jacobian_autodiff(tape, model, jacobian, start_idx, dq_dof)#
Computes the Jacobian for this objective using automatic differentiation.
- Parameters:
tape (wp.Tape) – Autodiff tape.
model (newton.Model) – The kinematic model.
jacobian (wp.array3d(dtype=wp.float)) – Output array for the Jacobian.
start_idx (int) – Starting index in the Jacobian for this objective.
dq_dof (wp.array2d(dtype=wp.float)) – Derivative of q with respect to DoF.
- compute_residuals(body_q, joint_q, model, residuals, start_idx)#
Computes the residuals for this objective and writes them into the residuals array.
- Parameters:
body_q (wp.array2d(dtype=wp.transform)) – Array of body transforms for each problem.
joint_q (wp.array2d(dtype=wp.float)) – Array of joint coordinates for each problem.
model (newton.Model) – The kinematic model.
residuals (wp.array2d(dtype=wp.float)) – Output array for residuals.
start_idx (int) – Starting index in the residuals array for this objective.
- init_buffers(model, jacobian_mode)#
Initializes any buffers required for Jacobian computation.
- Parameters:
model (newton.Model) – The kinematic model.
jacobian_mode (IKJacobianMode) – The Jacobian computation mode (analytic or autodiff).
- residual_dim()#
Returns the number of residuals (constraints) this objective contributes. Must be implemented by subclasses.
- supports_analytic()#
Returns True if this objective supports analytic Jacobian computation. Subclasses should override if analytic Jacobian is available.