Robotics StackExchange | Archived questions

[ROS 1 Noetic] Reuse an existing roslaunch server with roslaunch.scriptapi.ROSLaunch()

Hi,

I have a small service written in Python that launches a rosbag play every time a request comes to it. It's running on ROS1 Noetic on Ubuntu 18.04.

Currently, I create a ROSLaunch object when initiating the node;

# Init ROS launch variables
self.launch = roslaunch.scriptapi.ROSLaunch()
self.launch.start()

And launch the rosbag play on its callback like this:

# Set up launch command
rosbag_args = "-l -s " + str(start) + " -u " + str(duration) + " " + " ".join(bags) 
remap_args = [["/image_publisher/image_raw/compressed", "/replay/image_publisher/image_raw/compressed"], ["/vcd", "/replay/vcd"]]
rosbag_node = roslaunch.core.Node('rosbag', 'play', name='rosbag_replayer', args=rosbag_args, remap_args = remap_args)

# Launch replayer node
self.rosbag_play_thread = launch.launch(rosbag_node)

The code works fine, but since I use a roslaunch file to launch the servce (as well as several other nodes), I noticed I'm creating two roslaunch servers: One when calling roslaunch on the command line and other when the service initiates.

Is there a way to reuse an existing roslaunch server when calling roslaunch.scriptapi.ROSLaunch()?

I don't know if having two separate roslaunch servers is really that impactful resource-wise, but I'm just curious.

Kind regards and thank you!

Asked by fjiriarte on 2023-07-04 05:07:07 UTC

Comments

Answers