Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. % Reference direction of Earth's magnetic field
  2. h = quaternProd(q, quaternProd([0 Magnetometer], quaternConj(q)));
  3. b = [0 norm([h(2) h(3)]) 0 h(4)];
  4.  
  5. % Estimated direction of gravity and magnetic field
  6. v = [2*(q(2)*q(4) - q(1)*q(3))
  7. 2*(q(1)*q(2) + q(3)*q(4))
  8. q(1)^2 - q(2)^2 - q(3)^2 + q(4)^2];
  9.  
  10. w = [2*b(2)*(0.5 - q(3)^2 - q(4)^2) + 2*b(4)*(q(2)*q(4) - q(1)*q(3))
  11. 2*b(2)*(q(2)*q(3) - q(1)*q(4)) + 2*b(4)*(q(1)*q(2) + q(3)*q(4))
  12. 2*b(2)*(q(1)*q(3) + q(2)*q(4)) + 2*b(4)*(0.5 - q(2)^2 - q(3)^2)];
  13.  
  14. % Error is sum of cross product between estimated direction and measured direction of fields
  15. e = cross(Accelerometer, v) + cross(Magnetometer, w);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement