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 import ros.pkg.srs_knowledge.msg.*;
00057 import ros.pkg.geometry_msgs.msg.Pose2D;
00058 import org.srs.srs_knowledge.knowledge_engine.*;
00059 import com.hp.hpl.jena.rdf.model.*;
00060 import com.hp.hpl.jena.query.QueryExecutionFactory;
00061 import com.hp.hpl.jena.query.ResultSet;
00062 import com.hp.hpl.jena.query.QueryExecution;
00063 import com.hp.hpl.jena.query.QuerySolution;
00064
00065 import org.srs.srs_knowledge.task.Task;
00066
00067 public class MoveTask extends org.srs.srs_knowledge.task.Task
00068 {
00069 public MoveTask(String targetContent)
00070 {
00071 this.initTask(targetContent);
00072 setTaskType(TaskType.MOVETO_LOCATION);
00073 }
00074
00075 private void initTask(String targetContent) {
00076 acts = new ArrayList<ActionTuple>();
00077
00078 setTaskTarget(targetContent);
00079 System.out.println("TASK.JAVA: Created CurrentTask " + "move "
00080 + targetContent);
00081 constructTask();
00082 }
00083
00084 protected boolean constructTask() {
00085 return createSimpleMoveTaskNew();
00086 }
00087
00088 private boolean createSimpleMoveTaskNew() {
00089
00090 ActionTuple act = new ActionTuple();
00091
00092 CUAction ca = new CUAction();
00093 GenericAction genericAction = new GenericAction();
00094
00095 double x = 1;
00096 double y = 1;
00097 double theta = 0;
00098
00099 if (this.targetContent.charAt(0) == '['
00100 && this.targetContent.charAt(targetContent.length() - 1) == ']') {
00101 StringTokenizer st = new StringTokenizer(targetContent, " [],");
00102 if (st.countTokens() == 3) {
00103 try {
00104 x = Double.parseDouble(st.nextToken());
00105 y = Double.parseDouble(st.nextToken());
00106 theta = Double.parseDouble(st.nextToken());
00107 System.out.println(x + " " + y + " " + theta);
00108 } catch (Exception e) {
00109 System.out.println(e.getMessage());
00110 return false;
00111 }
00112 }
00113 } else {
00114 System.out.println("======MOVE COMMAND FORMAT=======");
00115
00116 String mapNameSpace = OntoQueryUtil.ObjectNameSpace;
00117 String prefix = "PREFIX srs: <http://www.srs-project.eu/ontologies/srs.owl#>\n"
00118 + "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"
00119 + "PREFIX mapNamespacePrefix: <" + mapNameSpace + ">\n";
00120 String queryString = "SELECT ?x ?y ?theta WHERE { "
00121 + "<" + mapNameSpace + targetContent + ">"
00122 + " srs:xCoordinate ?x . " + "<" + mapNameSpace + targetContent + ">" + " srs:yCoordinate ?y . "
00123 + "<" + mapNameSpace + targetContent + ">"
00124 + " srs:orientationTheta ?theta .}";
00125
00126
00127 if (KnowledgeEngine.ontoDB == null) {
00128 System.out.println("Ontology Database is NULL");
00129 return false;
00130 }
00131
00132 try {
00133 ArrayList<QuerySolution> rset = KnowledgeEngine.ontoDB.executeQueryRaw(prefix
00134 + queryString);
00135 if (rset.size() == 0) {
00136 System.out.println("ERROR: No move target found from database");
00137 return false;
00138 } else if (rset.size() == 1) {
00139 System.out
00140 .println("INFO: OK info retrieved from DB... ");
00141 QuerySolution qs = rset.get(0);
00142 x = qs.getLiteral("x").getFloat();
00143 y = qs.getLiteral("y").getFloat();
00144 theta = qs.getLiteral("theta").getFloat();
00145 System.out.println("x is " + x + ". y is " + y
00146 + ". theta is " + theta);
00147 } else {
00148 System.out.println("WARNING: Multiple options... ");
00149 QuerySolution qs = rset.get(0);
00150 x = qs.getLiteral("x").getFloat();
00151 y = qs.getLiteral("y").getFloat();
00152 theta = qs.getLiteral("theta").getFloat();
00153 System.out.println("x is " + x + ". y is " + y
00154 + ". theta is " + theta);
00155 }
00156 } catch (Exception e) {
00157 System.out.println("Exception --> " + e.getMessage());
00158 return false;
00159 }
00160 }
00161
00162
00163
00164
00165
00166
00167
00168 genericAction.jsonActionInfo = SRSJSONParser.encodeMoveAction("move", x, y, theta);
00169 ca.generic = genericAction;
00170 ca.actionType = "generic";
00171
00172 act.setCUAction(ca);
00173 act.setActionId(1);
00174 addNewActionTuple(act);
00175
00176
00177
00178 act = new ActionTuple();
00179
00180 ca = new CUAction();
00181 genericAction = new GenericAction();
00182
00183 genericAction.jsonActionInfo = SRSJSONParser.encodeCustomAction("finish_success", null);
00184
00185 ca.generic = genericAction;
00186 ca.actionType = "generic";
00187
00188 act.setActionName("finish_success");
00189 ca.status = 1;
00190
00191 act.setCUAction(ca);
00192 act.setActionId(2);
00193 act.setParentId(1);
00194 act.setCondition(true);
00195 addNewActionTuple(act);
00196
00197
00198
00199 act = new ActionTuple();
00200
00201 ca = new CUAction();
00202 genericAction = new GenericAction();
00203
00204 genericAction.jsonActionInfo = SRSJSONParser.encodeCustomAction("finish_fail", null);
00205 ca.generic = genericAction;
00206 ca.actionType = "generic";
00207
00208 act.setActionName("finish_fail");
00209
00210 ca.status = -1;
00211 act.setCUAction(ca);
00212 act.setActionId(3);
00213 act.setParentId(1);
00214 act.setCondition(false);
00215 addNewActionTuple(act);
00216
00217 System.out.println("number of actions: " + acts.size());
00218 return true;
00219 }
00220
00221
00222 public boolean replan(OntologyDB onto, OntoQueryUtil ontoQuery) {
00223 return false;
00224 }
00225 }