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

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