00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef LMasterRSlave_h_DEFINED
00013 #define LMasterRSlave_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 LMasterRSlaveState {
00021 LMRS_IDLE,
00022 LMRS_START,
00023 LMRS_ADJUSTING_DIFF_JOINT_VALUE,
00024 LMRS_MOVING_TO_BROADBASE,
00025 LMRS_MOVING_TO_SLEEPING,
00026 LMRS_MASTER_SLAVE
00027 };
00028
00029 enum MovingResult {
00030 MOVING_CONT,
00031 MOVING_FINISH
00032 };
00033
00034 const int HEAD_TILT = 0;
00035 const int HEAD_PAN = 1;
00036 const int HEAD_ROLL = 2;
00037 const int RFLEG_J1 = 3;
00038 const int RFLEG_J2 = 4;
00039 const int RFLEG_J3 = 5;
00040 const int LFLEG_J1 = 6;
00041 const int LFLEG_J2 = 7;
00042 const int LFLEG_J3 = 8;
00043 const int RRLEG_J1 = 9;
00044 const int RRLEG_J2 = 10;
00045 const int RRLEG_J3 = 11;
00046 const int LRLEG_J1 = 12;
00047 const int LRLEG_J2 = 13;
00048 const int LRLEG_J3 = 14;
00049 const int NUM_JOINTS = 15;
00050
00051 static const char* const JOINT_LOCATOR[] = {
00052 "PRM:/r1/c1-Joint2:j1",
00053 "PRM:/r1/c1/c2-Joint2:j2",
00054 "PRM:/r1/c1/c2/c3-Joint2:j3",
00055
00056 "PRM:/r4/c1-Joint2:j1",
00057 "PRM:/r4/c1/c2-Joint2:j2",
00058 "PRM:/r4/c1/c2/c3-Joint2:j3",
00059
00060 "PRM:/r2/c1-Joint2:j1",
00061 "PRM:/r2/c1/c2-Joint2:j2",
00062 "PRM:/r2/c1/c2/c3-Joint2:j3",
00063
00064 "PRM:/r5/c1-Joint2:j1",
00065 "PRM:/r5/c1/c2-Joint2:j2",
00066 "PRM:/r5/c1/c2/c3-Joint2:j3",
00067
00068 "PRM:/r3/c1-Joint2:j1",
00069 "PRM:/r3/c1/c2-Joint2:j2",
00070 "PRM:/r3/c1/c2/c3-Joint2:j3"
00071 };
00072
00073 const double BROADBASE_ANGLE[] = {
00074 45,
00075 0,
00076 0,
00077
00078 117,
00079 90,
00080 30,
00081
00082 117,
00083 90,
00084 30,
00085
00086 -117,
00087 70,
00088 30,
00089
00090 -117,
00091 70,
00092 30
00093 };
00094
00095 const double SLEEPING_ANGLE[] = {
00096 -10,
00097 0,
00098 0,
00099
00100 60,
00101 0,
00102 30,
00103
00104 60,
00105 0,
00106 30,
00107
00108 -117,
00109 0,
00110 147,
00111
00112 -117,
00113 0,
00114 147
00115 };
00116
00117 class LMasterRSlave : public OObject {
00118 public:
00119 LMasterRSlave();
00120 virtual ~LMasterRSlave() {}
00121
00122 OSubject* subject[numOfSubject];
00123 OObserver* observer[numOfObserver];
00124
00125 virtual OStatus DoInit (const OSystemEvent& event);
00126 virtual OStatus DoStart (const OSystemEvent& event);
00127 virtual OStatus DoStop (const OSystemEvent& event);
00128 virtual OStatus DoDestroy(const OSystemEvent& event);
00129
00130 void ReadyEffector(const OReadyEvent& event);
00131 void NotifySensor(const ONotifyEvent& event);
00132
00133 private:
00134 void OpenPrimitives();
00135 void NewCommandVectorData();
00136 void SetJointGain();
00137 MovingResult AdjustDiffJointValue();
00138 MovingResult MoveToBroadBase();
00139 MovingResult MoveToSleeping();
00140 MovingResult MasterSlave();
00141
00142 RCRegion* FindFreeRegion();
00143 void SetJointValue(RCRegion* rgn, int idx, double start, double end);
00144 void InitSensorIndex(OSensorFrameVectorData* sensorVecData);
00145 void Sensor2Command(OSensorFrameVectorData* sensorVec, int sensorIdx,
00146 OCommandVectorData* commandVec, int commandIndex,
00147 OPrimitiveID id);
00148
00149 static const size_t NUM_JOINTS = 15;
00150 static const size_t NUM_COMMAND_VECTOR = 2;
00151
00152 static const word TILT_PGAIN = 0x000a;
00153 static const word TILT_IGAIN = 0x0008;
00154 static const word TILT_DGAIN = 0x000c;
00155
00156 static const word PAN_PGAIN = 0x000d;
00157 static const word PAN_IGAIN = 0x0008;
00158 static const word PAN_DGAIN = 0x000b;
00159
00160 static const word ROLL_PGAIN = 0x000a;
00161 static const word ROLL_IGAIN = 0x0008;
00162 static const word ROLL_DGAIN = 0x000c;
00163
00164 static const word J1_PGAIN = 0x0016;
00165 static const word J1_IGAIN = 0x0004;
00166 static const word J1_DGAIN = 0x0008;
00167
00168 static const word J2_PGAIN = 0x0014;
00169 static const word J2_IGAIN = 0x0004;
00170 static const word J2_DGAIN = 0x0006;
00171
00172 static const word J3_PGAIN = 0x0023;
00173 static const word J3_IGAIN = 0x0004;
00174 static const word J3_DGAIN = 0x0005;
00175
00176 static const word PSHIFT = 0x000e;
00177 static const word ISHIFT = 0x0002;
00178 static const word DSHIFT = 0x000f;
00179
00180 static const int BROADBASE_MAX_COUNTER = 48;
00181 static const int SLEEPING_MAX_COUNTER = 48;
00182
00183 LMasterRSlaveState lmasterRSlaveState;
00184
00185 OPrimitiveID jointID[NUM_JOINTS];
00186 RCRegion* region[NUM_COMMAND_VECTOR];
00187
00188 bool initSensorIndex;
00189 int sensorIndex[NUM_JOINTS];
00190 RCRegion* latestSensorRegion;
00191 };
00192
00193 #endif // LMasterRSlave_h_DEFINED