00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "Representations/Motion/JointDataBuffer.h"
00011 #include "GT2004LEDControl.h"
00012 #include "Tools/Player.h"
00013 #include "Tools/RobotConfiguration.h"
00014 #include "Platform/GTAssert.h"
00015
00016 GT2004LEDControl::GT2004LEDControl(LEDControlInterfaces& interfaces)
00017 : LEDControl(interfaces),
00018 executeCallCount(0), lastMotionFrameNumber(0)
00019 {
00020 }
00021
00022 void GT2004LEDControl::showRequestedHeadLEDs()
00023 {
00024 const int numOfBlinkSequences = 16;
00025 const int lengthOfBlinkSequences = 4;
00026
00027 const int blinkSequences[numOfBlinkSequences][lengthOfBlinkSequences] =
00028 {
00029 {0,0,0,0},{0,0,0,1},{0,0,1,0},{0,0,1,1},
00030 {0,1,0,0},{0,1,0,1},{0,1,1,0},{0,1,1,1},
00031 {1,0,0,0},{1,0,0,1},{1,0,1,0},{1,0,1,1},
00032 {1,1,0,0},{1,1,0,1},{1,1,1,0},{1,1,1,1}
00033 };
00034
00035 int c = (executeCallCount) / 16;
00036 int i;
00037
00038 i = (int)ledRequest.headWhiteLED;
00039 if(i > numOfBlinkSequences) i = 0;
00040 ledCode |= (headWhite * blinkSequences[i][c % lengthOfBlinkSequences]);
00041
00042 i = (int)ledRequest.headOrangeLED;
00043 if(i > numOfBlinkSequences) i = 0;
00044 ledCode |= (headOrange * blinkSequences[i][c % lengthOfBlinkSequences]);
00045 }
00046
00047 void GT2004LEDControl::showRequestedFaceLEDs()
00048 {
00049 const int numOfBlinkSequences = 16;
00050 const int lengthOfBlinkSequences = 4;
00051
00052 const int blinkSequences[numOfBlinkSequences][lengthOfBlinkSequences] =
00053 {
00054 {0,0,0,0},{0,0,0,1},{0,0,1,0},{0,0,1,1},
00055 {0,1,0,0},{0,1,0,1},{0,1,1,0},{0,1,1,1},
00056 {1,0,0,0},{1,0,0,1},{1,0,1,0},{1,0,1,1},
00057 {1,1,0,0},{1,1,0,1},{1,1,1,0},{1,1,1,1}
00058 };
00059
00060 int c = (executeCallCount) / 16;
00061 for(int faceLEDNumber = 1; faceLEDNumber <= 14; faceLEDNumber++)
00062 {
00063 int i = (int)ledRequest.faceLED[faceLEDNumber-1];
00064 if(i > numOfBlinkSequences) i = 0;
00065
00066 int faceLed = (face1 * blinkSequences[i][c % lengthOfBlinkSequences]);
00067 faceLed = faceLed << (faceLEDNumber - 1);
00068 ledCode |= faceLed;
00069 }
00070 }
00071
00072 void GT2004LEDControl::showRequestedBackWhiteLEDs()
00073 {
00074 const int numOfBlinkSequences = 16;
00075 const int lengthOfBlinkSequences = 4;
00076
00077 const int blinkSequences[numOfBlinkSequences][lengthOfBlinkSequences] =
00078 {
00079 {0,0,0,0},{0,0,0,1},{0,0,1,0},{0,0,1,1},
00080 {0,1,0,0},{0,1,0,1},{0,1,1,0},{0,1,1,1},
00081 {1,0,0,0},{1,0,0,1},{1,0,1,0},{1,0,1,1},
00082 {1,1,0,0},{1,1,0,1},{1,1,1,0},{1,1,1,1}
00083 };
00084
00085 int c = (executeCallCount) / 16;
00086 int i;
00087
00088 i = (int)ledRequest.backFrontWhiteLED;
00089 if(i > numOfBlinkSequences) i = 0;
00090 ledCode |= (backFrontWhite * blinkSequences[i][c % lengthOfBlinkSequences]);
00091
00092 i = (int)ledRequest.backMiddleWhiteLED;
00093 if(i > numOfBlinkSequences) i = 0;
00094 ledCode |= (backMiddleWhite * blinkSequences[i][c % lengthOfBlinkSequences]);
00095
00096 i = (int)ledRequest.backRearWhiteLED;
00097 if(i > numOfBlinkSequences) i = 0;
00098 ledCode |= (backRearWhite * blinkSequences[i][c % lengthOfBlinkSequences]);
00099 }
00100
00101 void GT2004LEDControl::showRequestedBackColoredLEDs()
00102 {
00103 const int numOfBlinkSequences = 16;
00104 const int lengthOfBlinkSequences = 4;
00105
00106 const int blinkSequences[numOfBlinkSequences][lengthOfBlinkSequences] =
00107 {
00108 {0,0,0,0},{0,0,0,1},{0,0,1,0},{0,0,1,1},
00109 {0,1,0,0},{0,1,0,1},{0,1,1,0},{0,1,1,1},
00110 {1,0,0,0},{1,0,0,1},{1,0,1,0},{1,0,1,1},
00111 {1,1,0,0},{1,1,0,1},{1,1,1,0},{1,1,1,1}
00112 };
00113
00114 int c = (executeCallCount) / 16;
00115 int i;
00116
00117 i = (int)ledRequest.backFrontBlueLED;
00118 if(i > numOfBlinkSequences) i = 0;
00119 ledCode |= (backFrontBlue * blinkSequences[i][c % lengthOfBlinkSequences]);
00120
00121 i = (int)ledRequest.backMiddleOrangeLED;
00122 if(i > numOfBlinkSequences) i = 0;
00123 ledCode |= (backMiddleOrange * blinkSequences[i][c % lengthOfBlinkSequences]);
00124
00125 i = (int)ledRequest.backRearRedLED;
00126 if(i > numOfBlinkSequences) i = 0;
00127 ledCode |= (backRearRed * blinkSequences[i][c % lengthOfBlinkSequences]);
00128 }
00129
00130
00131
00132 void GT2004LEDControl::showBatteryState()
00133 {
00134 const int numOfBlinkSequences = 2;
00135 const int lengthOfBlinkSequences = 4;
00136 const int blinkSequences[numOfBlinkSequences][lengthOfBlinkSequences] =
00137 {
00138 {1,1,1,1},{0,0,1,1}
00139 };
00140
00141 int battPower = SystemCall::getRemainingPower();
00142
00143 int c = (executeCallCount) / 16;
00144
00145 if (battPower < 25)
00146 ledCode |= (wireless * blinkSequences[0][c % lengthOfBlinkSequences]);
00147 else if (battPower < 15)
00148 ledCode |= (wireless * blinkSequences[1][c % lengthOfBlinkSequences]);
00149 }
00150
00151 void GT2004LEDControl::showWLANStatus()
00152 {
00153
00154 int bits[] = {off, modeRed, modeRed + modeGreen + modeBlue, modeGreen, modeRed + modeGreen + modeBlue};
00155 int wLanCount = 0;
00156 if (wLanStatus & 1) wLanCount++;
00157 if (wLanStatus & 2) wLanCount++;
00158 if (wLanStatus & 4) wLanCount++;
00159 if (wLanStatus & 8) wLanCount++;
00160
00161 ledCode |= bits[wLanCount];
00162 }
00163
00164 void GT2004LEDControl::showCognitionProcessFrameLostWarning()
00165 {
00166 if(ledRequest.showCognitionFrameLostWarning)
00167 {
00168 ledCode |= headWhite;
00169 ledCode |= modeRed;
00170 ledCode |= modeGreen;
00171 ledCode |= modeBlue;
00172 ledCode |= wireless;
00173 ledCode |= face1;
00174 ledCode |= face2;
00175 ledCode |= face3;
00176 ledCode |= face4;
00177 ledCode |= face5;
00178 ledCode |= face6;
00179 ledCode |= face7;
00180 ledCode |= face8;
00181 ledCode |= face9;
00182 ledCode |= face10;
00183 ledCode |= face11;
00184 ledCode |= face12;
00185 ledCode |= face13;
00186 ledCode |= face14;
00187 }
00188 }
00189
00190 void GT2004LEDControl::showMotionProcessFrameLostWarning()
00191 {
00192 if( (frameNumber - lastMotionFrameNumber) != 1 )
00193 {
00194 ledCode |= backFrontBlue;
00195 ledCode |= backFrontWhite;
00196 ledCode |= backMiddleOrange;
00197 ledCode |= backMiddleWhite;
00198 ledCode |= backRearRed;
00199 ledCode |= backRearWhite;
00200 }
00201 lastMotionFrameNumber = frameNumber;
00202 }
00203
00204
00205 void GT2004LEDControl::execute()
00206 {
00207 ledCode = off;
00208
00209 showWLANStatus();
00210 showBatteryState();
00211 showRequestedFaceLEDs();
00212 showRequestedBackWhiteLEDs();
00213 showRequestedBackColoredLEDs();
00214 showRequestedHeadLEDs();
00215
00216 showCognitionProcessFrameLostWarning();
00217 showMotionProcessFrameLostWarning();
00218
00219 executeCallCount++;
00220 ledValue.data[0] = ledCode;
00221 }
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291