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

Shutdown system (computer) with a ROS node

asked 2015-07-25 09:10:11 -0500

nwanda gravatar image

Is it possible to shutdown the system from within a ROS node?

In my case, I would like to shutdown the system once the battery level reaches a certain point, however I don't know how to do it or if it is even possible.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2015-07-26 01:21:36 -0500

gvdhoorn gravatar image

Just to add to the answer by @FooBar (ROS nodes are really just regular Linux programs that have chosen to communicate with each other via the ROS middleware): shutting down a Linux system with a desktop environment is often possible without using something like shutdown (which requires special privileges). See "Linux: Programatically shutdown or reboot computer from a user-level process" on stackoverflow for an example where they use ConsoleKit / DBus:

dbus-send \
    --system \
    ---dest=org.freedesktop.ConsoleKit \
    --type=method_call \
    --print-reply \
    --reply-timeout=2000 \
    /org/freedesktop/ConsoleKit/Manager \

You could invoke dbus-send using the system(..) function call in C/C++, or execute it from a Python node.

For Python there are better (more integrated) ways to interface with ConsoleKit / DBus (copied from "shutting down computer (linux) using python" on stackoverflow):

import dbus
sys_bus = dbus.SystemBus()
ck_srv = sys_bus.get_object('org.freedesktop.ConsoleKit',
ck_iface = dbus.Interface(ck_srv, 'org.freedesktop.ConsoleKit.Manager')
stop_method = ck_iface.get_dbus_method("Stop")

You could fi wrap the call to stop_method() (which is just an example) in a ROS service call (I wouldn't use parameters for this, it is clearly a synchronous action).

edit flag offensive delete link more


This raised another question: Is it possible to close all nodes from within another node? Since this system is controlling some motors I would like to send a command to stop the motors and close all nodes before shutting down.

nwanda gravatar image nwanda  ( 2015-09-28 14:46:42 -0500 )edit

As you already said: this is another question. Please open a new one for that.

gvdhoorn gravatar image gvdhoorn  ( 2015-09-29 01:57:55 -0500 )edit

You are totally right. I have already posted a different question. Thanks for the help!

nwanda gravatar image nwanda  ( 2015-09-29 10:18:22 -0500 )edit

answered 2015-07-25 10:18:41 -0500

NEngelhard gravatar image

updated 2015-07-25 10:22:54 -0500

A ROS-Node is a normal program that uses the ROS-Stuff. So you can (and have to) do whatever you want in your node, but there is nothing special in ROS that shuts down your computer.

You could create a service (the ubuntu-version, not a ROS-Service) that will be launched with root-rights (you'll need them to shutdown the system), that e.g. checks a ros-param. If you set this param, the service could shutdown the machine. Otherwise, you'd have to start you node with root-rights.

edit flag offensive delete link more

Question Tools



Asked: 2015-07-25 09:10:11 -0500

Seen: 2,073 times

Last updated: Jul 26 '15