00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef PIDControl7_h_DEFINED
00013 #define PIDControl7_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 PIDControl7State {
00021 PCS7_IDLE,
00022 PCS7_START,
00023 PCS7_ADJUSTING_DIFF_JOINT_VALUE,
00024 PCS7_MOVING_TO_BROADBASE,
00025 PCS7_MOVING_TO_SLEEPING,
00026 PCS7_DISABLE_JOINT_GAIN,
00027 PCS7_INPUT_PARAMETER,
00028 PCS7_STEP_INPUT
00029 };
00030
00031 enum MovingResult {
00032 MOVING_CONT,
00033 MOVING_FINISH
00034 };
00035
00036 const int HEAD_TILT1 = 0;
00037 const int HEAD_PAN = 1;
00038 const int HEAD_TILT2 = 2;
00039 const int RFLEG_J1 = 3;
00040 const int RFLEG_J2 = 4;
00041 const int RFLEG_J3 = 5;
00042 const int LFLEG_J1 = 6;
00043 const int LFLEG_J2 = 7;
00044 const int LFLEG_J3 = 8;
00045 const int RRLEG_J1 = 9;
00046 const int RRLEG_J2 = 10;
00047 const int RRLEG_J3 = 11;
00048 const int LRLEG_J1 = 12;
00049 const int LRLEG_J2 = 13;
00050 const int LRLEG_J3 = 14;
00051 const int TAIL_TILT = 15;
00052 const int TAIL_PAN = 16;
00053 const int NUM_JOINTS = 17;
00054
00055 static const char* const JOINT_LOCATOR[] = {
00056 "PRM:/r1/c1-Joint2:11",
00057 "PRM:/r1/c1/c2-Joint2:12",
00058 "PRM:/r1/c1/c2/c3-Joint2:13",
00059
00060 "PRM:/r4/c1-Joint2:41",
00061 "PRM:/r4/c1/c2-Joint2:42",
00062 "PRM:/r4/c1/c2/c3-Joint2:43",
00063
00064 "PRM:/r2/c1-Joint2:21",
00065 "PRM:/r2/c1/c2-Joint2:22",
00066 "PRM:/r2/c1/c2/c3-Joint2:23",
00067
00068 "PRM:/r5/c1-Joint2:51",
00069 "PRM:/r5/c1/c2-Joint2:52",
00070 "PRM:/r5/c1/c2/c3-Joint2:53",
00071
00072 "PRM:/r3/c1-Joint2:31",
00073 "PRM:/r3/c1/c2-Joint2:32",
00074 "PRM:/r3/c1/c2/c3-Joint2:33",
00075
00076 "PRM:/r6/c1-Joint2:61",
00077 "PRM:/r6/c2-Joint2:62"
00078 };
00079
00080 const double BROADBASE_ANGLE[] = {
00081 0,
00082 0,
00083 40,
00084
00085 120,
00086 90,
00087 30,
00088
00089 120,
00090 90,
00091 30,
00092
00093 -120,
00094 70,
00095 30,
00096
00097 -120,
00098 70,
00099 30,
00100
00101 0,
00102 0
00103 };
00104
00105 const double SLEEPING_ANGLE[] = {
00106 0,
00107 0,
00108 0,
00109
00110 59,
00111 0,
00112 30,
00113
00114 59,
00115 0,
00116 30,
00117
00118 -119,
00119 4,
00120 122,
00121
00122 -119,
00123 4,
00124 122,
00125
00126 0,
00127 0
00128 };
00129
00130 struct PIDControl7Info {
00131 int jointIndex;
00132 word pgain;
00133 word igain;
00134 word dgain;
00135 int desiredValue;
00136 int effectorCounter;
00137 int sensorCounter;
00138
00139 PIDControl7Info() {
00140 jointIndex = RFLEG_J1;
00141 pgain = 0;
00142 igain = 0;
00143 dgain = 0;
00144 desiredValue = 0;
00145 effectorCounter = 0;
00146 sensorCounter = 0;
00147 }
00148 };
00149
00150 class PIDControl7 : public OObject {
00151 public:
00152 PIDControl7();
00153 virtual ~PIDControl7() {}
00154
00155 OSubject* subject[numOfSubject];
00156 OObserver* observer[numOfObserver];
00157
00158 virtual OStatus DoInit (const OSystemEvent& event);
00159 virtual OStatus DoStart (const OSystemEvent& event);
00160 virtual OStatus DoStop (const OSystemEvent& event);
00161 virtual OStatus DoDestroy(const OSystemEvent& event);
00162
00163 void ReadyEffector(const OReadyEvent& event);
00164 void NotifySensor(const ONotifyEvent& event);
00165
00166 private:
00167 void OpenPrimitives();
00168 void NewCommandVectorData();
00169 void SetJointGain();
00170
00171 MovingResult AdjustDiffJointValue();
00172 MovingResult MoveToBroadBase();
00173 MovingResult MoveToSleeping();
00174
00175 RCRegion* FindFreeRegion();
00176 void SetJointValue(RCRegion* rgn, int idx, double start, double end);
00177 void SetJointValueForStepInput(RCRegion* rgn, int idx, double val);
00178 void InitSensorIndex(OSensorFrameVectorData* sensorVecData);
00179 void DisableJointGainOfAllLegs();
00180 void InputParameter();
00181 MovingResult StepInput();
00182 void SaveLogData();
00183
00184 bool YesNo(const char* prompt);
00185 int InputKey(const char* prompt);
00186
00187 static const size_t NUM_COMMAND_VECTOR = 2;
00188
00189 static const word TILT1_PGAIN = 0x000a;
00190 static const word TILT1_IGAIN = 0x0004;
00191 static const word TILT1_DGAIN = 0x0002;
00192
00193 static const word PAN_PGAIN = 0x0008;
00194 static const word PAN_IGAIN = 0x0002;
00195 static const word PAN_DGAIN = 0x0004;
00196
00197 static const word TILT2_PGAIN = 0x000a;
00198 static const word TILT2_IGAIN = 0x0008;
00199 static const word TILT2_DGAIN = 0x000c;
00200
00201 static const word J1_PGAIN = 0x0010;
00202 static const word J1_IGAIN = 0x0004;
00203 static const word J1_DGAIN = 0x0001;
00204
00205 static const word J2_PGAIN = 0x000a;
00206 static const word J2_IGAIN = 0x0004;
00207 static const word J2_DGAIN = 0x0001;
00208
00209 static const word J3_PGAIN = 0x0010;
00210 static const word J3_IGAIN = 0x0004;
00211 static const word J3_DGAIN = 0x0001;
00212
00213 static const word TAIL_PGAIN = 0x000a;
00214 static const word TAIL_IGAIN = 0x0004;
00215 static const word TAIL_DGAIN = 0x0004;
00216
00217 static const word PSHIFT = 0x000e;
00218 static const word ISHIFT = 0x0002;
00219 static const word DSHIFT = 0x000f;
00220
00221 static const int BROADBASE_MAX_COUNTER = 24;
00222 static const int SLEEPING_MAX_COUNTER = 24;
00223
00224 static const int STEP_INPUT_NUM_FRAMES = 4;
00225 static const int HOLD_TIME_NUM_FRAMES = 256;
00226
00227 PIDControl7State pidControl7State;
00228 PIDControl7Info pidControl7Info;
00229
00230 OPrimitiveID jointID[NUM_JOINTS];
00231 RCRegion* region[NUM_COMMAND_VECTOR];
00232 OJointValue* logData;
00233
00234 bool initSensorIndex;
00235 int sensorIndex[NUM_JOINTS];
00236 };
00237
00238 #endif // PIDControl7_h_DEFINED