Alexandre Salconi-Denis / Mbed 2 deprecated ProjetOctopode

Dependencies:   debug mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers directive.cpp Source File

directive.cpp

00001 
00002 #include "directive.h"
00003 
00004 Serial pc(SERIAL_TX, SERIAL_RX);
00005 int tabIR[12][2]= {
00006     {80, 400},{50, 600},{40, 700},{30, 900},{25,1100},
00007     {20,1300},{15,1600},{10,2400},{ 8,2700},{ 7,3000},
00008     { 6,3200},{ 5,3100}
00009 };
00010 
00011 
00012 
00013 
00014 
00015 
00016 Directive::Directive():TTask(0)//on veux que cette tache sois exec toute les fois que TTaskGen sexecute.
00017 {
00018     
00019     /* initialize random seed: */
00020     srand (time(NULL));
00021     myMaze = new Labyrinthe();
00022     
00023     myMaze->setDirection(UP);
00024     //c=0;
00025     ssc32 = new Serial(PB_6, PB_7);
00026     ctrDesPattes = new Faculter_motrice(ssc32/*pc*/);
00027     m_valueCapteurUltrasonic = 0;
00028     m_valueCapteurIR = 0;
00029     m_valueCapteurProximiter = 0;
00030     for(int i =0; i < DIRECTIVE_TABLEAUDECOMMANDE_SIZE; i++)tableauDeCommange[i]= 0;
00031     size_tableauDeCommange=0;
00032     debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r set explorer \n\r");
00033     myMaze->setMyPos(Labyrinthe::explorer);
00034     //myMaze->setC(EXPLORER,C5);
00035     //m_CtrlBridge = m_CtrlBridge->getInstance();
00036     //a enlever de commentaire//m_ListDesModules = m_CtrlBridge->findModule(0,1,0,0);
00037     
00038     //Serial pc(USBTX, USBRX);
00039     
00040     //ssc32->set_flow_control(0);
00041     
00042     
00043     //debug("\n\r directive Init");
00044     m_ListDesModules = m_CtrlBridge->findModule(0,CAPTEUR,DISTANCE,0);
00045     m_ListDesModules.append(m_CtrlBridge->findModule(0,CAPTEUR,PROXIMITEE,0));
00046     for(int i=0; i < m_ListDesModules.size(); i++) debug(DEBUG_DIRECTIVE_TEST,"\n\r  m_ListDesModules[%i]:%i",i,m_ListDesModules[i]);
00047     
00048     m_capteurUltrasonic= m_CtrlBridge->findModule(0,CAPTEUR,ULTRASONIQUE,0x27/*0b100111*/);
00049     if(!(m_capteurUltrasonic.empty())) 
00050     {
00051         debug(DEBUG_DIRECTIVE_TEST,"\n\r m_capteurUltrasonic found");
00052         for(int i=0; i < m_capteurUltrasonic.size(); i++) debug(DEBUG_DIRECTIVE_TEST,"\n\r  m_capteurUltrasonic[%i]:%i",i,m_capteurUltrasonic[i]);
00053     }
00054     else                               debug(DEBUG_DIRECTIVE_TEST,"\n\r m_capteurUltrasonic not found");
00055     
00056     
00057     m_capteurIR= m_CtrlBridge->findModule(0,CAPTEUR,DISTANCE,0x27/*0b100111*/);
00058     if(!(m_capteurIR.empty()))
00059     {
00060         debug(DEBUG_DIRECTIVE_TEST,"\n\r m_capteurIR found");
00061         for(int i=0; i < m_capteurIR.size(); i++) debug(DEBUG_DIRECTIVE_TEST,"\n\r  m_capteurIR[%i]:%i",i,m_capteurIR[i]);
00062     }
00063     else debug(DEBUG_DIRECTIVE_TEST,"\n\r m_capteurIR not found");
00064     
00065     m_capteurProximiter= m_CtrlBridge->findModule(0,CAPTEUR,PROXIMITEE,0x0E/*0b001110*/);
00066     if(!(m_capteurProximiter.empty()))
00067     {
00068         debug(DEBUG_DIRECTIVE_TEST,"\n\r m_capteurProximiter found");
00069         for(int i=0; i < m_capteurProximiter.size(); i++) debug(DEBUG_DIRECTIVE_TEST,"\n\r  m_capteurProximiter[%i]:%i",i,m_capteurProximiter[i]);
00070     }
00071     else debug(DEBUG_DIRECTIVE_TEST,"\n\r m_capteurProximiter not found");
00072     
00073     ctrDesPattes->moveUp();
00074     
00075     bool getUp=true;
00076     while((getUp)&& (! ctrDesPattes->isSeqComplet())) 
00077     {
00078         ctrDesPattes->exec();
00079         
00080         if(ctrDesPattes->get_idFrame() >= 5)
00081         getUp = false;
00082         
00083     }
00084     
00085     followThePath = false;
00086     ctrDesPattes->calibre();
00087     
00088     
00089     #ifdef DEBUG_DIRECTIVE_GRAPHICAL_INTERFACE
00090         //analiseMaze();
00091         ///wait(2);
00092         //debug("\x1B[2J"); //clear screen
00093         /*debug("\x1B[25l");//hide cursor
00094         debug("\x1B[;H");*/ //cursor default position
00095         
00096         //createSLbox(0,0,5,15,"Mode");
00097         /*createDLbox(0,0,10,20,"Menu");//(1,12,10,20,"test2");
00098             setText(1,3,"1) BrainControle");
00099         setText(1,4,"2) Show Maze");*/
00100         //createDLbox(16,0,5,15,"Stage");
00101         
00102         myMaze->setC(Labyrinthe::mur,0,0,Labyrinthe::C1);
00103         myMaze->setC(Labyrinthe::vide,0,0,Labyrinthe::C2);
00104         myMaze->setC(Labyrinthe::mur,0,0,Labyrinthe::C3);
00105         myMaze->setC(Labyrinthe::mur,0,0,Labyrinthe::C4);
00106         myMaze->setC(Labyrinthe::vide,0,0,Labyrinthe::C5);
00107         myMaze->setC(Labyrinthe::vide,0,0,Labyrinthe::C6);
00108         myMaze->setC(Labyrinthe::mur,0,0,Labyrinthe::C7);
00109         myMaze->setC(Labyrinthe::mur,0,0,Labyrinthe::C8);
00110         myMaze->setC(Labyrinthe::mur,0,0,Labyrinthe::C9);
00111         
00112         myMaze->setC(Labyrinthe::vide,3,0,Labyrinthe::C1);
00113         myMaze->setC(Labyrinthe::vide,3,0,Labyrinthe::C2);
00114         myMaze->setC(Labyrinthe::mur ,3,0,Labyrinthe::C3);
00115         myMaze->setC(Labyrinthe::vide,3,0,Labyrinthe::C4);
00116         myMaze->setC(Labyrinthe::vide,3,0,Labyrinthe::C5);
00117         myMaze->setC(Labyrinthe::vide,3,0,Labyrinthe::C6);
00118         myMaze->setC(Labyrinthe::mur ,3,0,Labyrinthe::C7);
00119         myMaze->setC(Labyrinthe::mur ,3,0,Labyrinthe::C8);
00120         myMaze->setC(Labyrinthe::mur ,3,0,Labyrinthe::C9);
00121         
00122         myMaze->setC(Labyrinthe::vide,6,0,Labyrinthe::C1);
00123         myMaze->setC(Labyrinthe::mur ,6,0,Labyrinthe::C2);
00124         myMaze->setC(Labyrinthe::mur ,6,0,Labyrinthe::C3);
00125         myMaze->setC(Labyrinthe::vide,6,0,Labyrinthe::C4);
00126         myMaze->setC(Labyrinthe::vide,6,0,Labyrinthe::C5);
00127         myMaze->setC(Labyrinthe::mur ,6,0,Labyrinthe::C6);
00128         myMaze->setC(Labyrinthe::mur ,6,0,Labyrinthe::C7);
00129         myMaze->setC(Labyrinthe::mur ,6,0,Labyrinthe::C8);
00130         myMaze->setC(Labyrinthe::mur ,6,0,Labyrinthe::C9);
00131         
00132         myMaze->setC(Labyrinthe::mur ,0,-3,Labyrinthe::C1);
00133         myMaze->setC(Labyrinthe::mur ,0,-3,Labyrinthe::C2);
00134         myMaze->setC(Labyrinthe::mur ,0,-3,Labyrinthe::C3);
00135         myMaze->setC(Labyrinthe::mur ,0,-3,Labyrinthe::C4);
00136         myMaze->setC(Labyrinthe::vide,0,-3,Labyrinthe::C5);
00137         myMaze->setC(Labyrinthe::mur ,0,-3,Labyrinthe::C6);
00138         myMaze->setC(Labyrinthe::mur ,0,-3,Labyrinthe::C7);
00139         myMaze->setC(Labyrinthe::vide,0,-3,Labyrinthe::C8);
00140         myMaze->setC(Labyrinthe::vide,0,-3,Labyrinthe::C9);
00141         
00142         myMaze->setC(Labyrinthe::mur ,3,-3,Labyrinthe::C1);
00143         myMaze->setC(Labyrinthe::mur ,3,-3,Labyrinthe::C2);
00144         myMaze->setC(Labyrinthe::mur ,3,-3,Labyrinthe::C3);
00145         myMaze->setC(Labyrinthe::vide,3,-3,Labyrinthe::C4);
00146         myMaze->setC(Labyrinthe::vide,3,-3,Labyrinthe::C5);
00147         myMaze->setC(Labyrinthe::vide,3,-3,Labyrinthe::C6);
00148         myMaze->setC(Labyrinthe::vide,3,-3,Labyrinthe::C7);
00149         myMaze->setC(Labyrinthe::mur ,3,-3,Labyrinthe::C8);
00150         myMaze->setC(Labyrinthe::vide,3,-3,Labyrinthe::C9);
00151         
00152         myMaze->setC(Labyrinthe::mur ,6,-3,Labyrinthe::C1);
00153         myMaze->setC(Labyrinthe::mur ,6,-3,Labyrinthe::C2);
00154         myMaze->setC(Labyrinthe::mur ,6,-3,Labyrinthe::C3);
00155         myMaze->setC(Labyrinthe::vide,6,-3,Labyrinthe::C4);
00156         myMaze->setC(Labyrinthe::mur ,6,-3,Labyrinthe::C5);
00157         myMaze->setC(Labyrinthe::mur ,6,-3,Labyrinthe::C6);
00158         myMaze->setC(Labyrinthe::vide,6,-3,Labyrinthe::C7);
00159         myMaze->setC(Labyrinthe::vide,6,-3,Labyrinthe::C8);
00160         myMaze->setC(Labyrinthe::mur ,6,-3,Labyrinthe::C9);
00161     #endif
00162     myMaze->setMyPos(Labyrinthe::explorer);
00163     
00164     #ifdef DEBUG_DIRECTIVE_TEST_CAPTEUR
00165     debug("\x1B[2J"); //clear screen
00166     char areaLatt =0;
00167     char areaVert =0;
00168     int idCommand = 0;
00169     while(idCommand != 9)
00170     {
00171         
00172          
00173              debug("\n\r press any key");
00174             idCommand = fgetc(pc) - '0';
00175             debug("\x1B[;H"); //cursor default position
00176         debug("\x1B[2J"); //clear screen
00177         
00178         updateModuleValue();
00179                 
00180         //////////////////////////////
00181         // Traitement du Labyrinthe //
00182         //////////////////////////////
00183         debug("\n\r        -invert ultrasonicToCm: %02f         ",inchToCm(ultrasonicToInch(m_valueCapteurIR)));
00184         debug("\n\r        -invert IRToCm(%02f): %02f         ",ADCTomv(m_valueCapteurUltrasonic),IRToCm(ADCTomv(m_valueCapteurUltrasonic)));
00185         //debug("\n\r        -IR(value):%i         ",m_valueCapteurIR);
00186         debug("\n\r        -IRToCm(%02f): %02f         ",ADCTomv(m_valueCapteurIR),IRToCm(ADCTomv(m_valueCapteurIR)));
00187         
00188         debug("\n\r        -ultrasonic(value):%f         ",m_valueCapteurUltrasonic);
00189         debug("\n\r        -ultrasonicToInch: %02f         ",ultrasonicToInch(m_valueCapteurUltrasonic));
00190         debug("\n\r        -ultrasonicToCm: %02f         ",inchToCm(ultrasonicToInch(m_valueCapteurUltrasonic)));
00191         
00192         debug("\n\r        -m_valueCapteurProximiter: %02d         ",m_valueCapteurProximiter);
00193         //wait(.5);
00194                 
00195                 
00196         if((inchToCm(ultrasonicToInch(m_valueCapteurUltrasonic))<= 1) /*&& (IRToCm(ADCTomv(m_valueCapteurIR)) <= 80)*/)//enlever parce que il est lock avec des limites 
00197         { //capteur ultrasson embrouiller/imprecis
00198             debug("\n\r        -Capteur Ultrasson brouiller");
00199             //addTableauDeCommande(6);
00200         } 
00201         else if(inchToCm(ultrasonicToInch(m_valueCapteurUltrasonic)) <= DIRECTIVE_ULTRASONIC_LIMIT_SHORT)
00202         { //plus proche que 1 case
00203             debug("\n\r        -Objet proche %g <= %i cm",inchToCm(ultrasonicToInch(m_valueCapteurUltrasonic)),DIRECTIVE_ULTRASONIC_LIMIT_SHORT);
00204             
00205             areaLatt =0;
00206             
00207             if(IRToCm(ADCTomv(m_valueCapteurIR)) <= DIRECTIVE_IR_LIMIT_SHORT)
00208             {
00209                 /*
00210                     /---\
00211                     |?M?| //vert 0
00212                     |.X.| //latt 0
00213                     |...|
00214                     \---/
00215                 */
00216                 areaVert = 0;
00217             }
00218             else
00219             {
00220                 /*
00221                     /-M-\
00222                     |?V?| //vert 1
00223                     |.X.| //latt 0
00224                     |...|
00225                     \---/
00226                 */
00227                 areaVert = 1;
00228             }
00229             
00230             
00231         }
00232         else if(inchToCm(ultrasonicToInch(m_valueCapteurUltrasonic)) <= DIRECTIVE_ULTRASONIC_LIMIT_MIDDLE)
00233         { //plus proche que 2 case
00234              debug("\n\r        -Objet proche %g <= %i cm",inchToCm(ultrasonicToInch(m_valueCapteurUltrasonic)),DIRECTIVE_ULTRASONIC_LIMIT_MIDDLE);
00235             //modifier vue que il ne detecte pas asser loin
00236                     /*
00237                     /-M-\
00238                     |?V?| //vert 1
00239                     |.X.| //latt 0
00240                     |...|
00241                     \---/
00242                 */
00243             areaLatt =0;
00244             areaVert =1;
00245         } 
00246         else if(inchToCm(ultrasonicToInch(m_valueCapteurUltrasonic)) <= DIRECTIVE_ULTRASONIC_LIMIT_LONG)
00247         { //plus proche que 2 case
00248             debug("\n\r        -Objet proche %g <= %i cm",inchToCm(ultrasonicToInch(m_valueCapteurUltrasonic)),DIRECTIVE_ULTRASONIC_LIMIT_LONG);
00249             //modifier vue que il ne detecte pas asser loin
00250             /*
00251                     /-M-\
00252                     |?V?| //vert 1
00253                     |.X.| //latt 0
00254                     |...|
00255                     \---/
00256                 */
00257             areaLatt =0;
00258             areaVert =1;
00259         } 
00260         else if(inchToCm(ultrasonicToInch(m_valueCapteurUltrasonic)) > DIRECTIVE_ULTRASONIC_LIMIT_LONG)
00261         { //plus proche que 2 case
00262         debug("\n\r        -Objet proche %g >= %i cm",inchToCm(ultrasonicToInch(m_valueCapteurUltrasonic)),DIRECTIVE_ULTRASONIC_LIMIT_LONG);
00263         //modifier vue que il ne detecte pas asser loin
00264         /*
00265                             /?V?\
00266                             |?V?| //vert 2
00267                             |.X.| //latt 0
00268                             |...| // objet possiblement a proximiter
00269                             \---/
00270                         */
00271             
00272             areaLatt =0;
00273             areaVert =2;
00274         }
00275         
00276         
00277         
00278         /*if(IRToCm(ADCTomv(m_valueCapteurIR)) <= 60) 
00279         {
00280             debug("\n\r          -Confirmation IR");
00281             areaVert =2;
00282         } 
00283         else if(IRToCm(ADCTomv(m_valueCapteurIR)) <= 30) 
00284         {
00285             debug("\n\r          -Confirmation IR");
00286             areaVert =1;
00287         }*/
00288         
00289         
00290         if(areaVert >= areaLatt) 
00291         {
00292             switch(areaVert) 
00293             {
00294                 case 0:
00295                     /*
00296                         /---\
00297                         |?M?| //vert 0
00298                         |.X.| //latt 0
00299                         |...|
00300                         \---/
00301                     */
00302                     
00303                     debug("\n\r +---+ ");
00304                     debug("\n\r |?M?| //vert 0 ");
00305                     debug("\n\r |.X.| //latt 0 ");
00306                     debug("\n\r |...| ");
00307                     debug("\n\r +---+ ");
00308                     break;
00309                 case 1://impossible pour le moment IR trop instable//
00310                     
00311                  
00312                     
00313                     if(areaLatt == 1) 
00314                     {
00315                         /*
00316                             /?M?\
00317                             |VVV| //vert 1
00318                             |.X.| //latt 1
00319                             |...| // objet possiblement a proximiter
00320                             \---/
00321                         */
00322                         debug("\n\r +-M-+ ");
00323                         debug("\n\r |VVV| //vert 1 ");
00324                         debug("\n\r |.X.| //latt 1 ");
00325                         debug("\n\r |...| // objet possiblement a proximiter ");
00326                         debug("\n\r +---+ ");
00327                     }
00328                     else
00329                     {
00330                         /*
00331                         /-M-\
00332                         |?V?| //vert 1
00333                         |.X.| //latt 0
00334                         |...|
00335                         \---/
00336                          */
00337                     
00338                         debug("\n\r +-M-+ ");
00339                         debug("\n\r |?V?| //vert 1 ");
00340                         debug("\n\r |.X.| //latt 0 ");
00341                         debug("\n\r |...| ");
00342                         debug("\n\r +---+ ");
00343                     }
00344                     break;
00345                 case 2:
00346                    
00347                     switch(areaLatt) 
00348                     {
00349                         case 0://impossible pour le moment IR trop instable//
00350                             /*
00351                                 /?V?\
00352                                 |?V?| //vert 2
00353                                 |.X.| //latt 0
00354                                 |...| // objet possiblement a proximiter
00355                                 \---/
00356                             */
00357                             debug("\n\r +?V?+ ");
00358                             debug("\n\r |?V?| //vert 2 ");
00359                             debug("\n\r |.X.| //latt 0 ");
00360                             debug("\n\r |...| // objet possiblement a proximiter ");
00361                             debug("\n\r +---+ ");
00362                             break;
00363                         case 1://impossible pour le moment IR trop instable//
00364                             /*
00365                                 /?V?\
00366                                 |VVV| //vert 2
00367                                 |.X.| //latt 1
00368                                 |...| // objet possiblement a proximiter
00369                                 \---/
00370                             */
00371                             debug("\n\r +-M-+ ");
00372                             debug("\n\r |VVV| //vert 2 ");
00373                             debug("\n\r |.X.| //latt 1 ");
00374                             debug("\n\r |...| // objet possiblement a proximiter ");
00375                             debug("\n\r +---+ ");
00376                             break;
00377                         case 2:
00378                             /*
00379                                 /VVV\
00380                                 |VVV| //vert 2
00381                                 |.X.| //latt 2
00382                                 |...|
00383                                 \---/
00384                             */
00385                             debug("\n\r +VVV+ ");
00386                             debug("\n\r |VVV| //vert 2 ");
00387                             debug("\n\r |.X.| //latt 2 ");
00388                             debug("\n\r |...| ");
00389                             debug("\n\r +---+ ");
00390                             break;
00391                     }
00392                     break;
00393             }
00394         }
00395         /*if((ultrasonicToInch(m_valueCapteurUltrasonic)< 1) && (IRToCm(ADCTomv(m_valueCapteurIR)) <= 80)) 
00396         { //capteur ultrasson embrouiller/imprecis
00397             debug(DEBUG_DIRECTIVE_TEST,"\n\r        -Capteur Ultrasson brouiller");
00398             //addTableauDeCommande(6);
00399         } 
00400         else if(ultrasonicToInch(m_valueCapteurUltrasonic) >=24) 
00401         { //plus proche que 10pouce
00402             debug(DEBUG_DIRECTIVE_TEST,"\n\r        -Objet proche 2pi");
00403             areaLatt =2;
00404             areaVert =2;
00405         } 
00406         else if(ultrasonicToInch(m_valueCapteurUltrasonic) >=12) 
00407         { //plus proche que 10pouce
00408             debug(DEBUG_DIRECTIVE_TEST,"\n\r        -Objet proche 2pi");
00409             areaLatt =1;
00410             areaVert =1;
00411         }
00412         debug(DEBUG_DIRECTIVE_TEST,": %i",ultrasonicToInch(m_valueCapteurUltrasonic));
00413         
00414         if(IRToCm(ADCTomv(m_valueCapteurIR)) <= 60) 
00415         {
00416             debug(DEBUG_DIRECTIVE_TEST,"\n\r          -Confirmation IR");
00417             areaVert =2;
00418         } 
00419         else if(IRToCm(ADCTomv(m_valueCapteurIR)) <= 30) 
00420         {
00421             debug(DEBUG_DIRECTIVE_TEST,"\n\r          -Confirmation IR");
00422             areaVert =1;
00423         }
00424         debug(DEBUG_DIRECTIVE_TEST,": %i",IRToCm(ADCTomv(m_valueCapteurIR)));*/
00425     }
00426     #endif
00427     
00428 }
00429 Directive::~Directive()
00430 {
00431     
00432     if(ctrDesPattes)
00433     delete ctrDesPattes;
00434     if(ssc32)
00435     delete ssc32;
00436     if(myMaze)
00437     delete myMaze;
00438 }
00439 void Directive::task(void)//ALL CODE HERE//
00440 {
00441     #ifdef DEBUG_DIRECTIVE_MINIMAL_PRESENTATION
00442      if(pc.readable())
00443      {
00444             int idCommand=0;
00445             idCommand = fgetc(pc) - '0';
00446             string mymap;
00447             switch(idCommand)
00448             {
00449                 case 1:
00450                     debug("\n\r 1: Show Map ");
00451                     
00452                     mymap = myMaze->showMap();
00453                     debug("\n\r  Labyrinthe map: X:%02i Y:%02i \n\r",(signed char)(myMaze->getX()),(signed char)(myMaze->getY()));
00454                     //char caseCaract = 0;
00455                     debug("\n\r");
00456                     for(int i=0; i<3; i++) debug(" [%c] ",myMaze->caseToChar((Labyrinthe::case_t)mymap[i+6]));
00457                     debug("\n\r");
00458                     for(int i=0; i<3; i++) debug(" [%c] ",myMaze->caseToChar((Labyrinthe::case_t)mymap[i+3]));
00459                     debug("\n\r");
00460                     for(int i=0; i<3; i++) debug(" [%c] ",myMaze->caseToChar((Labyrinthe::case_t)mymap[i]));
00461                     debug("\n\r");
00462                     break;
00463                     
00464                 case 2:
00465                     debug("\n\r  *2: Show tableauDeCommange[]");
00466                     debug("\n\r        -TAB:");
00467                     for(int i =0; i<DIRECTIVE_TABLEAUDECOMMANDE_SIZE; i++) debug("[%02x]",tableauDeCommange[i]);
00468                     if(followThePath == true)
00469                     debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r EN MODE FOLLOW THE PATH");
00470                     else
00471                     debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r HORS MODE FOLLOW THE PATH");
00472                     break;
00473                     
00474                 case 3:
00475                     debug("\n\r  *3: Show value Capteurs");
00476                     debug("\n\r        -IRToCm(%02f): %02f",ADCTomv(m_valueCapteurIR),IRToCm(ADCTomv(m_valueCapteurIR)));
00477                     debug("\n\r        -ultrasonicToInch to cm: %02f",inchToCm(ultrasonicToInch(m_valueCapteurUltrasonic)));
00478                     debug("\n\r        -m_valueCapteurProximiter: %02d",m_valueCapteurProximiter);
00479                     break;
00480                     
00481                 default:
00482                     debug("\n\n\r Press key 0-9 to select an option");
00483                     debug("\n\r  *1: Show Map");
00484                     debug("\n\r  *2: Show tableauDeCommange[]");
00485                     debug("\n\r  *3: Show value Capteurs");
00486                     break;
00487             }
00488     }
00489     #endif
00490     
00491     #ifdef DEBUG_BOOT_GRAPHICAL_INTERFACE
00492         debug("\x1B[2J"); //clear screen
00493         debug("\x1B[25l");//hide cursor
00494         debug("\x1B[;H"); //cursor default position
00495         debug("\n\r--------In task directive--------");
00496         for(int i = 0; i<size_tableauDeCommange; i++) debug("\n\r tableauDeCommange[%i]: %x",i,tableauDeCommange[i]);
00497         
00498         /*
00499             createDLbox(0,0,10,25,"BrainControle");
00500             setText(1,3,"1) Move Up");
00501             setText(1,4,"2) Move Down");
00502             setText(1,5,"3) Move Left");
00503             setText(1,6,"4) Move Right");
00504             
00505             int idCommand;
00506             do{
00507             if(pc.readable()){
00508             idCommand = fgetc(pc) - '0';
00509             switch(idCommand)
00510             {
00511             case 1:
00512             myMaze->goUp();
00513             break;
00514             case 2:
00515             myMaze->goDown();
00516             break;
00517             case 3:
00518             myMaze->goLeft();
00519             break;
00520             case 4:
00521             myMaze->goRight();
00522             break;
00523             }
00524             myMaze->setMyPos(Labyrinthe::explorer);
00525             
00526             string mymap = myMaze->showMap();
00527             debug(DEBUG_DIRECTIVE_LABYRINTH,"\n\r  Labyrinthe map: X:%02x Y:%02x \n\r",myMaze->getX(),myMaze->getY());
00528             for(int i=0; i<3; i++) debug(DEBUG_DIRECTIVE_LABYRINTH," [%02X] ",mymap[i+6]);
00529             debug(DEBUG_DIRECTIVE_LABYRINTH,"\n\r");
00530             for(int i=0; i<3; i++) debug(DEBUG_DIRECTIVE_LABYRINTH," [%02X] ",mymap[i+3]);
00531             debug(DEBUG_DIRECTIVE_LABYRINTH,"\n\r");
00532             for(int i=0; i<3; i++) debug(DEBUG_DIRECTIVE_LABYRINTH," [%02X] ",mymap[i]);
00533             debug(DEBUG_DIRECTIVE_LABYRINTH,"\n\r");
00534             
00535             #ifdef DBG_MAIN_DELAY_SEC
00536             debug("\n\r\n wait \n\r\n");
00537             wait(DBG_MAIN_DELAY_SEC);
00538             #endif
00539             
00540             debug("\x1B[2J"); //clear screen
00541             debug("\x1B[;H"); //cursor default position
00542             createDLbox(0,0,10,25,"BrainControle");
00543             setText(1,3,"1) Move Up");
00544             setText(1,4,"2) Move Down");
00545             setText(1,5,"3) Move Left");
00546             setText(1,6,"4) Move Right");
00547             }
00548         }while(1);   */
00549     #endif
00550     
00551     //debug(DEBUG_DIRECTIVE_TEST,"\n\rIn task directive");
00552     #ifndef DEBUG_DIRECTIVE_LEG_DISABLE
00553         if(ctrDesPattes->isSeqComplet()) 
00554         {
00555             
00556             ////////////////
00557             // Inspection //
00558             ////////////////
00559             //updateModuleValue();
00560             
00561             if((tableauDeCommange[0] == TBL_CMD_MARCHE) && (size_tableauDeCommange == 1)) 
00562             {
00563                 //addTableauDeCommande(0x81);
00564                 //addTableauDeCommande(0x82);
00565                 //mabey//addTableauDeCommande(0x83);
00566                 addTableauDeCommande(0x84);
00567                 
00568                 //addTableauDeCommande(0x85);
00569                 //mabey//addTableauDeCommande(0x86);
00570                 addTableauDeCommande(0x87);
00571                 addTableauDeCommande(0x88);
00572             }
00573             
00574             
00575             if(tableauDeCommange[0] == 0) 
00576             {
00577                 //pas sur que c'Est tout ce qui doit etre ici mais je vois pas quoi d'autre pour le moment.
00578                 
00579                 ////////////////
00580                 // Inspection //
00581                 ////////////////
00582                 //flag.append(1,0);//0x02);
00583                 /*for(int i=0; i<m_ListDesModules.length(); ++i) {
00584                     wait_us(300);
00585                     flag.clear();
00586                     flag.append(1,7);
00587                     data.clear();
00588                     debug("\n\r result: %d",m_CtrlBridge->send(m_ListDesModules.at(i),flag,data));
00589                     
00590                     debug("\n\r flag: %d",flag[0]);
00591                     debug("\n\r data: %x",data[0]);
00592                 }*/
00593                 
00594                 updateModuleValue();
00595                 
00596                 //////////////////////////////
00597                 // Traitement du Labyrinthe //
00598                 //////////////////////////////
00599                 #ifdef DEBUG_DIRECTIVE_LABYRINTH
00600                 debug("\n\r        -IRToCm(%02f): %02f",ADCTomv(m_valueCapteurIR),IRToCm(ADCTomv(m_valueCapteurIR)));
00601                 debug("\n\r        -ultrasonicToInch: %02f",inchToCm(ultrasonicToInch(m_valueCapteurUltrasonic)));
00602                 debug("\n\r        -m_valueCapteurProximiter: %02d",m_valueCapteurProximiter);
00603                 #endif
00604     #endif //DEBUG_DIRECTIVE_LEG_DISABLE
00605                 if(followThePath == true)
00606                 debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r EN MODE FOLLOW THE PATH");
00607                 else
00608                 debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r HORS MODE FOLLOW THE PATH");
00609                 
00610                 analiseMaze();
00611                 char nextCase=0;
00612                 /*switch(myMaze->getDirection()) {
00613                     case UP:
00614                     nextCase = myMaze->getC(myMaze->getX(),myMaze->getY()+1);
00615                     break;
00616                     
00617                     case DOWN:
00618                     nextCase = myMaze->getC(myMaze->getX(),myMaze->getY()-1);
00619                     break;
00620                     
00621                     case LEFT:
00622                     nextCase = myMaze->getC(myMaze->getX()-1,myMaze->getY());
00623                     break;
00624                     
00625                     case RIGHT:
00626                     nextCase = myMaze->getC(myMaze->getX()+1,myMaze->getY());
00627                     break;
00628                 }*/
00629                 if(( myMaze->getC_Foward() == Labyrinthe::vide ) ||  (myMaze->getC_Foward() == Labyrinthe::pasExplorer ))
00630                     followThePath = false;
00631                 
00632                 
00633             
00634                 if(followThePath == false) 
00635                 {
00636                     nextCase = myMaze->getC_Foward();
00637                     
00638                     debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r nextCase: [%02x]",nextCase);
00639                     switch(nextCase ) 
00640                     {
00641                         case Labyrinthe::vide :
00642                             #ifdef DEBUG_DIRECTIVE_LEG_DISABLE
00643                                 debug("nextCase Vide\n\r");
00644                             #endif
00645                             debug(DEBUG_DIRECTIVE_TEST," Javance");
00646                             #ifndef DEBUG_DIRECTIVE_LEG_DISABLE
00647                                 addTableauDeCommande(TBL_CMD_MARCHE);
00648                             #endif
00649                             //if(followThePath == true)
00650                             //followThePath = false;
00651                             myMaze->moveFoward();
00652                             myMaze->setMyPos(Labyrinthe::explorer);
00653                             break;
00654                         
00655                         case Labyrinthe::explorer :// ici pt amiliorer
00656                             debug(DEBUG_DIRECTIVE_TEST," \n\rnext case deja explorer");
00657                             if(rand()%2) 
00658                             {
00659                                 debug(DEBUG_DIRECTIVE_TEST,"\n\r jeverifie si alternative");
00660                                 
00661                                 /*#ifndef DEBUG_DIRECTIVE_LEG_DISABLE
00662                                 addTableauDeCommande(TBL_CMD_MARCHE);
00663                                 #endif*/
00664                                 nextCase = checkOtherWay(myMaze->getDirection(),1);
00665                                 
00666                                 turnRightDirection(myMaze->getDirection(),nextCase);
00667                                 debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\rnextcase: %i",nextCase);
00668                                 switch(nextCase) 
00669                                 { // on verifie si on a une direction possible
00670                                     case UP:
00671                                         debug(DEBUG_DIRECTIVE_TEST,"\n\r Je tourne UP");
00672                                         turnRightDirection(myMaze->getDirection(),UP);
00673                                         myMaze->setDirection(UP);
00674                                         
00675                                         
00676                                         break;
00677                                     case DOWN:
00678                                         debug(DEBUG_DIRECTIVE_TEST,"\n\r Je tourne DOWN");
00679                                         turnRightDirection(myMaze->getDirection(),DOWN);
00680                                         myMaze->setDirection(DOWN);
00681                                         
00682                                         break;
00683                                     case LEFT:
00684                                         debug(DEBUG_DIRECTIVE_TEST,"\n\r Je tourne LEFT");
00685                                         turnRightDirection(myMaze->getDirection(),LEFT);
00686                                         myMaze->setDirection(LEFT);
00687                                         
00688                                         break;
00689                                     case RIGHT:
00690                                         debug(DEBUG_DIRECTIVE_TEST,"\n\r Je tourne RIGHT");
00691                                         turnRightDirection(myMaze->getDirection(),RIGHT);
00692                                         myMaze->setDirection(RIGHT);
00693                                         
00694                                         break;
00695                                     default: //aucun autre chemin
00696                                         debug(DEBUG_DIRECTIVE_TEST,"\n\r aucune autre place alors J'avance");
00697                                         myMaze->moveFoward();
00698                                         myMaze->setMyPos(Labyrinthe::explorer);
00699                                         #ifndef DEBUG_DIRECTIVE_LEG_DISABLE
00700                                         addTableauDeCommande(TBL_CMD_MARCHE);
00701                                         #endif
00702                                         break;
00703                                 }
00704                             } 
00705                             else 
00706                             {
00707                                 debug(DEBUG_DIRECTIVE_TEST,"\n\r jeverifie pas si alternative");
00708                                 myMaze->moveFoward();
00709                                 #ifndef DEBUG_DIRECTIVE_LEG_DISABLE
00710                                 addTableauDeCommande(TBL_CMD_MARCHE);
00711                                 #endif
00712                             }
00713                             //myMaze->moveFoward();
00714                             //myMaze->setMyPos(Labyrinthe::explorer);
00715                             break;
00716                         
00717                         case Labyrinthe::mur:
00718                             debug(DEBUG_DIRECTIVE_TEST,"\n\r UN MURRRRRRRR\n\r");
00719                             if(searchNewWay()) 
00720                             {
00721                                 debug(DEBUG_DIRECTIVE_TEST,"\n\r New Path found ");
00722                                 followThePath = true;
00723                             } 
00724                             else 
00725                             {
00726                                 debug(DEBUG_DIRECTIVE_TEST,"\n\r New Path not found ");
00727                             }
00728                             /* switch(checkOtherWay(myMaze->getDirection()))// on verifie si on a une direction possible
00729                                 {
00730                                 case UP:
00731                                 debug(DEBUG_DIRECTIVE_TEST,"\n\r Je tourne UP ");
00732                                 myMaze->setDirection(UP);
00733                                 //myMaze->moveFoward();
00734                                 break;
00735                                 case DOWN:
00736                                 debug(DEBUG_DIRECTIVE_TEST,"\n\r Je tourne DOWN ");
00737                                 myMaze->setDirection(DOWN);
00738                                 //myMaze->moveFoward();
00739                                 break;
00740                                 case LEFT:
00741                                 debug(DEBUG_DIRECTIVE_TEST,"\n\r Je tourne LEFT");
00742                                 myMaze->setDirection(LEFT);
00743                                 //myMaze->moveFoward();
00744                                 break;
00745                                 case RIGHT:
00746                                 debug(DEBUG_DIRECTIVE_TEST,"\n\r Je tourne RIGHT");
00747                                 myMaze->setDirection(RIGHT);
00748                                 //myMaze->moveFoward();
00749                                 break;
00750                                 default://aucun autre chemin
00751                                 /debug(DEBUG_DIRECTIVE_TEST,"\n\r Je tourne completement ");
00752                                 if(myMaze->getDirection() %2)
00753                                 myMaze->setDirection(myMaze->getDirection()+1);
00754                                 else
00755                                 myMaze->setDirection(myMaze->getDirection()-1);
00756                                 
00757                                 //myMaze->moveFoward();
00758                                 
00759                                 break;
00760                                 }
00761                             myMaze->setMyPos(Labyrinthe::explorer);*/
00762                             break;
00763                         
00764                         case Labyrinthe::pasExplorer ://pas sur
00765                             debug(DEBUG_DIRECTIVE_TEST," pasExplorer");
00766                             #ifndef DEBUG_DIRECTIVE_LEG_DISABLE
00767                                 addTableauDeCommande(TBL_CMD_MARCHE);
00768                             #endif
00769                             break;
00770                     }
00771                 } 
00772                 else 
00773                 { // on suis un chemin
00774                     debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\rmode follow the path\n\n\r");
00775                     positionXY tempPosition;
00776                     
00777                     //std::list<positionXY>::iterator it=bufferNewWay.begin();
00778                     for (std::list<positionXY>::iterator it=bufferNewWay.begin(); it != bufferNewWay.end(); ++it) 
00779                     {
00780                         //tempPosition = *(it);
00781                         debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\rtempPosition.posX: %i",(*it).posX);
00782                         debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\rtempPosition.posY: %i",(*it).posY);
00783                         debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\rtempPosition.direction: %i",(*it).direction);
00784                     } //std::cout << ' ' << *it;
00785                     
00786                     if((bufferNewWay.front()).direction != myMaze->getDirection()) //turn time
00787                     {
00788                         debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r     le chemin a pas la meme direction");
00789                         debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r     current dir : %i",myMaze->getDirection());
00790                         debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r     next dir : %i",(bufferNewWay.front()).direction);
00791                         
00792                         addTableauDeCommande(TBL_CMD_RECULE);
00793                         addTableauDeCommande(TBL_CMD_RECULE);
00794                         turnRightDirection(myMaze->getDirection(),(bufferNewWay.front()).direction);
00795                         switch((bufferNewWay.front()).direction) 
00796                         {
00797                             case UP:
00798                                 debug(DEBUG_DIRECTIVE_TEST,"\n\r Je tourne UP");
00799                                 myMaze->setDirection(UP);
00800                                 
00801                                 /*if(((bufferNewWay.front()).direction + myMaze->getDirection()) == (UP + DOWN))
00802                                 {
00803                                     if(rand()%2)
00804                                     {
00805                                     addTableauDeCommande(TBL_CMD_TURN_LEFT);
00806                                     addTableauDeCommande(TBL_CMD_TURN_LEFT);
00807                                     }
00808                                     else
00809                                     {
00810                                     addTableauDeCommande(TBL_CMD_TURN_RIGHT);
00811                                     addTableauDeCommande(TBL_CMD_TURN_RIGHT);
00812                                     }
00813                                 }*/
00814                                 break;
00815                             case DOWN:
00816                                 debug(DEBUG_DIRECTIVE_TEST,"\n\r Je tourne DOWN");
00817                                 myMaze->setDirection(DOWN);
00818                                 
00819                                 break;
00820                             case LEFT:
00821                                 debug(DEBUG_DIRECTIVE_TEST,"\n\r Je tourne LEFT");
00822                                 myMaze->setDirection(LEFT);
00823                                 
00824                                 break;
00825                             case RIGHT:
00826                                 debug(DEBUG_DIRECTIVE_TEST,"\n\r Je tourne RIGHT");
00827                                 myMaze->setDirection(RIGHT);
00828                                 break;
00829                         }
00830                         //bufferNewWay.pop_front();
00831                     } 
00832                     else 
00833                     {
00834                         debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r     le chemin a la meme direction");
00835                         //myMaze->getXY_Foward(tempPosition.posX,tempPosition.posY);
00836                         tempPosition.posX = myMaze->getX();
00837                         tempPosition.posY = myMaze->getY();
00838                         debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r     current X: %i",tempPosition.posX);
00839                         debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r     current Y: %i",tempPosition.posY);
00840                         debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r     buffer X: %i",(bufferNewWay.front()).posX);
00841                         debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r     buffer Y: %i",(bufferNewWay.front()).posY);
00842                         if((tempPosition.posX == (bufferNewWay.front()).posX) && (tempPosition.posY == (bufferNewWay.front()).posY)) 
00843                         {
00844                             updateMaze();
00845                             
00846                             nextCase = myMaze->getC_Foward();
00847                             
00848                             if(nextCase == Labyrinthe::mur)
00849                             {
00850                                 debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r     problem");
00851                                 followThePath = false;
00852                             }
00853                             else
00854                             {
00855                             debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r     aucun problem");
00856                             #ifndef DEBUG_DIRECTIVE_LEG_DISABLE
00857                                 addTableauDeCommande(TBL_CMD_MARCHE);
00858                             #endif
00859                             myMaze->moveFoward();
00860                             myMaze->setMyPos(Labyrinthe::explorer);
00861                             bufferNewWay.pop_front();
00862                             }
00863                         } 
00864                         else
00865                             debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r     problem");
00866                         
00867                     }
00868                     
00869                     
00870                     
00871                     if(bufferNewWay.empty())
00872                         followThePath = false;
00873                         
00874                        
00875    
00876         
00877          
00878              
00879             
00880                     /*do{
00881                         //tempPosition.posX = (bufferNewWay.front()).posX;
00882                         //tempPosition.posY = (bufferNewWay.front()).posY;
00883                         
00884                         tempPosition = bufferNewWay.front();
00885                         bufferNewWay.pop_front();
00886                         debug("\n\r bufferNewWay: %i",bufferNewWay.size());
00887                         debug("\n\rtempPosition.posX: %i",tempPosition.posX);
00888                         debug("\n\rtempPosition.posY: %i",tempPosition.posY);
00889                     }while(bufferNewWay.size() != 0);*/
00890                 }
00891                 #ifdef DEBUG_DIRECTIVE_SHOW_MAP_LABYRINTH
00892                     string mymap = myMaze->showMap();
00893                     debug("\n\r  Labyrinthe map: X:%02i Y:%02i \n\r",(signed char)(myMaze->getX()),(signed char)(myMaze->getY()));
00894                     //char caseCaract = 0;
00895                     debug("\n\r");
00896                     for(int i=0; i<3; i++) debug(" [%c] ",myMaze->caseToChar((Labyrinthe::case_t)mymap[i+6]));
00897                     debug("\n\r");
00898                     for(int i=0; i<3; i++) debug(" [%c] ",myMaze->caseToChar((Labyrinthe::case_t)mymap[i+3]));
00899                     debug("\n\r");
00900                     for(int i=0; i<3; i++) debug(" [%c] ",myMaze->caseToChar((Labyrinthe::case_t)mymap[i]));
00901                     debug("\n\r");
00902                 #endif
00903     #ifndef DEBUG_DIRECTIVE_LEG_DISABLE
00904                     /*if((ultrasonicToInch(m_valueCapteurUltrasonic)< 1) && (IRToCm(ADCTomv(m_valueCapteurIR)) <= 80)) //capteur ultrasson embrouiller/imprecis
00905                         {
00906                         debug(DEBUG_DIRECTIVE_TEST,"\n\r        -Capteur Ultrasson brouiller");
00907                         addTableauDeCommande(6);
00908                         }
00909                         else if(ultrasonicToInch(m_valueCapteurUltrasonic) < 10) { //plus proche que 10pouce
00910                         debug(DEBUG_DIRECTIVE_TEST,"\n\r        -Objet proche");
00911                         if(IRToCm(ADCTomv(m_valueCapteurIR)) <= 10) {
00912                         debug(DEBUG_DIRECTIVE_TEST,"\n\r          -Confirmation IR");
00913                         addTableauDeCommande(7);
00914                         
00915                         
00916                         //ici potentielle scaning
00917                         } else {
00918                         addTableauDeCommande(4);
00919                         addTableauDeCommande(4);
00920                         addTableauDeCommande(4);
00921                         }
00922                         } else {
00923                         debug(DEBUG_DIRECTIVE_TEST,"\n\r        -Nothing:");
00924                         addTableauDeCommande(6);
00925                         
00926                         
00927                         int randomNbr = rand() % 4;
00928                         switch(randomNbr)
00929                         {
00930                         case 1:
00931                         debug(DEBUG_DIRECTIVE_TEST," Javance");
00932                         addTableauDeCommande(6);
00933                         break;
00934                         case 2:
00935                         debug(DEBUG_DIRECTIVE_TEST," Je tourne a gauche");
00936                         addTableauDeCommande(4);
00937                         break;
00938                         case 3:
00939                         debug(DEBUG_DIRECTIVE_TEST," Je tourne a droite");
00940                         addTableauDeCommande(5);
00941                         break;
00942                         default:
00943                         debug(DEBUG_DIRECTIVE_TEST," Jattend");
00944                         break;
00945                         }
00946                         
00947                         
00948                         //addTableauDeCommande(6);
00949                     }*/
00950                      #ifdef DEBUG_DIRECTIVE_TASK_PAUSE
00951                         debug("\n\r press any 9 key");
00952                         for(int idCmd=0; idCmd != 9; idCmd = fgetc(pc) - '0');
00953                         #endif
00954                     ///////////////
00955                     // Mouvement //
00956                     ///////////////
00957             } 
00958             else 
00959             {
00960                 
00961                 switch(tableauDeCommange[0]) 
00962                 {
00963                     case 11:
00964                         debug(DEBUG_DIRECTIVE_TEST,"\n\r        -set_calibre");
00965                         ctrDesPattes->calibre();
00966                         break;
00967                     case 2:
00968                         debug(DEBUG_DIRECTIVE_TEST,"\n\r        -set_moveUp");
00969                         ctrDesPattes->moveUp();
00970                         break;
00971                     case 3:
00972                         debug(DEBUG_DIRECTIVE_TEST,"\n\r        -set_moveDown");
00973                         ctrDesPattes->moveDown();
00974                         break;
00975                     case 4:
00976                         debug(DEBUG_DIRECTIVE_TEST,"\n\r        -set_turnLeft");
00977                         ctrDesPattes->turnLeft();
00978                         break;
00979                     case 5:
00980                         debug(DEBUG_DIRECTIVE_TEST,"\n\r        -set_trunRight");
00981                         ctrDesPattes->trunRight();
00982                         break;
00983                     case 6:
00984                         debug(DEBUG_DIRECTIVE_TEST,"\n\r        -set_moveFront");
00985                         ctrDesPattes->moveFront();
00986                         break;
00987                     case 7:
00988                         debug(DEBUG_DIRECTIVE_TEST,"\n\r        -set_moveBack");
00989                         ctrDesPattes->moveBack();
00990                         break;
00991                     /*case 8:
00992                         ctrDesPattes->moveBack();
00993                     break;*/
00994                     case 0x81:
00995                         debug(DEBUG_DIRECTIVE_TEST,"\n\r        -set_Repositioner 1");
00996                         ctrDesPattes->repositioner(1);
00997                         break;
00998                     case 0x82:
00999                         debug(DEBUG_DIRECTIVE_TEST,"\n\r        -set_Repositioner 2");
01000                         ctrDesPattes->repositioner(2);
01001                         break;
01002                     case 0x83:
01003                         debug(DEBUG_DIRECTIVE_TEST,"\n\r        -set_Repositioner 3");
01004                         ctrDesPattes->repositioner(3);
01005                         break;
01006                     case 0x84:
01007                         debug(DEBUG_DIRECTIVE_TEST,"\n\r        -set_Repositioner 4");
01008                         ctrDesPattes->repositioner(4);
01009                         break;
01010                     case 0x85:
01011                         debug(DEBUG_DIRECTIVE_TEST,"\n\r        -set_Repositioner 5");
01012                         ctrDesPattes->repositioner(5);
01013                         break;
01014                     case 0x86:
01015                         debug(DEBUG_DIRECTIVE_TEST,"\n\r        -set_Repositioner 6");
01016                         ctrDesPattes->repositioner(6);
01017                         break;
01018                     case 0x87:
01019                         debug(DEBUG_DIRECTIVE_TEST,"\n\r        -set_Repositioner 7");
01020                         ctrDesPattes->repositioner(7);
01021                         break;
01022                     case 0x88:
01023                         debug(DEBUG_DIRECTIVE_TEST,"\n\r        -set_Repositioner 8");
01024                         ctrDesPattes->repositioner(8);
01025                         break;
01026                 }
01027                 debug(DEBUG_DIRECTIVE_TEST,"\n\r        -TAB:");
01028                 for(int i =0; i<DIRECTIVE_TABLEAUDECOMMANDE_SIZE; i++) debug(DEBUG_DIRECTIVE_TEST,"[%02x]",tableauDeCommange[i]);
01029                 for(int i =0; i<DIRECTIVE_TABLEAUDECOMMANDE_SIZE; i++) tableauDeCommange[i]= tableauDeCommange[i+1];
01030                 tableauDeCommange[DIRECTIVE_TABLEAUDECOMMANDE_SIZE-1] = 0;
01031                 if(size_tableauDeCommange != 0) size_tableauDeCommange--;
01032             }
01033             
01034         } 
01035         else
01036         {
01037             ctrDesPattes->exec();
01038         }
01039     #endif //DEBUG_DIRECTIVE_LEG_DISABLE
01040     ////////////////////
01041     // Update memoire //
01042     ////////////////////
01043     
01044     ////////////
01045     // Autre? //
01046     ////////////
01047     
01048     
01049     //debug(DEBUG_DIRECTIVE_TEST,"\n\rOut task directive");
01050     #ifdef DEBUG_BOOT_GRAPHICAL_INTERFACE
01051         #ifdef DBG_MAIN_DELAY_SEC
01052             debug("\n\r\n wait \n\r\n");
01053             wait(DBG_MAIN_DELAY_SEC);
01054         #endif
01055         debug("\n\r---------------------");
01056     #endif
01057 }
01058 double Directive::IRToCm (double miliVolt)
01059 {
01060     double result=0;
01061     //debug("\n\r double value: %02f",miliVolt);
01062     if(miliVolt < tabIR[0][1])result = tabIR[0][0];
01063     else if(miliVolt > tabIR[11][1])result = tabIR[11][0];
01064     
01065     for(int i =1; (result==0)&&(i<12); i++) 
01066     {
01067         if((tabIR[i-1][1]<=miliVolt) && (tabIR[i][1]>miliVolt)) 
01068         {
01069             result=tabIR[i-1][0]+((tabIR[i][0]-tabIR[i-1][0])*((tabIR[i-1][1]-miliVolt)/(tabIR[i-1][1]-tabIR[i][1])));
01070         }
01071     }
01072     return result;
01073 }
01074 void Directive::addTableauDeCommande(unsigned char value)
01075 {
01076     if(size_tableauDeCommange!=DIRECTIVE_TABLEAUDECOMMANDE_SIZE) 
01077     {
01078         tableauDeCommange[size_tableauDeCommange]=value;
01079         size_tableauDeCommange++;
01080         
01081     }
01082 }
01083 
01084 void Directive::updateModuleValue(void)
01085 {
01086     string flag,data;
01087     double tempValue=0;
01088     flag.clear();
01089     data.clear();
01090     flag.append(1,7);
01091     //debug("\n\n\r  flag size:%i \n\r",flag.size());
01092     if(m_CtrlBridge->send(m_capteurUltrasonic[0],flag,data))
01093     {
01094         /*if(data[0] != 1)//patch?
01095             tempValue = data[0];*/
01096         
01097         if(data.size() == 2) 
01098         {
01099             tempValue = data[0];
01100             //tempValue = (tempValue<<8) + data[1];
01101             tempValue = (data[0]<<8) + data[1];
01102         } 
01103         else
01104         tempValue = data[0];
01105         
01106         if(data.size() != 0)
01107             m_valueCapteurUltrasonic = m_valueCapteurUltrasonic+((tempValue -m_valueCapteurUltrasonic)/DIRECTIVE_ULTRASONIC_BUFFER_LENGHT);
01108     }
01109     #ifdef DEBUG_DIRECTIVE_UPDATE_MODULE
01110     debug("\n\r m_valueCapteurUltrasonic");
01111     debug("\n\n\r  data size:%i \n\r",data.size());
01112     switch(data.size())
01113     {
01114         case 1:
01115             debug("\n\r        -data(value):%i         ",data[0]);
01116             break;
01117         case 2:
01118             debug("\n\r        -data(value):%i         ",(data[0]<<8) + data[1]);
01119             break;
01120     }
01121     //debug("\n\r        -data(value):%i         ",data[0]);
01122     debug("\n\r        -tempValue(value):%02f         ",tempValue);
01123     #endif
01124     tempValue=0;
01125     flag.clear();
01126     data.clear();
01127     flag.append(1,7);
01128    
01129     //debug("\n\n\r  flag size:%i \n\r",flag.size());
01130     if(m_CtrlBridge->send(m_capteurIR[0],flag,data)) 
01131     {
01132         
01133         if(data.size() == 2) 
01134         {
01135             //tempValue = data[0]<<8;
01136             //debug("\n\n\r monI: %02f",tempValue);
01137             //debug("\n\n\r mondata: %i",data[0]<<8);
01138             //tempValue = (tempValue<<8) + data[1];
01139             tempValue = (data[0]<<8) + data[1];
01140         } 
01141         else
01142         tempValue = data[0];
01143         
01144         if(data.size() != 0)
01145             m_valueCapteurIR=m_valueCapteurIR+((tempValue-m_valueCapteurIR)/DIRECTIVE_IR_BUFFER_LENGHT);
01146     }
01147     #ifdef DEBUG_DIRECTIVE_UPDATE_MODULE
01148     debug("\n\r m_valueCapteurIR");
01149     debug("\n\n\r  data size:%i \n\r",data.size());
01150     switch(data.size())
01151     {
01152         case 1:
01153             debug("\n\r        -data(value):%i         ",data[0]);
01154             break;
01155         case 2:
01156             debug("\n\r        -data(value):%i         ",(data[0]<<8) + data[1]);
01157             break;
01158     }
01159     //debug("\n\r        -data(value):%i         ",data[0]);
01160     debug("\n\r        -tempValue(value):%02f         ",tempValue);
01161     #endif
01162     //debug("\n\n\r  data size:%i \n\r",data.size());
01163    // debug("\n\r        -IR(value):%f         ",m_valueCapteurIR);
01164     //for(int i=0; i<data.size();i++)debug("\n\r        -data[%i]:%i",i,data[i]);
01165     
01166     flag.clear();
01167     data.clear();
01168     flag.append(1,7);
01169     //debug("\n\n\r  flag size:%i \n\r",flag.size());
01170     if(m_CtrlBridge->send(m_capteurProximiter[0],flag,data))
01171     
01172         m_valueCapteurProximiter = data[0];
01173         
01174        // debug("\n\n\r  data size:%i \n\r",data.size());
01175        // debug("\n\r        -m_valueCapteurProximiter(value):%i         ",m_valueCapteurProximiter);
01176 }
01177 
01178 void Directive::analiseMaze(void)
01179 {
01180      string mymap = myMaze->showMap();
01181      
01182      #ifdef DEBUG_DIRECTIVE_LABYRINTH
01183      debug("\n\r ----------------analiseMaze--------------\n\r");
01184      debug("\n\r  Labyrinthe map: X:%02i Y:%02i \n\r",(signed char)(myMaze->getX()),(signed char)(myMaze->getY()));
01185      
01186      debug("Direction: ");
01187     switch(myMaze->getDirection()) 
01188     {
01189         case UP:
01190             debug("Up \n\r");
01191             break;
01192         case DOWN:
01193             debug("Down \n\r");
01194             break;
01195         case LEFT:
01196             debug("Left \n\r");
01197             break;
01198         case RIGHT:
01199             debug("Right \n\r");
01200             break;
01201     }
01202     
01203     for(int i=0; i<3; i++) debug(" [%c] ",myMaze->caseToChar((Labyrinthe::case_t)mymap[i+6]));
01204     debug("\n\r");
01205     for(int i=0; i<3; i++) debug(" [%c] ",myMaze->caseToChar((Labyrinthe::case_t)mymap[i+3]));
01206     debug("\n\r");
01207     for(int i=0; i<3; i++) debug(" [%c] ",myMaze->caseToChar((Labyrinthe::case_t)mymap[i]));
01208     debug("\n\r");
01209      #endif
01210      
01211     
01212     
01213     
01214     
01215     
01216     
01217     
01218     
01219     #ifndef DEBUG_DIRECTIVE_LABYRINTH_USER_CTRL
01220         /*if((ultrasonicToInch(m_valueCapteurUltrasonic)< 1) && (IRToCm(ADCTomv(m_valueCapteurIR)) <= 80)) 
01221         { //capteur ultrasson embrouiller/imprecis
01222             debug(DEBUG_DIRECTIVE_TEST,"\n\r        -Capteur Ultrasson brouiller");
01223             //addTableauDeCommande(6);
01224         } 
01225         else if(ultrasonicToInch(m_valueCapteurUltrasonic) >=24) 
01226         { //plus proche que 10pouce
01227             debug(DEBUG_DIRECTIVE_TEST,"\n\r        -Objet proche 2pi");
01228             areaLatt =2;
01229             areaVert =2;
01230         } 
01231         else if(ultrasonicToInch(m_valueCapteurUltrasonic) >=12) 
01232         { //plus proche que 10pouce
01233             debug(DEBUG_DIRECTIVE_TEST,"\n\r        -Objet proche 2pi");
01234             areaLatt =1;
01235             areaVert =1;
01236         }
01237         debug(DEBUG_DIRECTIVE_TEST,": %i",ultrasonicToInch(m_valueCapteurUltrasonic));
01238         
01239         if(IRToCm(ADCTomv(m_valueCapteurIR)) <= 60) 
01240         {
01241             debug(DEBUG_DIRECTIVE_TEST,"\n\r          -Confirmation IR");
01242             areaVert =2;
01243         } 
01244         else if(IRToCm(ADCTomv(m_valueCapteurIR)) <= 30) 
01245         {
01246             debug(DEBUG_DIRECTIVE_TEST,"\n\r          -Confirmation IR");
01247             areaVert =1;
01248         }
01249         debug(DEBUG_DIRECTIVE_TEST,": %i",IRToCm(ADCTomv(m_valueCapteurIR)));*///old one
01250         
01251     updateMaze();
01252     
01253     #ifdef DEBUG_DIRECTIVE_LABYRINTH
01254         mymap = myMaze->showMap();
01255         //char caseCaract = 0;
01256         debug("\n\r");
01257         for(int i=0; i<3; i++) debug(" [%c] ",myMaze->caseToChar((Labyrinthe::case_t)mymap[i+6]));
01258         debug("\n\r");
01259         for(int i=0; i<3; i++) debug(" [%c] ",myMaze->caseToChar((Labyrinthe::case_t)mymap[i+3]));
01260         debug("\n\r");
01261         for(int i=0; i<3; i++) debug(" [%c] ",myMaze->caseToChar((Labyrinthe::case_t)mymap[i]));
01262         debug("\n\r");
01263         
01264         debug("\n\r-------------------\n\r");
01265     #endif
01266     
01267 }
01268 
01269 char Directive::checkOtherWay(char dir, bool checkExplorer)
01270 {
01271     char result = 0;
01272     char order[3];
01273     
01274     
01275     
01276     bool fini = false;
01277     
01278     switch(rand() % 6) 
01279     {
01280         case 0://[0],[1],[2]
01281             order[0] = 0;
01282             order[1] = 1;
01283             order[2] = 2;
01284             break;
01285         case 1://[0],[2],[1]
01286             order[0] = 0;
01287             order[1] = 2;
01288             order[2] = 1;
01289             break;
01290         case 2://[1],[0],[2]
01291             order[0] = 1;
01292             order[1] = 0;
01293             order[2] = 2;
01294             break;
01295         case 3://[2],[0],[1]
01296             order[0] = 2;
01297             order[1] = 0;
01298             order[2] = 1;
01299             break;
01300         case 4://[1],[2],[0]
01301             order[0] = 1;
01302             order[1] = 2;
01303             order[2] = 0;
01304             break;
01305         case 5://[2],[1],[0]
01306             order[0] = 2;
01307             order[1] = 1;
01308             order[2] = 0;
01309             break;
01310     }
01311     debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\rresult: ");
01312     for(int i=0; (i<3)&&(!fini); i++) 
01313     {
01314         switch(order[i]) 
01315         { // inclure un état memoir affin que si il a le choix entre une case vide et une explorer il priorise la vide// pt faire de meme avec pas explorer
01316             case 0:
01317                 result = myMaze->getC_ToLeft();
01318                 debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r getC_ToLeft: %i %i ****",result,myMaze->getC_ToLeft());
01319                 //if(((Labyrinthe::case_t)result != Labyrinthe::error)&&((Labyrinthe::case_t)result != Labyrinthe::mur) &&((checkExplorer)?((Labyrinthe::case_t)result != Labyrinthe::explorer):1) )
01320                 if(((Labyrinthe::case_t)result == Labyrinthe::vide)&&((Labyrinthe::case_t)result != Labyrinthe::mur) &&((checkExplorer)?((Labyrinthe::case_t)result != Labyrinthe::explorer):1) ) 
01321                 {
01322                     fini = true;
01323                     result = LEFT;
01324                 }
01325                 break;
01326             case 1:
01327                 result = myMaze->getC_Backward();
01328                 debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r getC_Backward: %i %i ****",result,myMaze->getC_Backward());
01329                 if(/*((Labyrinthe::case_t)result != Labyrinthe::error)&&*/((Labyrinthe::case_t)result != Labyrinthe::mur)&&((checkExplorer)?((Labyrinthe::case_t)result != Labyrinthe::explorer):1)) 
01330                 {
01331                     fini = true;
01332                     result = DOWN;
01333                 }
01334                 break;
01335             case 2:
01336                 result = myMaze->getC_ToRight();
01337                 debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r getC_ToRight: %i %i ****",result,myMaze->getC_ToRight());
01338                 if(/*((Labyrinthe::case_t)result != Labyrinthe::error)&&*/((Labyrinthe::case_t)result != Labyrinthe::mur)&&((checkExplorer)?((Labyrinthe::case_t)result != Labyrinthe::explorer):1)) 
01339                 {
01340                     fini = true;
01341                     result = RIGHT;
01342                 }
01343                 break;
01344         }
01345     }
01346     
01347     if(fini) 
01348     {
01349         switch(dir) 
01350         {
01351             /*case UP:
01352             break;*/
01353             case DOWN:
01354                 switch(result) 
01355                 {
01356                     case LEFT:
01357                         result = RIGHT;
01358                         break;
01359                     case DOWN:
01360                         result = UP;
01361                         break;
01362                     case RIGHT:
01363                         result = LEFT;
01364                         break;
01365                 }
01366                 break;
01367             case LEFT:
01368                 switch(result) 
01369                 {
01370                     case LEFT:
01371                         result = DOWN;
01372                         break;
01373                     case DOWN:
01374                         result = RIGHT;
01375                         break;
01376                     case RIGHT:
01377                         result = UP;
01378                         break;
01379                 }
01380                 break;
01381             case RIGHT:
01382                 switch(result) 
01383                 {
01384                     case LEFT:
01385                         result = UP;
01386                         break;
01387                     case DOWN:
01388                         result = LEFT;
01389                         break;
01390                     case RIGHT:
01391                         result = DOWN;
01392                         break;
01393                 }
01394                 break;
01395         }
01396     } 
01397     else
01398         result =0;
01399     return result;
01400 }
01401 
01402 void Directive::updateMaze(void)
01403 {
01404    char areaLatt =0;
01405     char areaVert =0;
01406     
01407    if((inchToCm(ultrasonicToInch(m_valueCapteurUltrasonic))<= 1) /*&& (IRToCm(ADCTomv(m_valueCapteurIR)) <= 80)*/)//enlever parce que il est lock avec des limites 
01408         { //capteur ultrasson embrouiller/imprecis
01409         
01410             debug(DEBUG_DIRECTIVE_TEST,"\n\r        -Capteur Ultrasson brouiller");
01411             //addTableauDeCommande(6);
01412         } 
01413         else if((inchToCm(ultrasonicToInch(m_valueCapteurUltrasonic))) <= DIRECTIVE_ULTRASONIC_LIMIT_SHORT)
01414         { //plus proche que 1 case
01415         #ifdef DEBUG_DIRECTIVE_UPDATE_MODULE
01416             debug("\n\r        -Objet proche %02f <= %i cm",inchToCm(ultrasonicToInch(m_valueCapteurUltrasonic)),DIRECTIVE_ULTRASONIC_LIMIT_SHORT);
01417             #endif
01418             areaLatt =0;
01419             
01420             if(IRToCm(ADCTomv(m_valueCapteurIR)) <= DIRECTIVE_IR_LIMIT_SHORT)
01421             {
01422                 /*
01423                     /---\
01424                     |?M?| //vert 0
01425                     |.X.| //latt 0
01426                     |...|
01427                     \---/
01428                 */
01429                 areaVert = 0;
01430             }
01431             else
01432             {
01433                 /*
01434                     /-M-\
01435                     |?V?| //vert 1
01436                     |.X.| //latt 0
01437                     |...|
01438                     \---/
01439                 */
01440                 areaVert = 1;
01441             }            
01442         }
01443         else if(inchToCm(ultrasonicToInch(m_valueCapteurUltrasonic)) <= DIRECTIVE_ULTRASONIC_LIMIT_MIDDLE)
01444         { //plus proche que 2 case
01445         #ifdef DEBUG_DIRECTIVE_UPDATE_MODULE
01446              debug("\n\r        -Objet proche %g <= %i cm",inchToCm(ultrasonicToInch(m_valueCapteurUltrasonic)),DIRECTIVE_ULTRASONIC_LIMIT_MIDDLE);
01447              #endif
01448             //modifier vue que il ne detecte pas asser loin
01449                     /*
01450                     /-M-\
01451                     |?V?| //vert 1
01452                     |.X.| //latt 0
01453                     |...|
01454                     \---/
01455                 */
01456             areaLatt =0;
01457             areaVert =1;
01458         } 
01459         else if(inchToCm(ultrasonicToInch(m_valueCapteurUltrasonic)) <= DIRECTIVE_ULTRASONIC_LIMIT_LONG)
01460         { //plus proche que 2 case
01461         #ifdef DEBUG_DIRECTIVE_UPDATE_MODULE
01462             debug("\n\r        -Objet proche %g <= %i cm",inchToCm(ultrasonicToInch(m_valueCapteurUltrasonic)),DIRECTIVE_ULTRASONIC_LIMIT_LONG);
01463             #endif
01464             //modifier vue que il ne detecte pas asser loin
01465             /*
01466                     /-M-\
01467                     |?V?| //vert 1
01468                     |.X.| //latt 0
01469                     |...|
01470                     \---/
01471                 */
01472             areaLatt =0;
01473             areaVert =1;
01474         } 
01475         else if(inchToCm(ultrasonicToInch(m_valueCapteurUltrasonic)) > DIRECTIVE_ULTRASONIC_LIMIT_LONG)
01476         { //plus proche que 2 case
01477         #ifdef DEBUG_DIRECTIVE_UPDATE_MODULE
01478             debug("\n\r        -Objet proche %g >= %i cm",inchToCm(ultrasonicToInch(m_valueCapteurUltrasonic)),DIRECTIVE_ULTRASONIC_LIMIT_LONG);
01479             #endif
01480             //modifier vue que il ne detecte pas asser loin
01481             /*
01482                 /?V?\
01483                 |?V?| //vert 2
01484                 |.X.| //latt 0
01485                 |...| // objet possiblement a proximiter
01486                 \---/
01487             */
01488             
01489             areaLatt =0;
01490             areaVert =2;
01491         }
01492         
01493         //debug("\n\r    areaLatt: %i,    areaVert: %i",areaLatt,areaVert);
01494     #endif
01495     
01496     #ifdef DEBUG_DIRECTIVE_LABYRINTH_USER_CTRL
01497         debug("\n\r---analise maze(manualy CTRL)---\n\r");
01498         int idCommand = -1;
01499         areaVert = 9;
01500         areaLatt = 9;
01501         /*do {
01502             debug("\n\r Enter areaVert [0,1,2]: ");
01503             idCommand = fgetc(pc) - '0';
01504             debug(" %i",idCommand);
01505         } while((idCommand < 0) && (idCommand > 2));
01506         areaVert = idCommand;
01507         
01508         do {
01509             debug("\n\r Enter areaLatt [0,1,2]: ");
01510             idCommand = fgetc(pc) - '0';
01511             debug(" %i",idCommand);
01512         } while((idCommand < 0) && (idCommand > 2));
01513         areaLatt = idCommand;*/
01514         
01515         debug("\n\r");
01516     #endif
01517     //changer lalgoritme ici
01518     
01519     /*
01520         /---\
01521         |?M?| //vert 0
01522         |.X.| //latt 0
01523         |...|
01524         \---/
01525         
01526         /-M-\
01527         |?V?| //vert 1
01528         |.X.| //latt 0
01529         |...|
01530         \---/
01531         
01532         /?M?\
01533         |VVV| //vert 1
01534         |.X.| //latt 1
01535         |...| // objet possiblement a proximiter
01536         \---/
01537         
01538         /?M?\
01539         |VVV| //vert 1
01540         |.X.| //latt 2
01541         |...| // cas impossible
01542         \---/
01543         
01544         /?V?\
01545         |?V?| //vert 2
01546         |.X.| //latt 0
01547         |...| // objet possiblement a proximiter
01548         \---/
01549         
01550         /?V?\
01551         |VVV| //vert 2
01552         |.X.| //latt 1
01553         |...| // objet possiblement a proximiter
01554         \---/
01555         
01556         /VVV\
01557         |VVV| //vert 2
01558         |.X.| //latt 2
01559         |...|
01560         \---/
01561     */
01562     //vertical==0 latt==0 //mur devant
01563     //vertical==1 latt==1
01564     #ifdef DEBUG_DIRECTIVE_UPDATE_MODULE
01565             debug("\n\r   vertical:%i \n\r   latt: %i",areaVert,areaLatt);
01566     #endif
01567     ////////////////////////////////////
01568     //345  
01569     //012  | numerotation des case
01570     ///////////////////////////////////
01571     signed char fieldX[6]= {0,0,0,0,0,0};
01572     signed char fieldY[6]= {0,0,0,0,0,0};
01573     bool fieldSet = false;
01574     
01575     switch(myMaze->getDirection()) 
01576     {
01577         case UP:
01578             fieldX[0] = myMaze->getX()-1;
01579             fieldY[0] = myMaze->getY()+1;
01580             fieldX[1] = myMaze->getX();
01581             fieldY[1] = myMaze->getY()+1;
01582             fieldX[2] = myMaze->getX()+1;
01583             fieldY[2] = myMaze->getY()+1;
01584             fieldX[3] = myMaze->getX()-1;
01585             fieldY[3] = myMaze->getY()+2;
01586             fieldX[4] = myMaze->getX();
01587             fieldY[4] = myMaze->getY()+2;
01588             fieldX[5] = myMaze->getX()+1;
01589             fieldY[5] = myMaze->getY()+2;
01590             break;
01591         
01592         case DOWN:
01593             fieldX[0] = myMaze->getX()-1;
01594             fieldY[0] = myMaze->getY()-1;
01595             fieldX[1] = myMaze->getX();
01596             fieldY[1] = myMaze->getY()-1;
01597             fieldX[2] = myMaze->getX()+1;
01598             fieldY[2] = myMaze->getY()-1;
01599             fieldX[3] = myMaze->getX()-1;
01600             fieldY[3] = myMaze->getY()-2;
01601             fieldX[4] = myMaze->getX();
01602             fieldY[4] = myMaze->getY()-2;
01603             fieldX[5] = myMaze->getX()+1;
01604             fieldY[5] = myMaze->getY()-2;
01605             break;
01606         
01607         case LEFT:
01608             fieldX[0] = myMaze->getX()-1;
01609             fieldY[0] = myMaze->getY()-1;
01610             fieldX[1] = myMaze->getX()-1;
01611             fieldY[1] = myMaze->getY();
01612             fieldX[2] = myMaze->getX()-1;
01613             fieldY[2] = myMaze->getY()+1;
01614             fieldX[3] = myMaze->getX()-2;
01615             fieldY[3] = myMaze->getY()-1;
01616             fieldX[4] = myMaze->getX()-2;
01617             fieldY[4] = myMaze->getY();
01618             fieldX[5] = myMaze->getX()-2;
01619             fieldY[5] = myMaze->getY()+1;
01620             break;
01621         
01622         case RIGHT:
01623             fieldX[0] = myMaze->getX()+1;
01624             fieldY[0] = myMaze->getY()-1;
01625             fieldX[1] = myMaze->getX()+1;
01626             fieldY[1] = myMaze->getY();
01627             fieldX[2] = myMaze->getX()+1;
01628             fieldY[2] = myMaze->getY()+1;
01629             fieldX[3] = myMaze->getX()+2;
01630             fieldY[3] = myMaze->getY()-1;
01631             fieldX[4] = myMaze->getX()+2;
01632             fieldY[4] = myMaze->getY();
01633             fieldX[5] = myMaze->getX()+2;
01634             fieldY[5] = myMaze->getY()+1;
01635             break;
01636     }
01637     if(areaVert >= areaLatt) 
01638     {
01639         switch(areaVert) 
01640         {
01641             case 0:
01642                 /*
01643                     /---\
01644                     |?M?| //vert 0
01645                     |.X.| //latt 0
01646                     |...|
01647                     \---/
01648                 */
01649                 myMaze->setC(Labyrinthe::mur,fieldX[1],fieldY[1]);
01650                 fieldSet = true;
01651                 break;
01652             case 1:
01653                 /*
01654                     /-M-\
01655                     |?V?| //vert 1
01656                     |.X.| //latt 0
01657                     |...|
01658                     \---/
01659                 */
01660                 myMaze->setC(Labyrinthe::vide,fieldX[1],fieldY[1]);
01661                 myMaze->setC(Labyrinthe::mur,fieldX[4],fieldY[4]);
01662                 fieldSet = true;
01663                 
01664                 if(areaLatt == 1) 
01665                 {
01666                     /*
01667                         /?M?\
01668                         |VVV| //vert 1
01669                         |.X.| //latt 1
01670                         |...| // objet possiblement a proximiter
01671                         \---/
01672                     */
01673                     myMaze->setC(Labyrinthe::vide,fieldX[0],fieldY[0]);
01674                     myMaze->setC(Labyrinthe::vide,fieldX[2],fieldY[2]);
01675                 }
01676                 break;
01677             case 2:
01678                 fieldSet = true;
01679                 switch(areaLatt) 
01680                 {
01681                     case 0:
01682                         /*
01683                             /?V?\
01684                             |?V?| //vert 2
01685                             |.X.| //latt 0
01686                             |...| // objet possiblement a proximiter
01687                             \---/
01688                         */
01689                         myMaze->setC(Labyrinthe::vide,fieldX[1],fieldY[1]);
01690                         myMaze->setC(Labyrinthe::vide,fieldX[4],fieldY[4]);
01691                         break;
01692                     case 1:
01693                         /*
01694                             /?V?\
01695                             |VVV| //vert 2
01696                             |.X.| //latt 1
01697                             |...| // objet possiblement a proximiter
01698                             \---/
01699                         */
01700                         for(int i = 0; i<3; i++)myMaze->setC(Labyrinthe::vide,fieldX[i],fieldY[i]);
01701                         myMaze->setC(Labyrinthe::vide,fieldX[4],fieldY[4]);
01702                         break;
01703                     case 2:
01704                         /*
01705                             /VVV\
01706                             |VVV| //vert 2
01707                             |.X.| //latt 2
01708                             |...|
01709                             \---/
01710                         */
01711                         for(int i = 0; i<6; i++)myMaze->setC( Labyrinthe::vide,fieldX[i],fieldY[i]);
01712                         break;
01713                 }
01714                 break;
01715         }
01716     }
01717     
01718     if(fieldSet == false) 
01719     { // on a un cas impossible
01720         //myMaze->setC(Labyrinthe::error,fieldX[1],fieldY[1]);
01721     }
01722     
01723     ////////////////////////////////////
01724 }
01725 void Directive::checkOtherWay(char &caseFront, char &caseBack, char &caseLeft, char &caseRight)
01726 {
01727     caseFront = myMaze->getC_Foward();
01728     caseBack  = myMaze->getC_Backward();
01729     caseRight = myMaze->getC_ToRight();
01730     caseLeft = myMaze->getC_ToLeft();
01731 }
01732 bool Directive::searchNewWay(void)
01733 {
01734     debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r ---- Search new way ----\n\r");
01735     debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r  Labyrinthe map: X:%02i Y:%02i \n\r",(signed char)(myMaze->getX()),(signed char)(myMaze->getY()));
01736     bool result=false;
01737     string backupMap = myMaze->getAllMap();
01738     signed char backupPosX = myMaze->getX();
01739     signed char backupPosY = myMaze->getY();
01740     string searchMap = backupMap;
01741     char tempdir,nextCase=0;
01742     positionXY tempPosition;
01743     char backupDir = myMaze->getDirection();
01744     
01745     
01746     bool noOtherWay = false;//si apres un moment tu est entourer de mur
01747     bool wrongWay = false; //si jamais vien un moment que tu est pris /doit rebrousser chemin
01748     //bool checkAutour = false;
01749     
01750     bufferNewWay.clear();
01751     tempPosition.posX = myMaze->getX();
01752     tempPosition.posY = myMaze->getY();
01753     //bufferNewWay.push_back(tempPosition); // pas sur de lutiliter
01754     
01755     debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r Debut Boucle");
01756     //asdfasda// Ici voire pour pt amiliorer et cheker a gauche et a droite au cas ou tu verai une case vide parce que la tu cours direct dans un mur avant de tourner.
01757     while((!result)&&(!noOtherWay)) 
01758     {
01759         // nextCase = 0;
01760         debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r Cycle Boucle\n\r");
01761         nextCase = myMaze->getC_Foward();
01762         
01763         debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r nextCase: [%02x]",nextCase);
01764         switch(nextCase ) 
01765         {
01766             
01767             case Labyrinthe::pasExplorer :
01768             case Labyrinthe::vide :
01769                 debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r vide ou pas explorer: ");
01770                 myMaze->moveFoward();
01771                 result = true;
01772                 break;
01773             
01774             case Labyrinthe::explorer :// ici pt amiliorer
01775                 //add position a la liste
01776                 debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r Explorer");
01777                 myMaze->moveFoward();
01778                 //myMaze->setMyPos(Labyrinthe::error);
01779                 break;
01780             
01781             case Labyrinthe::mur:
01782                 tempdir = rand() % 2;
01783                 debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r Mur: %i",tempdir);
01784                 if(tempdir == 1) 
01785                 {
01786                     debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r left right");
01787                     tempdir = myMaze->getC_ToLeft();
01788                     debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r nextCase: [%02x]",tempdir);
01789                     if((Labyrinthe::case_t)tempdir != Labyrinthe::mur) 
01790                     {
01791                         debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r turn Left");
01792                         myMaze->turnLeft();
01793                         
01794                         //backupDir = myMaze->getDirection();
01795                     } 
01796                     else 
01797                     {
01798                         tempdir = myMaze->getC_ToRight();
01799                         debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r nextCase: [%02x]",tempdir);
01800                         if((Labyrinthe::case_t)tempdir != Labyrinthe::mur) 
01801                         {
01802                             debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r turn Right");
01803                             myMaze->turnRight();
01804                             
01805                             //backupDir = myMaze->getDirection();
01806                         } 
01807                         else 
01808                         {
01809                             debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r aucun coter");
01810                             wrongWay = true; // verifie dans la liste
01811                         }
01812                     }
01813                     
01814                 } 
01815                 else 
01816                 {
01817                     debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r right left");
01818                     tempdir = myMaze->getC_ToRight();
01819                     debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r nextCase: [%02x]",tempdir);
01820                     if((Labyrinthe::case_t)tempdir != Labyrinthe::mur) 
01821                     {
01822                         debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r turn Right");
01823                         myMaze->turnRight();
01824                         
01825                         //backupDir = myMaze->getDirection();
01826                     } 
01827                     else 
01828                     {
01829                         tempdir = myMaze->getC_ToLeft();
01830                         debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r nextCase: [%02x]",tempdir);
01831                         if((Labyrinthe::case_t)tempdir != Labyrinthe::mur) 
01832                         {
01833                             debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r turn Left");
01834                             myMaze->turnLeft();
01835                             
01836                             //backupDir = myMaze->getDirection();
01837                         } 
01838                         else 
01839                         {
01840                             debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r aucun coter");
01841                             wrongWay = true; // verifie dans la liste
01842                         }
01843                     }
01844                     /* if(wrongWay == false)
01845                     myMaze->moveFoward();*/
01846                 }
01847                 
01848                 //myMaze->setMyPos(Labyrinthe::error);
01849                 break;
01850         }
01851         
01852         tempPosition.posX = myMaze->getX();
01853         tempPosition.posY = myMaze->getY();
01854         tempPosition.direction = myMaze->getDirection();
01855         
01856         /*debug("\n\rtempPosition.posX: %i",tempPosition.posX);
01857             debug("\n\rtempPosition.posY: %i",tempPosition.posY);
01858             debug("\n\rbufferNewWay.posX: %i",(bufferNewWay.back().posX));
01859         debug("\n\rbufferNewWay.posY: %i",(bufferNewWay.back().posY));*/
01860         
01861         if((bufferNewWay.empty())||(((bufferNewWay.back().posX) != tempPosition.posX) || ((bufferNewWay.back().posY) != tempPosition.posY))) 
01862         {
01863             bufferNewWay.push_back(tempPosition);
01864             debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r bufferNewWay: %i",bufferNewWay.size());
01865             debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\rtempPosition.posX: %i",tempPosition.posX);
01866             debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\rtempPosition.posY: %i",tempPosition.posY);
01867         } 
01868         else if((bufferNewWay.empty())&& ((backupPosX != myMaze->getX()) || (backupPosY != myMaze->getY())) ) 
01869         {
01870             bufferNewWay.push_back(tempPosition);
01871             debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r bufferNewWay: %i",bufferNewWay.size());
01872             debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\rtempPosition.posX: %i",tempPosition.posX);
01873             debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\rtempPosition.posY: %i",tempPosition.posY);
01874         } 
01875         else if(((bufferNewWay.back()).posX == tempPosition.posX) && ((bufferNewWay.back()).posY == tempPosition.posY) && ((bufferNewWay.back()).direction != tempPosition.direction))//ra fait un tours
01876         {
01877             debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r pop back a cause dun tournie");
01878             bufferNewWay.pop_back();
01879             bufferNewWay.push_back(tempPosition);
01880         }
01881         
01882         else
01883         {
01884             debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r buffer non adder");
01885             
01886         }
01887         
01888         
01889         if(wrongWay) 
01890         {
01891             char caseFront,caseBack,caseLeft,caseRight;
01892             char wallCount;
01893             char directive;
01894             bool haveValuesChange = false;
01895             bool caseVideTrouver = false;
01896             bool caseExplorerTrouver = false;
01897             debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\n\r wrong way patching");
01898             debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r bufferNewWay size: %i",bufferNewWay.size());
01899             std::list<positionXY>::iterator it;
01900             do 
01901             {
01902                 debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r --wrong way boucle");
01903                 
01904                 //bufferNewWay.pop_back();
01905                 if(!bufferNewWay.empty()) 
01906                 {
01907                     directive = 0;//defenir fait rien
01908                     it=bufferNewWay.end();
01909                     haveValuesChange = false;
01910                     caseVideTrouver = false;
01911                     caseExplorerTrouver = false;
01912                     tempPosition.posX = (bufferNewWay.back()).posX;
01913                     tempPosition.posY = bufferNewWay.back().posY;
01914                     
01915                     
01916                     myMaze->setX(bufferNewWay.back().posX);
01917                     myMaze->setY(bufferNewWay.back().posY);
01918                     wallCount = 0;
01919                     checkOtherWay(caseFront,caseBack,caseLeft,caseRight);
01920                     
01921                     if((Labyrinthe::case_t)caseFront == Labyrinthe::mur)wallCount++;
01922                     if((Labyrinthe::case_t)caseBack  == Labyrinthe::mur)wallCount++;
01923                     if((Labyrinthe::case_t)caseLeft  == Labyrinthe::mur)wallCount++;
01924                     if((Labyrinthe::case_t)caseRight == Labyrinthe::mur)wallCount++;
01925                     
01926                     if(wallCount == 3)
01927                     {
01928                         debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r PATH trouver ");
01929                         myMaze->setC(Labyrinthe::mur,tempPosition.posX,tempPosition.posY);
01930                     }
01931                     debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r checkOtherWay front: %i, back: %i, LEFT: %i, RIGHT: %i",caseFront,caseBack,caseLeft,caseRight);
01932                     //tempPosition.posX = (bufferNewWay.back()).posX;
01933                     //tempPosition.posY = bufferNewWay.back().posY;
01934                     /*if(((Labyrinthe::case_t)caseFront == Labyrinthe::vide) || ((Labyrinthe::case_t)caseBack == Labyrinthe::vide) || ((Labyrinthe::case_t)caseLeft == Labyrinthe::vide) || ((Labyrinthe::case_t)caseRight == Labyrinthe::vide))
01935                     {
01936                         debug("\n\r Path vide trouver!!!");
01937                         caseVideTrouver = true;
01938                         wrongWay = false;
01939                     }*/
01940                     
01941                     //else
01942                     //{
01943                         it--;
01944                         if(/*((Labyrinthe::case_t)caseFront != Labyrinthe::error) &&*/ ((Labyrinthe::case_t)caseFront != Labyrinthe::mur)) 
01945                         { // une anciene case est potentiele,emt bonne
01946                             myMaze->getXY_Foward(tempPosition.posX,tempPosition.posY);
01947                             
01948                             if((Labyrinthe::case_t)caseFront == Labyrinthe::vide)
01949                             {
01950                                 debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r Path vide trouver!!!");
01951                                 caseVideTrouver = true;
01952                                 haveValuesChange = true;
01953                                 directive = 1;
01954                                 wrongWay = false;
01955                                 //debug("\n\r moveFoward");
01956                             }
01957                             if((!caseVideTrouver) && (!caseExplorerTrouver))
01958                             {
01959                                 caseExplorerTrouver = true;
01960                             /*if(((*it).posX != tempPosition.posX) && ((*it).posY != tempPosition.posY)) {
01961                                 wrongWay = false;
01962                                 myMaze->moveFoward();//setDirection(UP);
01963                                 debug("\n\r moveFoward");
01964                                 debug("\n\r chemin trouver");
01965                                 haveValuesChange = true;
01966                             } else if(bufferNewWay.size() == 1) {*/
01967                               //  debug("\n\r Last thing in buffer");
01968                                 //myMaze->moveFoward();//setDirection(UP);
01969                                 directive = 1;// move foward
01970                                 haveValuesChange = true;
01971                                // debug("\n\r moveFoward");
01972                             }
01973                         }
01974                         
01975                         if(/*((Labyrinthe::case_t)caseBack != Labyrinthe::error) &&*/ ((Labyrinthe::case_t)caseBack != Labyrinthe::mur)) 
01976                         { // une anciene case est potentiele,emt bonne
01977                             myMaze->getXY_Backward(tempPosition.posX,tempPosition.posY);
01978                             
01979                             if((Labyrinthe::case_t)caseBack == Labyrinthe::vide)
01980                             {
01981                                 debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r Path vide trouver!!!");
01982                                 caseVideTrouver = true;
01983                                 haveValuesChange = true;
01984                                 directive = 2;
01985                                 wrongWay = false;
01986                                 //debug("\n\r moveFoward");
01987                             }
01988                             if((!caseVideTrouver) && (!caseExplorerTrouver))
01989                             {
01990                                 caseExplorerTrouver = true;
01991                             /*if(((*it).posX != tempPosition.posX) && ((*it).posY != tempPosition.posY)) {
01992                                 wrongWay = false;
01993                                 myMaze->turnBack();//setDirection(DOWN);
01994                                 debug("\n\r turn Back");
01995                                 debug("\n\r chemin trouver");
01996                                 haveValuesChange = true;
01997                             } else if(bufferNewWay.size() == 1) {*/
01998                                 //debug("\n\r Last thing in buffer");
01999                                 //myMaze->turnBack();//setDirection(DOWN);
02000                                 directive = 2;
02001                                 //debug("\n\r turn Back");
02002                                 haveValuesChange = true;
02003                             }
02004                             debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r direction: %i",myMaze->getDirection());
02005                         }
02006                         
02007                         if(/*((Labyrinthe::case_t)caseLeft != Labyrinthe::error) &&*/ ((Labyrinthe::case_t)caseLeft != Labyrinthe::mur)) 
02008                         { // une anciene case est potentiele,emt bonne
02009                             myMaze->getXY_Left(tempPosition.posX,tempPosition.posY);
02010                             
02011                             if((Labyrinthe::case_t)caseLeft == Labyrinthe::vide)
02012                             {
02013                                 debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r Path vide trouver!!!");
02014                                 caseVideTrouver = true;
02015                                 haveValuesChange = true;
02016                                 directive = 3;
02017                                 wrongWay = false;
02018                                 //debug("\n\r moveFoward");
02019                             }
02020                             if((!!caseVideTrouver) && (!caseExplorerTrouver))
02021                             {
02022                                 caseExplorerTrouver = true;
02023                             /*if(((*it).posX != tempPosition.posX) && ((*it).posY != tempPosition.posY)) {
02024                                 wrongWay = false;
02025                                 myMaze->turnLeft();//setDirection(LEFT);
02026                                 debug("\n\r turn Left");
02027                                 debug("\n\r chemin trouver");
02028                                 haveValuesChange = true;
02029                             } else if(bufferNewWay.size() == 1) {*/
02030                                 //debug("\n\r Last thing in buffer");
02031                                 //myMaze->turnLeft();//setDirection(LEFT);
02032                                 directive = 3;
02033                                 //debug("\n\r turn Left");
02034                                 haveValuesChange = true;
02035                             }
02036                         }
02037                         
02038                         if(/*((Labyrinthe::case_t)caseRight != Labyrinthe::error) &&*/ ((Labyrinthe::case_t)caseRight != Labyrinthe::mur)) 
02039                         { // une anciene case est potentiele,emt bonne
02040                             myMaze->getXY_Right(tempPosition.posX,tempPosition.posY);
02041                             
02042                             if((Labyrinthe::case_t)caseRight == Labyrinthe::vide)
02043                             {
02044                                 debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r Path vide trouver!!!");
02045                                 caseVideTrouver = true;
02046                                 haveValuesChange = true;
02047                                 directive = 4;
02048                                 wrongWay = false;
02049                                 //debug("\n\r moveFoward");
02050                             }
02051                             if((!caseVideTrouver)&& (!caseExplorerTrouver))
02052                             {
02053                                 caseExplorerTrouver = true;
02054                             /*if(((bufferNewWay.back()).posX != tempPosition.posX) && ((bufferNewWay.back()).posY != tempPosition.posY)) {
02055                                 wrongWay = false;
02056                                 myMaze->turnRight();//setDirection(RIGHT);
02057                                 debug("\n\r turn Right");
02058                                 debug("\n\r chemin trouver");
02059                                 haveValuesChange = true;
02060                             } else if(bufferNewWay.size() == 1) {*/
02061                                 //debug("\n\r Last thing in buffer");
02062                                 //myMaze->turnRight();//setDirection(RIGHT);
02063                                 directive = 4;
02064                                // debug("\n\r turn Right");
02065                                 haveValuesChange = true;
02066                             }
02067                         }
02068                         
02069                     //} 
02070                     
02071                     
02072                 }   
02073                 else
02074                     noOtherWay = true;
02075                 
02076                 
02077                 if(haveValuesChange)
02078                 {
02079                     switch(directive)
02080                     {
02081                         case 0:
02082                             debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r doNothing");
02083                             break;
02084                         case 1:
02085                             debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r moveFoward");
02086                             myMaze->moveFoward();
02087                             break;
02088                         case 2:
02089                             debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r turn Back");
02090                             myMaze->turnBack();
02091                             break;
02092                         case 3:
02093                             debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r turn Left");
02094                             myMaze->turnLeft();
02095                             break;
02096                         case 4:
02097                             debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r turn Right");
02098                             myMaze->turnRight();
02099                             break;
02100                     }
02101                     tempPosition.posX = myMaze->getX();
02102                     tempPosition.posY = myMaze->getY();
02103                     tempPosition.direction = myMaze->getDirection();
02104                     debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r bufferNewWay: %i",bufferNewWay.size());
02105                     debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\rtempPosition.posX: %i",tempPosition.posX);
02106                     debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\rtempPosition.posY: %i",tempPosition.posY);
02107                     debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\rtempPosition.direction: %i",tempPosition.direction);
02108                     for (std::list<positionXY>::iterator it=bufferNewWay.begin(),itEnd;( it != bufferNewWay.end()) && (!bufferNewWay.empty()); ++it) 
02109                     {
02110                         //tempPosition = *(it);
02111                         itEnd = bufferNewWay.end();
02112                         debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r Bouble de meme position");
02113                         debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\rtempPosition.posX: %i",(*it).posX);
02114                         debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\rtempPosition.posY: %i",(*it).posY);
02115                         debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\rtempPosition.direction: %i",(*it).direction);
02116                         if(((*it).posX == tempPosition.posX) && ((*it).posY == tempPosition.posY) && ((*it).direction == tempPosition.direction))
02117                         {
02118                             while(((*it).posX != (*itEnd).posX) &&
02119                                   ((*it).posY != (*itEnd).posY) &&
02120                                   ((*it).direction != (*itEnd).direction) && (!bufferNewWay.empty()))
02121                             {
02122                                 itEnd = bufferNewWay.end();
02123                                 debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r pop back et enmurer");
02124                                 debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r     tempPosition.posX: %i",(bufferNewWay.back()).posX);
02125                                 debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r     tempPosition.posY: %i",(bufferNewWay.back()).posY);
02126                                 debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r     tempPosition.direction: %i",(bufferNewWay.back()).direction);
02127                                 myMaze->setC(Labyrinthe::mur,(bufferNewWay.back()).posX,(bufferNewWay.back()).posY);
02128                                 bufferNewWay.pop_back();
02129                             }
02130                             //it--;
02131                             noOtherWay = true;//placer ici pour patcher vue que je suis taner
02132                             //checkAutour = true;
02133                         }
02134                     }
02135                     if(((bufferNewWay.back()).posX == tempPosition.posX) && ((bufferNewWay.back()).posY == tempPosition.posY) && ((bufferNewWay.back()).direction != tempPosition.direction))//ra fait un tours
02136                     {
02137                         debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r pop back a cause dun tournie");
02138                         bufferNewWay.pop_back();
02139                     }
02140                     bufferNewWay.push_back(tempPosition);
02141                     //bufferNewWay.pop_back();//on enleve pour pouvoir lire le dernier
02142                 }
02143                 else
02144                 {
02145                     debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r pop back");
02146                     bufferNewWay.pop_back();//on enleve pour pouvoir lire le dernier
02147                 }
02148                 #ifdef DEBUG_DIRECTIVE_LABYRINTH
02149                 string mymap = myMaze->showMap();
02150                 debug("\n\r  Labyrinthe map: X:%02i Y:%02i \n\r",(signed char)(myMaze->getX()),(signed char)(myMaze->getY()));
02151                 //char caseCaract = 0;
02152                 debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r direction: %i",myMaze->getDirection());
02153                 debug("\n\r");
02154                 for(int i=0; i<3; i++) debug(" [%c] ",myMaze->caseToChar((Labyrinthe::case_t)mymap[i+6]));
02155                 debug("\n\r");
02156                 for(int i=0; i<3; i++) debug(" [%c] ",myMaze->caseToChar((Labyrinthe::case_t)mymap[i+3]));
02157                 debug("\n\r");
02158                 for(int i=0; i<3; i++) debug(" [%c] ",myMaze->caseToChar((Labyrinthe::case_t)mymap[i]));
02159                 #endif
02160                 
02161                 #ifdef DEBUG_DIRECTIVE_TASK_PAUSE
02162                 debug(DEBUG_DIRECTIVE_LABYRINTH,"\n\r press any key...\n\r");
02163                 
02164                 fgetc(pc);
02165                 #endif
02166                 
02167             } while((wrongWay) && (!noOtherWay));
02168             debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r Fin Boucle");
02169         }
02170         #ifdef DEBUG_DIRECTIVE_TASK_PAUSE
02171         debug("\n\r press any key...\n\r"); fgetc(pc);
02172         #endif
02173     }
02174     
02175     myMaze->setX(backupPosX);
02176     myMaze->setY(backupPosY);
02177     myMaze->setAllMap(backupMap);
02178     myMaze->setDirection(backupDir);
02179     if(noOtherWay)
02180     {
02181         result = false;
02182         myMaze->setAllMap("");
02183         myMaze->setX(0);
02184         myMaze->setY(0);
02185         myMaze->setDirection(backupDir);
02186     }
02187     
02188     debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\n\r dans le buffer");
02189     debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r bufferNewWay: %i",bufferNewWay.size());
02190     for (std::list<positionXY>::iterator it=bufferNewWay.begin(); it != bufferNewWay.end(); ++it) {
02191         //tempPosition = *(it);
02192         debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\rtempPosition.posX: %i",(*it).posX);
02193         debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\rtempPosition.posY: %i",(*it).posY);
02194         debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\rtempPosition.direction: %i",(*it).direction);
02195     }
02196     debug(DEBUG_DIRECTIVE_MAZE_GRAPHICAL_INTERFACE_ENABLE,"\n\r ----------------");
02197     return result;
02198 }
02199 
02200 bool Directive::isAnotherWay(void)
02201 {
02202     bool result=false;
02203     
02204     return result;
02205 }
02206 void Directive::turnRightDirection(char currentDir, char nextDir)
02207 {
02208                                 
02209                             
02210     #ifndef DEBUG_DIRECTIVE_LEG_DISABLE
02211     if(((nextDir + currentDir) == (UP + DOWN)) ||
02212         ((nextDir + currentDir) == (LEFT + RIGHT)))
02213     {
02214         if(rand()%2)
02215         {
02216             for(int loop=0; loop < DIRECTIVE_NUMBER_TURN_90_DEG; loop++) addTableauDeCommande(TBL_CMD_TURN_LEFT);
02217             for(int loop=0; loop < DIRECTIVE_NUMBER_TURN_90_DEG; loop++) addTableauDeCommande(TBL_CMD_TURN_LEFT);
02218             //addTableauDeCommande(TBL_CMD_TURN_LEFT);
02219         }
02220         else
02221         {
02222             for(int loop=0; loop < DIRECTIVE_NUMBER_TURN_90_DEG; loop++) addTableauDeCommande(TBL_CMD_TURN_RIGHT);
02223             for(int loop=0; loop < DIRECTIVE_NUMBER_TURN_90_DEG; loop++) addTableauDeCommande(TBL_CMD_TURN_RIGHT);
02224             //addTableauDeCommande(TBL_CMD_TURN_RIGHT);
02225         }
02226     }
02227     else
02228     {
02229      switch(currentDir)
02230      {
02231         case UP:
02232             if(nextDir == LEFT) 
02233             {
02234                 for(int loop=0; loop < DIRECTIVE_NUMBER_TURN_90_DEG; loop++) addTableauDeCommande(TBL_CMD_TURN_LEFT);
02235             }
02236             else if(nextDir == RIGHT)
02237             {
02238                 for(int loop=0; loop < DIRECTIVE_NUMBER_TURN_90_DEG; loop++) addTableauDeCommande(TBL_CMD_TURN_RIGHT);
02239             }
02240             break;
02241         case DOWN:
02242             if(nextDir == LEFT) 
02243             {
02244                 for(int loop=0; loop < DIRECTIVE_NUMBER_TURN_90_DEG; loop++) addTableauDeCommande(TBL_CMD_TURN_RIGHT);
02245             }
02246             else if(nextDir == LEFT)
02247             {
02248                 for(int loop=0; loop < DIRECTIVE_NUMBER_TURN_90_DEG; loop++) addTableauDeCommande(TBL_CMD_TURN_LEFT);
02249             }
02250             break;
02251         case LEFT:
02252             if(nextDir == UP)   
02253             {
02254                 for(int loop=0; loop < DIRECTIVE_NUMBER_TURN_90_DEG; loop++) addTableauDeCommande(TBL_CMD_TURN_RIGHT);
02255             }
02256             else if(nextDir == DOWN)
02257             {
02258                 for(int loop=0; loop < DIRECTIVE_NUMBER_TURN_90_DEG; loop++) addTableauDeCommande(TBL_CMD_TURN_LEFT);
02259             }
02260             break;
02261         case RIGHT:
02262              if(nextDir == UP)  
02263             {
02264                 for(int loop=0; loop < DIRECTIVE_NUMBER_TURN_90_DEG; loop++) addTableauDeCommande(TBL_CMD_TURN_LEFT);
02265             }
02266             else if(nextDir == DOWN)
02267             {
02268                 for(int loop=0; loop < DIRECTIVE_NUMBER_TURN_90_DEG; loop++) addTableauDeCommande(TBL_CMD_TURN_RIGHT);
02269             }
02270             break;
02271      }
02272     }
02273     #endif
02274 }