Ask Your Question
0

Is it possible to get the number of all existing ROS_Nodes or to shut down all Nodes except one?

asked 2018-04-16 03:14:00 -0600

bambucha gravatar image

I'm trying to shut down all Nodes except 1 within a C++ program. Therefore I want to count the number of ROS_Nodes and kill n-2 nodes. ( My_Node and roscore shall still exist). Or is there any other way to do so?

Thanks for your Help

edit retag flag offensive close merge delete

Comments

To avoid an xy-problem, it might be good if you could clarify why you want to do this. It might not be necessary.

gvdhoorn gravatar image gvdhoorn  ( 2018-04-16 04:06:22 -0600 )edit

I need it, because I have to restart Gazebo with another enviroment. But the Linux-Computer is remote controlled to this. Therefore I have to shut down every ROS_Node, except the one which handles the remote.

bambucha gravatar image bambucha  ( 2018-04-16 04:17:32 -0600 )edit

If you can manage the state of "your node", then would deployment using Docker perhaps be an option? Reusing roscore instances is not necessarily always very stable (left over parameters, etc).

gvdhoorn gravatar image gvdhoorn  ( 2018-04-16 04:33:05 -0600 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2018-04-16 04:05:44 -0600

gvdhoorn gravatar image

updated 2018-04-16 04:07:08 -0600

You could use a combination of the Master API and Slave API to do what you want (first retrieve all registered nodes, iterate over them, compare their names and request the ones you don't want/need any longer to shutdown).

See #q271776 (among others) for a question that deals with something similar.

Therefore I want to count the number of ROS_Nodes and kill n-2 nodes. ( My_Node and roscore shall still exist).

Note: I would recommend to do this by name, not "by number". That seems very brittle.

Also: roscore is not a node.

edit flag offensive delete link more

Comments

sorry for the mistake with the roscore and node! And thanks for the post #q271776, I saw this before. My Problem is to understand this. Because I have never used Python before. Thanks :)

bambucha gravatar image bambucha  ( 2018-04-16 04:21:28 -0600 )edit

Well, it's mostly XML-RPC, so you could do the same thing using C++. It's just that the libraries that are already there are in Python.

gvdhoorn gravatar image gvdhoorn  ( 2018-04-16 09:35:51 -0600 )edit
1

Could I ask you to mark the question as answered if/when you feel it has been answered? Thanks.

gvdhoorn gravatar image gvdhoorn  ( 2018-04-16 09:36:09 -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

Stats

Asked: 2018-04-16 03:14:00 -0600

Seen: 88 times

Last updated: Apr 16 '18