BallTrackingHead7.h

Go to the documentation of this file.
00001 //
00002 // Copyright 2002,2004 Sony Corporation 
00003 //
00004 // Permission to use, copy, modify, and redistribute this software for
00005 // non-commercial use is hereby granted.
00006 //
00007 // This software is provided "as is" without warranty of any kind,
00008 // either expressed or implied, including but not limited to the
00009 // implied warranties of fitness for a particular purpose.
00010 //
00011 
00012 #ifndef BallTrackingHead7_h_DEFINED
00013 #define BallTrackingHead7_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 <MoNetData.h>
00024 #include "def.h"
00025 
00026 enum BallTrackingHead7State {
00027     BTHS7_IDLE,
00028     BTHS7_WAITING_STAND2STAND_RESULT,
00029     BTHS7_SEARCHING_BALL,
00030     BTHS7_TRACKING_BALL
00031 };
00032 
00033 const MoNetCommandID STAND2STAND_NULL =   2; // see MONETCMD.CFG
00034 const MoNetCommandID PLAY_FOUND_SOUND = 200; // see MONETCMD.CFG
00035 const MoNetCommandID PLAY_LOST_SOUND  = 201; // see MONETCMD.CFG
00036 
00037 static const char* const FBK_LOCATOR = "PRM:/r1/c1/c2/c3/i1-FbkImageSensor:F1";
00038 static const char* const JOINT_LOCATOR[] = {
00039     "PRM:/r1/c1/c2-Joint2:12",   // HEAD PAN
00040     "PRM:/r1/c1/c2/c3-Joint2:13" // HEAD TILT2
00041 };
00042 
00043 class BallTrackingHead7 : public OObject {
00044 public:
00045     BallTrackingHead7();
00046     virtual ~BallTrackingHead7() {}
00047 
00048     OSubject*  subject[numOfSubject];
00049     OObserver* observer[numOfObserver];
00050 
00051     virtual OStatus DoInit   (const OSystemEvent& event);
00052     virtual OStatus DoStart  (const OSystemEvent& event);
00053     virtual OStatus DoStop   (const OSystemEvent& event);
00054     virtual OStatus DoDestroy(const OSystemEvent& event);
00055 
00056     void NotifyResult(const ONotifyEvent& event);
00057     void NotifyImage(const ONotifyEvent& event);
00058     void NotifySensor(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         = 4;
00065     static const int         PAN_INDEX          = 0;
00066     static const int         TILT2_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       = 56.9;
00072     static const double      FIELD_VIEW_V       = 45.2;
00073 
00074     void OpenPrimitives();
00075     void NewCommandVectorData();
00076     void Execute(MoNetCommandID cmdID);
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     BallTrackingHead7State  state;
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 // BallTrackingHead7_h_DEFINED

Generated on Sun Dec 2 23:04:27 2007 for openSDK by  doxygen 1.3.9.1