MadgwickAHRS#
- class mobgap.orientation_estimation.MadgwickAHRS(
- beta: float = 0.2,
- initial_orientation: ~numpy.ndarray | ~scipy.spatial.transform._rotation.Rotation = cf(<scipy.spatial.transform._rotation.Rotation object>),
The MadwickAHRS algorithm to estimate the orientation of an IMU.
This method applies a simple gyro integration with an additional correction step that tries to align the estimated orientation of the z-axis with gravity direction estimated from the acceleration data. This implementation is based on the paper [1]. An open source C-implementation of the algorithm can be found at [2]. The original code is published under GNU-GPL.
- Parameters:
- beta
This parameter controls how harsh the acceleration based correction is. A high value performs large corrections and a small value small and gradual correction. A high value should only be used if the sensor is moved slowly. A value of 0 is identical to just the Gyro Integration (see also
gaitmap.trajectory_reconstruction.SimpleGyroIntegrationfor a separate implementation).- initial_orientation
The initial orientation of the sensor that is assumed. It is critical that this value is close to the actual orientation. Otherwise, the estimated orientation will drift until the real orientation is found. In some cases, the algorithm will not be able to converge if the initial orientation is too far off and the orientation will slowly oscillate. If you pass a array, remember that the order of elements must be x, y, z, w.
Warning
This orientation needs to be provided based on the global coordinate system, which is rotated relative to the sensor frame defined in mobgap. The defualt initial orientation is hence
mobgap.consts.INITIAL_MOBILISED_ORIENTATION. If you want to provide a different initial orientation, you need to rotate it accordingly, depending on your definition.
- Other Parameters:
- data
The data passed to the estimate method.
- sampling_rate_hz
The sampling rate of this data
- Attributes:
orientation_Orientations as pd.DataFrame.
- orientation_object_
The orientations as a single scipy Rotation object
rotated_data_Rotated data.
Notes
This class uses Numba as a just-in-time-compiler to achieve fast run times. In result, the first execution of the algorithm will take longer as the methods need to be compiled first.
[1]Madgwick, S. O. H., Harrison, A. J. L., & Vaidyanathan, R. (2011). Estimation of IMU and MARG orientation using a gradient descent algorithm. IEEE International Conference on Rehabilitation Robotics, 1-7. https://doi.org/10.1109/ICORR.2011.5975346
Examples
Your data must be a pd.DataFrame with columns defined by
SF_COLS.>>> import pandas as pd >>> from gaitmap.utils.consts import SF_COLS >>> data = pd.DataFrame(..., columns=SF_COLS) >>> sampling_rate_hz = 100 >>> # Create an algorithm instance >>> mad = MadgwickAHRS(beta=0.2, initial_orientation=np.array([0, 0, 0, 1.0])) >>> # Apply the algorithm >>> mad = mad.estimate(data, sampling_rate_hz=sampling_rate_hz) >>> # Inspect the results >>> mad.orientation_ <pd.Dataframe with resulting quaternions> >>> mad.orientation_object_ <scipy.Rotation object>
Methods
clone()Create a new instance of the class with all parameters copied over.
estimate(data, *, sampling_rate_hz, **_)Estimate the orientation of the sensor.
get_params([deep])Get parameters for this algorithm.
set_params(**params)Set the parameters of this Algorithm.
- __init__(
- beta: float = 0.2,
- initial_orientation: ~numpy.ndarray | ~scipy.spatial.transform._rotation.Rotation = cf(<scipy.spatial.transform._rotation.Rotation object>),
- clone() Self[source]#
Create a new instance of the class with all parameters copied over.
This will create a new instance of the class itself and all nested objects
- estimate( ) Self[source]#
Estimate the orientation of the sensor.
- Parameters:
- data
Continuous sensor data including gyro and acc values. The gyro data is expected to be in deg/s! The data can either be in the sensor or the body frame. Both will result in the same estimated sensor orientation, but the output of
rotated_data_will be in the normal global frame if the data is in the sensor frame and in the body-aligned global frame if the data is in the body frame.- sampling_rate_hz
The sampling rate of the data in Hz
- Returns:
- self
The class instance with all result attributes populated
- get_params(deep: bool = True) dict[str, Any][source]#
Get parameters for this algorithm.
- Parameters:
- deep
Only relevant if object contains nested algorithm objects. If this is the case and deep is True, the params of these nested objects are included in the output using a prefix like
nested_object_name__(Note the two “_” at the end)
- Returns:
- params
Parameter names mapped to their values.