Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

Lookout.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_Lookout_h_
00003 #define INCLUDED_Lookout_h_
00004 
00005 #include <queue>
00006 
00007 #include "Behaviors/BehaviorBase.h"
00008 #include "Motion/HeadPointerMC.h"
00009 #include "Events/VisionObjectEvent.h"
00010 #include "Crew/LookoutRequests.h"
00011 
00012 namespace DualCoding {
00013 
00014 
00015 //! The Lookout accepts LookoutRequests to move the head and collect sensor information.
00016 /*!
00017  HeadMotionType can be none (user will point the head himself),
00018  pointAt, scan, track, or search.  The data collected can be an image
00019  or distance reading, or for scan operations, it can be a list of
00020  locations where certain VisionObject or VisionRegion streams reported
00021  hits.
00022 
00023 */
00024 
00025 class Lookout : public BehaviorBase {
00026 public:
00027   //! Constructor
00028   Lookout();
00029 
00030   virtual void doStart();
00031   virtual void doStop();
00032   virtual void doEvent();
00033 
00034   static std::string getClassDescription() { return "Moves head and collects data according to request"; }
00035   virtual std::string getDescription() const { return getClassDescription(); }
00036 
00037   virtual unsigned int executeRequest(const LookoutRequest&);
00038   bool busy() { return curReq != NULL; }
00039   void stopTrack();
00040 
00041   static std::vector<DualCoding::Point> groundSearchPoints(); //!< returns a vector of points for searching the ground around the robot
00042 
00043   void moveHeadToPoint();
00044   //  bool isLandmarkVisible() const { return landmark_inview; }
00045 
00046   void relax(); //!< Inactivates all Lookout motion commands; called when MapBuilder finishes
00047 
00048   static Point findLocationFor(const float normX, const float normY);
00049   static const unsigned int invalid_LO_ID=(unsigned int)-1;
00050   
00051 protected:
00052   virtual void executeRequest();
00053   virtual void requestComplete(bool result=true);
00054 
00055   template<class T>
00056   void pushRequest(const LookoutRequest& req) {
00057     requests.push(new T(dynamic_cast<const T&>(req)));
00058   }
00059     
00060 
00061   //@name PointAtRequest functions
00062   //@{
00063   void processPointAtEvent(const EventBase& event);
00064   bool findPixelModes();
00065 #ifdef TGT_HAS_IR_DISTANCE
00066   bool findDistanceMode();
00067   float getDistanceModeValue();
00068 #endif
00069   //@}
00070 
00071   //@name ScanRequest functions
00072   //@{
00073   void setupScan();
00074   void triggerScanMotionSequence();
00075   void processScanEvent(const EventBase& event);
00076   void scanAlongLine(const Point& start,const Point& end);
00077   void scanAlongPolygon(const std::vector<Point>& vertices, const bool closed=false);
00078   void scanArea(const Point &topLeft, const Point &topRight,
00079     const Point &bottomLeft, const Point &bottomRight);
00080 
00081   static Point findLocationFor(const VisionObjectEvent& visev) {
00082     return findLocationFor(visev.getCenterX(), visev.getCenterY());
00083   }
00084 
00085   static Point findLocationFor(const CMVision::region* reg);
00086 
00087   void storeVisionRegionDataTo(std::vector<Point>&, const std::set<color_index>&, int);
00088 #ifdef TGT_HAS_IR_DISTANCE
00089   void storeIRDataTo(std::vector<Point>&);
00090 #endif
00091   //@}
00092 
00093   //@name TrackRequest functions
00094   //@{
00095   void setupTrack();
00096   void processTrackEvent(const EventBase& event);
00097   /*
00098   void processTrackVision(float normX, float normY, bool isCurrentlyVisible);
00099   void trackObjectAt(float normX, float normY); //! tracks point at [normX,normY] in cam frame
00100   Point findLocationFor(float, float);
00101   */
00102   //@}
00103 
00104   //@name SearchRequest functions
00105   //@{
00106   void setupSearch();
00107   void processSearchEvent(const EventBase& event);
00108   void triggerSearchMotionSequence();
00109   static void searchAt(HeadPointerMC &hpmc_temp,
00110            std::vector<float> &jointvals,
00111            const Point &target);
00112   //@}
00113 
00114 
00115 private:
00116   Lookout& operator=(const Lookout&);
00117   Lookout(const Lookout&);
00118 
00119 protected:
00120   std::vector<std::map<uchar,unsigned int> > pixelHistograms;
00121   std::priority_queue<float> distanceSamples;
00122 
00123   MC_ID pointer_id;  //!< id for HeadPointerMC for pointing the camera
00124   MC_ID posture_id;  //!< id for PostureMC for pointing the IR sensors
00125   MC_ID sequence_id; //!< id for MotionSequenceMC for scanning
00126   std::queue<LookoutRequest*> requests;  //!< queue of pending LookoutRequest instances, including the current request
00127   LookoutRequest *curReq;           //!< pointer to request currently being executed
00128   LookoutPointRequest *curPAR;      //!< current Point-At request (same object as curReq)
00129   bool successSave;
00130 
00131   enum TrackerStates {
00132     inactive,
00133     moveToAcquire,
00134     tracking,
00135     searching,
00136     centering,
00137     lost
00138   } trackerState;
00139   unsigned int idCounter;
00140 
00141   enum LookoutTimerSourceId_t {
00142     settle_timer = 1,
00143     sample_timer,
00144     lost_timer,
00145     scan_timer, //scan_timer has to be at the end of enum list
00146   };
00147 };
00148 
00149 } //namespace
00150 
00151 #endif

Tekkotsu v5.1CVS
Generated Fri Mar 16 05:26:43 2012 by Doxygen 1.6.3