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@6:1ee8795b7578, 2018-09-24 (annotated)
- Committer:
- SimonRez
- Date:
- Mon Sep 24 14:20:04 2018 +0000
- Revision:
- 6:1ee8795b7578
- Parent:
- 5:f07bafaf11d7
- Child:
- 7:e21056555296
Potmeter met encoder;
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" |
SimonRez | 6:1ee8795b7578 | 3 | #include "QEI.h" |
vsluiter | 0:c8f15874531b | 4 | |
SimonRez | 2:52b3c0b95388 | 5 | Ticker Blinker; |
SimonRez | 2:52b3c0b95388 | 6 | |
SimonRez | 2:52b3c0b95388 | 7 | DigitalOut ledr(LED_RED); |
SimonRez | 2:52b3c0b95388 | 8 | DigitalOut ledg(LED_GREEN); |
SimonRez | 2:52b3c0b95388 | 9 | DigitalOut ledb(LED_BLUE); |
SimonRez | 4:651d06e860e7 | 10 | |
SimonRez | 5:f07bafaf11d7 | 11 | PwmOut pwmpin(PTA2); |
SimonRez | 5:f07bafaf11d7 | 12 | DigitalOut direct(PTB23); |
SimonRez | 6:1ee8795b7578 | 13 | AnalogIn pot1(A0); |
SimonRez | 6:1ee8795b7578 | 14 | |
SimonRez | 6:1ee8795b7578 | 15 | QEI encoder(D12,D13,NC,32); |
SimonRez | 5:f07bafaf11d7 | 16 | |
SimonRez | 4:651d06e860e7 | 17 | InterruptIn sw2(SW2); |
SimonRez | 4:651d06e860e7 | 18 | InterruptIn sw3(SW3); |
SimonRez | 2:52b3c0b95388 | 19 | |
vsluiter | 0:c8f15874531b | 20 | MODSERIAL pc(USBTX, USBRX); |
vsluiter | 0:c8f15874531b | 21 | |
SimonRez | 4:651d06e860e7 | 22 | |
vsluiter | 0:c8f15874531b | 23 | int main() |
vsluiter | 0:c8f15874531b | 24 | { |
SimonRez | 2:52b3c0b95388 | 25 | ledr = 1; |
SimonRez | 2:52b3c0b95388 | 26 | ledg = 1; |
SimonRez | 2:52b3c0b95388 | 27 | ledb = 1; |
SimonRez | 2:52b3c0b95388 | 28 | |
SimonRez | 4:651d06e860e7 | 29 | 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 ~~~A$$De$troyer69~~~ \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 | 30 | |
SimonRez | 5:f07bafaf11d7 | 31 | pwmpin.period_us(60); |
SimonRez | 5:f07bafaf11d7 | 32 | pwmpin = 0; |
SimonRez | 5:f07bafaf11d7 | 33 | |
SimonRez | 2:52b3c0b95388 | 34 | while (true) |
SimonRez | 2:52b3c0b95388 | 35 | { |
SimonRez | 6:1ee8795b7578 | 36 | pwmpin.write(pot1.read()); |
SimonRez | 5:f07bafaf11d7 | 37 | direct = 1; |
SimonRez | 6:1ee8795b7578 | 38 | pc.printf("potmeter: %f, encoder: %i \r\n", pot1.read(), encoder.getPulses()); |
SimonRez | 5:f07bafaf11d7 | 39 | wait(0.2f); |
vsluiter | 0:c8f15874531b | 40 | } |
vsluiter | 0:c8f15874531b | 41 | } |
SimonRez | 2:52b3c0b95388 | 42 | |
SimonRez | 2:52b3c0b95388 | 43 |