newton.actuators.DriveBase#
- class newton.actuators.DriveBase[source]#
Bases:
objectBase class for actuator drives.
Drives compute actuator output effort from authored drive parameters, commanded inputs (targets, feedforward), and simulation state. The output may still be constrained by one or more
ClampingBaseobjects.Subclasses must override
computeandresolve_arguments.Validation contract:
resolve_arguments()validates scalar parameter values (e.g.kp >= 0) before they are batched into Warp arrays.__init__receives pre-built arrays and validates shapes only — reading back array contents for value checks would force a synchronous device-to-host copy on every construction.- classmethod resolve_arguments(args)#
Resolve user-provided arguments with defaults.
- bind_params()#
Build the per-actuator parameter pack and wire attributes to it.
Called once when the implicit effort mode is installed. Override to:
Pack the drive’s parameters into a contiguous
(num_actuators, P)array — rowifor actuator sloti, layout matchingevaluate_force.Re-point the drive’s parameter arrays (e.g.
kp) at columns of the pack so later writes stay visible.
None(the default) means the drive does not support implicit actuation.
- compute(positions, velocities, target_pos, target_vel, feedforward, pos_indices, vel_indices, target_pos_indices, target_vel_indices, forces, state, dt, device=None)#
Compute actuator output effort and write to
forces[i].- Parameters:
positions (wp.array[wp.float32]) – Joint positions [m or rad].
velocities (wp.array[wp.float32]) – Joint velocities [m/s or rad/s].
target_pos (wp.array[wp.float32]) – Target positions [m or rad].
target_vel (wp.array[wp.float32]) – Target velocities [m/s or rad/s].
feedforward (wp.array[wp.float32] | None) – Feedforward effort [N or N·m] (may be
None).pos_indices (wp.array[wp.uint32]) – Indices into positions for each DOF.
vel_indices (wp.array[wp.uint32]) – Indices into velocities for each DOF.
target_pos_indices (wp.array[wp.uint32]) – Indices into target_pos.
target_vel_indices (wp.array[wp.uint32]) – Indices into target_vel and feedforward.
forces (wp.array[wp.float32]) – Scratch buffer to write effort [N or N·m] to. Shape
(N,).state (State | None) – Drive state (
Noneif stateless).dt (float) – Timestep [s].
device (Device | None) – Warp device for kernel launches.
- finalize(device, num_actuators)#
Called by
Actuatorafter construction to set up device-specific resources.Override in subclasses that need to place tensors or networks on a specific device, or pre-compute index tensors.
- is_graphable()#
Return True if compute() can be captured in a CUDA graph.
- is_stateful()#
Return True if this drive maintains internal state.
- prepare_implicit(positions, velocities, target_pos, target_vel, pos_indices, vel_indices, target_pos_indices, target_vel_indices, drive_state, dt, inv_mass=None, device=None)#
Refresh the parameter pack before an implicit solve step.
Called by the implicit effort mode once per step, before the solve kernel. Drives whose
evaluate_forcelaw needs per-step preparation (e.g. a neural network linearized about the current state) override this to rewrite the pack built bybind_params()in place. The default is a no-op — parameter-static laws like PD need nothing here.
- state(num_actuators, device)#
Create and return a new state object, or None if stateless.
- update_state(current_state, next_state)#
Advance internal state after a compute step.
- Parameters:
current_state (State) – Current drive state.
next_state (State) – Next drive state to write.