ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

My rosbag info shows messages, but my ros msgs are empty.

asked 2017-04-18 04:28:40 -0500

Joy16 gravatar image

updated 2017-04-18 18:52:50 -0500

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()
edit retag flag offensive close merge delete

Comments

What is your question?

Thomas D gravatar image Thomas D  ( 2017-04-18 08:12:55 -0500 )edit

My rosbag messages contain no data. All fields in the ros messages are empty

Joy16 gravatar image Joy16  ( 2017-04-18 16:30:03 -0500 )edit

How are you playing back your bag files? How did you determine that your messages are empty? Are you setting the parameter use_sim_time to true?

Thomas D gravatar image Thomas D  ( 2017-04-18 16:38:39 -0500 )edit

Ya. I set rosparam set use_sim_time true. Iam lpaying my rosbag file as rosbag play --clock 17Apr18.bag -l my messages are empty as a rostopic echo on any topic gives me empty fields.

header: 
  seq:0
  stamp: 
    secs:0
    nsecs:   
  frame_id: '"
  data =[]
Joy16 gravatar image Joy16  ( 2017-04-18 17:07:25 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-04-18 17:47:52 -0500

ahendrix gravatar image

You are writing empty message objects into your bag file:

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())

bag.write() writes the message object that you give it to the bag file with the specific topic name. Since you're supplying default-constructed messages (which are empty), that's what it is writing to the bag file.

If you want to subscribe to a topic and record the messages on that topic to a bag, you need to either call the robag command-line tool from your program and let it subscribe, or you need to create subscribers on each of the topics that you care about, and then actually write the received messages to the bag file.

edit flag offensive delete link more

Comments

Hi! Thanks a lot! I am sorry, I had not posted the latest code. I am subscribing to these topics, but I am sure how to pass them to bag.write()

Joy16 gravatar image Joy16  ( 2017-04-18 18:54:28 -0500 )edit

#This is giving me stop_writing_chunk error

def callbackt(data):       
               bag.write("/cam",data)

def callbackRestart(data):
 if data.state == 0:
   global flag_bag
   if flag_bag == 1:
    rospy.Subscriber("/cam",Image,callback)
Joy16 gravatar image Joy16  ( 2017-04-18 19:35:24 -0500 )edit

You need to shut down the subscribers that write to the bag before you close the bag file.

ahendrix gravatar image ahendrix  ( 2017-04-18 20:19:58 -0500 )edit

You should probably set up your subscribers once (instead of every time you get callbackRestart); note that because subscriber callbacks happen in a separate thread, the if flag_bag == 1: won't prevent callbacks.

ahendrix gravatar image ahendrix  ( 2017-04-18 20:23:23 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2017-04-18 04:28:40 -0500

Seen: 1,798 times

Last updated: Apr 18 '17