00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef LMasterRSlave7_h_DEFINED
00013 #define LMasterRSlave7_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_TILT1 = 0;
00035 const int HEAD_PAN = 1;
00036 const int HEAD_TILT2 = 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 TAIL_TILT = 15;
00050 const int TAIL_PAN = 16;
00051 const int NUM_JOINTS = 17;
00052
00053 static const char* const JOINT_LOCATOR[] = {
00054 "PRM:/r1/c1-Joint2:11",
00055 "PRM:/r1/c1/c2-Joint2:12",
00056 "PRM:/r1/c1/c2/c3-Joint2:13",
00057
00058 "PRM:/r4/c1-Joint2:41",
00059 "PRM:/r4/c1/c2-Joint2:42",
00060 "PRM:/r4/c1/c2/c3-Joint2:43",
00061
00062 "PRM:/r2/c1-Joint2:21",
00063 "PRM:/r2/c1/c2-Joint2:22",
00064 "PRM:/r2/c1/c2/c3-Joint2:23",
00065
00066 "PRM:/r5/c1-Joint2:51",
00067 "PRM:/r5/c1/c2-Joint2:52",
00068 "PRM:/r5/c1/c2/c3-Joint2:53",
00069
00070 "PRM:/r3/c1-Joint2:31",
00071 "PRM:/r3/c1/c2-Joint2:32",
00072 "PRM:/r3/c1/c2/c3-Joint2:33",
00073
00074 "PRM:/r6/c1-Joint2:61",
00075 "PRM:/r6/c2-Joint2:62"
00076 };
00077
00078 const double BROADBASE_ANGLE[] = {
00079 0,
00080 0,
00081 40,
00082
00083 120,
00084 90,
00085 30,
00086
00087 120,
00088 90,
00089 30,
00090
00091 -120,
00092 70,
00093 30,
00094
00095 -120,
00096 70,
00097 30,
00098
00099 0,
00100 0
00101 };
00102
00103 const double SLEEPING_ANGLE[] = {
00104 0,
00105 0,
00106 0,
00107
00108 59,
00109 0,
00110 30,
00111
00112 59,
00113 0,
00114 30,
00115
00116 -119,
00117 4,
00118 122,
00119
00120 -119,
00121 4,
00122 122,
00123
00124 0,
00125 0
00126 };
00127
00128 class LMasterRSlave7 : public OObject {
00129 public:
00130 LMasterRSlave7();
00131 virtual ~LMasterRSlave7() {}
00132
00133 OSubject* subject[numOfSubject];
00134 OObserver* observer[numOfObserver];
00135
00136 virtual OStatus DoInit (const OSystemEvent& event);
00137 virtual OStatus DoStart (const OSystemEvent& event);
00138 virtual OStatus DoStop (const OSystemEvent& event);
00139 virtual OStatus DoDestroy(const OSystemEvent& event);
00140
00141 void ReadyEffector(const OReadyEvent& event);
00142 void NotifySensor(const ONotifyEvent& event);
00143
00144 private:
00145 void OpenPrimitives();
00146 void NewCommandVectorData();
00147 void SetJointGain();
00148 MovingResult AdjustDiffJointValue();
00149 MovingResult MoveToBroadBase();
00150 MovingResult MoveToSleeping();
00151 MovingResult MasterSlave();
00152
00153 RCRegion* FindFreeRegion();
00154 void SetJointValue(RCRegion* rgn, int idx, double start, double end);
00155 void InitSensorIndex(OSensorFrameVectorData* sensorVecData);
00156 void Sensor2Command(OSensorFrameVectorData* sensorVec, int sensorIdx,
00157 OCommandVectorData* commandVec, int commandIndex,
00158 OPrimitiveID id);
00159
00160 static const size_t NUM_COMMAND_VECTOR = 2;
00161
00162 static const word TILT1_PGAIN = 0x000a;
00163 static const word TILT1_IGAIN = 0x0004;
00164 static const word TILT1_DGAIN = 0x0002;
00165
00166 static const word PAN_PGAIN = 0x0008;
00167 static const word PAN_IGAIN = 0x0002;
00168 static const word PAN_DGAIN = 0x0004;
00169
00170 static const word TILT2_PGAIN = 0x000a;
00171 static const word TILT2_IGAIN = 0x0008;
00172 static const word TILT2_DGAIN = 0x000c;
00173
00174 static const word J1_PGAIN = 0x0010;
00175 static const word J1_IGAIN = 0x0004;
00176 static const word J1_DGAIN = 0x0001;
00177
00178 static const word J2_PGAIN = 0x000a;
00179 static const word J2_IGAIN = 0x0004;
00180 static const word J2_DGAIN = 0x0001;
00181
00182 static const word J3_PGAIN = 0x0010;
00183 static const word J3_IGAIN = 0x0004;
00184 static const word J3_DGAIN = 0x0001;
00185
00186 static const word TAIL_PGAIN = 0x000a;
00187 static const word TAIL_IGAIN = 0x0004;
00188 static const word TAIL_DGAIN = 0x0004;
00189
00190 static const word PSHIFT = 0x000e;
00191 static const word ISHIFT = 0x0002;
00192 static const word DSHIFT = 0x000f;
00193
00194 static const int BROADBASE_MAX_COUNTER = 24;
00195 static const int SLEEPING_MAX_COUNTER = 24;
00196
00197 LMasterRSlaveState lmasterRSlaveState;
00198
00199 OPrimitiveID jointID[NUM_JOINTS];
00200 RCRegion* region[NUM_COMMAND_VECTOR];
00201
00202 bool initSensorIndex;
00203 int sensorIndex[NUM_JOINTS];
00204 RCRegion* latestSensorRegion;
00205 };
00206
00207 #endif // LMasterRSlave7_h_DEFINED