Match ROS Message Timestamps

A function to find matching timestamps between two sets of ROS messages
58 Downloads
Updated 3 Jul 2019

View License

Match ROS timestamps from matchFrom into matchTo where each of these is a cell array of ROS messages. This returns an array the same size as matchFrom which contains the corresponding index in matchTo for each message.

Take two cell arrays of ROS messages with headers, and match the timestamps from the first to the nearest message in the second. If the difference is greater than maxDelta then the index is returned as -1. The messages do not need to be in timestamp order.

Requires the ROS toolbox

INPUT:
matchFrom - an Nx1 cell array of some ROS message type with a Header field in each one. So that matchFrom{1}.Header.Stamp exists.
matchTo - an Mx1 cell array of some ROS message type with a Header field in each one. So that matchTo{1}.Header.Stamp exists.
maxDelta (optional) - the maximum difference in seconds to match two messages between. This is Inf by default.
matchFromOffset (optional) - an offset in seconds to apply to all messages in 'matchFrom', in case they came from different clock sources

OUTPUT:
indexes - an Nx1 matrix which maps each message in 'matchFrom' to the nearest message in 'matchTo'. So the nearest message to matchFrom{x} is matchTo{indexes(x)}
fromTimes - an Nx1 matrix of the matchFrom message times in seconds
toTimes - an Mx1 matrix of the matchTo message times in seconds
diffs - an Nx1 matrix of the match messages time differences

Published 2019 by https://github.com/jaspereb

Cite As

Jasper Brown (2024). Match ROS Message Timestamps (https://www.mathworks.com/matlabcentral/fileexchange/72026-match-ros-message-timestamps), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2019a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Specialized Messages in Help Center and MATLAB Answers
Tags Add Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.0