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

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:44 2016 by Doxygen 1.6.3