00001
00002
00003
00004
00005
00006
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
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166