newton.sensors.SensorIMU#
- class newton.sensors.SensorIMU(model, sites, verbose=None, request_state_attributes=True)[source]#
Bases:
objectInertial 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_qddto be computed by the solver. This requires a solver that supports computingbody_qdd, and requestingbody_qddfrom the model before callingmodel.state(). Instantiating the SensorIMU will automatically requestbody_qddfrom 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_qddfrom 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_qddfrom the model. If False,modelis not modified and the attribute must be requested elsewhere before callingmodel.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,).