Ask Your Question
4

Start a node from python code - rospy equivalence rosrun - rosgui qt

asked 2012-08-20 01:54:39 -0600

clotz gravatar image

updated 2018-03-21 12:08:43 -0600

130s gravatar image

Hallo,

I'm writing a plugin for my rosgui in python. At the moment I'm trying to write an "pressed-button" action which starts a rosnode. I's there a python-command equivalent to "rosrun pkg node" or the launch-command "<node name="..." pkg="..." type="...">?

Unfortunately I couldn't find something in the documentations yet.

Thanks for Help.

edit retag flag offensive close merge delete

4 Answers

Sort by » oldest newest most voted
4

answered 2012-09-08 16:28:23 -0600

jbohren gravatar image

As of now the internal roslaunch python API is unstable, but that doesn't mean you can't use it, it just means that there's no guarantee your code is going to continue to work.

Stu Glaser wrote a simple qt-based roslaunch frontend which can be found here: https://kforge.ros.org/rxlaunch/hg/file/9456528dd14c/rxlaunch.py and this gives a simple example of how to do what roslaunch does via Python. (it also has some code taken from roslaunch itself)

If you want to start a node from Python, and want to be able to expect that it will continue to work, you could call out to rosrun with the Python subprocess module

Also, "rosrun" is just a bash script.

edit flag offensive delete link more

Comments

1

Any updates on this yet?

2ROS0 gravatar image2ROS0 ( 2017-05-05 15:28:44 -0600 )edit
0

answered 2020-02-17 12:29:11 -0600

machinekoder gravatar image

Just use Popen:

import shlex
from psutil import Popen
# start
node_process = Popen(
    shlex.split('rosrun foo bar')
)
# stop
node_process.terminate()
edit flag offensive delete link more
0

answered 2016-03-12 18:37:29 -0600

You can use the roslaunch api for python (ref):

import roslaunch

package = 'rqt_gui' executable = 'rqt_gui' node = roslaunch.core.Node(package, executable)

launch = roslaunch.scriptapi.ROSLaunch() launch.start()

process = launch.launch(node) print process.is_alive() process.stop()

edit flag offensive delete link more
0

answered 2012-09-08 14:31:54 -0600

130s gravatar image

Not entirely sure what you mean but I assume you've already checked rospy.init_node?

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-08-20 01:54:39 -0600

Seen: 7,467 times

Last updated: Feb 17