How to check if ROS-Master is running from rosjava
Im working on an android app which displays the camera image of the PR2. If the ROS-Master is running, everything works as expected. However, if the Master-Server is offline it tries to connect until android invokes OnPause(). Because Im shutting down the RosImageView-Node in OnPause, it crashes (I guess because the node never was active and cannot unregister from the Masterserver which is not online).
Of course I could just remove the image.shutdown() but I wonder if there is a clean way to check if the ROS-Master is online. Another thing Id like to know is if there is a way to specify a timeout for the connection attempt to the master server.
Im running the node like this:
NodeConfiguration nodeConfiguration = NodeConfiguration
.createDefault();
nodeConfiguration.setMasterUri(masterUri);
nodeConfiguration.setHost(InetAddressFactory.createNonLoopback()
.getHostAddress());
Log.i("roboremote", "ROS node started");
nodeRunner.run(image, nodeConfiguration);
and OnPause looks like this:
protected void onPause() {
super.onPause();
if (image != null) {
image.shutdown();
}
}