xioTechnologies / Fusion

MIT License
1.01k stars 241 forks source link

Make FusionCalibration and FusionMath functions available in Python #104

Closed wheaney closed 1 year ago

wheaney commented 1 year ago

The exported CPython library doesn't allow access to the FusionMath nor FusionCalibration functions. So I can't do something like the advanced C examples that are calibrating gyro and accel inputs.

xioTechnologies commented 1 year ago

imufusion does not implement functions from FusionMath.h because this functionality is already provided by numpy. The code below shows how to implement the inertial and magnetic calibration models using numpy.

def inertial(uncalibrated, misalignment, sensitivity, offset):
    return (numpy.matrix(misalignment) * numpy.diag(sensitivity) * numpy.array([uncalibrated - offset]).T).A1

def magnetic(uncalibrated, soft_iron_matrix, hard_iron_offset):
    return (numpy.matrix(soft_iron_matrix) * numpy.array([uncalibrated]).T).A1 - hard_iron_offset
wheaney commented 1 year ago

Ah, I see, thanks!