newton.actuators.BatteryBase#
- class newton.actuators.BatteryBase(actuator_start, actuators, *, world=None, world_count=0)[source]#
Bases:
objectBase class for actuator batteries.
A battery powers the motors of one or more actuators (see
MotorDC). One object holds several batteries of the same type: its parameter arrays have one entry per battery.step()andreset()read and write these arrays onsim_control, with one entry per actuator of the model, indexed likeActuator.actuator_indices:input
actuator_supply_current: the current each motor draws from its battery [A], written by the motor;output
actuator_supply_voltage: the supply voltage of each motor [V], read by the motor.
The motors and the batteries form an explicit loop: the motors read the voltage of the previous step. With one
Controlper step, e.g. to differentiate several steps on one tape, pass the next step’sControlas next_control tostep().Subclasses must override
resolve_arguments(),step()andreset().Validation contract:
resolve_arguments()validates scalar parameter values before they are batched into Warp arrays.__init__receives pre-built arrays and validates shapes only — reading back array contents would force a synchronous device-to-host copy on every construction.- classmethod resolve_arguments(args)#
Resolve user-provided arguments with defaults.
- __init__(actuator_start, actuators, *, world=None, world_count=0)#
Initialize the batteries.
- Parameters:
actuator_start (wp.array[wp.int32]) – Start of each battery’s actuators in actuators. Shape
(B + 1,).actuators (wp.array[wp.int32]) – Actuators of all batteries, sorted by battery, so that battery
bpowersactuators[actuator_start[b]:actuator_start[b + 1]].world (wp.array[wp.int32] | None) – World of each battery,
-1for none. Shape(B,).Noneplaces every battery outside any world.world_count (int) – Number of worlds, which sets the shape of the mask in
reset().
- Raises:
ValueError – world does not have one entry per battery.
- reset(sim_control, *, world_mask=None)#
Reset the batteries and the supply voltage of their actuators.
Writes
actuator_supply_voltagefor the actuators of the reset batteries. Call after resetting worlds.- Parameters:
sim_control (Any) – Object carrying
actuator_supply_voltage, e.g.Control.world_mask (wp.array[wp.bool] | None) – Optional boolean mask of shape
(world_count + 1,)specifying which worlds to reset. Entries before the last select local worlds by index, and the final entry selects batteries whose world is-1. IfNone, all batteries are reset.
- step(sim_control, next_control=None)#
Update the supply voltage of the actuators from their current.
Reads
actuator_supply_currentfrom sim_control and writesactuator_supply_voltageto next_control for the actuators of the batteries. Call once per step, after the actuators have stepped.
- actuators#
Actuators of all batteries, sorted by battery.
- num_batteries#
Number of batteries B.
- world#
World of each battery,
-1for none, shape (B,).
- world_count#
Number of worlds.