Prom_Roebi_0.1
Dependencies: Farbsensor IRSensorLib PID_Control Servo mbed PixyLib
main.cpp@10:10bcb7fee9a6, 2017-05-20 (annotated)
- Committer:
- ZHAW_Prometheus
- Date:
- Sat May 20 12:01:27 2017 +0000
- Revision:
- 10:10bcb7fee9a6
- Parent:
- 9:b83994ef4b08
- Child:
- 12:472b26872a42
Vers. 20.05.2017 14:00
Who changed what in which revision?
User | Revision | Line number | New 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 | 9:b83994ef4b08 | 22 | |
ZHAW_Prometheus | 9:b83994ef4b08 | 23 | PID_Control pid; |
ZHAW_Prometheus | 9:b83994ef4b08 | 24 | |
ZHAW_Prometheus | 0:422088ad7fc5 | 25 | //IRSensoren |
ZHAW_Prometheus | 10:10bcb7fee9a6 | 26 | DigitalOut enable(PC_1); |
ZHAW_Prometheus | 10:10bcb7fee9a6 | 27 | DigitalOut bit0(PH_1); |
ZHAW_Prometheus | 10:10bcb7fee9a6 | 28 | DigitalOut bit1(PC_2); |
ZHAW_Prometheus | 10:10bcb7fee9a6 | 29 | DigitalOut bit2(PC_3); |
ZHAW_Prometheus | 10:10bcb7fee9a6 | 30 | AnalogIn distance(PB_1); |
ZHAW_Prometheus | 0:422088ad7fc5 | 31 | //Motoren |
ZHAW_Prometheus | 10:10bcb7fee9a6 | 32 | DigitalOut enableMotorDriver(PB_2); |
ZHAW_Prometheus | 10:10bcb7fee9a6 | 33 | PwmOut pwmLeft(PA_8); |
ZHAW_Prometheus | 10:10bcb7fee9a6 | 34 | PwmOut pwmRight(PA_9); |
ZHAW_Prometheus | 0:422088ad7fc5 | 35 | //LED's |
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 | 0:422088ad7fc5 | 40 | //Farbauswertung |
ZHAW_Prometheus | 10:10bcb7fee9a6 | 41 | AnalogIn SensorG(PA_0); |
ZHAW_Prometheus | 10:10bcb7fee9a6 | 42 | AnalogIn SensorR(PA_1); |
ZHAW_Prometheus | 10:10bcb7fee9a6 | 43 | Servo ServoAusw(PB_7); |
ZHAW_Prometheus | 10:10bcb7fee9a6 | 44 | Servo ServoFoerder(PC_7); |
ZHAW_Prometheus | 1:5c44e2462a8b | 45 | //Lift |
ZHAW_Prometheus | 10:10bcb7fee9a6 | 46 | Servo ServoLift(PB_6); |
ZHAW_Prometheus | 7:5949f408b6da | 47 | //Kamera |
ZHAW_Prometheus | 8:077d0bb213a2 | 48 | Pixy pixy(cam); |
ZHAW_Prometheus | 8:077d0bb213a2 | 49 | |
ZHAW_Prometheus | 8:077d0bb213a2 | 50 | //Robotersteuerung |
ZHAW_Prometheus | 10:10bcb7fee9a6 | 51 | Button userButton(2, usrButton); |
ZHAW_Prometheus | 1:5c44e2462a8b | 52 | Farbauswertung farbauswertung(&SensorG, &SensorR, &ServoAusw); |
ZHAW_Prometheus | 10:10bcb7fee9a6 | 53 | Fahren fahren(&enable, &bit0, &bit1, &bit2, &distance, &enableMotorDriver, pwmLeft, pwmRight, pixy, pid, userButton); |
ZHAW_Prometheus | 9:b83994ef4b08 | 54 | LiftAnsteuerung lift(10, 1, &ServoLift); |
ZHAW_Prometheus | 0:422088ad7fc5 | 55 | |
ZHAW_Prometheus | 8:077d0bb213a2 | 56 | |
ZHAW_Prometheus | 0:422088ad7fc5 | 57 | int main() |
ZHAW_Prometheus | 0:422088ad7fc5 | 58 | { |
ZHAW_Prometheus | 9:b83994ef4b08 | 59 | //farbauswertung.setSerialOutput(&pc); |
ZHAW_Prometheus | 9:b83994ef4b08 | 60 | //fahren.setSerialOutput(&pc); |
ZHAW_Prometheus | 8:077d0bb213a2 | 61 | pid.setPIDValues( 0.001f, 0.001f, 0.00015f, 0.3f, -0.3f, 1000); |
ZHAW_Prometheus | 1:5c44e2462a8b | 62 | |
ZHAW_Prometheus | 8:077d0bb213a2 | 63 | //ServoLift = 1.2f; //1.2 |
ZHAW_Prometheus | 1:5c44e2462a8b | 64 | ServoFoerder = 0.1f; //0.1 |
ZHAW_Prometheus | 1:5c44e2462a8b | 65 | |
ZHAW_Prometheus | 1:5c44e2462a8b | 66 | fahren.fahrInit(); |
ZHAW_Prometheus | 0:422088ad7fc5 | 67 | |
ZHAW_Prometheus | 0:422088ad7fc5 | 68 | Ticker farbe; |
schuema4 | 3:017c85c4b14b | 69 | farbe.attach(&farbauswertung, &Farbauswertung::auswertung, 0.01); |
ZHAW_Prometheus | 0:422088ad7fc5 | 70 | |
ZHAW_Prometheus | 1:5c44e2462a8b | 71 | Ticker drive; |
schuema4 | 3:017c85c4b14b | 72 | drive.attach(&fahren, &Fahren::fahrRutine, 0.01); |
ZHAW_Prometheus | 1:5c44e2462a8b | 73 | |
ZHAW_Prometheus | 7:5949f408b6da | 74 | Ticker elevator; |
ZHAW_Prometheus | 9:b83994ef4b08 | 75 | elevator.attach(&lift, &LiftAnsteuerung::steuerung, 0.1); |
ZHAW_Prometheus | 7:5949f408b6da | 76 | |
ZHAW_Prometheus | 10:10bcb7fee9a6 | 77 | Ticker inputUserButton; |
ZHAW_Prometheus | 10:10bcb7fee9a6 | 78 | inputUserButton.attach(&userButton, &Button::setState, 1); |
ZHAW_Prometheus | 10:10bcb7fee9a6 | 79 | |
ZHAW_Prometheus | 8:077d0bb213a2 | 80 | |
ZHAW_Prometheus | 1:5c44e2462a8b | 81 | |
ZHAW_Prometheus | 0:422088ad7fc5 | 82 | while (1) { |
ZHAW_Prometheus | 10:10bcb7fee9a6 | 83 | pc.printf("State Button: %d\n\r", userButton.getState()); |
ZHAW_Prometheus | 10:10bcb7fee9a6 | 84 | wait(5.0); |
ZHAW_Prometheus | 9:b83994ef4b08 | 85 | |
ZHAW_Prometheus | 0:422088ad7fc5 | 86 | } |
ZHAW_Prometheus | 0:422088ad7fc5 | 87 | } |