Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

LookoutRequests.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_LookoutRequests_h_
00003 #define INCLUDED_LookoutRequests_h_
00004 
00005 #include "Shared/newmat/newmat.h"
00006 #include "Shared/ProjectInterface.h"
00007 #include "Shared/WorldState.h"
00008 
00009 #include "Sketch.h"
00010 #include "Point.h"
00011 #include "ShapeRoot.h"
00012 #include "VRmixin.h"
00013 
00014 namespace DualCoding {
00015   
00016 //! Base class for requests to the Lookout
00017 
00018 class LookoutRequest {
00019 public:
00020   enum HeadMotionType_t { 
00021     noMotion, //!< use current head position
00022     pointAt,  //!< move head to specified gaze point
00023     scan, //!< scan head along specified path
00024     track,  //!< move head to track object
00025     search, //!< spiral search for a known object
00026     numHeadMotionTypes
00027   };
00028 
00029   static const char* const headMotionTypeNames[numHeadMotionTypes];
00030 
00031   HeadMotionType_t getHeadMotionType() const { return headMotionType; }
00032   void setHeadMotionType(const HeadMotionType_t htype) { headMotionType = htype; }
00033 
00034   enum LookoutResultType_t {
00035     noResult,      //!< don't return anything (just move the head)
00036     imageResult,     //!< take a picture
00037 #ifdef TGT_HAS_IR_DISTANCE
00038     distanceResult,  //!< measure distance with IR rangefinder
00039 #endif
00040     interestPoints   //!< collection of interest points (from scanning)
00041   };
00042 
00043   LookoutResultType_t getResultType() const { return resultType; }
00044   void setResultType(const LookoutResultType_t rtype) { resultType = rtype; }
00045 
00046   //! Constructor
00047   LookoutRequest(HeadMotionType_t htype=noMotion, LookoutResultType_t rtype=noResult) :
00048     headMotionType(htype), resultType(rtype), requestID(0) {}
00049 
00050   //! Destructor
00051   virtual ~LookoutRequest() {}
00052 
00053   //! Copy constructor
00054   LookoutRequest(const LookoutRequest &req) : 
00055     headMotionType(req.headMotionType),
00056     resultType(req.resultType),
00057     requestID(req.requestID) {}
00058 
00059   HeadMotionType_t  headMotionType;
00060   LookoutResultType_t resultType;
00061   unsigned int requestID;   //!< Non-zero value assigned when the request is added to the queue
00062 
00063 private:
00064   LookoutRequest& operator=(const LookoutRequest&);
00065 
00066 public:
00067   // ------------ Tasks that may be implemented during a scan or track request ----------------
00068   //! Base class for Lookout tasks; cannot instantiate directly
00069   class Task {
00070   public:
00071     enum TaskType_t { noTask, visObjTask, visRegTask, irTask };
00072 
00073     virtual TaskType_t getTaskType() const = 0;
00074     virtual Task* clone() const = 0;
00075 
00076     //! Constructor
00077     Task(AngPi _dTheta) : dTheta(_dTheta), data() {}
00078 
00079     //! Copy constructor
00080     Task(const Task& t) : dTheta(t.dTheta), data(t.data) {}
00081 
00082     //! Destructor
00083     virtual ~Task() {}
00084 
00085     AngPi dTheta; //!< angular step size during scan
00086     std::vector<Point> data; //!< measured data stored here in base frame coordinates
00087     Task& operator=(const Task&);
00088   };
00089 
00090   class IRTask : public Task {
00091   public:
00092     IRTask(AngPi _dTheta) : Task(_dTheta) {}
00093     IRTask(const IRTask& t) : Task(t) {}
00094     virtual TaskType_t getTaskType() const { return irTask; }
00095     virtual Task* clone() const { return new IRTask(*this); }
00096   };
00097 
00098   //! Base class for vision tasks, should not be instantiated
00099   class VisionTask : public Task {
00100   public:
00101     virtual TaskType_t getTaskType() const { return noTask; }
00102     std::set<color_index> index;
00103     VisionTask(const VisionTask& vt) : Task(vt), index(vt.index) {}
00104     VisionTask(const std::set<color_index>& _index, AngPi _dTheta)
00105       : Task(_dTheta), index(_index) {}
00106     VisionTask(int _index, AngPi _dTheta)
00107       : Task(_dTheta), index() { index.insert(_index); }
00108     virtual Task* clone() const { return new VisionTask(*this); }
00109   };
00110 
00111   //! Uses bult-in object detectors (like pink ball detector) via VisionObjectEvent stream
00112   class VisionObjectTask : public VisionTask {
00113   public:
00114     VisionObjectTask(const std::set<color_index>& sid, AngPi _dTheta=0)
00115       : VisionTask(sid,_dTheta) {}
00116     VisionObjectTask(const VisionObjectTask& vot) : VisionTask(vot) {}
00117     virtual TaskType_t getTaskType() const { return visObjTask; }
00118     virtual Task* clone() const { return new VisionObjectTask(*this); }
00119   };
00120 
00121   //! Uses built-in colored region detectors via Region event stream
00122   class VisionRegionTask : public VisionTask {
00123   public:
00124     VisionRegionTask(const std::set<color_index>& colorIndex, AngPi _dTheta=0,
00125          unsigned int _minArea=200)
00126       : VisionTask(colorIndex,_dTheta), minArea(_minArea) {}
00127     VisionRegionTask(int colorIndex, AngPi _dTheta,
00128          unsigned int _minArea=200)
00129       : VisionTask(colorIndex,_dTheta), minArea(_minArea) {}
00130     VisionRegionTask(const VisionRegionTask& vrt)
00131       : VisionTask(vrt), minArea(vrt.minArea) {}
00132     virtual TaskType_t getTaskType() const { return visRegTask; }
00133     virtual Task* clone() const { return new VisionRegionTask(*this); }
00134     unsigned int minArea;
00135   };
00136 
00137   // ---------------- end of Task classes ----------------
00138 
00139 };
00140 
00141 //================ LookoutPointRequest ================
00142 
00143 //! Take a picture of or measure a distance to a point in space
00144 class LookoutPointRequest : public LookoutRequest {
00145 public:
00146   //! Constructor
00147   LookoutPointRequest() : 
00148     LookoutRequest(noMotion,imageResult),
00149 #ifdef TGT_HAS_CAMERA
00150     joint(CameraFrameOffset),
00151 #else
00152   joint(0),
00153 #endif
00154     toBaseMatrix(),
00155     gazePt(), motionSettleTime(1000), 
00156     numSamples(1), sampleCounter(0), sampleInterval(0),
00157     image(), sketchFunc(VRmixin::sketchFromSeg)
00158   {}
00159 
00160   //! Copy constructor
00161   LookoutPointRequest(const LookoutPointRequest &p)
00162     : LookoutRequest(p), joint(p.joint), toBaseMatrix(p.toBaseMatrix),
00163       gazePt(p.gazePt), motionSettleTime(p.motionSettleTime),
00164       numSamples(p.numSamples), sampleCounter(p.sampleCounter), sampleInterval(p.sampleInterval),
00165       image(p.image), sketchFunc(p.sketchFunc)
00166   {}
00167 
00168 public:
00169   void setTarget(const Point &target) {
00170     gazePt = target;
00171     headMotionType = pointAt;
00172   }
00173 
00174   unsigned int joint; //!< joint reference frame from which base frame transformation matrix is created, e.g., Camera, IR, etc.
00175   NEWMAT::Matrix toBaseMatrix; //!< transformation matrix from joint frame to base frame
00176   Point gazePt; //!< point to look at; can be in either egocentric or allocentric reference frame
00177   unsigned int motionSettleTime;  //!< Time in msec to wait before taking measurements or throwing completion event after head reaches gazePt.
00178   int numSamples; //!< Number of samples to take; if > 1, return the mode (for pixels) or median (for distance)
00179   int sampleCounter; //!< Number of samples collected so far
00180   int sampleInterval; //!< Interval in msec between successive samples
00181   Sketch<uchar> image; //<! stores image here
00182   Sketch<uchar> (*sketchFunc)(); //<! function used to generate image
00183 
00184 private:
00185   LookoutPointRequest& operator=(const LookoutPointRequest&); // don't call
00186 };
00187 
00188 
00189 // ================ LookoutScanRequest ================
00190 
00191 class LookoutScanRequest : public LookoutRequest {
00192 public:
00193 
00194   std::vector<Task*> tasks;
00195   float scanSpeed; //!< speed in rad/msec
00196   ShapeRoot searchArea;
00197   unsigned int motionSettleTime;
00198 
00199   static const float defSpd;  //!< default scan speed
00200 
00201   //! Constructor
00202   LookoutScanRequest(float _speed=defSpd): 
00203     LookoutRequest(scan,interestPoints),
00204     tasks(), scanSpeed(_speed), searchArea(), motionSettleTime(1000) {}
00205 
00206   //! Constructor
00207   LookoutScanRequest(const Task& _task, float _speed=defSpd) :
00208     LookoutRequest(scan,interestPoints), tasks(), scanSpeed(_speed), searchArea(), motionSettleTime(1000)
00209   { addTask(_task); }
00210 
00211   //! Copy constructor
00212   LookoutScanRequest(const LookoutScanRequest& req)
00213     : LookoutRequest(req), tasks(), scanSpeed(req.scanSpeed), searchArea(req.searchArea), motionSettleTime(req.motionSettleTime)
00214   {
00215     for (std::vector<Task*>::const_iterator it = req.tasks.begin();
00216    it != req.tasks.end(); it++) 
00217       addTask(**it);
00218   }
00219 
00220   //! Destructor
00221   virtual ~LookoutScanRequest();
00222 
00223   void addTask(const Task& t) { tasks.push_back(t.clone()); }
00224 
00225 };  // end of LookoutScanRequest
00226 
00227 
00228 
00229 // ================ LookoutTrackRequest ================
00230 
00231 // ! Track an object with the head
00232 class LookoutTrackRequest : public LookoutRequest {
00233 public:
00234 
00235   friend class Lookout;
00236 
00237   //! Constructor
00238   LookoutTrackRequest(const ShapeRoot& target=ShapeRoot())
00239     : LookoutRequest(track), targetShape(target),
00240       minBlobArea(80), exitTest(NULL), cindex(0) {}
00241 
00242   //! Copy constructor
00243   LookoutTrackRequest(const LookoutTrackRequest& req)
00244     : LookoutRequest(req), targetShape(req.targetShape),
00245       minBlobArea(req.minBlobArea), exitTest(req.exitTest), cindex(req.cindex) {}
00246 
00247   ShapeRoot targetShape;
00248   int minBlobArea; //!< Minimum acceptable size of a region
00249   bool (*exitTest)();  //!< If true, target has been found
00250 
00251 private:
00252   color_index cindex;
00253 
00254   LookoutTrackRequest& operator=(const LookoutTrackRequest&); //!< don't call this
00255 };
00256 
00257 
00258 // ================ LookoutSearchRequest ================
00259 
00260 //! Search for an object and return when found
00261 class LookoutSearchRequest : public LookoutRequest {
00262 public:
00263 
00264   friend class Lookout;
00265 
00266   //! Constructor
00267   LookoutSearchRequest(const ShapeRoot& target=ShapeRoot())
00268     : LookoutRequest(search,imageResult), targetShape(target), 
00269       minBlobArea(80), exitTest(NULL), cindex(0) {}
00270 
00271   //! Copy constructor
00272   LookoutSearchRequest(const LookoutSearchRequest& req)
00273     : LookoutRequest(req), targetShape(req.targetShape), 
00274       minBlobArea(req.minBlobArea), exitTest(req.exitTest), cindex(req.cindex) {}
00275 
00276   ShapeRoot targetShape;
00277   int minBlobArea; //!< Minimum acceptable size of a region
00278   bool (*exitTest)();  //!< If true, target has been found
00279 
00280 private:
00281   color_index cindex;
00282 
00283   LookoutSearchRequest& operator=(const LookoutSearchRequest&); //!< don't call this
00284 };
00285 
00286 
00287 } // namespace
00288 
00289 #endif

DualCoding 4.0
Generated Thu Nov 22 00:52:36 2007 by Doxygen 1.5.4