MovingLegs/MovingLegs/MovingLegs.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 MovingLegs_h_DEFINED
00013 #define MovingLegs_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 MovingLegsState {
00021     MLS_IDLE,
00022     MLS_START,
00023     MLS_ADJUSTING_DIFF_JOINT_VALUE,
00024     MLS_MOVING_TO_BROADBASE,
00025     MLS_MOVING_TO_SLEEPING
00026 };
00027 
00028 enum MovingResult {
00029     MOVING_CONT,
00030     MOVING_FINISH
00031 };
00032 
00033 static const char* const JOINT_LOCATOR[] = {
00034     "PRM:/r4/c1-Joint2:j1",       // RFLEG J1 (Right Front Leg)
00035     "PRM:/r4/c1/c2-Joint2:j2",    // RFLEG J2
00036     "PRM:/r4/c1/c2/c3-Joint2:j3", // RFLEG J3
00037 
00038     "PRM:/r2/c1-Joint2:j1",       // LFLEG J1 (Left Front Leg)
00039     "PRM:/r2/c1/c2-Joint2:j2",    // LFLEG J2
00040     "PRM:/r2/c1/c2/c3-Joint2:j3", // LFLEG J3
00041 
00042     "PRM:/r5/c1-Joint2:j1",       // RRLEG J1 (Right Rear Leg)
00043     "PRM:/r5/c1/c2-Joint2:j2",    // RRLEG J2
00044     "PRM:/r5/c1/c2/c3-Joint2:j3", // RRLEG J3
00045 
00046     "PRM:/r3/c1-Joint2:j1",       // LRLEG J1 (Left Rear Leg)
00047     "PRM:/r3/c1/c2-Joint2:j2",    // LRLEG J2
00048     "PRM:/r3/c1/c2/c3-Joint2:j3"  // LRLEG J3
00049 };
00050 
00051 const double BROADBASE_ANGLE[] = {
00052     117,  // RFLEG J1
00053     90,   // RFLEG J2
00054     30,   // RFLEG J3
00055 
00056     117,  // LFLEG J1
00057     90,   // LFLEG J2
00058     30,   // LFLEG J3
00059     
00060     -117, // RRLEG J1
00061     70,   // RRLEG J2
00062     30,   // RRLEG J3
00063 
00064     -117, // LRLEG J1
00065     70,   // LRLEG J2
00066     30    // LRLEG J3
00067 };
00068 
00069 const double SLEEPING_ANGLE[] = {
00070     60,   // RFLEG J1
00071     0,    // RFLEG J2
00072     30,   // RFLEG J3
00073 
00074     60,   // LFLEG J1
00075     0,    // LFLEG J2
00076     30,   // LFLEG J3
00077 
00078     -117, // RRLEG J1
00079     0,    // RRLEG J2
00080     147,  // RRLEG J3
00081 
00082     -117, // LRLEG J1
00083     0,    // LRLEG J2
00084     147   // LRLEG J3
00085 };
00086 
00087 class MovingLegs : public OObject {
00088 public:
00089     MovingLegs();
00090     virtual ~MovingLegs() {}
00091 
00092     OSubject*  subject[numOfSubject];
00093     OObserver* observer[numOfObserver];
00094 
00095     virtual OStatus DoInit   (const OSystemEvent& event);
00096     virtual OStatus DoStart  (const OSystemEvent& event);
00097     virtual OStatus DoStop   (const OSystemEvent& event);
00098     virtual OStatus DoDestroy(const OSystemEvent& event);
00099     
00100     void Ready(const OReadyEvent& event);
00101 
00102 private:
00103     void          OpenPrimitives();
00104     void          NewCommandVectorData();
00105     void          SetJointGain();
00106     MovingResult  AdjustDiffJointValue();
00107     MovingResult  MoveToBroadBase();
00108     MovingResult  MoveToSleeping();
00109 
00110     RCRegion* FindFreeRegion();
00111     void SetJointValue(RCRegion* rgn, int idx, double start, double end);
00112 
00113     static const size_t NUM_JOINTS         = 12;
00114     static const size_t NUM_COMMAND_VECTOR = 2;
00115 
00116     static const word   J1_PGAIN = 0x0016;
00117     static const word   J1_IGAIN = 0x0004;
00118     static const word   J1_DGAIN = 0x0008;
00119 
00120     static const word   J2_PGAIN = 0x0014;
00121     static const word   J2_IGAIN = 0x0004;
00122     static const word   J2_DGAIN = 0x0006;
00123 
00124     static const word   J3_PGAIN = 0x0023;
00125     static const word   J3_IGAIN = 0x0004;
00126     static const word   J3_DGAIN = 0x0005;
00127 
00128     static const word   PSHIFT   = 0x000e;
00129     static const word   ISHIFT   = 0x0002;
00130     static const word   DSHIFT   = 0x000f;
00131 
00132     static const int BROADBASE_MAX_COUNTER = 48; // 128ms * 48 = 6144ms
00133     static const int SLEEPING_MAX_COUNTER  = 48; // 128ms * 48 = 6144ms
00134     
00135     MovingLegsState  movingLegsState;
00136     OPrimitiveID     jointID[NUM_JOINTS];
00137     RCRegion*        region[NUM_COMMAND_VECTOR];
00138 };
00139 
00140 #endif // MovingLegs_h_DEFINED

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