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 "Motion/HeadPointerMC.h"
00009 #include "Events/VisionObjectEvent.h"
00010 #include "Crew/LookoutRequests.h"
00011
00012 namespace DualCoding {
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 class Lookout : public BehaviorBase {
00026 public:
00027
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();
00042
00043 void moveHeadToPoint();
00044
00045
00046 void relax();
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
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
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
00094
00095 void setupTrack();
00096 void processTrackEvent(const EventBase& event);
00097
00098
00099
00100
00101
00102
00103
00104
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;
00124 MC_ID posture_id;
00125 MC_ID sequence_id;
00126 std::queue<LookoutRequest*> requests;
00127 LookoutRequest *curReq;
00128 LookoutPointRequest *curPAR;
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,
00146 };
00147 };
00148
00149 }
00150
00151 #endif