Module: pyIMU.madgwick
Madgwick(**kwargs)
Madgwick gradient-descent AHRS filter (NED convention).
Initialization Parameters
dt:float, default0.01- Default time step used when
update(..., dt<=0).
- Default time step used when
gain:float, optional- Convenience gain applied to both IMU and MARG unless overridden.
gain_imu:float, default0.033(orgainif provided)- Gain used for IMU updates (
gyr+acc).
- Gain used for IMU updates (
gain_marg:float, default0.041(orgainif provided)- Gain used for MARG updates (
gyr+acc+mag).
- Gain used for MARG updates (
acc_in_g:bool, defaultTrueTrue: accelerometer input expected ing.False: input treated asm/s^2and converted tog.
gyr_in_dps:bool, defaultFalseTrue: gyroscope input expected indeg/sand converted torad/s.
convention:str, default"NED"- Only
NEDis currently supported.
- Only
Methods
update(gyr, acc, mag=None, dt=-1) -> Quaterniongyr:Vector3Dgyro sample.acc:Vector3Daccel sample.mag: optionalVector3Dmagnetometer sample.dt: time step in seconds. If<=0, uses instancedt.
Behavior:
- First call initializes orientation from accel (
accel2q) or accel+mag (accelmag2q). - Later calls run IMU or MARG update equations.
Outputs (instance fields updated on each update(...) call):
q:Quaternion- Current attitude estimate.
azero:Vector3D- Gravity-removed acceleration in sensor/body frame, in
g.
- Gravity-removed acceleration in sensor/body frame, in
aglobal:Vector3D- Gravity-removed acceleration in earth/NED frame, in
g.
- Gravity-removed acceleration in earth/NED frame, in
updateIMU(q, gyr, acc, dt, gain) -> QuaternionupdateMARG(q, gyr, acc, mag, dt, gain) -> QuaternionupdateIMU_inplace(...) -> QuaternionupdateMARG_inplace(...) -> Quaternion
Use inplace variants to mutate and reuse an existing quaternion object.