-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathPFpredict.m
executable file
·38 lines (27 loc) · 1001 Bytes
/
PFpredict.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
function [x] = PFpredict(x,dt,IMU_meas_prev,IMU_meas_current,IMU_noise)
%Extract states
Vn = x(1);
Ve = x(2);
psi = x(3);
ax_prev = IMU_meas_prev(2);
ay_prev = IMU_meas_prev(3);
yawRate_prev = IMU_meas_prev(4);
ax_current = IMU_meas_current(2);
ay_current = IMU_meas_current(3);
yawRate_current = IMU_meas_current(4);
accelNoise = IMU_noise(1);
gyroNoise = IMU_noise(2);
%Predict states forward
psi_current = psi + 0.5*(yawRate_prev + yawRate_current) * dt;
%Convert velocities to body frame:
% Cbn = [cos(psi) , -sin(psi) ;...
% sin(psi) , cos(psi)];
Vx = Vn*cos(psi) + Ve*sin(psi);
Vy = Vn*(-sin(psi)) + Ve*cos(psi);
dvx = 0.5*dt*(ax_prev + ax_current);
Vx = Vx + dvx;
dvy = 0.5*dt*(ay_prev + ay_current);
Vy = Vy + dvy;
Vn = Vx * cos(psi_current) - Vy * sin(psi_current);
Ve = Vx * sin(psi_current) - Vy * cos(psi_current);
x = [Vn;Ve;psi_current];