c4dynamics.sensors.navigation.imu.measure#
- imu.measure(rb: rigidbody, t: float = -1, store: bool = False)[source]#
Measures body rates and specific acceleration of a rigid body.
If store = True, the method stores the measured sample [ax, ay, az, p, q, r] along with a timestamp (t = -1 by default, if not provided otherwise).
- Parameters:
rb (rigidbody) – A
rigidbodyobject (or any 12-variable state object using the same[x, y, z, vx, vy, vz, phi, theta, psi, p, q, r]ordering) providing the true reference state for the sample.t (float, optional) – Timestamp [seconds]. Defaults -1.
store (bool, optional) – A flag indicating whether to store the measured values. Defaults False.
- Returns:
out (tuple) – Accelerations and rates, (ax, ay, az, p, q, r), [m/s², m/s², m/s², rad/s, rad/s, rad/s].
Note
The accelerometer’s inertial term requires a previous sample. As measure keeps that sample internally (there’s no x_true_prev argument to pass), the very first call after construction reports the gravity-projection term alone.
Example
measure in a program simulating an imu riding a rigid body through a short maneuver, storing the samples for later use:
>>> import c4dynamics as c4d >>> import numpy as np >>> np.random.seed(321) >>> rb = c4d.rigidbody() >>> imu_sensor = c4d.sensors.imu() >>> dt = 0.005 >>> for t in np.arange(0, 1, dt): ... rb.inteqm(np.zeros(3), np.zeros(3), dt) ... imu_sensor.measure(rb, t = t, store = True) ... rb.store(t) >>> imu_sensor.data('p')[1].shape (200,)