ardupilot/Tools/simulink/arducopter/functions/getTimeZero.m
Bredemeier, Fabian (TD-M) 2abfb1bec8 Copter: Simulink Model and init scripts
- arducopter.slx: Simulates ArduCopter Stabilize and Althold controller and optional plant model
- sid_pre.m: Loads *.bin files to Matlab structs
- sid_sim_init.m: Loads signals and parameters from Matlab structure into Simulink model
- sid_controller_validation.m: Validation of the flight controller model with the flight data loaded to the Matlab workspace.
2022-12-23 09:57:21 +11:00

48 lines
1.2 KiB
Matlab

function timeZero = getTimeZero(log, msgs, msgs2Ex)
% Get the earliest time stamp in the log
%
% Fabian Bredemeier - IAV GmbH
% License: GPL v3
% Create dummy zero timestamp
if isprop(log, 'RATE')
timeZero = log.RATE.TimeS(1);
else
error('Message RATE not contained in log.');
end
% Define messages that should not be included in search for time stamp
if nargin < 3
msgs2Exclude = {'FMT', 'FMTU', 'MODE', 'MULT', 'UNIT', 'PARM'};
else
msgs2Exclude = msgs2Ex;
end
for m = msgs
msg = m{1};
% Skip messages to exclude
if any(strcmp(msgs2Exclude, msg))
continue;
end
% Output warning if message is not included in log
if ~any(strcmp(fieldnames(log), msg))
warning(['Message ' msg ' not included in log!']);
end
% Skip message if message is deleted handle
if ~isvalid(log.(msg))
continue;
end
% Compare first time stamps and get lower start time
firstTime = log.(msg).TimeS(1);
if abs(timeZero - firstTime) > 2
error(['Time vector of ' msg ' invalid. The first time stamp is too far off. Aborting.']);
elseif firstTime < timeZero
timeZero = firstTime;
end
end
end