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

What's the right way to call rosbag in a launch file?

asked 2014-06-26 08:12:19 -0500

palmer.dorazio gravatar image

Hi there,

Since the Python API for rosbag is not really documented, I've decided to just start a couple bags from a launch file. I want to record some topics from my robot, and some from my desktop system. Here's what I have so far:

<launch>

<node pkg="rosbag" type="record" name="robot_bag"
    args="record -O /odom /diagnostics /tf"
    />

<node pkg="rosbag" type="record" name="harness_bag"
    args="record -O /cmd_vel /mobile_base/commands/velocity /move_base_simple/goal"
    />

</launch>

I've tried a few different things based on forum posts and one other question on this site, to no avail. The errors I've been getting are along the lines of:

Error writing: Error opening file: /cmd_vel.bag.active

and [robot_bag-1] process has died [pid 21226, exit code 1 ...

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2014-06-26 08:41:45 -0500

Thomas D gravatar image

updated 2014-06-26 08:43:00 -0500

I don't think you are using the -O flag the right way and you don't need record in the args. Try this:

<launch>
    <node pkg="rosbag" type="record" name="robot_bag"
              args="/odom /diagnostics /tf"
    />

  <node pkg="rosbag" type="record" name="harness_bag"
            args="/cmd_vel /mobile_base/commands/velocity /move_base_simple/goal"
    />
</launch>

If you want to have a prefix before the date/time in the bag filename add -o robot_bag and -o harness_bag as the first element of the args.

The error you are seeing is because the capital -O flag says to make the next element the bag file name. Since there is a leading slash to the next element (since you intend it to be a topic) it is trying to write a file in the root of your filesystem. You very likely do not have permissions to write files to the root of your filesystem (which is expected and encouraged) so there is an error. By using the lowercase -o flag it says to use the next element as a prefix for the date/time. Doing those things results in:

<launch>
    <node pkg="rosbag" type="record" name="robot_bag"
              args="-o robot_bag /odom /diagnostics /tf"
    />

  <node pkg="rosbag" type="record" name="harness_bag"
            args="-o harness_bag /cmd_vel /mobile_base/commands/velocity /move_base_simple/goal"
    />
</launch>

After running that launch file you should find that there are two bag files that end up in ~/.ros/.

See the rosbag command line usage page for more details.

edit flag offensive delete link more

Comments

Perfect, thanks! One more question: do you know of a way to direct the bag files elsewhere?

palmer.dorazio gravatar image palmer.dorazio  ( 2014-06-26 09:04:21 -0500 )edit
2

If you want the bag file to go to /tmp/mybag.bag then use `-o /tmp/mybag.bag`. Alternatively, if you want to save to a package directory in your workspace you can use `-o $(find package_name)/mybag.bag`. Best practice is to avoid using any username-specific locations, such as /home/user/mybag.bag.

Thomas D gravatar image Thomas D  ( 2014-06-26 09:31:27 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2014-06-26 08:12:19 -0500

Seen: 5,622 times

Last updated: Jun 26 '14