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

Modules/LEDControl/GT2004LEDControl.cpp

Go to the documentation of this file.
00001 /**
00002 * @file GT2004LEDControl.cpp
00003 * 
00004 * This file contains a class for LED Control.
00005 * @author Matthias Jüngel
00006 * @author Max Risler
00007 * @author Michael Wachter
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 * Change log :
00225 * 
00226 * $Log: GT2004LEDControl.cpp,v $
00227 * Revision 1.5  2004/06/29 09:23:38  petters
00228 * removed yellow from WLan Led Status
00229 *
00230 * Revision 1.4  2004/06/20 10:30:40  juengel
00231 * Removed orange from frame-lost warning.
00232 *
00233 * Revision 1.3  2004/06/15 17:49:06  juengel
00234 * Added showMotionProcessFrameLostWarning() and showCognitionProcessFrameLostWarning.
00235 *
00236 * Revision 1.2  2004/06/09 07:46:34  juengel
00237 * Added showFrameLostWarning().
00238 *
00239 * Revision 1.1  2004/05/22 22:16:10  loetzsch
00240 * renamed ATH2004LEDControl to GT2004LEDControl
00241 *
00242 * Revision 1.1.1.1  2004/05/22 17:20:14  cvsadm
00243 * created new repository GT2004_WM
00244 *
00245 * Revision 1.9  2004/05/14 14:12:07  wachter
00246 * - Added communication support for 5 robots
00247 * - rewrote parts of team-communication to be faster and more stable
00248 *
00249 * Revision 1.8  2004/04/07 12:28:56  risler
00250 * ddd checkin after go04 - first part
00251 *
00252 * Revision 1.2  2004/03/31 00:10:37  risler
00253 * bugfix battery led now blinks as intended
00254 *
00255 * Revision 1.1.1.1  2004/03/29 08:28:47  Administrator
00256 * initial transfer from tamara
00257 *
00258 * Revision 1.7  2004/03/25 21:20:31  juengel
00259 * Added head LEDs.
00260 *
00261 * Revision 1.6  2004/03/25 19:50:25  juengel
00262 * initialLedCodes are not used any more
00263 *
00264 * Revision 1.5  2004/03/25 17:39:17  loetzsch
00265 * renamed initial-setup-mode to back-mode
00266 *
00267 * Revision 1.4  2004/03/21 19:08:16  juengel
00268 * Added back*White LED support.
00269 *
00270 * Revision 1.3  2004/03/20 19:24:07  juengel
00271 * Added face LEDs to LEDRequest
00272 *
00273 * Revision 1.2  2004/03/20 17:17:58  juengel
00274 * no message
00275 *
00276 * Revision 1.1  2004/03/16 14:00:21  juengel
00277 * Integrated Improvments from "Günne"
00278 * -ATH2004ERS7Behavior
00279 * -ATHHeadControl
00280 * -KickSelectionTable
00281 * -KickEditor
00282 *
00283 * Revision 1.1  2004/03/15 17:11:39  hoffmann
00284 * - added ATH2004HeadControl
00285 * - added ATH2004LEDControl
00286 * - headmotiontester shows "tilt2"
00287 * - motion process updates odometry while no new robotPose is received, added to motion request
00288 * - some ui adjustments
00289 * - added member function to "field" to find out if robot is in own penalty area for use in the obstacles locator
00290 *
00291 */

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