Prom_Roebi_0.1

Dependencies:   Farbsensor IRSensorLib PID_Control Servo mbed PixyLib

Committer:
ZHAW_Prometheus
Date:
Fri May 26 09:11:49 2017 +0000
Revision:
16:ad45ef4fee04
Parent:
15:26dbcd6ff48d
Vers. 26.05.2017 11:10

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ZHAW_Prometheus 0:422088ad7fc5 1 #include "mbed.h"
ZHAW_Prometheus 0:422088ad7fc5 2 #include "cstdlib"
ZHAW_Prometheus 0:422088ad7fc5 3 #include "IRSensor.h"
ZHAW_Prometheus 0:422088ad7fc5 4 #include "Servo.h"
ZHAW_Prometheus 7:5949f408b6da 5 //#include "Pixy.h"
ZHAW_Prometheus 0:422088ad7fc5 6 #include "Farbauswertung.h"
ZHAW_Prometheus 1:5c44e2462a8b 7 #include "Fahren.h"
ZHAW_Prometheus 1:5c44e2462a8b 8 #include "liftAnsteuerung.h"
ZHAW_Prometheus 8:077d0bb213a2 9 #include "Pixy.h"
ZHAW_Prometheus 8:077d0bb213a2 10 #include "PID_Control.h"
ZHAW_Prometheus 0:422088ad7fc5 11
ZHAW_Prometheus 0:422088ad7fc5 12 /**
ZHAW_Prometheus 0:422088ad7fc5 13 *Aus- und Eingänge initialisieren
ZHAW_Prometheus 0:422088ad7fc5 14 */
ZHAW_Prometheus 1:5c44e2462a8b 15 //Button
ZHAW_Prometheus 9:b83994ef4b08 16 DigitalIn usrButton(USER_BUTTON);
ZHAW_Prometheus 9:b83994ef4b08 17
ZHAW_Prometheus 10:10bcb7fee9a6 18 //Serielle Ports deklarieren
ZHAW_Prometheus 9:b83994ef4b08 19 Serial pc(USBTX,USBRX);
ZHAW_Prometheus 9:b83994ef4b08 20 Serial cam(PA_9, PA_10);
ZHAW_Prometheus 12:472b26872a42 21 //Berechnungsklassen
ZHAW_Prometheus 9:b83994ef4b08 22 PID_Control pid;
ZHAW_Prometheus 0:422088ad7fc5 23 //IRSensoren
ZHAW_Prometheus 10:10bcb7fee9a6 24 DigitalOut enable(PC_1);
ZHAW_Prometheus 10:10bcb7fee9a6 25 DigitalOut bit0(PH_1);
ZHAW_Prometheus 10:10bcb7fee9a6 26 DigitalOut bit1(PC_2);
ZHAW_Prometheus 10:10bcb7fee9a6 27 DigitalOut bit2(PC_3);
ZHAW_Prometheus 10:10bcb7fee9a6 28 AnalogIn distance(PB_1);
ZHAW_Prometheus 0:422088ad7fc5 29 //Motoren
ZHAW_Prometheus 10:10bcb7fee9a6 30 DigitalOut enableMotorDriver(PB_2);
ZHAW_Prometheus 10:10bcb7fee9a6 31 PwmOut pwmLeft(PA_8);
ZHAW_Prometheus 10:10bcb7fee9a6 32 PwmOut pwmRight(PA_9);
ZHAW_Prometheus 0:422088ad7fc5 33 //Farbauswertung
ZHAW_Prometheus 10:10bcb7fee9a6 34 AnalogIn SensorG(PA_0);
ZHAW_Prometheus 10:10bcb7fee9a6 35 AnalogIn SensorR(PA_1);
ZHAW_Prometheus 10:10bcb7fee9a6 36 Servo ServoAusw(PB_7);
ZHAW_Prometheus 10:10bcb7fee9a6 37 Servo ServoFoerder(PC_7);
ZHAW_Prometheus 1:5c44e2462a8b 38 //Lift
ZHAW_Prometheus 10:10bcb7fee9a6 39 Servo ServoLift(PB_6);
ZHAW_Prometheus 7:5949f408b6da 40 //Kamera
ZHAW_Prometheus 8:077d0bb213a2 41 Pixy pixy(cam);
ZHAW_Prometheus 8:077d0bb213a2 42
ZHAW_Prometheus 8:077d0bb213a2 43 //Robotersteuerung
ZHAW_Prometheus 16:ad45ef4fee04 44 LiftAnsteuerung lift(7, 1, ServoLift);
ZHAW_Prometheus 16:ad45ef4fee04 45 Farbauswertung farbauswertung(&SensorG, &SensorR, ServoAusw, ServoFoerder, lift, 4, 8);
ZHAW_Prometheus 15:26dbcd6ff48d 46 Fahren fahren(enable, bit0, bit1, bit2, distance, enableMotorDriver, pwmLeft, pwmRight, pixy, pid);
ZHAW_Prometheus 0:422088ad7fc5 47
ZHAW_Prometheus 8:077d0bb213a2 48
ZHAW_Prometheus 0:422088ad7fc5 49 int main()
ZHAW_Prometheus 0:422088ad7fc5 50 {
ZHAW_Prometheus 12:472b26872a42 51 /*
ZHAW_Prometheus 12:472b26872a42 52 *Für Konsolenausgaben diese Zeilen aktivieren und in der While die dementsprechende Methode aufrufen.
ZHAW_Prometheus 12:472b26872a42 53 */
ZHAW_Prometheus 9:b83994ef4b08 54 //farbauswertung.setSerialOutput(&pc);
ZHAW_Prometheus 9:b83994ef4b08 55 //fahren.setSerialOutput(&pc);
ZHAW_Prometheus 12:472b26872a42 56
ZHAW_Prometheus 16:ad45ef4fee04 57 Ticker auswertung;
ZHAW_Prometheus 15:26dbcd6ff48d 58 Ticker drive;
ZHAW_Prometheus 15:26dbcd6ff48d 59
ZHAW_Prometheus 8:077d0bb213a2 60 pid.setPIDValues( 0.001f, 0.001f, 0.00015f, 0.3f, -0.3f, 1000);
ZHAW_Prometheus 15:26dbcd6ff48d 61 fahren.fahrInit();
ZHAW_Prometheus 0:422088ad7fc5 62
ZHAW_Prometheus 15:26dbcd6ff48d 63 while(usrButton){
ZHAW_Prometheus 15:26dbcd6ff48d 64 wait(1.0);
ZHAW_Prometheus 15:26dbcd6ff48d 65 }
ZHAW_Prometheus 0:422088ad7fc5 66
ZHAW_Prometheus 16:ad45ef4fee04 67 auswertung.attach(&farbauswertung, &Farbauswertung::auswertung, 0.5);
ZHAW_Prometheus 1:5c44e2462a8b 68
ZHAW_Prometheus 15:26dbcd6ff48d 69 drive.attach(&fahren, &Fahren::fahrRutine, 0.02);
ZHAW_Prometheus 15:26dbcd6ff48d 70
ZHAW_Prometheus 0:422088ad7fc5 71 while (1) {
ZHAW_Prometheus 15:26dbcd6ff48d 72 wait(10.0);
ZHAW_Prometheus 15:26dbcd6ff48d 73 //farbauswertung.printState();
ZHAW_Prometheus 15:26dbcd6ff48d 74 //fahren.printState();
ZHAW_Prometheus 0:422088ad7fc5 75 }
ZHAW_Prometheus 0:422088ad7fc5 76 }