I am having some concerns with using Python roslaunch API.
I am using Ubuntu with ROS Noetic. In my project, there is a need to call a roslaunch process iteratively in a Python loop. I found that it gets slower and slower everytime I called the roslaunch process (there seems to be a long wait time).
The code I used is like this:
for i in range(0, N_ITERATIONS):
# some codes here
# roslaunch calling part
with open(SHUTDOWN_SIGNAL_FILE, 'w') as f:
f.write('shutdown')
sim_launch = launch_sim_nodes()
# Wait for a while to let nodes initialize
while check_shutdown_signal() is True:
time.sleep(1.0)
# please keep a roscore running !!!! otherwise may hang
print("Shutting down Simulation launch...")
time.sleep(1.0)
sim_launch.shutdown() # Terminate the roslaunch process
The idea of roslaunch calling function is borrowed from the roswiki page (https://wiki.ros.org/roslaunch/API%20Usage):
def launch_sim_nodes():
“””
Launches the ROS nodes using the specified launch file.
“””
uuid = roslaunch.rlutil.get_or_generate_uuid(None, False)
roslaunch.configure_logging(uuid)
cli_args = ['Simulation', 'robot_simulations.launch']
roslaunch_file = roslaunch.rlutil.resolve_launch_arguments(cli_args)[0]
roslaunch_args = cli_args[2:]
launch = roslaunch.parent.ROSLaunchParent(uuid, [(roslaunch_file, roslaunch_args)])
launch.start()
return launch
Does anyone know why the calling of roslaunch (i.e. the time waited for the ros processed to be executed) is getting slower and slower overtime? I hope to have some work-around to make the whole thing much faster otherwise this will take more than a few hours to run such a iterations 🙁
Please let me know if you have any knowledge in dealing with this situation! Appreciate it!
Tried to open the roscore all the time … but it does not seems to relate to this problem. Cuz every roslaunch process has a unique pid and it is called and shutdown from time to time.
Ran Zheng is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.