PIDControl.h

Go to the documentation of this file.
00001 //
00002 // Copyright 2002 Sony Corporation 
00003 //
00004 // Permission to use, copy, modify, and redistribute this software for
00005 // non-commercial use is hereby granted.
00006 //
00007 // This software is provided "as is" without warranty of any kind,
00008 // either expressed or implied, including but not limited to the
00009 // implied warranties of fitness for a particular purpose.
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",       // HEAD TILT
00055     "PRM:/r1/c1/c2-Joint2:j2",    // HEAD PAN
00056     "PRM:/r1/c1/c2/c3-Joint2:j3", // HEAD ROLL
00057 
00058     "PRM:/r4/c1-Joint2:j1",       // RFLEG J1 (Right Front Leg)
00059     "PRM:/r4/c1/c2-Joint2:j2",    // RFLEG J2
00060     "PRM:/r4/c1/c2/c3-Joint2:j3", // RFLEG J3
00061 
00062     "PRM:/r2/c1-Joint2:j1",       // LFLEG J1 (Left Front Leg)
00063     "PRM:/r2/c1/c2-Joint2:j2",    // LFLEG J2
00064     "PRM:/r2/c1/c2/c3-Joint2:j3", // LFLEG J3
00065 
00066     "PRM:/r5/c1-Joint2:j1",       // RRLEG J1 (Right Rear Leg)
00067     "PRM:/r5/c1/c2-Joint2:j2",    // RRLEG J2
00068     "PRM:/r5/c1/c2/c3-Joint2:j3", // RRLEG J3
00069 
00070     "PRM:/r3/c1-Joint2:j1",       // LRLEG J1 (Left Rear Leg)
00071     "PRM:/r3/c1/c2-Joint2:j2",    // LRLEG J2
00072     "PRM:/r3/c1/c2/c3-Joint2:j3"  // LRLEG J3
00073 };
00074 
00075 const double BROADBASE_ANGLE[] = {
00076     45,   // TILT
00077     0,    // PAN
00078     0,    // ROLL
00079 
00080     117,  // RFLEG J1
00081     90,   // RFLEG J2
00082     30,   // RFLEG J3
00083 
00084     117,  // LFLEG J1
00085     90,   // LFLEG J2
00086     30,   // LFLEG J3
00087     
00088     -117, // RRLEG J1
00089     70,   // RRLEG J2
00090     30,   // RRLEG J3
00091 
00092     -117, // LRLEG J1
00093     70,   // LRLEG J2
00094     30    // LRLEG J3
00095 };
00096 
00097 const double SLEEPING_ANGLE[] = {
00098     -10,  // TILT
00099     0,    // PAN
00100     0,    // ROLL
00101 
00102     60,   // RFLEG J1
00103     0,    // RFLEG J2
00104     30,   // RFLEG J3
00105 
00106     60,   // LFLEG J1
00107     0,    // LFLEG J2
00108     30,   // LFLEG J3
00109 
00110     -117, // RRLEG J1
00111     0,    // RRLEG J2
00112     147,  // RRLEG J3
00113 
00114     -117, // LRLEG J1
00115     0,    // LRLEG J2
00116     147   // LRLEG J3
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; // 128ms * 48 = 6144ms
00208     static const int SLEEPING_MAX_COUNTER  = 48; // 128ms * 48 = 6144ms
00209 
00210     static const int STEP_INPUT_NUM_FRAMES = 4;
00211     static const int HOLD_TIME_NUM_FRAMES  = 256; // 8ms * 512 = 4096ms
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

Generated on Sun Dec 2 23:04:30 2007 for openSDK by  doxygen 1.3.9.1