h

Dependencies:   mbed

Fork of StateMachine by Roboshark

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include <mbed.h>
00002 
00003 #include "EncoderCounter.h"
00004 #include "Controller.h"
00005 #include "IRSensor.h"
00006 
00007 // DigitalOut myled(LED1);
00008 
00009 //DigitalOut led0(PC_8);
00010 //DigitalOut led1(PC_6);
00011 //DigitalOut led2(PB_12);
00012 //DigitalOut led3(PA_7);
00013 //DigitalOut led4(PC_0);
00014 //DigitalOut led5(PC_9);
00015 
00016 //AnalogIn distance(PB_1);
00017 //DigitalOut enable(PC_1);
00018 //DigitalOut bit0(PH_1);
00019 //DigitalOut bit1(PC_2);
00020 //DigitalOut bit2(PC_3);
00021 
00022 IRSensor irSensorF(PC_2);
00023 IRSensor irSensorR(PC_3);
00024 IRSensor irSensorL(PC_5);
00025 
00026 BottomSensor lineDetector(RX/D0);
00027 
00028 DigitalOut enableMotorDriver(PB_2);
00029 DigitalIn motorDriverFault(PB_14);
00030 DigitalIn motorDriverWarning(PB_15);
00031 
00032 PwmOut pwmLeft(PA_9);
00033 PwmOut pwmRight(PA_8);
00034 
00035 EncoderCounter counterLeft(PB_6, PB_7);
00036 EncoderCounter counterRight(PA_6, PC_7);
00037 
00038 Controller controller(pwmLeft, pwmRight, counterLeft, counterRight);
00039 
00040 int main()
00041 {
00042 
00043     controller.setDesiredSpeedLeft(150.0f); // Drehzahl in [rpm]
00044     controller.setDesiredSpeedRight(-150.0f);
00045     enable = 1;
00046     enableMotorDriver = 1; // Schaltet den Leistungstreiber ein
00047 
00048     while(1) {
00049 
00050         myled =! myled;
00051 
00052         if (irSensorf.read() < 0.2f) led0 = 1;
00053         else led0 = 0;
00054         
00055         if (irSensorR.read() < 0.2f) led1 = 1;
00056         else led1 = 0;
00057         
00058         if (irSensorL.read() < 0.2f) led2 = 1;
00059         else led2 = 0;
00060         
00061         //if (irSensor3.read() < 0.2f) led3 = 1;
00062         //else led3 = 0;
00063         
00064         //if (irSensor4.read() < 0.2f) led4 = 1;
00065         //else led4 = 0;
00066         
00067         //if (irSensor5.read() < 0.2f) led5 = 1;
00068         //else led0 = 5;
00069         
00070         printf("iSumLeft: %f, iSumRight: %f, counterDiff; %d \n\r", controller.getIntegralLeft(), controller.getIntegralRight(), (counterLeft.read()+counterRight.read()));
00071                 
00072         wait(0.2f); // 100 ms
00073         
00074     }
00075 }