Dependencies:   Farbsensor IRSensorLib PID_Control Servo mbed PixyLib

Committer:
ZHAW_Prometheus
Date:
Sun May 14 14:56:24 2017 +0000
Revision:
5:4b409c37e81f
Parent:
3:017c85c4b14b
Stand 14.05.17 16:56

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 0:422088ad7fc5 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 0:422088ad7fc5 9
ZHAW_Prometheus 0:422088ad7fc5 10 /**
ZHAW_Prometheus 0:422088ad7fc5 11 *Aus- und Eingänge initialisieren
ZHAW_Prometheus 0:422088ad7fc5 12 */
ZHAW_Prometheus 1:5c44e2462a8b 13 //Button
ZHAW_Prometheus 1:5c44e2462a8b 14 DigitalIn usrButton(USER_BUTTON);
ZHAW_Prometheus 0:422088ad7fc5 15 //IRSensoren
ZHAW_Prometheus 0:422088ad7fc5 16 DigitalOut enable(PC_1);
ZHAW_Prometheus 0:422088ad7fc5 17 DigitalOut bit0(PH_1);
ZHAW_Prometheus 0:422088ad7fc5 18 DigitalOut bit1(PC_2);
ZHAW_Prometheus 0:422088ad7fc5 19 DigitalOut bit2(PC_3);
ZHAW_Prometheus 0:422088ad7fc5 20 AnalogIn distance(PB_1);
ZHAW_Prometheus 0:422088ad7fc5 21 //Motoren
ZHAW_Prometheus 0:422088ad7fc5 22 DigitalOut enableMotorDriver(PB_2);
ZHAW_Prometheus 0:422088ad7fc5 23 PwmOut pwmLeft(PA_8);
ZHAW_Prometheus 0:422088ad7fc5 24 PwmOut pwmRight(PA_9);
ZHAW_Prometheus 0:422088ad7fc5 25 //LED's
ZHAW_Prometheus 0:422088ad7fc5 26 DigitalOut led0(PC_8);
ZHAW_Prometheus 0:422088ad7fc5 27 DigitalOut led1(PC_6);
ZHAW_Prometheus 0:422088ad7fc5 28 DigitalOut led5(PC_9);
ZHAW_Prometheus 1:5c44e2462a8b 29 DigitalOut led3(PA_7);
ZHAW_Prometheus 0:422088ad7fc5 30 //Farbauswertung
ZHAW_Prometheus 0:422088ad7fc5 31 AnalogIn SensorG(PA_0);
ZHAW_Prometheus 0:422088ad7fc5 32 AnalogIn SensorR(PA_1);
ZHAW_Prometheus 0:422088ad7fc5 33 Servo ServoAusw(PB_7);
ZHAW_Prometheus 1:5c44e2462a8b 34 Servo ServoFoerder(PC_7);
ZHAW_Prometheus 1:5c44e2462a8b 35 //Lift
ZHAW_Prometheus 5:4b409c37e81f 36 Servo ServoLift(PB_6);
ZHAW_Prometheus 1:5c44e2462a8b 37
ZHAW_Prometheus 0:422088ad7fc5 38 //Serielle Ausgabe
ZHAW_Prometheus 0:422088ad7fc5 39 Serial pc(SERIAL_TX,SERIAL_RX);
ZHAW_Prometheus 0:422088ad7fc5 40
ZHAW_Prometheus 1:5c44e2462a8b 41 Farbauswertung farbauswertung(&SensorG, &SensorR, &ServoAusw);
ZHAW_Prometheus 1:5c44e2462a8b 42 Fahren fahren(&enable, &bit0, &bit1, &bit2, &distance, &enableMotorDriver, &pwmLeft, &pwmRight);
ZHAW_Prometheus 5:4b409c37e81f 43 LiftAnsteuerung lift(100, 10, &ServoLift);
ZHAW_Prometheus 0:422088ad7fc5 44
ZHAW_Prometheus 0:422088ad7fc5 45 int main()
ZHAW_Prometheus 0:422088ad7fc5 46 {
ZHAW_Prometheus 0:422088ad7fc5 47 farbauswertung.setSerialOutput(&pc);
ZHAW_Prometheus 1:5c44e2462a8b 48 fahren.setSerialOutput(&pc);
ZHAW_Prometheus 5:4b409c37e81f 49 lift.setSerialOutput(&pc);
ZHAW_Prometheus 1:5c44e2462a8b 50
ZHAW_Prometheus 5:4b409c37e81f 51 ServoLift = 0.7f; //1.2
ZHAW_Prometheus 1:5c44e2462a8b 52 ServoFoerder = 0.1f; //0.1
ZHAW_Prometheus 1:5c44e2462a8b 53
ZHAW_Prometheus 1:5c44e2462a8b 54 fahren.fahrInit();
ZHAW_Prometheus 0:422088ad7fc5 55
ZHAW_Prometheus 0:422088ad7fc5 56 Ticker farbe;
schuema4 3:017c85c4b14b 57 farbe.attach(&farbauswertung, &Farbauswertung::auswertung, 0.01);
ZHAW_Prometheus 0:422088ad7fc5 58
ZHAW_Prometheus 1:5c44e2462a8b 59 Ticker drive;
schuema4 3:017c85c4b14b 60 drive.attach(&fahren, &Fahren::fahrRutine, 0.01);
ZHAW_Prometheus 1:5c44e2462a8b 61
ZHAW_Prometheus 5:4b409c37e81f 62 Ticker elevator;
ZHAW_Prometheus 5:4b409c37e81f 63 elevator.attach(&lift, &LiftAnsteuerung::steuerung, 0.01);
ZHAW_Prometheus 1:5c44e2462a8b 64
ZHAW_Prometheus 0:422088ad7fc5 65 while (1) {
ZHAW_Prometheus 0:422088ad7fc5 66
schuema4 3:017c85c4b14b 67 wait(0.001);
ZHAW_Prometheus 0:422088ad7fc5 68 }
ZHAW_Prometheus 0:422088ad7fc5 69 }