pot controller voor positie, kp handmatig instellen, werkt met motor 1 en 2
Dependencies: MODSERIAL QEI mbed-dsp mbed
Fork of PI_controller_verbeteringen by
main.cpp@3:40a25c2c24ba, 2018-09-12 (annotated)
- Committer:
- SimonRez
- Date:
- Wed Sep 12 11:52:10 2018 +0000
- Revision:
- 3:40a25c2c24ba
- Parent:
- 2:52b3c0b95388
- Child:
- 4:651d06e860e7
Helemaal werkend. NULL waarde geintegreerd en foutmelding
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vsluiter | 0:c8f15874531b | 1 | #include "mbed.h" |
vsluiter | 0:c8f15874531b | 2 | #include "MODSERIAL.h" |
vsluiter | 0:c8f15874531b | 3 | |
SimonRez | 2:52b3c0b95388 | 4 | Ticker Blinker; |
SimonRez | 2:52b3c0b95388 | 5 | |
SimonRez | 2:52b3c0b95388 | 6 | DigitalOut ledr(LED_RED); |
SimonRez | 2:52b3c0b95388 | 7 | DigitalOut ledg(LED_GREEN); |
SimonRez | 2:52b3c0b95388 | 8 | DigitalOut ledb(LED_BLUE); |
SimonRez | 3:40a25c2c24ba | 9 | DigitalIn sw2(PTC6); |
SimonRez | 2:52b3c0b95388 | 10 | |
vsluiter | 0:c8f15874531b | 11 | MODSERIAL pc(USBTX, USBRX); |
vsluiter | 0:c8f15874531b | 12 | |
SimonRez | 2:52b3c0b95388 | 13 | volatile char c; |
SimonRez | 2:52b3c0b95388 | 14 | volatile char color; |
SimonRez | 2:52b3c0b95388 | 15 | |
SimonRez | 2:52b3c0b95388 | 16 | void ButtonpressCheck() |
SimonRez | 2:52b3c0b95388 | 17 | { |
SimonRez | 2:52b3c0b95388 | 18 | if (c == 'r') |
SimonRez | 2:52b3c0b95388 | 19 | { |
SimonRez | 2:52b3c0b95388 | 20 | color = 'r'; |
SimonRez | 2:52b3c0b95388 | 21 | } |
SimonRez | 2:52b3c0b95388 | 22 | else if (c == 'g') |
SimonRez | 2:52b3c0b95388 | 23 | { |
SimonRez | 2:52b3c0b95388 | 24 | color = 'g'; |
SimonRez | 2:52b3c0b95388 | 25 | } |
SimonRez | 2:52b3c0b95388 | 26 | else if (c == 'b') |
SimonRez | 2:52b3c0b95388 | 27 | { |
SimonRez | 2:52b3c0b95388 | 28 | color = 'b'; |
SimonRez | 2:52b3c0b95388 | 29 | } |
SimonRez | 3:40a25c2c24ba | 30 | else if (c == NULL) |
SimonRez | 3:40a25c2c24ba | 31 | { |
SimonRez | 3:40a25c2c24ba | 32 | ledr = 1; |
SimonRez | 3:40a25c2c24ba | 33 | ledg = 1; |
SimonRez | 3:40a25c2c24ba | 34 | ledb = 1; |
SimonRez | 3:40a25c2c24ba | 35 | } |
SimonRez | 2:52b3c0b95388 | 36 | else |
SimonRez | 2:52b3c0b95388 | 37 | { |
SimonRez | 2:52b3c0b95388 | 38 | pc.printf("Character %c is not valid \r\n",c); |
SimonRez | 2:52b3c0b95388 | 39 | c = color; |
SimonRez | 3:40a25c2c24ba | 40 | |
SimonRez | 3:40a25c2c24ba | 41 | ledr = 0; |
SimonRez | 3:40a25c2c24ba | 42 | ledg = 0; |
SimonRez | 3:40a25c2c24ba | 43 | ledb = 0; |
SimonRez | 3:40a25c2c24ba | 44 | wait(0.1f); |
SimonRez | 3:40a25c2c24ba | 45 | ledr = 1; |
SimonRez | 3:40a25c2c24ba | 46 | ledg = 1; |
SimonRez | 3:40a25c2c24ba | 47 | ledb = 1; |
SimonRez | 3:40a25c2c24ba | 48 | wait(0.1f); |
SimonRez | 3:40a25c2c24ba | 49 | ledr = 0; |
SimonRez | 3:40a25c2c24ba | 50 | ledg = 0; |
SimonRez | 3:40a25c2c24ba | 51 | ledb = 0; |
SimonRez | 3:40a25c2c24ba | 52 | wait(0.1f); |
SimonRez | 3:40a25c2c24ba | 53 | ledr = 1; |
SimonRez | 3:40a25c2c24ba | 54 | ledg = 1; |
SimonRez | 3:40a25c2c24ba | 55 | ledb = 1; |
SimonRez | 3:40a25c2c24ba | 56 | wait(0.1f); |
SimonRez | 3:40a25c2c24ba | 57 | ledr = 0; |
SimonRez | 3:40a25c2c24ba | 58 | ledg = 0; |
SimonRez | 3:40a25c2c24ba | 59 | ledb = 0; |
SimonRez | 3:40a25c2c24ba | 60 | wait(0.1f); |
SimonRez | 3:40a25c2c24ba | 61 | ledr = 1; |
SimonRez | 3:40a25c2c24ba | 62 | ledg = 1; |
SimonRez | 3:40a25c2c24ba | 63 | ledb = 1; |
SimonRez | 3:40a25c2c24ba | 64 | wait(0.1f); |
SimonRez | 2:52b3c0b95388 | 65 | } |
SimonRez | 2:52b3c0b95388 | 66 | |
SimonRez | 2:52b3c0b95388 | 67 | if (color == 'r') |
SimonRez | 2:52b3c0b95388 | 68 | { |
SimonRez | 2:52b3c0b95388 | 69 | ledr = !ledr; |
SimonRez | 2:52b3c0b95388 | 70 | ledg = 1; |
SimonRez | 2:52b3c0b95388 | 71 | ledb = 1; |
SimonRez | 2:52b3c0b95388 | 72 | } |
SimonRez | 2:52b3c0b95388 | 73 | else if (color == 'g') |
SimonRez | 2:52b3c0b95388 | 74 | { |
SimonRez | 2:52b3c0b95388 | 75 | ledr = 1; |
SimonRez | 2:52b3c0b95388 | 76 | ledg = !ledg; |
SimonRez | 2:52b3c0b95388 | 77 | ledb = 1; |
SimonRez | 2:52b3c0b95388 | 78 | } |
SimonRez | 2:52b3c0b95388 | 79 | else if (color == 'b') |
SimonRez | 2:52b3c0b95388 | 80 | { |
SimonRez | 2:52b3c0b95388 | 81 | ledr = 1; |
SimonRez | 2:52b3c0b95388 | 82 | ledg = 1; |
SimonRez | 2:52b3c0b95388 | 83 | ledb = !ledb; |
SimonRez | 2:52b3c0b95388 | 84 | } |
SimonRez | 2:52b3c0b95388 | 85 | wait(0.25f); |
SimonRez | 2:52b3c0b95388 | 86 | ledr = 1; |
SimonRez | 2:52b3c0b95388 | 87 | ledg = 1; |
SimonRez | 2:52b3c0b95388 | 88 | ledb = 1; |
SimonRez | 2:52b3c0b95388 | 89 | |
SimonRez | 2:52b3c0b95388 | 90 | } |
SimonRez | 2:52b3c0b95388 | 91 | |
vsluiter | 0:c8f15874531b | 92 | int main() |
vsluiter | 0:c8f15874531b | 93 | { |
SimonRez | 2:52b3c0b95388 | 94 | ledr = 1; |
SimonRez | 2:52b3c0b95388 | 95 | ledg = 1; |
SimonRez | 2:52b3c0b95388 | 96 | ledb = 1; |
SimonRez | 2:52b3c0b95388 | 97 | |
SimonRez | 2:52b3c0b95388 | 98 | pc.printf("\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n ~~~Pu$$Y~~~ \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n"); |
SimonRez | 2:52b3c0b95388 | 99 | |
vsluiter | 0:c8f15874531b | 100 | pc.baud(115200); |
SimonRez | 2:52b3c0b95388 | 101 | Blinker.attach(ButtonpressCheck, 0.5); |
SimonRez | 2:52b3c0b95388 | 102 | |
vsluiter | 0:c8f15874531b | 103 | |
SimonRez | 2:52b3c0b95388 | 104 | |
SimonRez | 2:52b3c0b95388 | 105 | while (true) |
SimonRez | 2:52b3c0b95388 | 106 | { |
SimonRez | 2:52b3c0b95388 | 107 | c = pc.getc(); |
SimonRez | 3:40a25c2c24ba | 108 | |
SimonRez | 3:40a25c2c24ba | 109 | |
vsluiter | 0:c8f15874531b | 110 | } |
SimonRez | 2:52b3c0b95388 | 111 | |
vsluiter | 0:c8f15874531b | 112 | } |
SimonRez | 2:52b3c0b95388 | 113 | |
SimonRez | 2:52b3c0b95388 | 114 |