Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ardupilot
GitHub Repository: Ardupilot/ardupilot
Path: blob/master/Tools/simulink/arducopter/functions/demodYawAngle.m
9903 views
1
function [sigOut] = demodYawAngle(sigIn)
2
% Inverse the modulo of 360° operation used on the yaw angle signals
3
%
4
% Fabian Bredemeier - IAV GmbH
5
% License: GPL v3
6
7
% Output signal
8
sigOut = zeros(length(sigIn),1);
9
10
% Calcualte the differences between samples
11
sigDiff = diff(sigIn);
12
13
% If difference is larger than 2*pi, safe last sample as offset for
14
% following signals
15
offset = 0;
16
skip = 0; % Var to skip the signal sample directly after abrupt angle change
17
for i = 1:length(sigIn)
18
sigOut(i) = offset + sigIn(i+skip);
19
if i < length(sigDiff) && i > 1
20
% Reset prevent Adding
21
if abs(sigDiff(i)) < 90
22
skip = 0;
23
% Add to offset, if switch happened from 2pi to 0
24
elseif sigDiff(i) <= -90 && ~skip
25
offset = offset + 360;%(sigIn(i-2)+sigIn(i-1))/2; % Smooth signal values since they are oscillating at jumps
26
skip = 1;
27
% Subtract from offset, if switch happened from 0 tp 2 pi
28
elseif sigDiff(i) > 90 && ~skip
29
offset = offset - 360;%(sigIn(i+2)+sigIn(i+1))/2; % Smooth signal values since they are oscillating at jumps
30
skip = 1;
31
end
32
end
33
end
34
35
% Apply moving average filter to smooth out sample value jumps
36
steps = 10;
37
coeffFilt = ones(1, steps)/steps;
38
% sigOut = filter(coeffFilt, 1, sigOut);
39
sigOut = movmean(sigOut, 9);
40
end
41
42
43