Prom_Roebi_0.1

Dependencies:   Farbsensor IRSensorLib PID_Control Servo mbed PixyLib

Committer:
ZHAW_Prometheus
Date:
Sun May 21 12:11:14 2017 +0000
Revision:
14:bee8101aad45
Parent:
13:7ce78048b733
Child:
15:26dbcd6ff48d
Vers 21.05.2017 14: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 10:10bcb7fee9a6 11 #include "Button.h"
ZHAW_Prometheus 0:422088ad7fc5 12
ZHAW_Prometheus 0:422088ad7fc5 13 /**
ZHAW_Prometheus 0:422088ad7fc5 14 *Aus- und Eingänge initialisieren
ZHAW_Prometheus 0:422088ad7fc5 15 */
ZHAW_Prometheus 1:5c44e2462a8b 16 //Button
ZHAW_Prometheus 9:b83994ef4b08 17 DigitalIn usrButton(USER_BUTTON);
ZHAW_Prometheus 9:b83994ef4b08 18
ZHAW_Prometheus 10:10bcb7fee9a6 19 //Serielle Ports deklarieren
ZHAW_Prometheus 9:b83994ef4b08 20 Serial pc(USBTX,USBRX);
ZHAW_Prometheus 9:b83994ef4b08 21 Serial cam(PA_9, PA_10);
ZHAW_Prometheus 12:472b26872a42 22 //Berechnungsklassen
ZHAW_Prometheus 9:b83994ef4b08 23 PID_Control pid;
ZHAW_Prometheus 0:422088ad7fc5 24 //IRSensoren
ZHAW_Prometheus 10:10bcb7fee9a6 25 DigitalOut enable(PC_1);
ZHAW_Prometheus 10:10bcb7fee9a6 26 DigitalOut bit0(PH_1);
ZHAW_Prometheus 10:10bcb7fee9a6 27 DigitalOut bit1(PC_2);
ZHAW_Prometheus 10:10bcb7fee9a6 28 DigitalOut bit2(PC_3);
ZHAW_Prometheus 10:10bcb7fee9a6 29 AnalogIn distance(PB_1);
ZHAW_Prometheus 0:422088ad7fc5 30 //Motoren
ZHAW_Prometheus 10:10bcb7fee9a6 31 DigitalOut enableMotorDriver(PB_2);
ZHAW_Prometheus 10:10bcb7fee9a6 32 PwmOut pwmLeft(PA_8);
ZHAW_Prometheus 10:10bcb7fee9a6 33 PwmOut pwmRight(PA_9);
ZHAW_Prometheus 0:422088ad7fc5 34 //LED's
ZHAW_Prometheus 12:472b26872a42 35 /*
ZHAW_Prometheus 10:10bcb7fee9a6 36 DigitalOut led0(PC_8);
ZHAW_Prometheus 10:10bcb7fee9a6 37 DigitalOut led1(PC_6);
ZHAW_Prometheus 10:10bcb7fee9a6 38 DigitalOut led5(PC_9);
ZHAW_Prometheus 10:10bcb7fee9a6 39 DigitalOut led3(PA_7);
ZHAW_Prometheus 12:472b26872a42 40 */
ZHAW_Prometheus 0:422088ad7fc5 41 //Farbauswertung
ZHAW_Prometheus 10:10bcb7fee9a6 42 AnalogIn SensorG(PA_0);
ZHAW_Prometheus 10:10bcb7fee9a6 43 AnalogIn SensorR(PA_1);
ZHAW_Prometheus 10:10bcb7fee9a6 44 Servo ServoAusw(PB_7);
ZHAW_Prometheus 10:10bcb7fee9a6 45 Servo ServoFoerder(PC_7);
ZHAW_Prometheus 1:5c44e2462a8b 46 //Lift
ZHAW_Prometheus 10:10bcb7fee9a6 47 Servo ServoLift(PB_6);
ZHAW_Prometheus 7:5949f408b6da 48 //Kamera
ZHAW_Prometheus 8:077d0bb213a2 49 Pixy pixy(cam);
ZHAW_Prometheus 8:077d0bb213a2 50
ZHAW_Prometheus 8:077d0bb213a2 51 //Robotersteuerung
ZHAW_Prometheus 12:472b26872a42 52 Button userButton(usrButton, 2);
ZHAW_Prometheus 14:bee8101aad45 53 Farbauswertung farbauswertung(&SensorG, &SensorR, ServoAusw, ServoFoerder, userButton, 20, 40);
ZHAW_Prometheus 12:472b26872a42 54 Fahren fahren(enable, bit0, bit1, bit2, distance, enableMotorDriver, pwmLeft, pwmRight, pixy, pid, userButton);
ZHAW_Prometheus 14:bee8101aad45 55 LiftAnsteuerung lift(7, 1, ServoLift, userButton);
ZHAW_Prometheus 0:422088ad7fc5 56
ZHAW_Prometheus 8:077d0bb213a2 57
ZHAW_Prometheus 0:422088ad7fc5 58 int main()
ZHAW_Prometheus 0:422088ad7fc5 59 {
ZHAW_Prometheus 12:472b26872a42 60 /*
ZHAW_Prometheus 12:472b26872a42 61 *Für Konsolenausgaben diese Zeilen aktivieren und in der While die dementsprechende Methode aufrufen.
ZHAW_Prometheus 12:472b26872a42 62 */
ZHAW_Prometheus 9:b83994ef4b08 63 //farbauswertung.setSerialOutput(&pc);
ZHAW_Prometheus 9:b83994ef4b08 64 //fahren.setSerialOutput(&pc);
ZHAW_Prometheus 12:472b26872a42 65
ZHAW_Prometheus 8:077d0bb213a2 66 pid.setPIDValues( 0.001f, 0.001f, 0.00015f, 0.3f, -0.3f, 1000);
ZHAW_Prometheus 12:472b26872a42 67 fahren.fahrInit();
ZHAW_Prometheus 0:422088ad7fc5 68
ZHAW_Prometheus 0:422088ad7fc5 69 Ticker farbe;
ZHAW_Prometheus 13:7ce78048b733 70 farbe.attach(&farbauswertung, &Farbauswertung::auswertung, 0.1);
ZHAW_Prometheus 0:422088ad7fc5 71
ZHAW_Prometheus 1:5c44e2462a8b 72 Ticker drive;
ZHAW_Prometheus 14:bee8101aad45 73 drive.attach(&fahren, &Fahren::fahrRutine, 0.01);
ZHAW_Prometheus 1:5c44e2462a8b 74
ZHAW_Prometheus 7:5949f408b6da 75 Ticker elevator;
ZHAW_Prometheus 14:bee8101aad45 76 elevator.attach(&lift, &LiftAnsteuerung::steuerung, 2);
ZHAW_Prometheus 7:5949f408b6da 77
ZHAW_Prometheus 10:10bcb7fee9a6 78 Ticker inputUserButton;
ZHAW_Prometheus 10:10bcb7fee9a6 79 inputUserButton.attach(&userButton, &Button::setState, 1);
ZHAW_Prometheus 10:10bcb7fee9a6 80
ZHAW_Prometheus 8:077d0bb213a2 81
ZHAW_Prometheus 1:5c44e2462a8b 82
ZHAW_Prometheus 0:422088ad7fc5 83 while (1) {
ZHAW_Prometheus 12:472b26872a42 84 wait(100.0);
ZHAW_Prometheus 0:422088ad7fc5 85 }
ZHAW_Prometheus 0:422088ad7fc5 86 }