v7

Dependents:   robot_final

Robot.cpp

Committer:
fab16
Date:
2017-03-23
Revision:
9:aff70d8f388a
Parent:
8:9d0e8da27044
Child:
10:d88127a08e44

File content as of revision 9:aff70d8f388a:

#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,char mode){
        int temps;
        
        if(mode=='a'){
            temps = 0.1;
        }
        else{
            temps = 2;
        }
        
        switch(idAction){
        
            // deplacement simple
            case 'a' : 
            {
                if(obstacle==false){
                    this->deplacement.avancer(temps);
                    break;
                }
            }
               
            case 'b' :
            {
                this->deplacement.droite(temps);
                break;
            }
               
            case 'c' :
            {
                this->deplacement.reculer(temps);
                break;
            }
              
            case 'd' : 
            {
                this->deplacement.gauche(temps);
                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;
                }
            }
            
            case 'i' :
            {
                this->pattern.rectangle();
                break;
            }
            
            // led
            case 'j' :
            {
                this->led.K1000(1);
                break;
            }
            
            case 'k' :
            {
                this->led.K2000(1);
                break;
            }
            
            case 'l' :
            {
                this->led.K3000(1);
                break;
            }
            
            case 'm' :
            {
                this->led.K4000(1);
                break;
            }
            
            case 'n' :
            {
                this->led.LED_desynchrone(1);
                break;
            }
            
              case 'o' :
            {
                this->led.LED_Blinking(DigitalOut (LED1),1);
                break;
            }
            
             case 'p' :
            {
                this->led.LED_Blinking(DigitalOut (LED2),1);
                break;
            }
            
             case 'q' :
            {
                this->led.LED_Blinking(DigitalOut (LED3),1);
                break;
            }
            
             case 'r' :
            {
                this->led.LED_Blinking(DigitalOut (LED4),1);
                break;
            }
            
            
            // affichage
            
             case 's' :
            {
                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();
        
    }