Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

RobotInfo.cc

Go to the documentation of this file.
00001 #include "RobotInfo.h"
00002 #include <iostream>
00003 
00004 #if defined(TGT_ERS2xx) && defined(PLATFORM_APERIOS)
00005 #  include <OPENR/OPENRAPI.h>
00006 #endif
00007 
00008 // collecting these static allocations here so we don't have to have a separate file for each one
00009 // you can either make a .cc file dedicated to your Info.h, or just add an entry below...
00010 
00011 #include "ERS210Info.h"
00012 namespace ERS210Info {
00013   const char* const TargetName="ERS-210";
00014   ERS210Capabilities capabilities;
00015 }
00016 
00017 #include "ERS220Info.h"
00018 namespace ERS220Info {
00019   const char* const TargetName="ERS-220";
00020   ERS220Capabilities capabilities;
00021 }
00022 
00023 #include "ERS2xxInfo.h"
00024 namespace ERS2xxInfo {
00025   const char* const TargetName="ERS-2xx";
00026   ERS2xxCapabilities capabilities;
00027 }
00028 
00029 #include "ERS7Info.h"
00030 namespace ERS7Info {
00031   const char* const TargetName="ERS-7";
00032   ERS7Capabilities capabilities;
00033 }
00034 
00035 #include "LynxArm6Info.h"
00036 namespace LynxArm6Info {
00037   const char* const TargetName="LynxArm6";
00038   Capabilities capabilities(TargetName,NumOutputs,outputNames,NumButtons,buttonNames,NumSensors,sensorNames,PIDJointOffset,NumPIDJoints,0,0);
00039 }
00040 
00041 #include "Regis1Info.h"
00042 namespace Regis1Info {
00043   const char* const TargetName="Regis1";
00044   Regis1Capabilities capabilities;
00045 }
00046 
00047 #include "QBotPlusInfo.h"
00048 namespace QBotPlusInfo {
00049   const char* const TargetName="QBotPlus";
00050   QBotPlusCapabilities capabilities;
00051 }
00052 
00053 #include "QwerkInfo.h"
00054 namespace QwerkInfo {
00055   const char* const TargetName="Qwerk";
00056   Capabilities capabilities(TargetName,NumOutputs,outputNames,NumButtons,buttonNames,NumSensors,sensorNames,PIDJointOffset,NumPIDJoints,LEDOffset,NumLEDs);
00057 }
00058 
00059 #include "CreateInfo.h"
00060 namespace CreateInfo {
00061   const char* const TargetName="Create";
00062   Capabilities capabilities(TargetName,NumOutputs,outputNames,NumButtons,buttonNames,NumSensors,sensorNames,PIDJointOffset,NumPIDJoints,LEDOffset,NumLEDs);
00063 }
00064 
00065 
00066 // and now for RobotInfo's own stuff:
00067 namespace RobotInfo {
00068   
00069   const char* const detectModel() {
00070 #ifdef TGT_ERS2xx
00071 #  ifdef PLATFORM_APERIOS
00072     // might be running on either 210 or 220, check
00073     char robotDesignStr[orobotdesignNAME_MAX + 1];
00074     memset(robotDesignStr, 0, sizeof(robotDesignStr));
00075     if (OPENR::GetRobotDesign(robotDesignStr) != oSUCCESS) {
00076       std::cout << "OPENR::GetRobotDesign() failed." << std::endl;
00077       return TargetName;
00078     } else {
00079       if(strcmp(robotDesignStr,"ERS-210")==0)
00080         return ERS210Info::TargetName;
00081       else if(strcmp(robotDesignStr,"ERS-220")==0)
00082         return ERS220Info::TargetName;
00083       else {
00084         std::cerr << "ERROR: Unknown name '" << robotDesignStr << "' for target ERS2xx" << std::endl;
00085         return TargetName;
00086       }
00087     }
00088 #  else
00089 #    warning TGT_ERS2xx assuming ERS-210 for simulation on local platform
00090     return ERS210Info::TargetName;
00091 #  endif
00092     
00093 #else
00094     // target is directly the robot, return the target name
00095     return TargetName;
00096 #endif
00097   }
00098   
00099 #ifndef PLATFORM_APERIOS
00100   const char* const RobotName = detectModel();
00101 #else // have to use a string because aperios is annoying like that
00102   const std::string RobotName = detectModel();
00103 #endif
00104   
00105   
00106   Capabilities::Capabilities(const char* robName, size_t numOut, const char * const outNames[], size_t numBut, const char * const butNames[], size_t numSen, const char * const senNames[], size_t pidOff, size_t numPID, size_t ledOff, size_t numLED)
00107     : name(robName), numOutputs(numOut), numButtons(numBut), numSensors(numSen),
00108     outputs(outNames), buttons(butNames), sensors(senNames),
00109     outputToIndex(), buttonToIndex(), sensorToIndex(),
00110     pidJointOffset(pidOff), numPIDJoints(numPID), ledOffset(ledOff), numLEDs(numLED),
00111     fakeOutputs()
00112   {
00113     for(size_t i=0; i<numOutputs; ++i)
00114       outputToIndex[outputs[i]]=i;
00115     for(size_t i=0; i<numButtons; ++i)
00116       buttonToIndex[buttons[i]]=i;
00117     for(size_t i=0; i<numSensors; ++i)
00118       sensorToIndex[sensors[i]]=i;
00119     
00120     std::map<std::string, class Capabilities*>::const_iterator it=getCaps().find(robName);
00121     if(it!=getCaps().end())
00122       std::cerr << "WARNING: RobotInfo '" << robName << "' capabilities has already been registered!  Name conflict?  Replacing previous..." << std::endl;
00123     getCaps()[robName]=this;
00124   }
00125 
00126   std::map<std::string, class Capabilities*>& Capabilities::getCaps() {
00127     static std::map<std::string, class Capabilities*> caps;
00128     return caps;
00129   }
00130   
00131 }

Tekkotsu v4.0
Generated Thu Nov 22 00:54:55 2007 by Doxygen 1.5.4