00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef BallTrackingHead_h_DEFINED
00013 #define BallTrackingHead_h_DEFINED
00014
00015 #include <list>
00016 using namespace std;
00017
00018 #include <OPENR/OObject.h>
00019 #include <OPENR/OSubject.h>
00020 #include <OPENR/OObserver.h>
00021 #include <OPENR/ODataFormats.h>
00022 #include <OPENR/OFbkImage.h>
00023 #include <BallTrackingHeadData.h>
00024 #include "def.h"
00025
00026 enum BallTrackingHeadState {
00027 BTHS_IDLE,
00028 BTHS_START,
00029 BTHS_HEAD_ZERO_POS,
00030 BTHS_LEGS_SLEEPING,
00031 BTHS_SEARCHING_BALL,
00032 BTHS_TRACKING_BALL
00033 };
00034
00035 static const char* const FBK_LOCATOR = "PRM:/r1/c1/c2/c3/i1-FbkImageSensor:F1";
00036 static const char* const JOINT_LOCATOR[] = {
00037 "PRM:/r1/c1-Joint2:j1",
00038 "PRM:/r1/c1/c2-Joint2:j2"
00039 };
00040
00041 class BallTrackingHead : public OObject {
00042 public:
00043 BallTrackingHead();
00044 virtual ~BallTrackingHead() {}
00045
00046 OSubject* subject[numOfSubject];
00047 OObserver* observer[numOfObserver];
00048
00049 virtual OStatus DoInit (const OSystemEvent& event);
00050 virtual OStatus DoStart (const OSystemEvent& event);
00051 virtual OStatus DoStop (const OSystemEvent& event);
00052 virtual OStatus DoDestroy(const OSystemEvent& event);
00053
00054 void NotifyImage(const ONotifyEvent& event);
00055 void NotifySensor(const ONotifyEvent& event);
00056 void NotifyMovingHeadResult(const ONotifyEvent& event);
00057 void NotifyMovingLegsResult(const ONotifyEvent& event);
00058 void NotifyLostFoundSoundResult(const ONotifyEvent& event);
00059
00060 private:
00061 static const size_t NUM_COMMAND_VECTOR = 4;
00062 static const size_t NUM_SENSOR_VECTOR = 2;
00063 static const size_t NUM_JOINTS = 2;
00064 static const size_t NUM_FRAMES = 5;
00065 static const int TILT_INDEX = 0;
00066 static const int PAN_INDEX = 1;
00067 static const byte BALL_THRESHOLD = 10;
00068 static const int FOUND_THRESHOLD = 2;
00069 static const int LOST_THRESHOLD = 5;
00070 static const OCdtChannel BALL_CDT_CHAN = ocdtCHANNEL0;
00071 static const double FIELD_VIEW_H = 57.6;
00072 static const double FIELD_VIEW_V = 47.8;
00073
00074 void OpenPrimitives();
00075 void NewCommandVectorData();
00076 void PlaySound(BallTrackingHeadCommandType type);
00077
00078 void SetCdtVectorDataOfPinkBall();
00079 bool CentroidAndDeltaAngle(const OFbkImage& cdtImage,
00080 int* xcentroid, int* ycentroid,
00081 double* delta_pan, double* delta_pan);
00082
00083 void InitSensorIndex(OSensorFrameVectorData* sensorVec);
00084 void GetPanTiltAngle(longword frameNum, double* pan, double* tilt);
00085
00086 void SearchBall();
00087 void TrackBall(longword frameNum, double delta_pan, double delta_pan);
00088 void MoveHead(double s_pan, double s_tilt, double e_pan, double e_tilt,
00089 double *r_pan, double *r_tilt,
00090 double pan_limit, double tilt_limit);
00091 void SetJointValue(RCRegion* rgn, int idx, double start, double end);
00092 RCRegion* FindFreeRegion();
00093
00094 BallTrackingHeadState ballTrackingHeadState;
00095 OPrimitiveID fbkID;
00096 OPrimitiveID jointID[NUM_JOINTS];
00097 RCRegion* region[NUM_COMMAND_VECTOR];
00098 bool initSensorIndex;
00099 int sensoridx[NUM_JOINTS];
00100 list<RCRegion*> sensorRegions;
00101 double lastRefPan;
00102 double lastRefTilt;
00103 };
00104
00105 #endif // BallTrackingHead_h_DEFINED