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 import ros.pkg.geometry_msgs.msg.Pose;
00060 import org.srs.srs_knowledge.task.Task;
00061 import org.srs.srs_knowledge.knowledge_engine.*;
00062
00063 import com.hp.hpl.jena.rdf.model.*;
00064 import com.hp.hpl.jena.query.QueryExecutionFactory;
00065 import com.hp.hpl.jena.query.ResultSet;
00066 import com.hp.hpl.jena.query.QueryExecution;
00067 import com.hp.hpl.jena.query.QuerySolution;
00068 import com.hp.hpl.jena.ontology.Individual;
00069
00074 public class JustGraspActionUnit extends HighLevelActionUnit {
00075
00076 public JustGraspActionUnit(String objectClassName, int houseHoldId, String graspConfig) {
00077 init(objectClassName, houseHoldId, graspConfig, "");
00078 }
00079
00080 public JustGraspActionUnit(String objectClassName, int houseHoldId, String graspConfig, String workspace) {
00081 init(objectClassName, houseHoldId, graspConfig, workspace);
00082 }
00083
00084 private void init(String objectClassName, int houseHoldId, String graspConfig, String workspace) {
00085
00086 GenericAction graspAct = new GenericAction();
00087 objectClassName = (objectClassName == null) ? "" : objectClassName;
00088 ifObjectInfoSet = (objectClassName.trim().equals("")) ? false : true;
00089
00090 graspConfig = (graspConfig == null) ? "" : graspConfig;
00091 ifObjectInfoSet = true && ((graspConfig.trim().equals("")) ? false : true);
00092
00093 graspAct.jsonActionInfo = SRSJSONParser.encodeGraspAction("just_grasp", houseHoldId, objectClassName, workspace);
00094
00095 actionUnits.add(graspAct);
00096
00097
00098
00099
00100
00101 ifParametersSet = ifObjectInfoSet;
00102
00103 int size = actionUnits.size();
00104 nextActionMapIfFail = new int[size];
00105 nextActionMapIfSuccess = new int[size];
00106
00107
00108 for(int i = 0; i < size; i++) {
00109 nextActionMapIfFail[i] = COMPLETED_FAIL;
00110 nextActionMapIfSuccess[i] = COMPLETED_SUCCESS;
00111 }
00112 }
00113
00114 @Override
00115 public String getActionType() {
00116
00117 actionType = "MoveAndGrasp";
00118 return actionType;
00119 }
00120
00121 @Override
00122 public int getNextCUActionIndex(boolean statusLastStep) {
00123 if(currentActionInd == -1) {
00124 return 0;
00125 }
00126
00127 if ( currentActionInd >= 0 && currentActionInd < actionUnits.size() ) {
00128
00129 if(statusLastStep) {
00130
00131 System.out.println("NEXT ACTION IND (if Successful): " + nextActionMapIfSuccess[currentActionInd]);
00132 return nextActionMapIfSuccess[currentActionInd];
00133 }
00134 else {
00135 System.out.println("NEXT ACTION IND (if Failed): " + nextActionMapIfFail[currentActionInd]);
00136 return nextActionMapIfFail[currentActionInd];
00137 }
00138 }
00139 else {
00140 return INVALID_INDEX;
00141 }
00142 }
00143
00144 @Override
00145 public boolean setParameters(String action, String para, String reservedParam) {
00146 if(action.equals("grasp")) {
00147 setGraspInfo(para);
00148 }
00149 return ifParametersSet;
00150 }
00151
00152 private void setGraspInfo(String jsonInfo) {
00153
00154 GenericAction nga = new GenericAction();
00155 nga.jsonActionInfo = jsonInfo;
00156 actionUnits.set(1, nga);
00157 ifObjectInfoSet = true;
00158 ifParametersSet = ifObjectInfoSet;
00159
00160 }
00161
00162 @Override
00163 public boolean ifParametersSet() {
00164
00165 ifParametersSet = ifObjectInfoSet;
00166 return ifParametersSet;
00167 }
00168
00169
00170 private boolean ifObjectInfoSet = false;
00171 }