Main Content

insfilterMARG

Estimate pose from MARG and GPS data

Description

The insfilterMARG object implements sensor fusion of MARG and GPS data to estimate pose in the NED (or ENU) reference frame. MARG (magnetic, angular rate, gravity) data is typically derived from magnetometer, gyroscope, and accelerometer sensors. The filter uses a 22-element state vector to track the orientation quaternion, velocity, position, MARG sensor biases, and geomagnetic vector. The insfilterMARG object uses an extended Kalman filter to estimate these quantities.

Creation

Description

example

filter = insfilterMARG creates an insfilterMARG object with default property values.

filter = insfilterMARG('ReferenceFrame',RF) allows you to specify the reference frame, RF, of the filter. Specify RF as 'NED' (North-East-Down) or 'ENU' (East-North-Up). The default value is 'NED'.

filter = insfilterMARG(___,Name,Value) also allows you set properties of the created filter using one or more name-value pairs. Enclose each property name in single quotes.

Properties

expand all

Sample rate of the inertial measurement unit (IMU) in Hz, specified as a positive scalar.

Data Types: single | double

Reference location, specified as a 3-element row vector in geodetic coordinates (latitude, longitude, and altitude). Altitude is the height above the reference ellipsoid model, WGS84. The reference location units are [degrees degrees meters].

Data Types: single | double

Multiplicative process noise variance from the gyroscope in (rad/s)2, specified as a scalar or 3-element row vector of positive real finite numbers.

  • If GyroscopeNoise is specified as a row vector, the elements correspond to the noise in the x, y, and z axes of the gyroscope, respectively.

  • If GyroscopeNoise is specified as a scalar, the single element is applied to the x, y, and z axes of the gyroscope.

Data Types: single | double

Multiplicative process noise variance from the gyroscope bias in (rad/s)2, specified as a scalar or 3-element row vector of positive real numbers.

  • If GyroscopeBiasNoise is specified as a row vector, the elements correspond to the noise in the x, y, and z axes of the gyroscope bias, respectively.

  • If GyroscopeBiasNoise is specified as a scalar, the single element is applied to each axis.

Data Types: single | double

Multiplicative process noise variance from the accelerometer in (m/s2)2, specified as a scalar or 3-element row vector of positive real finite numbers.

  • If AccelerometerNoise is specified as a row vector, the elements correspond to the noise in the x, y, and z axes of the accelerometer, respectively.

  • If AccelerometerNoise is specified as a scalar, the single element is applied to each axis.

Data Types: single | double

Multiplicative process noise variance from the accelerometer bias in (m/s2)2, specified as a scalar or 3-element row vector of positive real numbers.

  • If AccelerometerBiasNoise is specified as a row vector, the elements correspond to the noise in the x, y, and z axes of the accelerometer bias, respectively.

  • If AccelerometerBiasNoise is specified as a scalar, the single element is applied to each axis.

Data Types: single | double

Additive process noise for geomagnetic vector in µT2, specified as a scalar or 3-element row vector of positive real numbers.

  • If GeomagneticVectorNoise is specified as a row vector, the elements correspond to the noise in the x, y, and z axes of the geomagnetic vector, respectively.

  • If GeomagneticVectorNoise is specified as a scalar, the single element is applied to each axis.

Data Types: single | double

Additive process noise for magnetometer bias in µT2, specified as a scalar or 3-element row vector.

  • If MagnetometerBiasNoise is specified as a row vector, the elements correspond to the noise in the x, y, and z axes of the magnetometer bias, respectively.

  • If MagnetometerBiasNoise is specified as a scalar, the single element is applied to each axis.

Data Types: single | double

State vector of the extended Kalman filter. The state values represent:

StateUnitsIndex
Orientation (quaternion parts)N/A1:4
Position (NED or ENU)m5:7
Velocity (NED or ENU)m/s8:10
Delta Angle Bias (XYZ)rad11:13
Delta Velocity Bias (XYZ)m/s14:16
Geomagnetic Field Vector (NED or ENU)µT17:19
Magnetometer Bias (XYZ)µT20:22

Data Types: single | double

State error covariance for the extended Kalman filter, specified as a 22-by-22-element matrix, or real numbers.

Data Types: single | double

Object Functions

correctCorrect states using direct state measurements for insfilterMARG
residualResiduals and residual covariances from direct state measurements for insfilterMARG
fusegpsCorrect states using GPS data for insfilterMARG
residualgpsResiduals and residual covariance from GPS measurements for insfilterMARG
fusemagCorrect states using magnetometer data for insfilterMARG
residualmagResiduals and residual covariance from magnetometer measurements for insfilterMARG
poseCurrent orientation and position estimate for insfilterMARG
predictUpdate states using accelerometer and gyroscope data for insfilterMARG
resetReset internal states for insfilterMARG
stateinfoDisplay state vector information for insfilterMARG
tuneTune insfilterMARG parameters to reduce estimation error
copyCreate copy of insfitlerMARG

Examples

collapse all

This example shows how to estimate the pose of an unmanned aerial vehicle (UAV) from logged sensor data and ground truth pose.

Load the logged sensor data and ground truth pose of an UAV.

load uavshort.mat

Initialize the insfilterMARG filter object.

