Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

DynamicInfo.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_DynamicInfo_h
00003 #define INCLUDED_DynamicInfo_h
00004 
00005 #include "Shared/CommonInfo.h"
00006 #include <cmath>
00007 
00008 // see http://tekkotsu.org/porting.html#configuration for more information on TGT_HAS_* flags
00009 #if defined(TGT_DYNAMIC)
00010 # define TGT_IS_DYNAMIC
00011 # define TGT_HAS_WEBCAM 1
00012 #endif
00013 
00014 //! Declares symbols for the 'Dynamic' robot model, used for tools which are model agnostic
00015 namespace DynamicInfo {
00016 
00017   extern const char* TargetName; //!< the name of the model, to be used for logging and remote GUIs
00018 
00019   const unsigned int FrameTime=32;        //!< time between frames in the motion system (milliseconds)
00020   const unsigned int NumFrames=1;        //!< the number of frames per buffer (don't forget also double buffered)
00021   const unsigned int SoundBufferTime=32; //!< the number of milliseconds per sound buffer... I'm not sure if this can be changed
00022   
00023   //!Corresponds to entries in ERS7Info::PrimitiveName, defined at the end of this file, these are the primary grouping
00024   /*!Right now all binary joints are slow, but perhaps this won't always be the case... hence the IsFast/Slow bitmasks to select which type, in order to be more general */
00025   //!@name Output Types Information
00026   extern unsigned NumWheels; //!< no wheels, just legs
00027   
00028   extern unsigned JointsPerArm; //!< no arms, just legs
00029   extern unsigned NumArms; //!< no arms, just legs
00030   extern unsigned NumArmJoints;
00031   
00032   extern unsigned JointsPerLeg; //!< The number of joints per leg
00033   extern unsigned NumLegs; //!< The number of legs
00034   extern unsigned NumLegJoints; //!< the TOTAL number of joints on ALL legs
00035   extern unsigned NumHeadJoints; //!< The number of joints in the neck
00036   extern unsigned NumTailJoints; //!< The number of joints assigned to the tail
00037   extern unsigned NumMouthJoints; //!< the number of joints that control the mouth
00038   extern unsigned NumEarJoints; //!< The number of joints which control the ears (NOT per ear, is total)
00039   extern unsigned NumButtons; //!< the number of buttons that are available, 2 head, 4 paws, 3 back, 1 underbelly see ERS7Info::ButtonOffset_t
00040   extern unsigned NumSensors;  //!< 3 IR (distance), 3 accel (force), 5 from power, see ERS7Info::SensorOffset_t
00041   extern unsigned NumLEDs; //!< The number of LEDs which can be controlled
00042   extern unsigned NumFacePanelLEDs; //!< The number of face panel LEDs
00043   
00044   extern unsigned NumPIDJoints; //!< The number of joints which use PID motion - everything except ears
00045   extern unsigned NumOutputs; //!< the total number of outputs
00046   extern unsigned NumReferenceFrames; //!< for the base, paws (NumLegs), camera, and IR sensors (3) reference frames
00047 
00048   using namespace CameraGeneric60;
00049   
00050   extern unsigned PIDJointOffset; //!< The beginning of the PID Joints
00051   extern unsigned LEDOffset; //!< the offset of LEDs in WorldState::outputs and MotionCommand functions, see LedOffset_t for specific offsets
00052   extern unsigned BaseFrameOffset; //!< Use with kinematics to refer to base reference frame
00053 
00054   //! Name for each button
00055   extern std::vector<const char *> buttonNames;
00056     
00057   //! Provides a string name for each sensor
00058   extern std::vector<const char *> sensorNames;
00059   
00060   //! Names for each of the outputs
00061   extern std::vector<const char *> outputNames;
00062   
00063   
00064   //! provides polymorphic robot capability detection/mapping
00065   class DynamicCapabilities : public RobotInfo::Capabilities {
00066   public:
00067     //! constructor
00068     DynamicCapabilities()
00069     : Capabilities(TargetName,0,NULL,0,NULL,0,NULL,0,0,0,0,0),
00070     memoization(true)
00071     {}
00072     
00073     DynamicCapabilities& operator=(const Capabilities& cap) {
00074       Capabilities::operator=(cap);
00075       TargetName=name;
00076       PIDJointOffset=pidJointOffset;
00077       NumPIDJoints=numPIDJoints;
00078       LEDOffset=ledOffset;
00079       NumLEDs=numLEDs;
00080       NumOutputs=numOutputs;
00081       
00082       NumReferenceFrames=frames.size();
00083       NumButtons=buttons.size();
00084       NumSensors=sensors.size();
00085       return *this;
00086     }
00087 
00088     inline unsigned int getOutputOffset(const std::string& out) {
00089       if(memoization) {
00090         unsigned pre = NumReferenceFrames;
00091         unsigned int i = memoLookup(frames,frameToIndex,NumReferenceFrames,out);
00092         if(pre!=NumReferenceFrames)
00093           numOutputs=NumOutputs=NumReferenceFrames;
00094         return i;
00095       } else {
00096         return lookupT("output",frameToIndex,out);
00097       }
00098     }
00099     inline unsigned int getFrameOffset(const std::string& frame) {
00100       if(memoization) { // assume all frames are also outputs since we can't tell
00101         unsigned pre = NumReferenceFrames;
00102         unsigned int i = memoLookup(frames,frameToIndex,NumReferenceFrames,frame);
00103         if(pre!=NumReferenceFrames)
00104           numOutputs=NumOutputs=NumReferenceFrames;
00105         return i;
00106       } else {
00107         return lookupT("frame",frameToIndex,frame);
00108       }
00109     }
00110     inline unsigned int getButtonOffset(const std::string& but) { return memoization ? memoLookup(buttons,buttonToIndex,NumButtons,but) : lookupT("button",buttonToIndex,but); }
00111     inline unsigned int getSensorOffset(const std::string& sen) { return memoization ? memoLookup(sensors,sensorToIndex,NumSensors,sen) : lookupT("sensor",sensorToIndex,sen); }
00112     
00113     inline unsigned int findOutputOffset(const std::string& out) {
00114       if(memoization) {
00115         unsigned pre = NumReferenceFrames;
00116         unsigned int i = memoLookup(frames,frameToIndex,NumReferenceFrames,out);
00117         if(pre!=NumReferenceFrames)
00118           numOutputs=NumOutputs=NumReferenceFrames;
00119         return i;
00120       } else {
00121         return lookup(frameToIndex,out);
00122       }
00123     }
00124     inline unsigned int findFrameOffset(const std::string& frame) {
00125       if(memoization) { // assume all frames are also outputs since we can't tell
00126         unsigned pre = NumReferenceFrames;
00127         unsigned int i = memoLookup(frames,frameToIndex,NumReferenceFrames,frame);
00128         if(pre!=NumReferenceFrames)
00129           numOutputs=NumOutputs=NumReferenceFrames;
00130         return i;
00131       } else {
00132         return lookup(frameToIndex,frame);
00133       }
00134     }
00135     inline unsigned int findButtonOffset(const std::string& but) { return memoization ? memoLookup(buttons,buttonToIndex,NumButtons,but) : lookup(buttonToIndex,but); }
00136     inline unsigned int findSensorOffset(const std::string& sen) { return memoization ? memoLookup(sensors,sensorToIndex,NumSensors,sen) : lookup(sensorToIndex,sen); }
00137     
00138     void enableMemoization(bool b) { memoization=b; }
00139     bool isMemoizing() const { return memoization; }
00140     
00141   protected:
00142     inline unsigned int memoLookup(std::vector<std::string>& idxToName, std::map<std::string,unsigned int>& nameToIndex, unsigned& dim, const std::string& capname) {
00143       std::map<std::string,unsigned int>::const_iterator it=nameToIndex.find(capname);
00144       if(it!=nameToIndex.end())
00145         return it->second;
00146       idxToName.push_back(capname);
00147       dim=idxToName.size();
00148       nameToIndex.insert(std::pair<std::string,unsigned int>(capname,dim-1));
00149       return dim-1;
00150     }
00151     
00152     bool memoization;
00153   };
00154   extern DynamicCapabilities capabilities;
00155   
00156   //! provides 2D array of constant width
00157   template<typename T, size_t N>
00158   struct DynamicInfoRow {
00159     T pid[N];
00160     T operator[](int i) { return pid[i]; }
00161   };
00162   
00163   //! This table holds the default PID values for each joint.  see PIDMC
00164   extern std::vector<DynamicInfoRow<float,3> > DefaultPIDs;
00165     
00166   //!These values are Sony's recommended maximum joint velocities, in rad/sec
00167   /*! a value <= 0 means infinite speed (e.g. LEDs)
00168    *  
00169    *  These limits are <b>not</b> enforced by the framework.  They are simply available for you to use as you see fit.
00170    *  HeadPointerMC and PostureMC are primary examples of included classes which do respect these values (although they can be overridden)
00171    *  
00172    *  These values were obtained from the administrators of the Sony OPEN-R BBS */
00173   extern std::vector<float> MaxOutputSpeed;
00174 
00175   //! This table holds the software limits of each of the outputs, first index is the output offset, second index is MinMaxRange_t (i.e. MinRange or MaxRange)
00176   extern std::vector<DynamicInfoRow<float,2> > outputRanges;
00177 
00178   //! This table holds the mechanical limits of each of the outputs, first index is the output offset, second index is MinMaxRange_t (i.e. MinRange or MaxRange)
00179   /*! Same as #outputRanges, don't know actual values because they were never specified by Sony */
00180   extern std::vector<DynamicInfoRow<float,2> > mechanicalLimits;
00181 }
00182   
00183 /*! @file
00184  * @brief Defines RobotInfo namespace for 'dynamic' models, gives some information about the robot's capabilities, such as joint counts, offsets, names and PID values
00185  * @author ejt (Creator)
00186  */
00187 
00188 #endif

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:37 2016 by Doxygen 1.6.3