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

roslaunch API

asked 2021-03-24 02:25:27 -0500

Aviad gravatar image

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

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-03-24 03:41:50 -0500

Roberto Z. gravatar image

updated 2021-03-25 07:42:12 -0500

[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)
edit flag offensive delete link more

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.

gvdhoorn gravatar image gvdhoorn  ( 2021-03-24 06:08:16 -0500 )edit

Thanks @gvdhoorn, I edited my original answer.

Roberto Z. gravatar image Roberto Z.  ( 2021-03-25 07:43:04 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2021-03-24 02:25:27 -0500

Seen: 455 times

Last updated: Mar 25 '21