Ask Your Question

Record with rosbag from launch file

asked 2013-01-18 19:56:04 -0600

amittleider gravatar image

updated 2013-01-19 20:14:00 -0600

I want to use rosbag record in my launch file with the parameters linking to a ros package. Normally, you can get a package path in a launch file by using ${find mypackage}, but this does not work in this case, I presume because the ${find pkg} command doesn't work in the args statement of the launch file (?).

<node name="record" pkg="rosbag" type="record" args="-a -O $(find mypkg)/subdir"/>

The error in the log shows that the rosbag node is trying to subscribe to topics named ${find and mypkg}/subdir, which clearly is not what is intended.

I definitely don't want to use an absolute path. Is there any way to specify the relative path here?

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2013-01-20 16:51:34 -0600

Thomas gravatar image

updated 2018-02-06 07:54:48 -0600

Procópio gravatar image

Here is a launch file I use to record data on our robot:

<!-- -*- xml -*- -->
   Record HRP-2 data automatically in three separate rosbags:
   - cameras images
   - hrpsys information (IMU, force sensors, robot position)
   - diagnostics (node output, diagnostics)

  <arg name="record_cameras" default="true" />
  <arg name="record_hrpsys" default="true" />

 <!-- Are we on the robot (hrp2_14) or simulating (sim)? -->
 <arg name="robot_machine_profile" default="hrp2_14" />

 <!-- Load the robot model and machine description -->
 <include file="$(find hrp2_bringup)/launch/common.launch">
   <arg name="robot_machine_profile" value="$(arg robot_machine_profile)" />

 <node pkg="rosbag" type="record" name="rosbag_record_cam"
       args="record -o /tmp/hrp2-cameras /wide/left/image_raw /wide/left/camera_info    /wide/right/image_raw /wide/right/camera_info /narrow/left/image_raw /narrow/left/camera_info    /narrow/right/image_raw /narrow/right/camera_info"
       if="$(arg record_cameras)" />

 <node pkg="rosbag" type="record" name="rosbag_record_hrpsys"
       args="record -o /tmp/hrp2-hrpsys /imu /joint_states /joint_command /force_0 /force_1 /force_2 /force_3 /base_link"
       if="$(arg record_hrpsys)" />

 <node pkg="rosbag" type="record" name="rosbag_record_diag"
       args="record -o /tmp/hrp2-diag /diagnostics /rosout"/>   

Please note that if you pass "-o" instead of "-O" then it becomes only a prefix and not the full bag filename. In this case, the timestamp is then used as a suffix to build the full filename.

You can write into a package directory using "$(find mypkg)" BUT if you will not be able to release your stack. I.e. if your stack get, at some point, installed through a Debian package, the directory will be owned by root and be read-only for you so your launch file will not work.

Even if rosbuild and others ROS tools behaves badly w.r.t this issue, the source directory of any package should always be considered as read-only.

edit flag offensive delete link more



For anybody getting this error "ERROR: cannot launch node of type [rosbag/rosbag]: can't locate node [rosbag] in package [rosbag]". The launchfile should be changed to "<node pkg="rosbag" type="record" ...".<="" p="">

jespestana gravatar image jespestana  ( 2015-04-22 02:31:39 -0600 )edit

I see you are creating different bags for different sensors. I like that idea, but how can you play back those files in sync if you need all topics from all sensors?

tanasis gravatar image tanasis  ( 2017-11-09 05:06:25 -0600 )edit

answered 2013-01-18 22:08:50 -0600

Namal Senarathne gravatar image

Have you tried $(find mypkg) with the parenthesis instead of curly braces?

edit flag offensive delete link more



Ok I severely messed up that syntax. But there is another problem: you must specify a file name with the -O option, not a directory. If you specify a directory name, no bag file is produced. So run the launch file twice, the first bag is overridden.Is there a way to specify the bag name as the time?

amittleider gravatar image amittleider  ( 2013-01-19 20:17:51 -0600 )edit

Your Answer

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

Add Answer

Question Tools



Asked: 2013-01-18 19:56:04 -0600

Seen: 24,003 times

Last updated: Feb 06 '18