How to handle node shutdown in java code?

asked 2016-04-01 14:05:27 -0600

PerceptualRobots gravatar image

I am trying to work out how to gracefully shutdown my node, without ctrl C. I assume that "rosnode kill" should close down the node, but it doesn't. I have the code below in my node but it is never called. Though when I run "rosnode kill" I do see in the log this "Shutdown requested by /rosnode with message "user request"".

So how should shutdown be handled in the code?

public class PCTControl extends AbstractNodeMain {
...
@Override
public void onShutdown(Node node) {
    final Log log = node.getLog();
    log.info("onShutdown called.");
    super.onShutdown(node);
  }
}
edit retag flag offensive close merge delete