f = insfilterMARG;
f.IMUSampleRate = imuFs;
f.ReferenceLocation = refloc;
f.AccelerometerBiasNoise = 2e-4;
f.AccelerometerNoise = 2;
f.GyroscopeBiasNoise = 1e-16;
f.GyroscopeNoise = 1e-5;
f.MagnetometerBiasNoise = 1e-10;
f.GeomagneticVectorNoise = 1e-12;
f.StateCovariance = 1e-9*ones(22);
f.State = initstate;
 
gpsidx = 1;
N = size(accel,1);
p = zeros(N,3);
q = zeros(N,1,'quaternion');

Fuse accelerometer, gyroscope, magnetometer, and GPS data.

for ii = 1:size(accel,1)               % Fuse IMU
   f.predict(accel(ii,:), gyro(ii,:));
        
   if ~mod(ii,fix(imuFs/2))            % Fuse magnetometer at 1/2 the IMU rate
       f.fusemag(mag(ii,:),Rmag);
   end
  
   if ~mod(ii,imuFs)                   % Fuse GPS once per second
       f.fusegps(lla(gpsidx,:),Rpos,gpsvel(gpsidx,:),Rvel);
       gpsidx = gpsidx + 1;
   end
 
   [p(ii,:),q(ii)] = pose(f);           %Log estimated pose
end

Calculate and display RMS errors.

posErr = truePos - p;
qErr = rad2deg(dist(trueOrient,q));
pRMS = sqrt(mean(posErr.^2));
qRMS = sqrt(mean(qErr.^2));
fprintf('Position RMS Error\n\tX: %.2f, Y: %.2f, Z: %.2f (meters)\n\n',pRMS(1),pRMS(2),pRMS(3));
Position RMS Error
	X: 0.57, Y: 0.53, Z: 0.68 (meters)
    
fprintf('Quaternion Distance RMS Error\n\t%.2f (degrees)\n\n',qRMS);
Quaternion Distance RMS Error
	0.28 (degrees)

Algorithms

Note: The following algorithm only applies to an NED reference frame.

insfilterMARG uses a 22-axis extended Kalman filter structure to estimate pose in the NED reference frame. The state is defined as:

x=[q0q1q2q3positionNpositionEpositionDνNνEνDΔθbiasXΔθbiasYΔθbiasZΔνbiasXΔνbiasYΔνbiasZgeomagneticFieldVectorNgeomagneticFieldVectorEgeomagneticFieldVectorDmagbiasXmagbiasYmagbiasZ]

where

  • q0, q1, q2, q3 –– Parts of orientation quaternion. The orientation quaternion represents a frame rotation from the platform's current orientation to the local NED coordinate system.

  • positionN, positionE, positionD –– Position of the platform in the local NED coordinate system.

  • νN, νE, νD –– Velocity of the platform in the local NED coordinate system.

  • ΔθbiasX, ΔθbiasY, ΔθbiasZ –– Bias in the integrated gyroscope reading.

  • ΔνbiasX, ΔνbiasY, ΔνbiasZ –– Bias in the integrated accelerometer reading.

  • geomagneticFieldVectorN, geomagneticFieldVectorE, geomagneticFieldVectorD –– Estimate of the geomagnetic field vector at the reference location.

  • magbiasX, magbiasY, magbiasZ –– Bias in the magnetometer readings.

Given the conventional formation of the predicted state estimate,

xk|k1=f(x^k1|k1,uk)

uk is controlled by accelerometer and gyroscope data that has been converted to delta velocity and delta angle through trapezoidal integration. The predicted state estimation is:

xk|k1=[q0q0'q1q1'q2q2'q3q3'q1q0'+q0q1'q3q2'+q2q3'q2q0'+q3q1'+q0q2'q1q3'q3q0'q2q1'+q1q2'+q0q3'positionN+(Δt)(νN)positionE+(Δt)(νE)positionD+(Δt)(νD)νN+(Δt)(gN)+(ΔνXΔνbiasX)(q02+q12q22q32)2(ΔνYΔνbiasY)(q0q3q1q2)+2(ΔνZΔνbiasZ)(q0q2+q1q3)νE+(Δt)(gE)+(ΔνYΔνbiasY)(q02q12+q22q32)+2(ΔνXΔνbiasX)(q0q3+q1q2)2(ΔνZΔνbiasZ)(q0q1q2q3)νD+(Δt)(gD)+(ΔνZΔνbiasZ)(q02q12q22+q32)2(ΔνXΔνbiasX)(q0q2q1q3)+2(ΔνYΔνbiasY)(q0q1+q2q3)ΔθbiasXΔθbiasYΔθbiasZΔνbiasXΔνbiasYΔνbiasZgeomagneticFieldVectorNgeomagneticFieldVectorEgeomagneticFieldVectorDmagbiasXmagbiasYmagbiasZ]

In the equation, (q0', q1', q2', q3') is the quaternion that accounts for the orientation change from one step to the next step. Assuming the orientation change is small, then the rotation vector can be approximated as (ΔθX − ΔθbiasX, ΔθY − ΔθbiasY, ΔθZ − ΔθbiasZ), where ΔθX, ΔθY, ΔθZ are the integrated gyroscope readings. (q0', q1', q2', q3') is then obtained by converting the approximated rotation vector to a quaternion. In each calculation, the quaternion is normalized such that the length of the quaternion is 1 and its real part q0 is nonnegative.

Additionally,

  • ΔνX, ΔνY, ΔνZ –– Integrated accelerometer readings.

  • Δt –– IMU sample time.

  • gN, gE, gD –– Constant gravity vector in the NED frame.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced in R2018b