v7

Dependents:   robot_final

Robot.cpp

Committer:
fab16
Date:
2017-03-15
Revision:
5:152295068384
Parent:
4:c8ae1b606d51
Child:
6:9d4190ab2739

File content as of revision 5:152295068384:

#include "Robot.h"
#include "m3pi.h"
   
    m3pi m3piR; 
    SRF05 srf(p9,p10);

   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(int idAction){
     
        switch(idAction){
        
            // deplacement simple
            case 0 : 
            {
                if(obstacle==false){
                    this->deplacement.avancer();
                    break;
                }
            }
               
            case 1 :
            {
                this->deplacement.droite();
                break;
            }
               
            case 2 :
            {
                this->deplacement.reculer();
                break;
            }
              
            case 3 : 
            {
                this->deplacement.gauche();
                break;
            }
                
            case 4 : 
            {
                this->deplacement.tourner_gauche();
                break;
            }
            
            case 5 :
            {
                this->deplacement.tourner_droite();
                break;
            }
            
            // pattern
            
            case 6 :
            {
                if(obstacle==false){
                    this->pattern.carre();
                    break;
                }
            }
            
             case 7 :
            {
                if(obstacle==false){
                    this->pattern.triangle();
                    break;
                }
            }
            
            // led
            case 8 :
            {
                this->led.K1000(1);
                break;
            }
            
            case 9 :
            {
                this->led.K2000(1);
                break;
            }
            
            case 10 :
            {
                this->led.K3000(1);
                break;
            }
            
            case 11 :
            {
                this->led.K4000(1);
                break;
            }
            
            case 12 :
            {
                this->led.LED_desynchrone(1);
                break;
            }
            
              case 13 :
            {
                this->led.LED_Blinking(DigitalOut (LED1),1);
                break;
            }
            
             case 14 :
            {
                this->led.LED_Blinking(DigitalOut (LED2),1);
                break;
            }
            
             case 15 :
            {
                this->led.LED_Blinking(DigitalOut (LED3),1);
                break;
            }
            
             case 16 :
            {
                this->led.LED_Blinking(DigitalOut (LED4),1);
                break;
            }
            
            
            // affichage
            
             case 17 :
            {
                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();
    }