Rosanswers logo

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?

Originally posted by amittleider on ROS Answers with karma: 227 on 2013-01-18

Post score: 9


2 Answers 2


Rosanswers logo

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.

Originally posted by Thomas with karma: 4478 on 2013-01-20

This answer was ACCEPTED on the original site

Post score: 21

Original comments

Comment by jespestana on 2015-04-22:
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" ...".

Comment by tanasis on 2017-11-09:
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?


Rosanswers logo

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

Originally posted by Namal Senarathne with karma: 246 on 2013-01-18

This answer was NOT ACCEPTED on the original site

Post score: 4

Original comments

Comment by amittleider on 2013-01-19:
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?


Your Answer

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