Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

Tools/RobotConfiguration.cpp

Go to the documentation of this file.
00001 /**
00002 * @file RobotConfiguration.cpp
00003 *
00004 * Implementation of class RobotConfiguration.
00005 * 
00006 * @author Martin Lötzsch
00007 */
00008 
00009 #include "RobotConfiguration.h"
00010 #include "Platform/SystemCall.h"
00011 #include "Tools/Debugging/Debugging.h"
00012 #include "Tools/Debugging/GenericDebugData.h"
00013 #include "Tools/Streams/InStreams.h"
00014 #include "Platform/ProcessFramework.h"
00015 
00016 static RobotConfiguration theRobotConfiguration[ROBOT_MAX];
00017 
00018 RobotConfiguration& getRobotConfiguration()
00019 {
00020   return theRobotConfiguration[PlatformProcess::getRobotIndex()];
00021 }
00022 
00023 RobotConfiguration::RobotConfiguration()
00024 : robotDimensions(RobotDimensionsERS210())
00025 {
00026 }
00027 
00028 void RobotConfiguration::load()
00029 {
00030   robotDesign = SystemCall::getRobotDesign();
00031   if(robotDesign == ERS210)
00032   {
00033     RobotDimensionsERS210 ers210;
00034     memcpy(&robotDimensions, &ers210, sizeof(RobotDimensions));
00035   }
00036   else
00037   {
00038     RobotDimensionsERS7 ers7;
00039     memcpy(&robotDimensions, &ers7, sizeof(RobotDimensions));
00040   }
00041   unsigned char address[6];
00042   SystemCall::getMacAddress(address);
00043   sprintf(macAddressString, "%02X%02X%02X%02X%02X%02X", int(address[0]), int(address[1]), 
00044           int(address[2]), int(address[3]), int(address[4]), int(address[5]));
00045   InConfigFile file("robot.cfg",macAddressString);
00046   if(file.exists() && !file.eof())
00047   {
00048     char ignore[50];
00049     file >> ignore >> robotCalibration.bodyTiltOffset
00050          >> ignore >> robotCalibration.bodyRollOffset
00051          >> ignore >> robotCalibration.headTiltOffset
00052          >> ignore >> robotCalibration.headRollOffset
00053          >> ignore >> robotCalibration.tiltFactor
00054          >> ignore >> robotCalibration.panFactor
00055          >> ignore >> robotCalibration.tilt2Factor;
00056     if(!robotCalibration.tiltFactor)
00057       robotCalibration.tiltFactor = 1;
00058     if(!robotCalibration.panFactor)
00059       robotCalibration.panFactor = 1;
00060     if(!robotCalibration.tilt2Factor)
00061       robotCalibration.tilt2Factor = 1;
00062   }
00063 }
00064 
00065 bool RobotConfiguration::handleMessage(InMessage& message)
00066 {
00067   switch(message.getMessageID())
00068   {
00069     case idBodyOffsets:
00070     {
00071       GenericDebugData d;
00072       message.bin >> d;
00073       robotCalibration.bodyTiltOffset = d.data[0];
00074       robotCalibration.bodyRollOffset = d.data[1];
00075       robotCalibration.headTiltOffset = d.data[2];
00076       robotCalibration.headRollOffset = d.data[3];
00077       robotCalibration.tiltFactor = d.data[4];
00078       robotCalibration.panFactor = d.data[5];
00079       robotCalibration.tilt2Factor = d.data[6];
00080       if(!robotCalibration.tiltFactor)
00081         robotCalibration.tiltFactor = 1;
00082       if(!robotCalibration.panFactor)
00083         robotCalibration.panFactor = 1;
00084       if(!robotCalibration.tilt2Factor)
00085         robotCalibration.tilt2Factor = 1;
00086       return true;
00087     }
00088   }
00089   return false;
00090 }
00091 
00092 In& operator>>(In& stream,RobotConfiguration& robotConfiguration)
00093 {
00094   stream.read(&robotConfiguration,sizeof(RobotConfiguration));
00095   return stream;
00096 }
00097  
00098 Out& operator<<(Out& stream, const RobotConfiguration& robotConfiguration)
00099 {
00100   stream.write(&robotConfiguration,sizeof(RobotConfiguration));
00101   return stream;
00102 }
00103 
00104 
00105 /*
00106 * Change Log:
00107 *
00108 * $Log: RobotConfiguration.cpp,v $
00109 * Revision 1.1.1.1  2004/05/22 17:35:55  cvsadm
00110 * created new repository GT2004_WM
00111 *
00112 * Revision 1.10  2004/03/12 21:59:49  roefer
00113 * Better default values for unspecified values in generic debug request
00114 *
00115 * Revision 1.9  2004/03/08 02:32:20  roefer
00116 * Calibration parameters changed
00117 *
00118 * Revision 1.8  2004/02/29 14:56:03  roefer
00119 * Additional calibration parameters
00120 *
00121 * Revision 1.7  2004/02/24 19:01:06  roefer
00122 * Additional calibration parameters added
00123 *
00124 * Revision 1.6  2004/01/23 00:13:24  roefer
00125 * ERS-7 simulation, first draft
00126 *
00127 * Revision 1.5  2004/01/15 23:20:17  roefer
00128 * RobotDesign detection in simulator
00129 *
00130 * Revision 1.4  2004/01/05 14:47:02  roefer
00131 * Type problem corrected
00132 *
00133 * Revision 1.3  2004/01/01 10:58:52  roefer
00134 * RobotDimensions are in a class now
00135 *
00136 * Revision 1.2  2003/12/31 12:21:25  roefer
00137 * getRobotDesign added
00138 *
00139 * Revision 1.1  2003/10/07 10:13:21  cvsadm
00140 * Created GT2004 (M.J.)
00141 *
00142 * Revision 1.3  2003/09/26 11:40:40  juengel
00143 * - sorted tools
00144 * - clean-up in DataTypes
00145 *
00146 * Revision 1.2  2003/07/05 09:49:05  roefer
00147 * Generic debug message for bodyOffsets improved
00148 *
00149 * Revision 1.1.1.1  2003/07/02 09:40:28  cvsadm
00150 * created new repository for the competitions in Padova from the 
00151 * tamara CVS (Tuesday 2:00 pm)
00152 *
00153 * removed unused solutions
00154 *
00155 * Revision 1.3  2003/05/08 14:55:03  juengel
00156 * Added getMacAddressString().
00157 *
00158 * Revision 1.2  2003/05/05 08:52:17  roefer
00159 * OUTPUT removed
00160 *
00161 * Revision 1.1  2003/05/03 16:20:01  roefer
00162 * robot.cfg added
00163 *
00164 *
00165 */
00166 

Generated on Thu Sep 23 19:57:41 2004 for GT2004 by doxygen 1.3.6