v7
Robot.cpp
- Committer:
- fab16
- Date:
- 2017-03-16
- Revision:
- 7:fa09588320d0
- Parent:
- 6:9d4190ab2739
- Child:
- 8:9d0e8da27044
File content as of revision 7:fa09588320d0:
#include "Robot.h" #include "m3pi.h" m3pi m3piR; SRF05 srf(p21,p22); Robot::Robot(){ obstacle = false; Affichage affichage; LED led; Deplacement deplacement; Pattern pattern; /* for(int i=0; i<4; i++){ this->tabObstacle[i]=false; }*/ } Robot::~Robot(){ // TODO fermer connexion bluetooth } Affichage Robot::getAffichage(){ return affichage; } LED Robot::getLed(){ return led; } Deplacement Robot::getDeplacement(){ return deplacement; } Pattern Robot::getPattern(){ return pattern; } void Robot::action(char idAction){ switch(idAction){ // deplacement simple case 'a' : { if(obstacle==false){ this->deplacement.avancer(); break; } } case 'b' : { this->deplacement.droite(); break; } case 'c' : { this->deplacement.reculer(); break; } case 'd' : { this->deplacement.gauche(); break; } case 'e': { this->deplacement.tourner_gauche(); break; } case 'f' : { this->deplacement.tourner_droite(); break; } // pattern case 'g' : { if(obstacle==false){ this->pattern.carre(); break; } } case 'h' : { if(obstacle==false){ this->pattern.triangle(); break; } } // led case 'i' : { this->led.K1000(1); break; } case 'j' : { this->led.K2000(1); break; } case 'k' : { this->led.K3000(1); break; } case 'l' : { this->led.K4000(1); break; } case 'm' : { this->led.LED_desynchrone(1); break; } case 'n' : { this->led.LED_Blinking(DigitalOut (LED1),1); break; } case 'o' : { this->led.LED_Blinking(DigitalOut (LED2),1); break; } case 'p' : { this->led.LED_Blinking(DigitalOut (LED3),1); break; } case 'q' : { this->led.LED_Blinking(DigitalOut (LED4),1); break; } // affichage case 'r' : { this->affichage.bonjour(); break; } } } void Robot::utiliserUltrason(){ affichage.effacerTout(); float result = srf.read(); //m3piR.printf("%.1f",result); affichage.affichageUltrason(result); if(result <= 8){ obstacle = true; } else{ obstacle = false; } affichage.afficherObstacle(obstacle); } void Robot::afficherObstacle(){ affichage.afficherObstacle(obstacle); } void Robot::scanneEnvironement(){ for(int i=1; i<4; i++){ utiliserUltrason(); if(obstacle==true){ tabObstacle[i]=true; } else{ tabObstacle[i]=false; } obstacle=false; wait(1); deplacement.quartRotation(); wait(2); } deplacement.quartRotation(); }