Go to the documentation of this file.00001 package org.ros.android.jskAndroidGui;
00002
00003 import java.util.ArrayList;
00004
00005 import org.ros.message.Time;
00006 import org.ros.namespace.GraphName;
00007 import org.ros.namespace.NameResolver;
00008 import org.ros.node.AbstractNodeMain;
00009 import org.ros.node.ConnectedNode;
00010 import org.ros.node.parameter.ParameterTree;
00011 import org.ros.node.topic.Publisher;
00012
00013 import android.util.Log;
00014
00015 import roseus.StringStamped;
00016 import std_msgs.Empty;
00017
00018 public class JskAndroidGuiNode extends AbstractNodeMain {
00019
00020 public boolean setupEnd = false;
00021 private Publisher<Empty> GetSpotPub;
00022 private Publisher<StringStamped> StartDemoPub, MoveToSpotPub, SelectPub,
00023 TweetPub, EmergencyStopPub;
00024 private ConnectedNode connectedNode;
00025 private ParameterTree parameterTree;
00026 private ArrayList<String> spots_list, tasks_list, image_list,
00027 camera_info_list, points_list;
00028
00029 @Override
00030 public GraphName getDefaultNodeName() {
00031 return null;
00032 }
00033
00034 public void tweetTask(String text) {
00035 StringStamped StrMsg_tweet = TweetPub.newMessage();
00036 StrMsg_tweet.getHeader().setStamp(
00037 Time.fromMillis(System.currentTimeMillis()));
00038 StrMsg_tweet.getHeader().setStamp(
00039 Time.fromMillis(System.currentTimeMillis()));
00040 StrMsg_tweet.setData(text);
00041 TweetPub.publish(StrMsg_tweet);
00042
00043 }
00044
00045 public void selectTask(String str) {
00046 StringStamped StrMsg_result = SelectPub.newMessage();
00047 StrMsg_result.getHeader().setStamp(
00048 Time.fromMillis(System.currentTimeMillis()));
00049 StrMsg_result.setData(str);
00050 SelectPub.publish(StrMsg_result);
00051 }
00052
00053 public void switchJoy() {
00054 StringStamped StrMsg_switchjoy = SelectPub.newMessage();
00055 StrMsg_switchjoy.getHeader().setStamp(
00056 Time.fromMillis(System.currentTimeMillis()));
00057 StrMsg_switchjoy.setData("Switchjoy");
00058 SelectPub.publish(StrMsg_switchjoy);
00059
00060 }
00061
00062 public void tasksSpinnerTask(String str) {
00063 StringStamped StrMsg = StartDemoPub.newMessage();
00064 StrMsg.getHeader()
00065 .setStamp(Time.fromMillis(System.currentTimeMillis()));
00066 StrMsg.setData(str);
00067 StartDemoPub.publish(StrMsg);
00068 }
00069
00070 public void spotsSpinnerTask(String str) {
00071 StringStamped StrMsg = MoveToSpotPub.newMessage();
00072 StrMsg.getHeader()
00073 .setStamp(Time.fromMillis(System.currentTimeMillis()));
00074 StrMsg.setData(str);
00075 MoveToSpotPub.publish(StrMsg);
00076 }
00077
00078 public void getSpot() {
00079 Empty EmptyMsg = GetSpotPub.newMessage();
00080 GetSpotPub.publish(EmptyMsg);
00081 }
00082
00083 public void stopJoint() {
00084 StringStamped StrMsg_stopjoint = EmergencyStopPub.newMessage();
00085 StrMsg_stopjoint.getHeader().setStamp(
00086 Time.fromMillis(System.currentTimeMillis()));
00087 StrMsg_stopjoint.setData("StopJoint");
00088 EmergencyStopPub.publish(StrMsg_stopjoint);
00089 }
00090
00091 public void stopNavigation() {
00092 StringStamped StrMsg_stopnavigation = EmergencyStopPub.newMessage();
00093 StrMsg_stopnavigation.getHeader().setStamp(
00094 Time.fromMillis(System.currentTimeMillis()));
00095 StrMsg_stopnavigation.setData("StopNavigation");
00096 EmergencyStopPub.publish(StrMsg_stopnavigation);
00097 }
00098
00099 public void getSpotsParam() {
00100 String defaultSpot_ns = "/jsk_spots";
00101 String targetSpot = "/eng2/7f";
00102 GraphName gspot = GraphName.of(defaultSpot_ns + targetSpot);
00103 NameResolver resolver_spot = connectedNode.getResolver()
00104 .newChild(gspot);
00105 Object[] spots_param_list = parameterTree.getList(
00106 resolver_spot.resolve("spots")).toArray();
00107 Log.i("JskAndroidGui:GetSpotsParam", "spots length = "
00108 + spots_param_list.length);
00109 spots_list.clear();
00110 spots_list.add("spots");
00111 for (int i = 0; i < spots_param_list.length; i++) {
00112 spots_list.add((String) spots_param_list[i]);
00113 Log.w("JskAndroidGui:GetSpotsParam", "lists:" + i + " "
00114 + spots_param_list[i]);
00115 }
00116 }
00117
00118 public void getTasksParam() {
00119 String defaultTask_ns = "/Tablet";
00120 GraphName guser = GraphName.of(defaultTask_ns);
00121 NameResolver resolver_user = connectedNode.getResolver()
00122 .newChild(guser);
00123 Object[] user_list = parameterTree.getList(
00124 resolver_user.resolve("UserList")).toArray();
00125 tasks_list.clear();
00126 tasks_list.add("tasks");
00127 for (int i = 0; i < user_list.length; i++) {
00128 GraphName gtask = GraphName.of(defaultTask_ns + "/User");
00129 NameResolver resolver_task = connectedNode.getResolver().newChild(
00130 gtask);
00131 Object[] task_param_list = parameterTree.getList(
00132 resolver_task.resolve((String) user_list[i])).toArray();
00133 Log.i("JskAndroidGui:GetTasksParam", "task length = "
00134 + task_param_list.length);
00135 for (int j = 0; j < task_param_list.length; j++) {
00136 Log.i("JskAndroidGui:GetTasksParam", "lists: " + i + " " + j
00137 + " /Tablet/" + (String) user_list[i] + "/"
00138 + (String) task_param_list[j]);
00139 tasks_list.add("/Tablet/" + (String) user_list[i] + "/"
00140 + (String) task_param_list[j]);
00141 }
00142 }
00143 }
00144
00145 public void getCameraParam() {
00146 String defaultCamera_ns = "/jsk_cameras";
00147 GraphName gcamera = GraphName.of(defaultCamera_ns);
00148 NameResolver resolver_camera = connectedNode.getResolver().newChild(
00149 gcamera);
00150 Object[] camera_names_list = parameterTree.getList(
00151 resolver_camera.resolve("CameraList")).toArray();
00152 Log.i("JskAndroidGui:GetCameraParam", "camera length = "
00153 + camera_names_list.length);
00154 image_list.clear();
00155 image_list.add("cameras");
00156 for (int i = 0; i < camera_names_list.length; i++) {
00157 Object[] camera_param_list = parameterTree.getList(
00158 resolver_camera.resolve((String) camera_names_list[i]))
00159 .toArray();
00160
00161
00162
00163
00164 image_list.add((String) camera_param_list[0]);
00165 camera_info_list.add((String) camera_param_list[1]);
00166 Log.w("JskAndroidGui:GetCameraParam", "lists:" + i + " "
00167 + camera_param_list[0] + camera_param_list[1]);
00168 }
00169 }
00170
00171 public void getPointsParam() {
00172 String defaultPoints_ns = "/jsk_points";
00173 GraphName gparam = GraphName.of(defaultPoints_ns);
00174 NameResolver resolver_point = connectedNode.getResolver().newChild(
00175 gparam);
00176 Object[] points_param_list = parameterTree.getList(
00177 resolver_point.resolve("points")).toArray();
00178 Log.i("JskAndroidGui:GetPointsParam", "point length = "
00179 + points_param_list.length);
00180 points_list.clear();
00181 points_list.add("points");
00182 for (int i = 0; i < points_param_list.length; i++) {
00183
00184
00185
00186 points_list.add((String) points_param_list[i]);
00187 Log.w("JskAndroidGui:GetPointsParam", "lists:" + i + " "
00188 + points_param_list[i]);
00189 }
00190 }
00191
00192 public ArrayList<String> getPointsList() {
00193 return points_list;
00194 }
00195
00196 public ArrayList<String> getTasksList() {
00197 return tasks_list;
00198 }
00199
00200 public ArrayList<String> getImageList() {
00201 return image_list;
00202 }
00203
00204 public ArrayList<String> getCameraInfoList() {
00205 return camera_info_list;
00206 }
00207
00208 public ArrayList<String> getSpotsList() {
00209 return spots_list;
00210 }
00211
00212 public ParameterTree getParameterTree() {
00213 return parameterTree;
00214 }
00215
00216 public void onStart(final ConnectedNode connectedNode) {
00217 this.connectedNode = connectedNode;
00218
00219 spots_list = new ArrayList<String>();
00220 tasks_list = new ArrayList<String>();
00221 image_list = new ArrayList<String>();
00222 camera_info_list = new ArrayList<String>();
00223 points_list = new ArrayList<String>();
00224
00225 parameterTree = connectedNode.getParameterTree();
00226
00227 GetSpotPub = connectedNode.newPublisher("/Tablet/GetSpot",
00228 std_msgs.Empty._TYPE);
00229 StartDemoPub = connectedNode.newPublisher("/Tablet/StartDemo",
00230 roseus.StringStamped._TYPE);
00231 MoveToSpotPub = connectedNode.newPublisher("/Tablet/MoveToSpot",
00232 roseus.StringStamped._TYPE);
00233 EmergencyStopPub = connectedNode.newPublisher(
00234 "/Tablet/EmergencyCommand", roseus.StringStamped._TYPE);
00235 SelectPub = connectedNode.newPublisher("/Tablet/Select",
00236 roseus.StringStamped._TYPE);
00237 TweetPub = connectedNode.newPublisher("/pr2twit_from_tablet",
00238 roseus.StringStamped._TYPE);
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248 getParamLoop();
00249
00250 setupEnd = true;
00251 }
00252
00253 public void getParamLoop() {
00254 try {
00255 getSpotsParam();
00256 getCameraParam();
00257 getTasksParam();
00258 getPointsParam();
00259 } catch (Exception ex) {
00260 Log.e("JskAndroidGui", "Param cast error: " + ex.toString());
00261 try {
00262 Thread.sleep(1000);
00263 } catch (Exception e) {
00264 e.printStackTrace();
00265 }
00266 getParamLoop();
00267 }
00268
00269 }
00270
00271 }