Advertisement
Guest User

Untitled

a guest
Jul 25th, 2014
597
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.40 KB | None | 0 0
  1. %% ================================================================
  2. %  Kalman Filter Prediction @ 100 Hz
  3. %  ================================================================
  4.  
  5. %% STATE VECTOR
  6. % dX = [errLAT errLong errAlt | errVN errVE errVD | errPhi errTheta errPsi |errorsBIASES (3 acc and 43 gyro biases)]
  7.  
  8. [q, Vned, Pned]=sinsq(q,Vned,Pned, A, W, DT, Gln, EARTH_R0, BA, BG);
  9.  
  10. % Convert quaternion to Rotation Matrix
  11. Cbn = quat2cbn(q);
  12.  
  13. % Dynamic Matrix calculation
  14. F = calculateF(Vned,A,Pned,Cbn);
  15.  
  16. % Matrix exponential
  17. Fk = expm(F*DT);
  18. Gk = calculateG(Cbn);
  19.  
  20. % Predicted covariance estimate
  21. P = Fk*P*Fk'+Gk*Q*Gk'*DT;
  22.  
  23.  
  24. %% ================================================================
  25. %  Kalman Filter Correction @ 1 Hz
  26. %  ================================================================
  27.  
  28. if(GPS_AVAILABLE)
  29.     ...
  30.  
  31.     H1   = calculateH1; % gps velocity measurement
  32.     dzV  = Vned-Vgps;
  33.     PHT1 = P*(H1');
  34.     RV   = diag(R_in(4:6)*0.1);
  35.  
  36.     K1   = PHT1/(H1*PHT1+RV);
  37.     dx   = K1*dzV;
  38.     P    = P-PHT1*K1';
  39.  
  40.     % Apply corrections
  41.     Pned = Pned + dx(1:3);
  42.     Vned = Vned + dx(4:6);
  43.    
  44.     % Correct attitude
  45.     nq  = norm(dx(7:9));
  46.     cnq = cos(nq/2);
  47.     snq = sin(nq/2);
  48.     dq  = [cnq; -dx(7:9)/nq*snq];
  49.     q   = quatmul(dq,q);
  50.    
  51.     % Correct Biases
  52.     BA = BA + dx(10:12);
  53.     BG = BG + dx(13:15);
  54.    
  55.     dx = zeros(plen,1);
  56.  
  57.     ...
  58. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement