newton.sensors.SensorIMU#

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

Bases: object

Inertial Measurement Unit Sensor.

This sensor measures the acceleration and angular velocity at the sites given.

Body Accelerations Attribute: This sensor requires the extended state attribute body_qdd to be computed by the solver. This requires a solver that supports computing body_qdd, and requesting body_qdd from the model before calling model.state(). Instantiating the SensorIMU will automatically request body_qdd from the model by default.

Example

Create a SensorIMU for a model with a list of site indices:

# Obtain shape indices (e.g. via selection or direct indexing)
sensor_sites = [0, 1, 2]  # indices of sites to attach IMU sensors

model = Model()
sensor = SensorIMU(model, sensor_sites)
state = model.state()

# Update after step()
sensor.update(state)
__init__(model, sites, verbose=None, request_state_attributes=True)#

Initialize SensorIMU.

Transparently requests the extended state attribute body_qdd from the model, which is required for acceleration data.

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

  • sites (list[int]) – List of site indices where IMU sensors are attached.

  • verbose (bool | None) – If True, print details. If None, uses wp.config.verbose.

  • request_state_attributes (bool) – If True (default), transparently request the extended state attribute body_qdd from the model. If False, model is not modified and the attribute must be requested elsewhere before calling model.state().

Raises:

ValueError – If invalid sites are passed.

update(state)#

Update the IMU sensor.

Parameters:

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

accelerometer: array(ndim=1, dtype=vec3f)#

Linear acceleration readings in sensor frame, shape (n_sensors,).

gyroscope: array(ndim=1, dtype=vec3f)#

Angular velocity readings in sensor frame, shape (n_sensors,).