Gruppe 3
/
PES1
für holdor
Fork of PES by
readCamera.cpp@21:d05dee0d1a7d, 2017-05-01 (annotated)
- Committer:
- Shukle
- Date:
- Mon May 01 09:47:45 2017 +0000
- Revision:
- 21:d05dee0d1a7d
- Parent:
- 15:7e9ecc4d7217
- Child:
- 22:ffd36f07c046
zusammengef?gt neues main und neue readcamera
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
itslinear | 11:7c5598781280 | 1 | #include "readCamera.h" |
itslinear | 11:7c5598781280 | 2 | |
Shukle | 10:75a18bf17c86 | 3 | |
Shukle | 10:75a18bf17c86 | 4 | Pixy pixy(I2C_SDA, I2C_SCL); |
Shukle | 10:75a18bf17c86 | 5 | Serial pc(SERIAL_TX, SERIAL_RX); |
Shukle | 10:75a18bf17c86 | 6 | |
Shukle | 10:75a18bf17c86 | 7 | static int i = 0; |
Shukle | 10:75a18bf17c86 | 8 | static int k = 0; |
Shukle | 10:75a18bf17c86 | 9 | static int range = 1; // 1: fährt strahl an, 2: fährt kegel an |
Shukle | 10:75a18bf17c86 | 10 | static int state = 0; |
Shukle | 21:d05dee0d1a7d | 11 | static double distance = 0; |
Shukle | 21:d05dee0d1a7d | 12 | static int yLimit = 155; |
Shukle | 10:75a18bf17c86 | 13 | int j; |
Shukle | 10:75a18bf17c86 | 14 | uint16_t blocks; |
Shukle | 10:75a18bf17c86 | 15 | |
Shukle | 10:75a18bf17c86 | 16 | |
itslinear | 12:b9faf8637183 | 17 | int readCamera() |
Shukle | 10:75a18bf17c86 | 18 | { |
Shukle | 10:75a18bf17c86 | 19 | pixy.setSerialOutput(&pc); |
Shukle | 10:75a18bf17c86 | 20 | |
Shukle | 10:75a18bf17c86 | 21 | while (1) { |
Shukle | 10:75a18bf17c86 | 22 | blocks = pixy.getBlocks(1); |
Shukle | 10:75a18bf17c86 | 23 | |
Shukle | 10:75a18bf17c86 | 24 | if (blocks) { |
Shukle | 10:75a18bf17c86 | 25 | i++; |
Shukle | 10:75a18bf17c86 | 26 | if (i % 5 == 0) { |
Shukle | 10:75a18bf17c86 | 27 | for (j = 0; j < blocks; j++) { |
Shukle | 10:75a18bf17c86 | 28 | int xAxis = pixy.blocks[j].x; |
Shukle | 10:75a18bf17c86 | 29 | int yAxis = pixy.blocks[j].y; |
Shukle | 10:75a18bf17c86 | 30 | |
Shukle | 10:75a18bf17c86 | 31 | |
Shukle | 10:75a18bf17c86 | 32 | |
Shukle | 10:75a18bf17c86 | 33 | // soll drehen bis in stahl, fahren bis kegel, 25 pixel links rechts kegel |
Shukle | 21:d05dee0d1a7d | 34 | if(xAxis < 180 && xAxis > 140 && yAxis > 155 && yAxis < yLimit ) { // wenn Klotz an Position zum aufnehmen |
Shukle | 21:d05dee0d1a7d | 35 | state = 400; |
Shukle | 10:75a18bf17c86 | 36 | range = 1; |
Shukle | 10:75a18bf17c86 | 37 | } else { |
Shukle | 10:75a18bf17c86 | 38 | if (range == 1){ // fährt Strahl an |
Shukle | 21:d05dee0d1a7d | 39 | if (xAxis < 140){ |
Shukle | 21:d05dee0d1a7d | 40 | distance = ((xAxis - 160)*(-0.625))-1; |
Shukle | 21:d05dee0d1a7d | 41 | state = 100 + (int) distance; |
Shukle | 21:d05dee0d1a7d | 42 | } else if (xAxis > 180){ |
Shukle | 21:d05dee0d1a7d | 43 | distance = ((xAxis - 160)*(0.625))-1; |
Shukle | 21:d05dee0d1a7d | 44 | state = 200 + (int) distance; |
Shukle | 10:75a18bf17c86 | 45 | } else{ // fährt gerade |
Shukle | 21:d05dee0d1a7d | 46 | distance = (((yAxis - yLimit)/(199-yLimit))*100); |
Shukle | 21:d05dee0d1a7d | 47 | state = 300 + (int) distance; |
Shukle | 21:d05dee0d1a7d | 48 | if (state == 400){ |
Shukle | 21:d05dee0d1a7d | 49 | state=399; |
Shukle | 21:d05dee0d1a7d | 50 | } |
Shukle | 10:75a18bf17c86 | 51 | range = 2; |
Shukle | 10:75a18bf17c86 | 52 | } |
Shukle | 10:75a18bf17c86 | 53 | } else { // fährt solange bis Kegelrand |
Shukle | 10:75a18bf17c86 | 54 | if (xAxis > 185 || xAxis < 135) { |
Shukle | 10:75a18bf17c86 | 55 | range = 1; |
Shukle | 10:75a18bf17c86 | 56 | } |
Shukle | 10:75a18bf17c86 | 57 | } |
Shukle | 10:75a18bf17c86 | 58 | } |
Shukle | 10:75a18bf17c86 | 59 | |
Shukle | 10:75a18bf17c86 | 60 | |
Shukle | 10:75a18bf17c86 | 61 | |
Shukle | 10:75a18bf17c86 | 62 | } |
Shukle | 10:75a18bf17c86 | 63 | k=0; |
Shukle | 10:75a18bf17c86 | 64 | } |
Shukle | 10:75a18bf17c86 | 65 | } else{ |
Shukle | 10:75a18bf17c86 | 66 | k++; |
Shukle | 10:75a18bf17c86 | 67 | if (k % 20 == 0) { |
Shukle | 10:75a18bf17c86 | 68 | i=0; |
Shukle | 10:75a18bf17c86 | 69 | state = 0; |
Shukle | 10:75a18bf17c86 | 70 | } |
Shukle | 10:75a18bf17c86 | 71 | } |
itslinear | 14:7e330f65f26e | 72 | //printf("%d\n\r",state); |
Shukle | 15:7e9ecc4d7217 | 73 | //printf("%d, %d\n\r", xAxis, yAxis); |
Shukle | 21:d05dee0d1a7d | 74 | return (double) state; |
Shukle | 10:75a18bf17c86 | 75 | } |
Shukle | 10:75a18bf17c86 | 76 | } |