$search
00001 /**************************************************************** 00002 * 00003 * Copyright (c) 2011, 2012 00004 * 00005 * School of Engineering, Cardiff University, UK 00006 * 00007 * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00008 * 00009 * Project name: srs EU FP7 (www.srs-project.eu) 00010 * ROS stack name: srs 00011 * ROS package name: srs_knowledge 00012 * Description: 00013 * 00014 * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00015 * 00016 * @author Ze Ji, email: jiz1@cf.ac.uk 00017 * 00018 * Date of creation: Oct 2011: 00019 * ToDo: 00020 * 00021 * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00022 * 00023 * Redistribution and use in source and binary forms, with or without 00024 * modification, are permitted provided that the following conditions are met: 00025 * 00026 * * Redistributions of source code must retain the above copyright 00027 * notice, this list of conditions and the following disclaimer. 00028 * * Redistributions in binary form must reproduce the above copyright 00029 * notice, this list of conditions and the following disclaimer in the 00030 * documentation and/or other materials provided with the distribution. 00031 * * Neither the name of the school of Engineering, Cardiff University nor 00032 * the names of its contributors may be used to endorse or promote products 00033 * derived from this software without specific prior written permission. 00034 * 00035 * This program is free software: you can redistribute it and/or modify 00036 * it under the terms of the GNU Lesser General Public License LGPL as 00037 * published by the Free Software Foundation, either version 3 of the 00038 * License, or (at your option) any later version. 00039 * 00040 * This program is distributed in the hope that it will be useful, 00041 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00042 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00043 * GNU Lesser General Public License LGPL for more details. 00044 * 00045 * You should have received a copy of the GNU Lesser General Public 00046 * License LGPL along with this program. 00047 * If not, see <http://www.gnu.org/licenses/>. 00048 * 00049 ****************************************************************/ 00050 00051 package org.srs.srs_knowledge.task; 00052 00053 import java.io.*; 00054 import java.util.StringTokenizer; 00055 //import org.apache.commons.logging.Log; 00056 import java.util.ArrayList; 00057 import ros.pkg.srs_knowledge.msg.*; 00058 import ros.pkg.geometry_msgs.msg.Pose2D; 00059 import org.srs.srs_knowledge.knowledge_engine.*; 00060 import com.hp.hpl.jena.rdf.model.*; 00061 import com.hp.hpl.jena.query.QueryExecutionFactory; 00062 import com.hp.hpl.jena.query.ResultSet; 00063 import com.hp.hpl.jena.query.QueryExecution; 00064 import com.hp.hpl.jena.query.QuerySolution; 00065 00066 import org.srs.srs_knowledge.task.Task; 00067 00068 public class ChargingTask extends org.srs.srs_knowledge.task.Task 00069 { 00070 public ChargingTask() 00071 { 00072 this.initTask(); 00073 setTaskType(TaskType.MOVETO_LOCATION); 00074 } 00075 00076 private void initTask() { 00077 acts = new ArrayList<ActionTuple>(); 00078 00079 //setTaskTarget(targetContent); 00080 System.out.println("TASK.JAVA: Created CurrentTask " + "Charging "); 00081 constructTask(); 00082 } 00083 00084 protected boolean constructTask() { 00085 return createSimpleChargingTask(); 00086 } 00087 00088 private boolean createSimpleChargingTask() { 00089 // boolean addNewActionTuple(ActionTuple act) 00090 ActionTuple act = new ActionTuple(); 00091 00092 CUAction ca = new CUAction(); 00093 GenericAction genericAction = new GenericAction(); 00094 ca.actionType = "generic"; 00095 00096 double x = 0; 00097 double y = 0; 00098 double theta = 0; 00099 00100 targetContent = "ChargingStation0"; 00101 setTaskTarget(targetContent); 00102 /* 00103 String prefix = "PREFIX srs: <http://www.srs-project.eu/ontologies/srs.owl#>\n" 00104 + "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" 00105 + "PREFIX ipa-kitchen-map: <http://www.srs-project.eu/ontologies/ipa-kitchen-map.owl#>\n"; 00106 String queryString = "SELECT ?x ?y ?theta WHERE { " 00107 + "ipa-kitchen-map:" + targetContent 00108 + " srs:xCoordinate ?x . " + "ipa-kitchen-map:" 00109 + targetContent + " srs:yCoordinate ?y . " 00110 + "ipa-kitchen-map:" + targetContent 00111 + " srs:orientationTheta ?theta .}"; 00112 */ 00113 String prefix = "PREFIX srs: <http://www.srs-project.eu/ontologies/srs.owl#>\n" 00114 + "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" 00115 + "PREFIX map: <" + OntoQueryUtil.ObjectNameSpace.trim() + ">\n"; 00116 00117 String queryString = "SELECT ?x ?y ?theta WHERE { " 00118 + "map:" + targetContent + " srs:xCoordinate ?x . " 00119 + "map:" + targetContent + " srs:yCoordinate ?y . " 00120 + "map:" + targetContent + " srs:orientationTheta ?theta .}"; 00121 if (KnowledgeEngine.ontoDB == null) { 00122 System.out.println("Ontology Database is NULL"); 00123 return false; 00124 } 00125 00126 try { 00127 ArrayList<QuerySolution> rset = KnowledgeEngine.ontoDB.executeQueryRaw(prefix + queryString); 00128 if (rset.size() == 0) { 00129 System.out.println("ERROR: No move target found from database"); 00130 return false; 00131 } else if (rset.size() == 1) { 00132 System.out 00133 .println("INFO: OK info retrieved from DB... "); 00134 QuerySolution qs = rset.get(0); 00135 x = qs.getLiteral("x").getFloat(); 00136 y = qs.getLiteral("y").getFloat(); 00137 theta = qs.getLiteral("theta").getFloat(); 00138 System.out.println("x is " + x + ". y is " + y 00139 + ". theta is " + theta); 00140 } else { 00141 System.out.println("WARNING: Multiple options... "); 00142 QuerySolution qs = rset.get(0); 00143 x = qs.getLiteral("x").getFloat(); 00144 y = qs.getLiteral("y").getFloat(); 00145 theta = qs.getLiteral("theta").getFloat(); 00146 System.out.println("x is " + x + ". y is " + y 00147 + ". theta is " + theta); 00148 } 00149 } catch (Exception e) { 00150 System.out.println("Exception --> " + e.getMessage()); 00151 return false; 00152 } 00153 /* 00154 genericAction.actionInfo.add("charging"); 00155 genericAction.actionInfo.add(Double.toString(x)); 00156 genericAction.actionInfo.add(Double.toString(y)); 00157 genericAction.actionInfo.add(Double.toString(theta)); 00158 */ 00159 genericAction.jsonActionInfo = SRSJSONParser.encodeMoveAction("charging", x, y, theta); 00160 ca.generic = genericAction; 00161 00162 act.setCUAction(ca); 00163 act.setActionId(1); 00164 addNewActionTuple(act); 00165 00166 // add finish action __ success 00167 00168 act = new ActionTuple(); 00169 00170 ca = new CUAction(); 00171 genericAction = new GenericAction(); 00172 ca.generic = genericAction; 00173 00174 act.setActionName("finish_success"); 00175 00176 ca.status = 1; 00177 00178 act.setCUAction(ca); 00179 act.setActionId(2); 00180 act.setParentId(1); 00181 act.setCondition(true); 00182 addNewActionTuple(act); 00183 00184 // add finish action __ fail 00185 00186 act = new ActionTuple(); 00187 00188 ca = new CUAction(); 00189 genericAction = new GenericAction(); 00190 00191 ca.generic = genericAction; 00192 00193 act.setActionName("finish_fail"); 00194 00195 ca.status = -1; 00196 00197 act.setCUAction(ca); 00198 act.setActionId(3); 00199 act.setParentId(1); 00200 act.setCondition(false); 00201 addNewActionTuple(act); 00202 00203 System.out.println("number of actions: " + acts.size()); 00204 return true; 00205 } 00206 00207 public boolean replan(OntologyDB onto, OntoQueryUtil ontoQuery) { 00208 return false; 00209 } 00210 }