Below is my code snippet to record rostopics using ROSbag API. My messages are empty when I do a rostopic echo. I am not sure what is happening.
My bag is being recorded and my
`rosbag info 17Apr17.bag` gives my this output:
path: 17Apr17.bag
version: 2.0
duration: 8.9s
start: Apr 17 2017 18:57:55.21 (1492469875.21)
end: Apr 17 2017 18:58:04.08 (1492469884.08)
size: 1022.8 KB
messages: 10656
compression: none [2/2 chunks]
types: baxter_core_msgs/EndEffectorState [ade777f069d738595bc19e246b8ec7a0]
sensor_msgs/Image [060021388200f6f0f447d0fcd9c64743]
sensor_msgs/JointState [3066dcd76a6cfaef579bd0f34173e9fd]
tf2_msgs/TFMessage [94810edda583a504dfda3829e70d7eec]
topics: /camera/depth/image_raw 888 msgs : sensor_msgs/Image
/camera/rgb/image_color 888 msgs : sensor_msgs/Image
/cameras/left_hand_camera/image 888 msgs : sensor_msgs/Image
/cameras/right_hand_camera/image 888 msgs : sensor_msgs/Image
/robot/end_effector/left_gripper/state 888 msgs : baxter_core_msgs/EndEffectorState
/robot/end_effector/right_gripper/state 888 msgs : baxter_core_msgs/EndEffectorState
/robot/joint_states 888 msgs : sensor_msgs/JointState
/softkinetic_left/depth/image_raw 888 msgs : sensor_msgs/Image
/softkinetic_left/rgb/image_color 888 msgs : sensor_msgs/Image
/softkinetic_right/depth/image_raw 888 msgs : sensor_msgs/Image
/softkinetic_right/rgb/image_color 888 msgs : sensor_msgs/Image
tf 888 msgs : tf2_msgs/TFMessage
CODE:
#!/usr/bin/env python
import rosbag
import rospy
from random import randint
from tf2_msgs.msg import TFMessage
from baxter_core_msgs.msg import DigitalIOState
from std_msgs.msg import String
from sensor_msgs.msg import Image
from sensor_msgs.msg import JointState
from baxter_core_msgs.msg import EndEffectorState
from create_folder import FileRead
flag = 1
print flag
tfMsg = TFMessage()
num = FileRead()
print num[0]
bag = rosbag.Bag("/home/dhiraj/ros_ws/src/baxter_examples/scripts/"+str(num[0])+".bag",'w')
# Flag = 0 will not record(callbackStop) the file and Flag=1 will recrd the file
# I need to record rosbag by the click of the buttons and hence the the setup
def callbackStop(data):
if data.state:
global flag
if flag == 1:
print "closing bag"
flag = 0
print "closing bag with flag", flag
bag.close()
def callbackRestart(data):
if data.state == 0:
print "ENTERING CALLBVBACK"
global flag
if flag == 1:
print "RECORDING NEW BAG"
bag.write("tf",tfMsg)
bag.write("/cameras/right_hand_camera/image",Image())
bag.write("/cameras/left_hand_camera/image",Image())
bag.write("/robot/joint_states",JointState())
bag.write("/robot/end_effector/right_gripper/state",EndEffectorState())
bag.write("/robot/end_effector/left_gripper/state",EndEffectorState())
bag.write("/softkinetic_left/rgb/image_color",Image())
bag.write("/softkinetic_right/rgb/image_color",Image())
bag.write("/softkinetic_left/depth/image_raw",Image())
bag.write("/softkinetic_right/depth/image_raw",Image())
bag.write("/camera/rgb/image_color",Image())
bag.write("/camera/depth/image_raw",Image())
def tf_info():
rospy.init_node("get_tf")
rightStart = rospy.Subscriber("/robot/digital_io/right_shoulder_button/state",DigitalIOState, callbackRestart)
bagClosRight = rospy.Subscriber("/robot/digital_io/right_itb_button2/state",DigitalIOState,callbackStop)
bagCloseLeft = rospy.Subscriber("/robot/digital_io/left_itb_button2/state",DigitalIOState,callbackStop)
leftRestart = rospy.Subscriber("/robot/digital_io/left_itb_button1/state",DigitalIOState,callbackSetFlag)
rightRestart = rospy.Subscriber("/robot/digital_io/right_itb_button1/state",DigitalIOState,callbackSetFlag)
rospy.spin()
if __name__=='__main__':
tf_info()
↧