newton.sensors.SensorIMU#

class newton.sensors.SensorIMU(model, sites, *, verbose=None, request_state_attributes=True)[source]#

Bases: object

Inertial Measurement Unit sensor.

Measures linear acceleration (specific force) and angular velocity at the given sites. Each site defines an IMU frame; outputs are expressed in that frame.

This sensor requires the BODY_QDD solver observable. The solver must support computing body_qdd (e.g. SolverKamino or SolverMuJoCo). The extended newton.State.body_qdd attribute remains supported during migration.

Experimental

The solver_observable_kinds attribute and the observables argument to update() may change with the solver observable API.

The sites parameter accepts label patterns – see Label Matching.

Example

import warp as wp
import newton
from newton.sensors import SensorIMU

builder = newton.ModelBuilder()
builder.add_ground_plane()
body = builder.add_body(xform=wp.transform((0, 0, 1), wp.quat_identity()))
builder.add_shape_sphere(body, radius=0.1)
builder.add_site(body, label="imu_0")
model = builder.finalize()

imu = SensorIMU(model, sites="imu_*", request_state_attributes=False)
solver = newton.solvers.SolverMuJoCo(model)
observables = solver.observables(kinds=imu.solver_observable_kinds)
state = model.state()

# after solver step
solver.step(state, state, None, None, dt=1.0 / 60.0, observables=observables)
imu.update(state, observables=observables)
acc = imu.accelerometer.numpy()
gyro = imu.gyroscope.numpy()
__init__(model, sites, *, verbose=None, request_state_attributes=True)#

Initialize SensorIMU.

The legacy State.body_qdd allocation path remains the default during the deprecation period. Set request_state_attributes=False and allocate solver_observable_kinds through the solver instead.

Parameters:
  • model (Model) – The model to use.

  • sites (str | list[str] | Pattern[str] | list[int]) – Glob pattern, list of glob patterns, compiled regular-expression pattern to match against site labels, or list of site indices. Regular expressions use full matching.

  • verbose (bool | None) – If True, print details. If False, suppress details. If None, print details when wp.config.log_level is configured for debug logging.

  • request_state_attributes (bool) –

    If True, request the deprecated extended state attribute body_qdd from the model. Defaults to True for backward compatibility. If False, update() must receive solver observables containing body_qdd or a state allocated through a separate legacy request.

    Deprecated since version 1.7: Passing True (including the default) is deprecated. Pass False, allocate solver_observable_kinds through the solver and pass Observables to update() instead.

Raises:

ValueError – If no labels match or invalid sites are passed.

update(state, *, observables=None)#

Update the IMU sensor.

Parameters:
  • state (State) – The state to update the sensor from.

  • observables (Observables | None) – Solver observables containing rigid-body accelerations. If None, use the legacy state.body_qdd attribute. Must be allocated by a solver for this sensor’s model.

Raises:

ValueError – If solver observables belong to a different model or the required body acceleration array is missing.

accelerometer: wp.array[wp.vec3f]#

Linear acceleration readings [m/s²] in sensor frame, shape (n_sensors,).

gyroscope: wp.array[wp.vec3f]#

Angular velocity readings [rad/s] in sensor frame, shape (n_sensors,).

solver_observable_kinds = frozenset({'body_qdd'})#

Solver observables required to update this sensor.