Lookout.h
Go to the documentation of this file.00001
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
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 class Lookout : public BehaviorBase {
00027 public:
00028
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();
00044
00045 void moveHeadToPoint();
00046
00047
00048 void relax();
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
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
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
00096
00097 void setupTrack();
00098 void processTrackEvent(const EventBase& event);
00099
00100
00101
00102
00103
00104
00105
00106
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;
00127 MC_ID posture_id;
00128 MC_ID sequence_id;
00129 std::queue<LookoutRequestBase*> requests;
00130 LookoutRequestBase *curReq;
00131 LookoutPointRequest *curPAR;
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,
00148 };
00149 };
00150
00151 }
00152
00153 #endif