---

Dependencies:   mbed

Fork of MicroMouse_MASTER_FIVE by PES2_R2D2.0

main.cpp

Committer:
ruesipat
Date:
2018-03-07
Revision:
0:a9fe4ef404bf
Child:
1:d9e840c48b1e

File content as of revision 0:a9fe4ef404bf:

#include "mbed.h"
 
#include "IRSensor.h"
#include "EncoderCounter.h"
#include "LowpassFilter.h"
#include "Controller.h"

DigitalIn button(USER_BUTTON);
DigitalOut myled(LED1);
DigitalOut led0(PC_8);
DigitalOut led1(PC_6);
DigitalOut led2(PB_12);
DigitalOut led3(PA_7);
DigitalOut led4(PC_0);
DigitalOut led5(PC_9);

DigitalOut enableMotorDriver(PB_2);
DigitalIn motorDriverFault(PB_14);
DigitalIn motorDriverWarning(PB_15);

PwmOut pwmLeft(PA_8);
PwmOut pwmRight(PA_9);

EncoderCounter controllerLeft(PB_6, PB_7);
EncoderCounter controllerRight(PA_6, PC_7);

Controller controller(pwmLeft, pwmRight, controllerLeft, controllerRight);
 
 
//AnalogIn analog_value(A0);
 
DigitalOut enable(PC_1);


AnalogIn distance(PB_1); //Kreieren der Ein - und Ausgangsobjekte
DigitalOut bit0(PH_1);
DigitalOut bit1(PC_2);
DigitalOut bit2(PC_3);



IRSensor irSensor0(distance, bit0, bit1, bit2, 0);
IRSensor irSensor1(distance, bit0, bit1, bit2, 1);
IRSensor irSensor2(distance, bit0, bit1, bit2, 2);
IRSensor irSensor3(distance, bit0, bit1, bit2, 3);
IRSensor irSensor4(distance, bit0, bit1, bit2, 4);
IRSensor irSensor5(distance, bit0, bit1, bit2, 5);

int main() {

    
    enableMotorDriver = 1; // Schaltet den Leistungstreiber ein

    enable = 1;
    
    while(1) {
        
        
        
        float distance0 = irSensor0.read();
        float distance1 = irSensor1.read();
        float distance2 = irSensor2.read();
        float distance3 = irSensor3.read();
        float distance4 = irSensor4.read();
        float distance5 = irSensor5.read();
        
        
        if ( distance0 < 0.1f){
        led0 = 1;
        controller.setDesiredSpeedLeft(0.0f); //Drehzahl in (rpm)
        controller.setDesiredSpeedRight(0.0f); //Drehzahl in (rpm)
        } 
        else{
        led0 = 0;
        controller.setDesiredSpeedLeft(50.0f); 
        controller.setDesiredSpeedRight(-50.0f); 
        }
        
        if ( distance1 < 0.1f){
        led1 = 1;
        controller.setDesiredSpeedLeft(-50.0f);
     //   controller.setDesiredSpeedRight(0.0f);
        } 
        else{
        led1 = 0;
    //    controller.setDesiredSpeedLeft(0.0f);
     //   controller.setDesiredSpeedRight(0.0f); 
        }        
        if ( distance2 < 0.1f){
        led2 = 1;
        //pwmLeft = 0.6; 
        //pwmRight = 0.4;
        } 
        else{
        led2 = 0;
        //pwmLeft = 0.5; 
        //pwmRight = 0.5;
        }        
        if ( distance3 < 0.1f){
        led3 = 1;
        //pwmLeft = 0.6; 
        //pwmRight = 0.4;
        } 
        else{
        led3 = 0;
        //pwmLeft = 0.5; 
        //pwmRight = 0.5;
        }        
        if ( distance4 < 0.1f){
        led4 = 1;
        //pwmLeft = 0.6; 
        //pwmRight = 0.4;
        } 
        else{
        led4 = 0;
        //pwmLeft = 0.5; 
        //pwmRight = 0.5;
        }     
                
        if ( distance5 < 0.1f){
        led5 = 1;
        controller.setDesiredSpeedRight(50.0f);
        //pwmRight = 0.4;
        } 
        else{
        led5 = 0;
        //pwmLeft = 0.5; 
        //pwmRight = 0.5;
        }        
                
        myled =! myled; // LED is ON
        wait(0.1f); // 100 ms

        
    }
}