00001
00002 #ifndef INCLUDED_DynamicInfo_h
00003 #define INCLUDED_DynamicInfo_h
00004
00005 #include "Shared/CommonInfo.h"
00006 #include <cmath>
00007
00008
00009 #if defined(TGT_DYNAMIC)
00010 # define TGT_IS_DYNAMIC
00011 # define TGT_HAS_WEBCAM 1
00012 #endif
00013
00014
00015 namespace DynamicInfo {
00016
00017 extern const char* TargetName;
00018
00019 const unsigned int FrameTime=32;
00020 const unsigned int NumFrames=1;
00021 const unsigned int SoundBufferTime=32;
00022
00023
00024
00025
00026 extern unsigned NumWheels;
00027
00028 extern unsigned JointsPerArm;
00029 extern unsigned NumArms;
00030 extern unsigned NumArmJoints;
00031
00032 extern unsigned JointsPerLeg;
00033 extern unsigned NumLegs;
00034 extern unsigned NumLegJoints;
00035 extern unsigned NumHeadJoints;
00036 extern unsigned NumTailJoints;
00037 extern unsigned NumMouthJoints;
00038 extern unsigned NumEarJoints;
00039 extern unsigned NumButtons;
00040 extern unsigned NumSensors;
00041 extern unsigned NumLEDs;
00042 extern unsigned NumFacePanelLEDs;
00043
00044 extern unsigned NumPIDJoints;
00045 extern unsigned NumOutputs;
00046 extern unsigned NumReferenceFrames;
00047
00048 using namespace CameraGeneric60;
00049
00050 extern unsigned PIDJointOffset;
00051 extern unsigned LEDOffset;
00052 extern unsigned BaseFrameOffset;
00053
00054
00055 extern std::vector<const char *> buttonNames;
00056
00057
00058 extern std::vector<const char *> sensorNames;
00059
00060
00061 extern std::vector<const char *> outputNames;
00062
00063
00064
00065 class DynamicCapabilities : public RobotInfo::Capabilities {
00066 public:
00067
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) {
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) {
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
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
00164 extern std::vector<DynamicInfoRow<float,3> > DefaultPIDs;
00165
00166
00167
00168
00169
00170
00171
00172
00173 extern std::vector<float> MaxOutputSpeed;
00174
00175
00176 extern std::vector<DynamicInfoRow<float,2> > outputRanges;
00177
00178
00179
00180 extern std::vector<DynamicInfoRow<float,2> > mechanicalLimits;
00181 }
00182
00183
00184
00185
00186
00187
00188 #endif