00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef PIDControl_h_DEFINED
00013 #define PIDControl_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 PIDControlState {
00021 PCS_IDLE,
00022 PCS_START,
00023 PCS_ADJUSTING_DIFF_JOINT_VALUE,
00024 PCS_MOVING_TO_BROADBASE,
00025 PCS_MOVING_TO_SLEEPING,
00026 PCS_DISABLE_JOINT_GAIN,
00027 PCS_INPUT_PARAMETER,
00028 PCS_STEP_INPUT
00029 };
00030
00031 enum MovingResult {
00032 MOVING_CONT,
00033 MOVING_FINISH
00034 };
00035
00036 const int HEAD_TILT = 0;
00037 const int HEAD_PAN = 1;
00038 const int HEAD_ROLL = 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 NUM_JOINTS = 15;
00052
00053 static const char* const JOINT_LOCATOR[] = {
00054 "PRM:/r1/c1-Joint2:j1",
00055 "PRM:/r1/c1/c2-Joint2:j2",
00056 "PRM:/r1/c1/c2/c3-Joint2:j3",
00057
00058 "PRM:/r4/c1-Joint2:j1",
00059 "PRM:/r4/c1/c2-Joint2:j2",
00060 "PRM:/r4/c1/c2/c3-Joint2:j3",
00061
00062 "PRM:/r2/c1-Joint2:j1",
00063 "PRM:/r2/c1/c2-Joint2:j2",
00064 "PRM:/r2/c1/c2/c3-Joint2:j3",
00065
00066 "PRM:/r5/c1-Joint2:j1",
00067 "PRM:/r5/c1/c2-Joint2:j2",
00068 "PRM:/r5/c1/c2/c3-Joint2:j3",
00069
00070 "PRM:/r3/c1-Joint2:j1",
00071 "PRM:/r3/c1/c2-Joint2:j2",
00072 "PRM:/r3/c1/c2/c3-Joint2:j3"
00073 };
00074
00075 const double BROADBASE_ANGLE[] = {
00076 45,
00077 0,
00078 0,
00079
00080 117,
00081 90,
00082 30,
00083
00084 117,
00085 90,
00086 30,
00087
00088 -117,
00089 70,
00090 30,
00091
00092 -117,
00093 70,
00094 30
00095 };
00096
00097 const double SLEEPING_ANGLE[] = {
00098 -10,
00099 0,
00100 0,
00101
00102 60,
00103 0,
00104 30,
00105
00106 60,
00107 0,
00108 30,
00109
00110 -117,
00111 0,
00112 147,
00113
00114 -117,
00115 0,
00116 147
00117 };
00118
00119 struct PIDControlInfo {
00120 int jointIndex;
00121 word pgain;
00122 word igain;
00123 word dgain;
00124 int desiredValue;
00125 int effectorCounter;
00126 int sensorCounter;
00127
00128 PIDControlInfo() {
00129 jointIndex = RFLEG_J1;
00130 pgain = 0;
00131 igain = 0;
00132 dgain = 0;
00133 desiredValue = 0;
00134 effectorCounter = 0;
00135 sensorCounter = 0;
00136 }
00137 };
00138
00139 class PIDControl : public OObject {
00140 public:
00141 PIDControl();
00142 virtual ~PIDControl() {}
00143
00144 OSubject* subject[numOfSubject];
00145 OObserver* observer[numOfObserver];
00146
00147 virtual OStatus DoInit (const OSystemEvent& event);
00148 virtual OStatus DoStart (const OSystemEvent& event);
00149 virtual OStatus DoStop (const OSystemEvent& event);
00150 virtual OStatus DoDestroy(const OSystemEvent& event);
00151
00152 void ReadyEffector(const OReadyEvent& event);
00153 void NotifySensor(const ONotifyEvent& event);
00154
00155 private:
00156 void OpenPrimitives();
00157 void NewCommandVectorData();
00158 void SetJointGain();
00159
00160 MovingResult AdjustDiffJointValue();
00161 MovingResult MoveToBroadBase();
00162 MovingResult MoveToSleeping();
00163
00164 RCRegion* FindFreeRegion();
00165 void SetJointValue(RCRegion* rgn, int idx, double start, double end);
00166 void SetJointValueForStepInput(RCRegion* rgn, int idx, double val);
00167 void InitSensorIndex(OSensorFrameVectorData* sensorVecData);
00168 void DisableJointGainOfAllLegs();
00169 void InputParameter();
00170 MovingResult StepInput();
00171 void SaveLogData();
00172
00173 bool YesNo(const char* prompt);
00174 int InputKey(const char* prompt);
00175
00176 static const size_t NUM_JOINTS = 15;
00177 static const size_t NUM_COMMAND_VECTOR = 2;
00178
00179 static const word TILT_PGAIN = 0x000a;
00180 static const word TILT_IGAIN = 0x0008;
00181 static const word TILT_DGAIN = 0x000c;
00182
00183 static const word PAN_PGAIN = 0x000d;
00184 static const word PAN_IGAIN = 0x0008;
00185 static const word PAN_DGAIN = 0x000b;
00186
00187 static const word ROLL_PGAIN = 0x000a;
00188 static const word ROLL_IGAIN = 0x0008;
00189 static const word ROLL_DGAIN = 0x000c;
00190
00191 static const word J1_PGAIN = 0x0016;
00192 static const word J1_IGAIN = 0x0004;
00193 static const word J1_DGAIN = 0x0008;
00194
00195 static const word J2_PGAIN = 0x0014;
00196 static const word J2_IGAIN = 0x0004;
00197 static const word J2_DGAIN = 0x0006;
00198
00199 static const word J3_PGAIN = 0x0023;
00200 static const word J3_IGAIN = 0x0004;
00201 static const word J3_DGAIN = 0x0005;
00202
00203 static const word PSHIFT = 0x000e;
00204 static const word ISHIFT = 0x0002;
00205 static const word DSHIFT = 0x000f;
00206
00207 static const int BROADBASE_MAX_COUNTER = 48;
00208 static const int SLEEPING_MAX_COUNTER = 48;
00209
00210 static const int STEP_INPUT_NUM_FRAMES = 4;
00211 static const int HOLD_TIME_NUM_FRAMES = 256;
00212
00213 PIDControlState pidControlState;
00214 PIDControlInfo pidControlInfo;
00215
00216 OPrimitiveID jointID[NUM_JOINTS];
00217 RCRegion* region[NUM_COMMAND_VECTOR];
00218 OJointValue* logData;
00219
00220 bool initSensorIndex;
00221 int sensorIndex[NUM_JOINTS];
00222 };
00223
00224 #endif // PIDControl_h_DEFINED