Ask Your Question
0

Proper way to shutdown /rosout (roscore).

asked 2017-06-05 07:45:07 -0500

JulianR gravatar image

Hello,

I have a project where i start gazebo and several other rosnodes.

I want to be able to shut them all down at some point. I have a node that waits for a certain message and then shuts all other nodes down following with a self shutdown call like:

system("rosnode kill NAME_OF_NODE"); // shutdown other nodes
ros::shutdown();                     // shutdown this node

This does work for everything except the /rosout node. The /rosout node always respawns if killed with rosnode kill. What I tried is to start a roscore in the starting programm before the other roslaunch files are executed, and then at the end, when all nodes finished cleanly I kill the roscore with kill all like:

system("roscore &");                 // start roscore 
...                                  // starting other nodes with roslaunch
system("killall roscore");           // kill roscore

But this does seem like a dirty way. Is there a better way to do this?

edit retag flag offensive close merge delete

Comments

3 Answers

Sort by ยป oldest newest most voted
1

answered 2017-06-07 13:58:01 -0500

Dale McConachie gravatar image

updated 2017-06-07 13:58:38 -0500

My solution is to use a launch file to start all the relevant nodes, with the "terminator" node set to required="true". When the terminator node exits, it will trigger all of the other nodes to close if they are using things like ros::ok() to determine if they should keep running. This only works when roscore has been started by this launch file.

edit flag offensive delete link more

Comments

This does work fine, There still is a red message informing about the Initiating of the shutdown, but I guess that is just how it is.

JulianR gravatar imageJulianR ( 2017-06-08 08:58:39 -0500 )edit
1

answered 2018-01-05 10:51:01 -0500

Cerin gravatar image

I manage ROS like this. I put all launch files inside one master "all.launch", and then I start that using the supervisor service, a simple tool for creating daemons. You can install this on Ubuntu with:

sudo apt-get install supervisor

I configure it by creating a file /etc/supervisor/conf.d/myrobot.conf which looks like:

[program:myrobot]
command=bash -c "source /usr/local/myrobot/src/ros/setup.bash; roslaunch myrobot all.launch"
directory=/usr/local/myrobot/src/ros
user=ubuntu
stdout_logfile=/var/log/supervisor-myrobot.log
stderr_logfile=/var/log/supervisor-myrobot.log
autostart=true
autorestart=true
startretries=3
priority=998
stopasgroup=true

Then, when the system boots, it launches all your ROS nodes automatically. If you want to cleanly stop it, you'd run:

sudo supervisorctl stop myrobot

Similarly, to start it, you'd run:

sudo supervisorctl start myrobot
edit flag offensive delete link more
0

answered 2017-06-07 14:05:00 -0500

Airuno2L gravatar image

Start everything from a launch file and everything will shutdown when you hit Ctrl+C on the terminal window that started the launch file.

edit flag offensive delete link more

Comments

You could also potentially emulate this by sending SIGINT to all relevant processes. The difference here is that sending SIGINT to the roslaunch process will pass the SIGINT along to all child processes, but will then escalate the signal all the way to SIGTERM if the process does close itself.

Dale McConachie gravatar imageDale McConachie ( 2017-06-07 14:12:04 -0500 )edit

I don't understand. I've never had something not close when I Ctrl+C a launch file, what would cause something to not close from that?

Airuno2L gravatar imageAiruno2L ( 2017-06-08 09:06:09 -0500 )edit
1

A couple of straightforward possibilities come to mind:

  • The program has installed its own SIGINT handler instead of using the one setup by ros::init
  • The program has a while(true){ do stuff without checking ros:ok() }

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

Dale McConachie gravatar imageDale McConachie ( 2017-06-08 10:39:16 -0500 )edit

Ok, thanks. I wonder if there is a way to make everything go straight to SIGKILL immediately after a Ctrl+C. I have a large launch file and some of the nodes are not ROS code so they take a while to close because it goes from SIGINT -> SIGTERM -> SIGKILL, which takes an annoying amount of time.

Airuno2L gravatar imageAiruno2L ( 2017-06-08 11:42:18 -0500 )edit

I'm not aware of any way to do that via roslaunch, but there could be one. If you have direct access to the code for these other nodes, you could install SIGINT handlers in them.

Dale McConachie gravatar imageDale McConachie ( 2017-06-08 12:42:14 -0500 )edit

This won't work if in a production environment where you've launched it from a daemon. You really should not be be running production code by manually launching it in a terminal.

Cerin gravatar imageCerin ( 2018-01-05 10:37:32 -0500 )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

2 followers

Stats

Asked: 2017-06-05 07:45:07 -0500

Seen: 4,640 times

Last updated: Jan 05 '18