Task.java
Go to the documentation of this file.
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 import ros.*;
00066 import ros.communication.*;
00067 
00068 public abstract class Task {
00069     public enum TaskType {
00070         GET_OBJECT, MOVETO_LOCATION, SEARCH_OBJECT, SCAN_AROUND, STOP_TASK, UNSPECIFIED
00071             };
00072     
00073     public Task() {
00074         // empty constructor.
00075         acts = new ArrayList<ActionTuple>();     // to be deprecated and replaced with allSubSeqs
00076         
00077         setTaskType(TaskType.UNSPECIFIED);
00078         currentAction = null;
00079         //ontoDB = new OntologyDB();
00080     }
00081 
00082     public abstract boolean replan(OntologyDB onto, OntoQueryUtil ontoQuery);
00083 
00084     protected abstract boolean constructTask();
00085 
00086     public void setTaskId(int id) {
00087         this.taskId = id;
00088     }
00089     
00090     public int getTaskId() {
00091         return taskId;
00092     }
00093     
00094     public void setTaskTarget(String target) {
00095         this.targetContent = target;
00096     }
00097     
00098     public String getTaskTarget() {
00099         return this.targetContent;
00100     }
00101     
00102     public void setTaskType(TaskType type) {
00103         this.taskType = type;
00104     }
00105 
00106     public CUAction getNextCUActionNew(boolean stateLastAction, String jsonFeedback) {
00107         
00108         if (currentAction == null) {
00109             for (int i = 0; i < acts.size(); i++) {
00110                 if (acts.get(i).getActionId() == 1) {
00111                     currentAction = acts.get(i);
00112                     currentActionLoc = i;
00113                     System.out.println(currentAction.getActionName());
00114                     
00115                     if (currentAction != null) 
00116                         return currentAction.getCUAction();
00117                     else 
00118                         return null;
00119                 }
00120             }
00121         } else {
00122             // ActionTuple at;
00123             // int parentId = at.getParentId();
00124             for (int i = 0; i < acts.size(); i++) {
00125                 // if(acts.get(currentActionLoc).getId() ==
00126                 // acts.get(i).getParentId() && stateLastAction ==
00127                 // acts.get(i).getCondition()){
00128                 if (currentAction.getActionId() == acts.get(i).getParentId()
00129                     && stateLastAction == acts.get(i).getCondition()) {
00130                     currentAction = acts.get(i);
00131                     currentActionLoc = i;
00132                     System.out.println(i);
00133                     System.out.println(currentAction.getActionName());
00134                     if (currentAction != null) 
00135                         return currentAction.getCUAction();
00136                     else 
00137                         return null;
00138                 }
00139             }
00140             System.out.println("no action found");
00141         }       
00142         
00143         return null;
00144     }
00145 
00146     public boolean addNewActionTuple(ActionTuple act) {
00147         return acts.add(act);
00148     }
00149 
00150     public boolean isEmpty() {
00151         try {
00152             if(allSubSeqs.size() == 0 && acts.size() == 0) {
00153                 return true;
00154             }
00155         }
00156         catch(NullPointerException e) {
00157             System.out.println(e.getMessage() + "\n" + e.toString());
00158             return true;
00159         }
00160         return false;
00161     }
00162 
00163     protected TaskType taskType;
00164     protected String targetContent;
00165     protected int taskId;
00166     protected ArrayList<ActionTuple> acts;
00167     protected int currentActionId = 1;
00168     protected ActionTuple currentAction;
00169     protected int currentActionLoc = 0;
00170     //   protected NodeHandle nodeHandle;
00171     protected ArrayList<HighLevelActionSequence> allSubSeqs = new ArrayList<HighLevelActionSequence>();
00172 }


srs_knowledge
Author(s): Ze Ji
autogenerated on Sun Jan 5 2014 12:03:29