00001 /* 00002 * Copyright (C) 2012 Google Inc. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 00005 * use this file except in compliance with the License. You may obtain a copy of 00006 * the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 00012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 00013 * License for the specific language governing permissions and limitations under 00014 * the License. 00015 */ 00016 00017 package org.ros.android.android_tutorial_map_viewer; 00018 00019 import org.ros.namespace.GraphName; 00020 import org.ros.node.AbstractNodeMain; 00021 import org.ros.node.ConnectedNode; 00022 import org.ros.node.Node; 00023 import org.ros.node.topic.Publisher; 00024 00028 public class SystemCommands extends AbstractNodeMain { 00029 00030 private Publisher<std_msgs.String> publisher; 00031 00032 @Override 00033 public GraphName getDefaultNodeName() { 00034 return GraphName.of("system_commands"); 00035 } 00036 00037 @Override 00038 public void onStart(ConnectedNode connectedNode) { 00039 publisher = connectedNode.newPublisher("syscommand", std_msgs.String._TYPE); 00040 } 00041 00042 public void reset() { 00043 publish("reset"); 00044 } 00045 00046 public void saveGeotiff() { 00047 publish("savegeotiff"); 00048 } 00049 00050 private void publish(String command) { 00051 if (publisher != null) { 00052 std_msgs.String message = publisher.newMessage(); 00053 message.setData(command); 00054 publisher.publish(message); 00055 } 00056 } 00057 00058 @Override 00059 public void onShutdown(Node arg0) { 00060 publisher = null; 00061 } 00062 }