ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
I solved this with two loops like this pseudo code, it does require checking the topic of every message but in the second loop the data is organized for processing:
struct MySyncedTopics
{
foo
bar
}
std::map<ros::Time, MySyncedTopics> sync_map
foreach msg in bag
{
if msg.topic_name == "foo"
sync_map[msg.timestamp].foo = msg
if msg.topic_name == "bar"
sync_map[msg.timestamp].bar = msg
}
foreach timestamp in sorted sync_map keys
{
if (not both messages exist at this timestamp)
{
print error message
continue
}
// do something with synchronized messages
....
}
2 | No.2 Revision |
I solved this with had to do something similar recently, I used two loops like this pseudo code, it does require checking the topic of every message but in the second loop the data is organized for processing:processing (it could be split into n+1 loops- one loop on each specific topic, I don't know if that is more efficient or more self-documenting or not):
struct MySyncedTopics
{
foo
bar
}
std::map<ros::Time, MySyncedTopics> sync_map
foreach msg in bag
{
if msg.topic_name == "foo"
sync_map[msg.timestamp].foo = msg
if msg.topic_name == "bar"
sync_map[msg.timestamp].bar = msg
}
foreach timestamp in sorted sync_map keys
{
if (not both messages exist at this timestamp)
{
print error message
continue
}
// do something with synchronized messages
....
}
3 | No.3 Revision |
I had to do something similar recently, I used two loops like this pseudo code, it does require checking the topic of every message but in the second loop the data is organized for processing (it could be split into n+1 loops- loops: one loop on each specific topic, topic plus a final processing, I don't know if that is more efficient or more self-documenting or not):
struct MySyncedTopics
{
foo
bar
}
std::map<ros::Time, MySyncedTopics> sync_map
foreach msg in bag
{
if msg.topic_name == "foo"
sync_map[msg.timestamp].foo = msg
if msg.topic_name == "bar"
sync_map[msg.timestamp].bar = msg
}
foreach timestamp in sorted sync_map keys
{
if (not both messages exist at this timestamp)
{
print error message
continue
}
// do something with synchronized messages
....
}