0
$\begingroup$

Rosanswers logo

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


Originally posted by khadija on ROS Answers with karma: 25 on 2018-03-28

Post score: 1


Original comments

Comment by gvdhoorn on 2018-03-28:
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.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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)

Originally posted by gstavrinos with karma: 641 on 2018-03-28

This answer was ACCEPTED on the original site

Post score: 4


Original comments

Comment by azerila on 2020-12-17:
but send_signal(subprocess.signal.SIGINT) didn't change .bag.active file to .bag file.

Comment by gstavrinos on 2020-12-17:
@azerila Check the newly edited answer. I have added a for loop for the created children "record" process.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.