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

Start or stop the ROS node in another node

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

tanghz gravatar image

updated 2020-09-19 21:01:48 -0600

lucasw gravatar image

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

Comments

How do you connect your smart phone to the robot?

AutoCar gravatar image AutoCar  ( 2019-01-22 16:31:43 -0600 )edit

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 image billy  ( 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 image jayess  ( 2019-01-23 00:57:18 -0600 )edit

4 Answers

Sort by ยป oldest newest most voted
2

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)

http://answers.ros.org/question/20315...

edit flag offensive delete link more

Comments

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 image tanghz  ( 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 image tanghz  ( 2015-12-27 00:42:06 -0600 )edit
2

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

Comments

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

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

answered 2020-10-06 04:48:21 -0600

Rufus gravatar image

From https://www.theconstructsim.com/launc...

import roslaunch
node = roslaunch.core.Node("other_pkg", "pkg_executable")
launch = roslaunch.scriptapi.ROSLaunch()
launch.start()
script = launch.launch(node)

Couldn't find the cpp equivalent way though

edit flag offensive delete link more
0

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: Shell.java in http://www.jcraft.com/jsch/examples/S... . If you run the Shell.java program, you can type command via System.in. 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));
channel.setInputStream(stream);

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

edit flag offensive delete link more

Question Tools

2 followers

Stats

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

Seen: 22,779 times

Last updated: Oct 06 '20