pose estimation from asynchronous sensors -凯发k8网页登录
this example shows how you might fuse sensors at different rates to estimate pose. accelerometer, gyroscope, magnetometer and gps are used to determine orientation and position of a vehicle moving along a circular path. you can use controls on the figure window to vary sensor rates and experiment with sensor dropout while seeing the effect on the estimated pose.
simulation setup
load prerecorded sensor data. the sensor data is based on a circular trajectory created using the waypointtrajectory
class. the sensor values were created using the gpssensor
and imusensor
classes. the circulartrajectorysensordata.mat
file used here can be generated with the generatecirculartrajsensordata
function.
ld = load('circulartrajectorysensordata.mat'); fs = ld.fs; % maximum marg rate gpsfs = ld.gpsfs; % maximum gps rate ratio = fs./gpsfs; refloc = ld.refloc; trajorient = ld.trajdata.orientation; trajvel = ld.trajdata.velocity; trajpos = ld.trajdata.position; trajacc = ld.trajdata.acceleration; trajangvel = ld.trajdata.angularvelocity; accel = ld.accel; gyro = ld.gyro; mag = ld.mag; lla = ld.lla; gpsvel = ld.gpsvel;
fusion filter
create an insfilterasync
to fuse imu gps measurements. this fusion filter uses a continuous-discrete extended kalman filter (ekf) to track orientation (as a quaternion), angular velocity, position, velocity, acceleration, sensor biases, and the geomagnetic vector.
this insfilterasync
has several methods to process sensor data: fuseaccel
, fusegyro
, fusemag
and fusegps
. because insfilterasync
uses a continuous-discrete ekf, the predict
method can step the filter forward an arbitrary amount of time.
fusionfilt = insfilterasync('referencelocation', refloc);
initialize the state vector of the insfilterasync
the insfilterasync
tracks the pose states in a 28-element vector. the states are:
states units index orientation (quaternion parts) 1:4 angular velocity (xyz) rad/s 5:7 position (ned) m 8:10 velocity (ned) m/s 11:13 acceleration (ned) m/s^2 14:16 accelerometer bias (xyz) m/s^2 17:19 gyroscope bias (xyz) rad/s 20:22 geomagnetic field vector (ned) ut 23:25 magnetometer bias (xyz) ut 26:28
ground truth is used to help initialize the filter states, so the filter converges to good answers quickly.
nav = 100; initstate = zeros(28,1); initstate(1:4) = compact( meanrot(trajorient(1:nav))); initstate(5:7) = mean( trajangvel(10:nav,:), 1); initstate(8:10) = mean( trajpos(1:nav,:), 1); initstate(11:13) = mean( trajvel(1:nav,:), 1); initstate(14:16) = mean( trajacc(1:nav,:), 1); initstate(23:25) = ld.magfield; % the gyroscope bias initial value estimate is low for the z-axis. this is % done to illustrate the effects of fusing the magnetometer in the % simulation. initstate(20:22) = deg2rad([3.125 3.125 3.125]); fusionfilt.state = initstate;
set the process noise values of the insfilterasync
the process noise variance describes the uncertainty of the motion model the filter uses.
fusionfilt.quaternionnoise = 1e-2; fusionfilt.angularvelocitynoise = 100; fusionfilt.accelerationnoise = 100; fusionfilt.magnetometerbiasnoise = 1e-7; fusionfilt.accelerometerbiasnoise = 1e-7; fusionfilt.gyroscopebiasnoise = 1e-7;
define the measurement noise values used to fuse sensor data
each sensor has some noise in the measurements. these values can typically be found on a sensor's datasheet.
rmag = 0.4; rvel = 0.01; racc = 610; rgyro = 0.76e-5; rpos = 3.4; fusionfilt.statecovariance = diag(1e-3*ones(28,1));
initialize scopes
the helperscrollingplotter
scope enables plotting of variables over time. it is used here to track errors in pose. the poseviewerwithswitches
scope allows 3d visualization of the filter estimate and ground truth pose. the scopes can slow the simulation. to disable a scope, set the corresponding logical variable to false.
useerrscope = true; % turn on the streaming error plot. useposeview = true; % turn on the 3d pose viewer. if useposeview posescope = poseviewerwithswitches(... 'xpositionlimits', [-30 30], ... 'ypositionlimits', [-30, 30], ... 'zpositionlimits', [-10 10]); end f = gcf; if useerrscope errscope = helperscrollingplotter(... 'numinputs', 4, ... 'timespan', 10, ... 'samplerate', fs, ... 'ylabel', {'degrees', ... 'meters', ... 'meters', ... 'meters'}, ... 'title', {'quaternion distance', ... 'position x error', ... 'position y error', ... 'position z error'}, ... 'ylimits', ... [ -1, 30 -2, 2 -2 2 -2 2]); end
simulation loop
the simulation of the fusion algorithm allows you to inspect the effects of varying sensor sample rates. further, fusion of individual sensors can be prevented by unchecking the corresponding checkbox. this can be used to simulate sensor dropout.
some configurations produce dramatic results. for example, turning off the gps sensor causes the position estimate to drift quickly. turning off the magnetometer sensor will cause the orientation estimate to slowly deviate from the ground truth as the estimate rotates too fast. conversely, if the gyroscope is turned off and the magnetometer is turned on, the estimated orientation shows a wobble and lacks the smoothness present if both sensors are used.
turning all sensors on but setting them to run at the lowest rate produces an estimate that visibly deviates from the ground truth and then snaps back to a more correct result when sensors are fused. this is most easily seen in the helperscrollingplotter
of the running estimate errors.
the main simulation runs at 100 hz. each iteration inspects the checkboxes on the figure window and, if the sensor is enabled, fuses the data for that sensor at the appropriate rate.
for ii=1:size(accel,1) fusionfilt.predict(1./fs); % fuse accelerometer if (f.userdata.accelerometer) && ... mod(ii, fix(fs/f.userdata.accelerometersamplerate)) == 0 fusionfilt.fuseaccel(accel(ii,:), racc); end % fuse gyroscope if (f.userdata.gyroscope) && ... mod(ii, fix(fs/f.userdata.gyroscopesamplerate)) == 0 fusionfilt.fusegyro(gyro(ii,:), rgyro); end % fuse magnetometer if (f.userdata.magnetometer) && ... mod(ii, fix(fs/f.userdata.magnetometersamplerate)) == 0 fusionfilt.fusemag(mag(ii,:), rmag); end % fuse gps if (f.userdata.gps) && mod(ii, fix(fs/f.userdata.gpssamplerate)) == 0 fusionfilt.fusegps(lla(ii,:), rpos, gpsvel(ii,:), rvel); end % plot the pose error [p,q] = pose(fusionfilt); posescope(p, q, trajpos(ii,:), trajorient(ii)); orienterr = rad2deg(dist(q, trajorient(ii) )); poserr = p - trajpos(ii,:); errscope(orienterr, poserr(1), poserr(2), poserr(3)); end
conclusion
the insfilterasync
allows for various and varying sample rates. the quality of the estimated outputs depends heavily on individual sensor fusion rates. any sensor dropout will have a profound effect on the output.