CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/Tools/simulink/arducopter/functions/getTimeZero.m
Views: 1799
1
function timeZero = getTimeZero(log, msgs, msgs2Ex)
2
% Get the earliest time stamp in the log
3
%
4
% Fabian Bredemeier - IAV GmbH
5
% License: GPL v3
6
7
% Create dummy zero timestamp
8
if isprop(log, 'RATE')
9
timeZero = log.RATE.TimeS(1);
10
else
11
error('Message RATE not contained in log.');
12
end
13
14
% Define messages that should not be included in search for time stamp
15
if nargin < 3
16
msgs2Exclude = {'FMT', 'FMTU', 'MODE', 'MULT', 'UNIT', 'PARM'};
17
else
18
msgs2Exclude = msgs2Ex;
19
end
20
21
for m = msgs
22
msg = m{1};
23
% Skip messages to exclude
24
if any(strcmp(msgs2Exclude, msg))
25
continue;
26
end
27
28
% Output warning if message is not included in log
29
if ~any(strcmp(fieldnames(log), msg))
30
warning(['Message ' msg ' not included in log!']);
31
end
32
33
% Skip message if message is deleted handle
34
if ~isvalid(log.(msg))
35
continue;
36
end
37
38
% Compare first time stamps and get lower start time
39
firstTime = log.(msg).TimeS(1);
40
if abs(timeZero - firstTime) > 2
41
error(['Time vector of ' msg ' invalid. The first time stamp is too far off. Aborting.']);
42
elseif firstTime < timeZero
43
timeZero = firstTime;
44
end
45
end
46
end
47
48
49