PIDControl7.h

Go to the documentation of this file.
00001 //
00002 // Copyright 2002,2004 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 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",       // HEAD TILT1
00057     "PRM:/r1/c1/c2-Joint2:12",    // HEAD PAN
00058     "PRM:/r1/c1/c2/c3-Joint2:13", // HEAD TILT2
00059 
00060     "PRM:/r4/c1-Joint2:41",       // RFLEG J1 (Right Front Leg)
00061     "PRM:/r4/c1/c2-Joint2:42",    // RFLEG J2
00062     "PRM:/r4/c1/c2/c3-Joint2:43", // RFLEG J3
00063 
00064     "PRM:/r2/c1-Joint2:21",       // LFLEG J1 (Left Front Leg)
00065     "PRM:/r2/c1/c2-Joint2:22",    // LFLEG J2
00066     "PRM:/r2/c1/c2/c3-Joint2:23", // LFLEG J3
00067 
00068     "PRM:/r5/c1-Joint2:51",       // RRLEG J1 (Right Rear Leg)
00069     "PRM:/r5/c1/c2-Joint2:52",    // RRLEG J2
00070     "PRM:/r5/c1/c2/c3-Joint2:53", // RRLEG J3
00071 
00072     "PRM:/r3/c1-Joint2:31",       // LRLEG J1 (Left Rear Leg)
00073     "PRM:/r3/c1/c2-Joint2:32",    // LRLEG J2
00074     "PRM:/r3/c1/c2/c3-Joint2:33", // LRLEG J3
00075 
00076     "PRM:/r6/c1-Joint2:61",       // TAIL TILT
00077     "PRM:/r6/c2-Joint2:62"        // TAIL PAN
00078 };
00079 
00080 const double BROADBASE_ANGLE[] = {
00081     0,    // TILT1
00082     0,    // PAN
00083     40,   // TILT2
00084 
00085     120,  // RFLEG J1
00086     90,   // RFLEG J2
00087     30,   // RFLEG J3
00088 
00089     120,  // LFLEG J1
00090     90,   // LFLEG J2
00091     30,   // LFLEG J3
00092     
00093     -120, // RRLEG J1
00094     70,   // RRLEG J2
00095     30,   // RRLEG J3
00096 
00097     -120, // LRLEG J1
00098     70,   // LRLEG J2
00099     30,   // LRLEG J3
00100 
00101     0,    // TAIL_TILT
00102     0     // TAIL_PAN
00103 };
00104 
00105 const double SLEEPING_ANGLE[] = {
00106     0,    // TILT1
00107     0,    // PAN
00108     0,    // TILT2
00109 
00110     59,   // RFLEG J1
00111     0,    // RFLEG J2
00112     30,   // RFLEG J3
00113 
00114     59,   // LFLEG J1
00115     0,    // LFLEG J2
00116     30,   // LFLEG J3
00117 
00118     -119, // RRLEG J1
00119     4,    // RRLEG J2
00120     122,  // RRLEG J3
00121 
00122     -119, // LRLEG J1
00123     4,    // LRLEG J2
00124     122,  // LRLEG J3
00125 
00126     0,    // TAIL_TILT
00127     0     // TAIL_PAN
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; // 128ms * 24 = 3072ms
00222     static const int SLEEPING_MAX_COUNTER  = 24; // 128ms * 24 = 3072ms
00223 
00224     static const int STEP_INPUT_NUM_FRAMES = 4;
00225     static const int HOLD_TIME_NUM_FRAMES  = 256; // 8ms * 512 = 4096ms
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

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