Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Farbsensor IRSensorLib PID_Control Servo mbed PixyLib
Farbauswertung.cpp@6:d611637e7cad, 2017-05-16 (annotated)
- Committer:
- schuema4
- Date:
- Tue May 16 14:02:23 2017 +0000
- Revision:
- 6:d611637e7cad
- Parent:
- 3:017c85c4b14b
- Child:
- 8:077d0bb213a2
version 16.05.17_16:02;
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 <cmath> |
ZHAW_Prometheus | 0:422088ad7fc5 | 4 | #include "Farbauswertung.h" |
ZHAW_Prometheus | 0:422088ad7fc5 | 5 | |
ZHAW_Prometheus | 0:422088ad7fc5 | 6 | |
ZHAW_Prometheus | 0:422088ad7fc5 | 7 | Farbauswertung::Farbauswertung(AnalogIn* SensorG, AnalogIn* SensorR, Servo* servoAusw) |
ZHAW_Prometheus | 0:422088ad7fc5 | 8 | { |
ZHAW_Prometheus | 0:422088ad7fc5 | 9 | init(SensorG, SensorR, servoAusw); |
ZHAW_Prometheus | 0:422088ad7fc5 | 10 | } |
ZHAW_Prometheus | 0:422088ad7fc5 | 11 | |
ZHAW_Prometheus | 0:422088ad7fc5 | 12 | |
ZHAW_Prometheus | 0:422088ad7fc5 | 13 | Farbauswertung::Farbauswertung() {} |
ZHAW_Prometheus | 0:422088ad7fc5 | 14 | |
ZHAW_Prometheus | 0:422088ad7fc5 | 15 | /** |
ZHAW_Prometheus | 0:422088ad7fc5 | 16 | * Deletes the IRSensor object. |
ZHAW_Prometheus | 0:422088ad7fc5 | 17 | */ |
ZHAW_Prometheus | 0:422088ad7fc5 | 18 | Farbauswertung::~Farbauswertung() {} |
ZHAW_Prometheus | 0:422088ad7fc5 | 19 | |
ZHAW_Prometheus | 0:422088ad7fc5 | 20 | |
ZHAW_Prometheus | 0:422088ad7fc5 | 21 | void Farbauswertung::init(AnalogIn* SensorG, AnalogIn* SensorR, Servo* servoAusw) |
ZHAW_Prometheus | 0:422088ad7fc5 | 22 | { |
ZHAW_Prometheus | 0:422088ad7fc5 | 23 | this->SensorG = SensorG; |
ZHAW_Prometheus | 0:422088ad7fc5 | 24 | this->SensorR = SensorR; |
ZHAW_Prometheus | 0:422088ad7fc5 | 25 | this->servoAusw = servoAusw; |
ZHAW_Prometheus | 0:422088ad7fc5 | 26 | farbsensor.init(SensorG, SensorR); |
schuema4 | 3:017c85c4b14b | 27 | zustand = gruen; |
schuema4 | 3:017c85c4b14b | 28 | merker_rot = 0; |
schuema4 | 3:017c85c4b14b | 29 | merker_rot1 = 0; |
schuema4 | 3:017c85c4b14b | 30 | merker_gruen =0; |
ZHAW_Prometheus | 1:5c44e2462a8b | 31 | ausschaltZeit = 0; |
schuema4 | 6:d611637e7cad | 32 | einschlatZeit = 120; |
ZHAW_Prometheus | 0:422088ad7fc5 | 33 | } |
ZHAW_Prometheus | 0:422088ad7fc5 | 34 | |
ZHAW_Prometheus | 0:422088ad7fc5 | 35 | void Farbauswertung::setSerialOutput(Serial *pc) |
ZHAW_Prometheus | 0:422088ad7fc5 | 36 | { |
ZHAW_Prometheus | 0:422088ad7fc5 | 37 | this->pc = pc; |
ZHAW_Prometheus | 0:422088ad7fc5 | 38 | } |
ZHAW_Prometheus | 0:422088ad7fc5 | 39 | |
schuema4 | 3:017c85c4b14b | 40 | int Farbauswertung::getState() |
schuema4 | 3:017c85c4b14b | 41 | { |
ZHAW_Prometheus | 0:422088ad7fc5 | 42 | return zustand; |
ZHAW_Prometheus | 0:422088ad7fc5 | 43 | } |
ZHAW_Prometheus | 0:422088ad7fc5 | 44 | |
schuema4 | 3:017c85c4b14b | 45 | void Farbauswertung::auswertung() |
schuema4 | 3:017c85c4b14b | 46 | { |
schuema4 | 3:017c85c4b14b | 47 | |
schuema4 | 6:d611637e7cad | 48 | if ((farbsensor.readg()>=68 && farbsensor.readg()<=70.5 && farbsensor.readr()>=69 && farbsensor.readr()<=72) || (farbsensor.readg()>=77 && farbsensor.readg()<=78 && farbsensor.readr()>=74 && farbsensor.readr()<=77) || (farbsensor.readg()>=75 && farbsensor.readg()<=76 && farbsensor.readr()>=75 && farbsensor.readr()<=77)) { |
schuema4 | 3:017c85c4b14b | 49 | |
schuema4 | 3:017c85c4b14b | 50 | zustand =rot; |
schuema4 | 3:017c85c4b14b | 51 | if (merker_gruen==1) { //Wenn wechsel Grün auf Rot Ausschaltzeit um X erhöhen |
schuema4 | 6:d611637e7cad | 52 | ausschaltZeit+=100; |
schuema4 | 3:017c85c4b14b | 53 | if(ausschaltZeit !=0) { //Wenn die einschaltzeit nicht gleich Null ist muss die zeit plus die Einschaltverzögerung verlängert werden |
schuema4 | 6:d611637e7cad | 54 | ausschaltZeit+=(einschlatZeit+100); |
ZHAW_Prometheus | 0:422088ad7fc5 | 55 | } |
ZHAW_Prometheus | 1:5c44e2462a8b | 56 | } |
schuema4 | 3:017c85c4b14b | 57 | merker_gruen = 0; |
schuema4 | 3:017c85c4b14b | 58 | } else { |
schuema4 | 3:017c85c4b14b | 59 | merker_gruen=1; |
schuema4 | 3:017c85c4b14b | 60 | zustand=gruen; //Grünes oder gar kein Lego |
schuema4 | 3:017c85c4b14b | 61 | } |
ZHAW_Prometheus | 1:5c44e2462a8b | 62 | |
schuema4 | 3:017c85c4b14b | 63 | if(zustand == rot || (merker_rot >=1 && merker_rot < einschlatZeit)) { //Einschaltverzögerung |
schuema4 | 3:017c85c4b14b | 64 | merker_rot ++; |
schuema4 | 3:017c85c4b14b | 65 | } |
schuema4 | 3:017c85c4b14b | 66 | if (merker_rot == einschlatZeit) { //wenn einschaltzeit abgelaufen => MerkerRot1 setzen + MerkerRot zurücksetzen |
schuema4 | 3:017c85c4b14b | 67 | merker_rot1=1; |
schuema4 | 3:017c85c4b14b | 68 | merker_rot=0; |
schuema4 | 3:017c85c4b14b | 69 | } |
schuema4 | 3:017c85c4b14b | 70 | |
schuema4 | 3:017c85c4b14b | 71 | if(merker_rot1>=1 && merker_rot1<ausschaltZeit) { // Ausschaltverzögerung + Auswurf schliessen |
schuema4 | 3:017c85c4b14b | 72 | merker_rot1 ++; |
schuema4 | 6:d611637e7cad | 73 | |
schuema4 | 3:017c85c4b14b | 74 | servoAusw->write(1.0f); |
schuema4 | 3:017c85c4b14b | 75 | } |
schuema4 | 3:017c85c4b14b | 76 | if (merker_rot1 == ausschaltZeit) { //wenn Ausschaltzeit abgelaufen => MerkerRot1 zurücksetzen + Auswurf öffnen |
schuema4 | 3:017c85c4b14b | 77 | merker_rot1=0; |
schuema4 | 3:017c85c4b14b | 78 | ausschaltZeit=0; |
schuema4 | 3:017c85c4b14b | 79 | servoAusw->write(0.01f); |
schuema4 | 3:017c85c4b14b | 80 | } |
schuema4 | 3:017c85c4b14b | 81 | |
schuema4 | 6:d611637e7cad | 82 | static int timer = 0; |
schuema4 | 6:d611637e7cad | 83 | ++timer; |
schuema4 | 6:d611637e7cad | 84 | |
schuema4 | 6:d611637e7cad | 85 | if( timer % 100 == 0) { |
schuema4 | 6:d611637e7cad | 86 | //Ausgaben an Konsole****************************************************** |
schuema4 | 6:d611637e7cad | 87 | if (pc) { |
schuema4 | 6:d611637e7cad | 88 | pc->printf("\n\r"); |
schuema4 | 6:d611637e7cad | 89 | pc->printf("Gruen:%f\n\r", farbsensor.readg()); |
schuema4 | 6:d611637e7cad | 90 | pc->printf("Rot:%f\n\r", farbsensor.readr()); |
schuema4 | 6:d611637e7cad | 91 | pc->printf("Status:%d\n\r",zustand); |
schuema4 | 6:d611637e7cad | 92 | pc->printf("Status Merker rt:%d\n\r",merker_rot); |
schuema4 | 6:d611637e7cad | 93 | pc->printf("Status Merker rot1:%d\n\r",merker_rot1); |
schuema4 | 6:d611637e7cad | 94 | pc->printf("Ausschaltzeit:%d\n\r",ausschaltZeit); |
schuema4 | 6:d611637e7cad | 95 | } |
ZHAW_Prometheus | 1:5c44e2462a8b | 96 | } |
schuema4 | 3:017c85c4b14b | 97 | |
ZHAW_Prometheus | 0:422088ad7fc5 | 98 | } |