-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathqprop.m
37 lines (32 loc) · 959 Bytes
/
qprop.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
function q = qprop(q, w, dt)
% QPROP Quaternion propagation
%
% Discretely propagates a quaternion via its average rotation rate over a
% time step.
%
% q = QPROP(q, w, dt)
%
% This function is vectorized to operate on numerous quaternions and
% rotation rates simultaneously.
%
% Input:
%
% q Quaternion to propagate (scalar last) (4-by-1 or 4-by-n)
% w Rotation rate (rad/s) (3-by-1 or 3-by-n)
% dt Time step (s) (scalar or 1-by-n)
%
% Output:
%
% q Propagated quaternion (4-by-1 or 4-by-n)
%
% Copyright 2016-2017 An Uncommon Lab
%#codegen
[w, w_mag] = normalize(w); % Rot. unit vector and speed
w_mag = 0.5 * w_mag .* dt; % Half rotation angle
swm = sin(w_mag);
qr = [swm .* w(1,:); ... % Rotation quaternion
swm .* w(2,:); ...
swm .* w(3,:); ...
cos(w_mag)];
q = qcomp(qr, q); % Updated quaternion
end % qprop