i have set of images metadata including time stamps , odometry data data set. want convert time series of images rosbag can plug out of code i'll write , switch in real time data after testing. tutorial, process of programmatically saving data rosbag seems work like:
import rosbag std_msgs.msg import int32, string bag = rosbag.bag('test.bag', 'w') try: str = string() str.data = 'foo' = int32() i.data = 42 bag.write('chatter', str) bag.write('numbers', i) finally: bag.close()
for images, data type different process same. however, when have data supposed associated each other, e.g. each image should paired timestamp , odometry recording. sample code seems write "chatter" , "numbers" disjointly. way publish data each image, paired other pieces of data automatically?
in other words, need commented lines in following code:
import rosbag import cv2 std_msgs.msg import int32, string sensor_msgs.msg import image bag = rosbag.bag('test.bag', 'w') data in data_list: (imname, timestamp, speed) = data ts_str = string() ts_str.data = timestamp s = float32() s.data = speed image = cv2.imread(imname) # convert cv2 image rosbag format # write image, ts_str , s rosbag jointly bag.close()
many of standard message types sensor_msgs/image or nav_msgs/odometry have attribute header
contains attribute stamp
meant used timestamps.
when creating bag file, set same timestamp in headers of messages belong , write them separate topics:
from sensor_msgs.msg import image nav_msgs.msg import odometry ... img_msg = image() odo_msg = odometry() img_msg.header.stamp = timestamp odo_msg.header.stamp = timestamp # set other values of messages... bag.write("image", img_msg) bag.write("odometry", odo_msg)
later when subscribing messages, can match messages different topics based on timestamp.
depending on how important exact synchronization of image , odometry application, might enough use last message got on each topic , assume fit together. in case need more precise, there message_filter takes care of synchronizing 2 topics , provides messages of both topics in 1 callback.
Comments
Post a Comment