roslaunch API
Hello friends,
I am trying to launch a launch file by the roslaunch api. For any reason when I run the simpe example the node was opened and was killed immediately. This is the code:
import roslaunch
package = 'rqt_gui'
executable = 'rqt_gui'
node = roslaunch.core.Node(package, executable)
launch = roslaunch.scriptapi.ROSLaunch()
launch.start()
process = launch.launch(node)
I don't find any post about this issue. It is happens also in the other examples.
Thanks, Aviad
Asked by Aviad on 2021-03-24 02:25:27 UTC
Answers
[EDITED ANSWER]
The thing is, when you run the example script, it will quit immediately. Also closing any process immediately after opening it.
To keep the process running you can modify roslaunch API example and integrate it into a ROS node:
- import rospy to write a ROS Node
- Declare a node using init_node()
- Keep python from exiting until this node is stopped using rospy.spin()
So this is a simple usage example integrated into a ROS node :
import rospy
import roslaunch
rospy.init_node('roslaunch_api_test')
package = 'rqt_gui'
executable = 'rqt_gui'
node = roslaunch.core.Node(package, executable)
launch = roslaunch.scriptapi.ROSLaunch()
launch.start()
process = launch.launch(node)
rospy.spin()
If you don't want to create a ROS node, find a different way to keep the process running, for instance:
import roslaunch
import time
package = 'rqt_gui'
executable = 'rqt_gui'
node = roslaunch.core.Node(package, executable)
launch = roslaunch.scriptapi.ROSLaunch()
launch.start()
process = launch.launch(node)
# keep process open for 2 seconds, then quit
time.sleep(2.0)
Asked by Roberto Z. on 2021-03-24 03:41:50 UTC
Comments
Pedantic perhaps, but: the example is to show the usage of the roslaunch
API. Not how to integrate it into a ROS node.
So the rospy.init_node(..)
and rospy
import are only needed if that (ie: starting a .launch
file from a node) is your goal.
Asked by gvdhoorn on 2021-03-24 06:08:16 UTC
Thanks @gvdhoorn, I edited my original answer.
Asked by Roberto Z. on 2021-03-25 07:43:04 UTC
Comments