Turtlebot record a synchronized data

asked 2018-04-04 08:49:46 -0500

khadija gravatar image

Hello

I need to collect database from my Turtlebot that takes RGB image, depth image, joy command, and IMU (angles). I need to record a synchronized data. After I do a lot of searching; I found examples of write data to a bag file: http://wiki.ros.org/rosbag/Code%20API and Time Synchronizer: http://wiki.ros.org/message_filters#C...

I tried to mix these two codes together as following:

#!/usr/bin/env python
# coding=utf-8

import rosbag
import rospy
import message_filters
from sensor_msgs.msg import Image
from sensor_msgs.msg import Imu
from sensor_msgs.msg import Joy
#from std_msgs.msg import Int32, String
import std_msgs.msg 

bag = rosbag.Bag('test2.bag', 'w')

try:
  def callback(image, imu, joy):
    # Solve all of perception here..
    str = String()
    str.data = 'foo' 
    i = Int32()
    i.data = 42

    bag.write('/camera/rgb/image_raw', Image)
    bag.write('/camera/depth/image_raw', Image)
    bag.write('/mobile_base/sensors/imu_data_raw', i)
    bag.write('/joy', i)

  image_sub = message_filters.Subscriber('/camera/depth/image_raw', Image)
  imu_sub = message_filters.Subscriber('/mobile_base/sensors/imu_data_raw', Imu)
  joy_sub = message_filters.Subscriber('/joy', Joy)

  ts = message_filters.TimeSynchronizer([image_sub, imu_sub, joy_sub], 10)
  #ts = message_filters.ApproximateTimeSynchronizer([image_sub, imu_sub], 10, 0.1, allow_headerless=False)
  ts.registerCallback(callback)
  rospy.spin()

except KeyboardInterrupt:
  pass
finally:
  bag.close()

but this result nothing!! is what I have done is correct or not ?!!

please help me

edit retag flag offensive close merge delete