newton.sensors.SensorIMU#
- class newton.sensors.SensorIMU(model, sites, *, verbose=None, request_state_attributes=True)[source]#
Bases:
objectInertial 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 extended state attribute
body_qdd. By default, constructing the sensor requestsbody_qddfrom the model so that subsequentmodel.state()calls allocate it automatically. The solver must also support computingbody_qdd(e.g.SolverMuJoCo).The
sitesparameter 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_*") solver = newton.solvers.SolverMuJoCo(model) state = model.state() # after solver step solver.step(state, state, None, None, dt=1.0 / 60.0) imu.update(state) acc = imu.accelerometer.numpy() gyro = imu.gyroscope.numpy()
- __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 (str | list[str] | list[int]) – List of site indices, single pattern to match against site labels, or list of patterns where any one matches.
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 no labels match or 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 [m/s²] in sensor frame, shape
(n_sensors,).
- gyroscope: array(ndim=1, dtype=vec3f)#
Angular velocity readings [rad/s] in sensor frame, shape
(n_sensors,).