00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef MovingLegs_h_DEFINED
00013 #define MovingLegs_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 MovingLegsState {
00021 MLS_IDLE,
00022 MLS_START,
00023 MLS_ADJUSTING_DIFF_JOINT_VALUE,
00024 MLS_MOVING_TO_BROADBASE,
00025 MLS_MOVING_TO_SLEEPING
00026 };
00027
00028 enum MovingResult {
00029 MOVING_CONT,
00030 MOVING_FINISH
00031 };
00032
00033 static const char* const JOINT_LOCATOR[] = {
00034 "PRM:/r4/c1-Joint2:j1",
00035 "PRM:/r4/c1/c2-Joint2:j2",
00036 "PRM:/r4/c1/c2/c3-Joint2:j3",
00037
00038 "PRM:/r2/c1-Joint2:j1",
00039 "PRM:/r2/c1/c2-Joint2:j2",
00040 "PRM:/r2/c1/c2/c3-Joint2:j3",
00041
00042 "PRM:/r5/c1-Joint2:j1",
00043 "PRM:/r5/c1/c2-Joint2:j2",
00044 "PRM:/r5/c1/c2/c3-Joint2:j3",
00045
00046 "PRM:/r3/c1-Joint2:j1",
00047 "PRM:/r3/c1/c2-Joint2:j2",
00048 "PRM:/r3/c1/c2/c3-Joint2:j3"
00049 };
00050
00051 const double BROADBASE_ANGLE[] = {
00052 117,
00053 90,
00054 30,
00055
00056 117,
00057 90,
00058 30,
00059
00060 -117,
00061 70,
00062 30,
00063
00064 -117,
00065 70,
00066 30
00067 };
00068
00069 const double SLEEPING_ANGLE[] = {
00070 60,
00071 0,
00072 30,
00073
00074 60,
00075 0,
00076 30,
00077
00078 -117,
00079 0,
00080 147,
00081
00082 -117,
00083 0,
00084 147
00085 };
00086
00087 class MovingLegs : public OObject {
00088 public:
00089 MovingLegs();
00090 virtual ~MovingLegs() {}
00091
00092 OSubject* subject[numOfSubject];
00093 OObserver* observer[numOfObserver];
00094
00095 virtual OStatus DoInit (const OSystemEvent& event);
00096 virtual OStatus DoStart (const OSystemEvent& event);
00097 virtual OStatus DoStop (const OSystemEvent& event);
00098 virtual OStatus DoDestroy(const OSystemEvent& event);
00099
00100 void Ready(const OReadyEvent& event);
00101
00102 private:
00103 void OpenPrimitives();
00104 void NewCommandVectorData();
00105 void SetJointGain();
00106 MovingResult AdjustDiffJointValue();
00107 MovingResult MoveToBroadBase();
00108 MovingResult MoveToSleeping();
00109
00110 RCRegion* FindFreeRegion();
00111 void SetJointValue(RCRegion* rgn, int idx, double start, double end);
00112
00113 static const size_t NUM_JOINTS = 12;
00114 static const size_t NUM_COMMAND_VECTOR = 2;
00115
00116 static const word J1_PGAIN = 0x0016;
00117 static const word J1_IGAIN = 0x0004;
00118 static const word J1_DGAIN = 0x0008;
00119
00120 static const word J2_PGAIN = 0x0014;
00121 static const word J2_IGAIN = 0x0004;
00122 static const word J2_DGAIN = 0x0006;
00123
00124 static const word J3_PGAIN = 0x0023;
00125 static const word J3_IGAIN = 0x0004;
00126 static const word J3_DGAIN = 0x0005;
00127
00128 static const word PSHIFT = 0x000e;
00129 static const word ISHIFT = 0x0002;
00130 static const word DSHIFT = 0x000f;
00131
00132 static const int BROADBASE_MAX_COUNTER = 48;
00133 static const int SLEEPING_MAX_COUNTER = 48;
00134
00135 MovingLegsState movingLegsState;
00136 OPrimitiveID jointID[NUM_JOINTS];
00137 RCRegion* region[NUM_COMMAND_VECTOR];
00138 };
00139
00140 #endif // MovingLegs_h_DEFINED