ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
This is what the roslaunch API example is missing:
- You need to import rospy if you are writing a ROS Node
- Declare a node using init_node()
- Keep python from exiting until this node is stopped using rospy.spin()
So this is the full contained simple usage example:
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()
2 | No.2 Revision |
This is what [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 is missing: and integrate it into a ROS node:
- You need import rospy to import rospy if you are writing 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 the full contained 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)