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

Revision history [back]

click to hide/show revision 1
initial version

What I use is this:

DeclareLaunchArgument('bag_version', default_value=['v2'], description='BAG file version, v1 or v2'),
DeclareLaunchArgument('bag_full_path', default_value=[''], description='Full path to BAG file'),

Ros1BagPlayNode = launch.actions.ExecuteProcess(
    cmd=['ros2', 'bag', 'play', '-s', 'rosbag_v2', LaunchConfiguration('bag_full_path')],
    name='rosbag_play',
    output='log',
    condition=IfCondition(PythonExpression(["'", LaunchConfiguration('bag_version'), "' == 'v1'"]))
)
Ros2BagPlayNode = launch.actions.ExecuteProcess(
    cmd=['ros2', 'bag', 'play', LaunchConfiguration('bag_full_path')],
    name='rosbag_play',
    output='log',
    condition=IfCondition(PythonExpression(["'", LaunchConfiguration('bag_version'), "' == 'v2'"]))
)

Then I can use ros2 launch foo.launch.py bag_full_path:=/a/b/c.bag bag_version:=v1 to allow me to switch between v1 and v2 bag file playback. If you're launching a Node, though, the above method is better.