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

add metadata to rosbag [closed]

asked 2016-08-03 04:15:08 -0500

F.Brosseau gravatar image

Hello everybody,

I am trying to add ros parameters to a bag file just after the record is done.

I am writing a python script to do that and I have followed this link : http://wiki.ros.org/rosbag/Cookbook. But I didn't manage to make it work.

Nothing is added to the bag file and I have no error message .....

There is my code :

  record_args = ""
  try:
    for param in rospy.get_param_names():
      record_args += str(param + ": " + str(rospy.get_param(param))+ " | ")
    subprocess.call(["rosbag", "record", "-a", "-O", "test"])
  except KeyboardInterrupt:
    with rosbag.Bag('test.bag','a') as bag:
      dump = String(data = record_args)
      for _, _, t in bag.read_messages():
        break
      bag.write('/rosparam', dump, t-rospy.rostime.Duration(0, 1))
  finally:
    bag.close()

Thanks in advance.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by F.Brosseau
close date 2016-08-05 03:14:50.582854

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-08-05 03:14:10 -0500

F.Brosseau gravatar image

I will answer my own question :

I use psutil instead of subprocess. There is the part of the code doing the job :

    process = psutil.Popen(["rosbag", "record", "-O",bag_filename]+topic_list)
    process.wait()
  except KeyboardInterrupt:
    process_util = psutil.Process(process.pid)
    children = process_util.get_children()
    for child_process in children:
      child_process.send_signal(signal.SIGINT)
      child_process.wait()
    process_util.send_signal(signal.SIGINT)
    process_util.wait()
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-08-03 04:15:08 -0500

Seen: 665 times

Last updated: Aug 05 '16