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

How to start ros2 bag play from launch file?

asked 2022-11-12 03:56:20 -0500

Haneko gravatar image

I would like to start a rosbag file from within a python launch file. How would it be possible to start the command line argument

$ ros2 bag play myfile.db3

within a python launch file. Thanks

My launchfile looks as the following:

from launch import LaunchDescription
from launch_ros.actions import Node

def generate_launch_description():
  ld = LaunchDescription()
  # ------------------------- Nodes ------------------------- #
  rosbag_play = (
    package='rosbag',
    executable='play',
    arguments= "--loop ~/path/to/myfile.db3",
    output='screen'
  )
  ...
  # -------------------------------------------------------- #
  ld.add_action(rosbag_play)
  ...
  return ld
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-11-13 23:56:49 -0500

ravijoshi gravatar image

Please modify your launch file with the following content:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from launch import LaunchDescription
from launch.actions import ExecuteProcess


def generate_launch_description():
    return LaunchDescription(
        [
            ExecuteProcess(
                cmd=[
                    "ros2",
                    "bag",
                    "play",
                    "--loop",
                    "path/to/bag.db3",
                ],
                output="screen",
            )
        ]
    )

The above answer is taken from here.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2022-11-12 03:56:20 -0500

Seen: 921 times

Last updated: Nov 13 '22