Ask Your Question

Start or stop the ROS node in another node

asked 2015-12-25 11:13:30 -0600

tanghz gravatar image

updated 2015-12-25 11:19:12 -0600

Sorry to disturb everyone. But I really have a problem and I don't know how to solve it.

I want to start or stop some ros nodes remotely. As I want to control a robot by my Android mobile phone through WIFI, and the robot maybe has no keyboard or displayer, so I cannot start the ros node by input "rosrun" or "roslaunch" in the terminal, and I want to use the smart phone to control some ros nodes, like start or stop them. For example, I want to let the robot to draw a map by GMapping node, so I press a button on my smart phone, and the Gmapping node run, then I press another button on my smart phone, the Gmapping node stops. And I have writed a node that could communicate with the smart phone.

I have been looking for the methods for a long time, and I cannot find a perfect method. I find this method link text that proposed by DimitriProsser is really good, however he only tell us the way to start.

So I want to know, are there other methods to achieve my goal? Thank you a lot!

edit retag flag offensive close merge delete

4 Answers

Sort by ยป oldest newest most voted

answered 2015-12-25 12:26:05 -0600

updated 2015-12-25 13:26:03 -0600

I think you can do it using launch files, I never used it in the end, but it works for starting and stopping nodes programmatically (as long as it is one you previously launched programmatically)

edit flag offensive delete link more


Thank you very much, I will try it. It would be better if there's a C++ tutorial. I think maybe I have to learn the Python programming language.

tanghz gravatar imagetanghz ( 2015-12-25 14:02:36 -0600 )edit

Thank you very much, now I solved it, I have answered my own question. Thank you very much.

tanghz gravatar imagetanghz ( 2015-12-27 00:42:06 -0600 )edit

answered 2015-12-27 00:40:26 -0600

tanghz gravatar image

updated 2015-12-27 06:16:22 -0600

For example, there is a launch file named "rplidar.launch" and located in the "rplidar_ros" package, after I start the launch file, the ros node name is "rplidarNode", then I start and stop it in the ROS C++ code:

system("roslaunch rplidar_ros rplidar.launch");  //start

system("rosnode kill rplidarNode");              //stop

By the way, remember to new a thread, or the code would block and you cannot stop the node.

edit flag offensive delete link more


what do you mean"new a thread"? I mean, the code blocks and how to solve the block?

sonictl gravatar imagesonictl ( 2016-12-07 06:19:17 -0600 )edit

answered 2019-04-14 03:22:36 -0600

YYGX gravatar image

Well, I know that my answer may be later, but I hope to help more people. One solution is using ssh. You can use the JCraft to do the ssh connection. JCraft can help you to make the command typed on your phone works well on the server(here is the computer on the robot). To do that, you can refer to the official example: in . If you run the program, you can type command via If you just want to make one command(for instance, roscore) work, you can change the official program like this:

InputStream stream = new ByteArrayInputStream("roscore\n".getBytes(StandardCharsets.UTF_8));

Then, you will find that roscore works once you start the program.

edit flag offensive delete link more

answered 2019-01-22 16:31:43 -0600

AutoCar gravatar image

How do you connect your smart phone to the robot?

edit flag offensive delete link more


I've done it using rosbridge and a webbrowser. I'm sure there are several ways.

But the mods are going to give you a hard time for asking a question using an answer on an unrelated topic. : (

billy gravatar imagebilly ( 2019-01-22 21:41:28 -0600 )edit

@AutoCar please don't use an answer to ask a question. This isn't a forum. You can ask a new question and reference this question instead.

jayess gravatar imagejayess ( 2019-01-23 00:57:18 -0600 )edit

Your Answer

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

Add Answer

Question Tools

1 follower


Asked: 2015-12-25 11:13:30 -0600

Seen: 11,598 times

Last updated: Apr 14