Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 package org.srs.srs_knowledge.task;
00052
00053 import java.io.*;
00054 import java.util.StringTokenizer;
00055 import java.util.ArrayList;
00056
00057 import ros.pkg.srs_knowledge.msg.*;
00058 import ros.pkg.geometry_msgs.msg.Pose2D;
00059
00060 import org.srs.srs_knowledge.task.Task;
00061 import org.srs.srs_knowledge.knowledge_engine.*;
00062
00063 import org.json.simple.JSONArray;
00064 import org.json.simple.JSONObject;
00065 import org.json.simple.JSONValue;
00066 import org.json.simple.parser.ParseException;
00067 import org.json.simple.parser.JSONParser;
00068
00073 public class MoveAndDetectionActionUnit extends HighLevelActionUnit {
00074
00075 public MoveAndDetectionActionUnit(ArrayList<Pose2D> positions, String objectClassName, int houseHoldId) {
00076 init(positions, objectClassName, houseHoldId, "");
00077 }
00078
00079
00080 public MoveAndDetectionActionUnit(ArrayList<Pose2D> positions, String objectClassName, int houseHoldId, String workspace) {
00081 init(positions, objectClassName, houseHoldId, workspace);
00082 }
00083
00084 private void init(ArrayList<Pose2D> positions, String objectClassName, int houseHoldId, String workspace) {
00085 for(Pose2D position:positions) {
00086 GenericAction ga = new GenericAction();
00087
00088 ga.jsonActionInfo = SRSJSONParser.encodeMoveAction("move", position.x, position.y, position.theta);
00089 actionUnits.add(ga);
00090
00091 GenericAction detAct = new GenericAction();
00092 detAct.jsonActionInfo = SRSJSONParser.encodeDetectAction("detect", houseHoldId, objectClassName, workspace);
00093 actionUnits.add(detAct);
00094 }
00095
00096
00097 ifParametersSet = true;
00098
00099 int size = actionUnits.size();
00100 nextActionMapIfFail = new int[size];
00101 nextActionMapIfSuccess = new int[size];
00102
00103 for(int i = 0; i < size; i++) {
00104 JSONObject tempAct = SRSJSONParser.decodeJsonActionInfo(actionUnits.get(i).jsonActionInfo);
00105 if(tempAct.get("action").equals("move")) {
00106 nextActionMapIfSuccess[i] = i + 1;
00107 nextActionMapIfFail[i] = i + 2;
00108 }
00109 else if(tempAct.get("action").equals("detect")) {
00110 nextActionMapIfSuccess[i] = COMPLETED_SUCCESS;
00111 nextActionMapIfFail[i] = i + 1;
00112 }
00113 if(nextActionMapIfFail[i] >= size) {
00114
00115 nextActionMapIfFail[i] = COMPLETED_FAIL;
00116 }
00117 }
00118 }
00119
00120 @Override
00121 public String getActionType() {
00122 actionType = "MoveAndDetection";
00123 return actionType;
00124 }
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134 public boolean ifParametersSet() {
00135 return ifParametersSet;
00136 }
00137
00138 }