Prom_Roebi_0.1

Dependencies:   Farbsensor IRSensorLib PID_Control Servo mbed PixyLib

Committer:
ZHAW_Prometheus
Date:
Thu May 18 09:12:46 2017 +0000
Revision:
8:077d0bb213a2
Parent:
7:5949f408b6da
Child:
9:b83994ef4b08
Version 18.05.2017 11:12

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 1:5c44e2462a8b 16 DigitalIn usrButton(USER_BUTTON);
ZHAW_Prometheus 0:422088ad7fc5 17 //IRSensoren
ZHAW_Prometheus 0:422088ad7fc5 18 DigitalOut enable(PC_1);
ZHAW_Prometheus 0:422088ad7fc5 19 DigitalOut bit0(PH_1);
ZHAW_Prometheus 0:422088ad7fc5 20 DigitalOut bit1(PC_2);
ZHAW_Prometheus 0:422088ad7fc5 21 DigitalOut bit2(PC_3);
ZHAW_Prometheus 0:422088ad7fc5 22 AnalogIn distance(PB_1);
ZHAW_Prometheus 0:422088ad7fc5 23 //Motoren
ZHAW_Prometheus 0:422088ad7fc5 24 DigitalOut enableMotorDriver(PB_2);
ZHAW_Prometheus 0:422088ad7fc5 25 PwmOut pwmLeft(PA_8);
ZHAW_Prometheus 0:422088ad7fc5 26 PwmOut pwmRight(PA_9);
ZHAW_Prometheus 0:422088ad7fc5 27 //LED's
ZHAW_Prometheus 0:422088ad7fc5 28 DigitalOut led0(PC_8);
ZHAW_Prometheus 0:422088ad7fc5 29 DigitalOut led1(PC_6);
ZHAW_Prometheus 0:422088ad7fc5 30 DigitalOut led5(PC_9);
ZHAW_Prometheus 1:5c44e2462a8b 31 DigitalOut led3(PA_7);
ZHAW_Prometheus 0:422088ad7fc5 32 //Farbauswertung
ZHAW_Prometheus 0:422088ad7fc5 33 AnalogIn SensorG(PA_0);
ZHAW_Prometheus 0:422088ad7fc5 34 AnalogIn SensorR(PA_1);
ZHAW_Prometheus 0:422088ad7fc5 35 Servo ServoAusw(PB_7);
ZHAW_Prometheus 1:5c44e2462a8b 36 Servo ServoFoerder(PC_7);
ZHAW_Prometheus 1:5c44e2462a8b 37 //Lift
ZHAW_Prometheus 1:5c44e2462a8b 38 Servo ServoLift(PA_6);
ZHAW_Prometheus 7:5949f408b6da 39 //Kamera
ZHAW_Prometheus 1:5c44e2462a8b 40
ZHAW_Prometheus 0:422088ad7fc5 41 //Serielle Ausgabe
ZHAW_Prometheus 8:077d0bb213a2 42 Serial pc(SERIAL_TX,SERIAL_RX);
ZHAW_Prometheus 0:422088ad7fc5 43
ZHAW_Prometheus 8:077d0bb213a2 44 //Kamera
ZHAW_Prometheus 8:077d0bb213a2 45 Serial cam(PC_5, PB_10);
ZHAW_Prometheus 8:077d0bb213a2 46 Pixy pixy(cam);
ZHAW_Prometheus 8:077d0bb213a2 47 PID_Control pid;
ZHAW_Prometheus 8:077d0bb213a2 48
ZHAW_Prometheus 8:077d0bb213a2 49 //Robotersteuerung
ZHAW_Prometheus 1:5c44e2462a8b 50 Farbauswertung farbauswertung(&SensorG, &SensorR, &ServoAusw);
ZHAW_Prometheus 8:077d0bb213a2 51 Fahren fahren(&enable, &bit0, &bit1, &bit2, &distance, &enableMotorDriver, &pwmLeft, &pwmRight, &pixy, &pid);
ZHAW_Prometheus 7:5949f408b6da 52 LiftAnsteuerung lift(100, 10, &ServoLift);
ZHAW_Prometheus 0:422088ad7fc5 53
ZHAW_Prometheus 8:077d0bb213a2 54
ZHAW_Prometheus 0:422088ad7fc5 55 int main()
ZHAW_Prometheus 0:422088ad7fc5 56 {
ZHAW_Prometheus 0:422088ad7fc5 57 farbauswertung.setSerialOutput(&pc);
ZHAW_Prometheus 1:5c44e2462a8b 58 fahren.setSerialOutput(&pc);
ZHAW_Prometheus 8:077d0bb213a2 59 pid.setPIDValues( 0.001f, 0.001f, 0.00015f, 0.3f, -0.3f, 1000);
ZHAW_Prometheus 1:5c44e2462a8b 60
ZHAW_Prometheus 8:077d0bb213a2 61 //ServoLift = 1.2f; //1.2
ZHAW_Prometheus 1:5c44e2462a8b 62 ServoFoerder = 0.1f; //0.1
ZHAW_Prometheus 1:5c44e2462a8b 63
ZHAW_Prometheus 1:5c44e2462a8b 64 fahren.fahrInit();
ZHAW_Prometheus 0:422088ad7fc5 65
ZHAW_Prometheus 8:077d0bb213a2 66 //Ticker camausw;
ZHAW_Prometheus 8:077d0bb213a2 67 //camausw.attach(&cam, &Camauswertung::auswertung, 0.5);
ZHAW_Prometheus 8:077d0bb213a2 68
ZHAW_Prometheus 0:422088ad7fc5 69 Ticker farbe;
schuema4 3:017c85c4b14b 70 farbe.attach(&farbauswertung, &Farbauswertung::auswertung, 0.01);
ZHAW_Prometheus 0:422088ad7fc5 71
ZHAW_Prometheus 1:5c44e2462a8b 72 Ticker drive;
schuema4 3:017c85c4b14b 73 drive.attach(&fahren, &Fahren::fahrRutine, 0.01);
ZHAW_Prometheus 1:5c44e2462a8b 74
ZHAW_Prometheus 7:5949f408b6da 75 Ticker elevator;
ZHAW_Prometheus 7:5949f408b6da 76 elevator.attach(&lift, &LiftAnsteuerung::steuerung, 0.01);
ZHAW_Prometheus 7:5949f408b6da 77
ZHAW_Prometheus 8:077d0bb213a2 78
ZHAW_Prometheus 1:5c44e2462a8b 79
ZHAW_Prometheus 0:422088ad7fc5 80 while (1) {
ZHAW_Prometheus 0:422088ad7fc5 81
schuema4 3:017c85c4b14b 82 wait(0.001);
ZHAW_Prometheus 0:422088ad7fc5 83 }
ZHAW_Prometheus 0:422088ad7fc5 84 }