00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef MovingHead_h_DEFINED
00013 #define MovingHead_h_DEFINED
00014
00015 #include <OPENR/OObject.h>
00016 #include <OPENR/OSubject.h>
00017 #include <OPENR/OObserver.h>
00018 #include "def.h"
00019
00020 enum MovingHeadState {
00021 MHS_IDLE,
00022 MHS_START,
00023 MHS_ADJUSTING_DIFF_JOINT_VALUE,
00024 MHS_MOVING_TO_ZERO_POS,
00025 MHS_SWING_HEAD
00026 };
00027
00028 enum MovingResult {
00029 MOVING_CONT,
00030 MOVING_FINISH
00031 };
00032
00033 static const char* const JOINT_LOCATOR[] = {
00034 "PRM:/r1/c1-Joint2:j1",
00035 "PRM:/r1/c1/c2-Joint2:j2",
00036 "PRM:/r1/c1/c2/c3-Joint2:j3"
00037 };
00038
00039 class MovingHead : public OObject {
00040 public:
00041 MovingHead();
00042 virtual ~MovingHead() {}
00043
00044 OSubject* subject[numOfSubject];
00045 OObserver* observer[numOfObserver];
00046
00047 virtual OStatus DoInit (const OSystemEvent& event);
00048 virtual OStatus DoStart (const OSystemEvent& event);
00049 virtual OStatus DoStop (const OSystemEvent& event);
00050 virtual OStatus DoDestroy(const OSystemEvent& event);
00051
00052 void Ready(const OReadyEvent& event);
00053
00054 private:
00055 void OpenPrimitives();
00056 void NewCommandVectorData();
00057 void SetJointGain();
00058 MovingResult AdjustDiffJointValue();
00059 MovingResult MoveToZeroPos();
00060 MovingResult SwingHead();
00061
00062 RCRegion* FindFreeRegion();
00063 void SetJointValue(RCRegion* rgn, int idx, double start, double end);
00064 void SetJointValue(RCRegion* rgn, int idx, int phase);
00065
00066 static const size_t NUM_COMMAND_VECTOR = 2;
00067 static const size_t NUM_JOINTS = 3;
00068 static const int TILT_INDEX = 0;
00069 static const int PAN_INDEX = 1;
00070 static const int ROLL_INDEX = 2;
00071
00072 static const word TILT_PGAIN = 0x000a;
00073 static const word TILT_IGAIN = 0x0008;
00074 static const word TILT_DGAIN = 0x000c;
00075
00076 static const word PAN_PGAIN = 0x000d;
00077 static const word PAN_IGAIN = 0x0008;
00078 static const word PAN_DGAIN = 0x000b;
00079
00080 static const word ROLL_PGAIN = 0x000a;
00081 static const word ROLL_IGAIN = 0x0008;
00082 static const word ROLL_DGAIN = 0x000c;
00083
00084 static const word PSHIFT = 0x000e;
00085 static const word ISHIFT = 0x0002;
00086 static const word DSHIFT = 0x000f;
00087
00088 static const int ZERO_POS_MAX_COUNTER = 16;
00089 static const int MAX_PHASE = 128;
00090
00091 MovingHeadState movingHeadState;
00092 OPrimitiveID jointID[NUM_JOINTS];
00093 RCRegion* region[NUM_COMMAND_VECTOR];
00094 };
00095
00096 #endif // MovingHead_h_DEFINED