Path: blob/master/Tools/simulink/arducopter/functions/getTimeZero.m
9717 views
function timeZero = getTimeZero(log, msgs, msgs2Ex)1% Get the earliest time stamp in the log2%3% Fabian Bredemeier - IAV GmbH4% License: GPL v356% Create dummy zero timestamp7if isprop(log, 'RATE')8timeZero = log.RATE.TimeS(1);9else10error('Message RATE not contained in log.');11end1213% Define messages that should not be included in search for time stamp14if nargin < 315msgs2Exclude = {'FMT', 'FMTU', 'MODE', 'MULT', 'UNIT', 'PARM'};16else17msgs2Exclude = msgs2Ex;18end1920for m = msgs21msg = m{1};22% Skip messages to exclude23if any(strcmp(msgs2Exclude, msg))24continue;25end2627% Output warning if message is not included in log28if ~any(strcmp(fieldnames(log), msg))29warning(['Message ' msg ' not included in log!']);30end3132% Skip message if message is deleted handle33if ~isvalid(log.(msg))34continue;35end3637% Compare first time stamps and get lower start time38firstTime = log.(msg).TimeS(1);39if abs(timeZero - firstTime) > 240error(['Time vector of ' msg ' invalid. The first time stamp is too far off. Aborting.']);41elseif firstTime < timeZero42timeZero = firstTime;43end44end45end46474849