Ask Your Question
1

how record rosbag with python

asked 2018-03-28 05:26:30 -0500

khadija gravatar image

Hello I use the command line (Terminal) to record images (RGB, RGBD), joy, and IMU data

>> rosbag record -O subset /camera/depth/image_raw /camera/rgb/image_raw /joy /mobile_base/sensors/imu_data_raw

How can I convert this command to python code script?

any help is appreciated

edit retag flag offensive close merge delete

Comments

Not a real answer (as this seems a bit of an xy-problem), but there is something called osrf/nodelet_rosbag. That exposes an action server interface to rosbag.

gvdhoorn gravatar image gvdhoorn  ( 2018-03-28 09:03:45 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
3

answered 2018-03-28 05:34:27 -0500

updated 2020-12-17 08:01:20 -0500

The (ugly) way that I have done this in the past, is roughly like this:

import subprocess, shlex, psutil
command = "rosbag record -O subset /camera/depth/image_raw /camera/rgb/image_raw /joy /mobile_base/sensors/imu_data_raw"
command = shlex.split(command)
rosbag_proc = subprocess.Popen(command)

and this is how you can kill the recording process:

for proc in psutil.process_iter():
    if "record" in proc.name() and set(command[2:]).issubset(proc.cmdline()):
        proc.send_signal(subprocess.signal.SIGINT)

rosbag_proc.send_signal(subprocess.signal.SIGINT)
edit flag offensive delete link more

Comments

but send_signal(subprocess.signal.SIGINT) didn't change .bag.active file to .bag file.

azerila gravatar image azerila  ( 2020-12-17 06:08:08 -0500 )edit
1

@azerila Check the newly edited answer. I have added a for loop for the created children "record" process.

gstavrinos gravatar image gstavrinos  ( 2020-12-17 07:46:52 -0500 )edit
0

answered 2018-09-17 15:31:31 -0500

jubeira gravatar image

Have you seen this? http://wiki.ros.org/rosbag/Code%20API...

You should be able to write nodes that subscribe to the topics you need, and write the results to a rosbag.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2018-03-28 05:26:30 -0500

Seen: 3,404 times

Last updated: Dec 17 '20