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@8:9b517db94f49, 2018-10-01 (annotated)
- Committer:
- rachieldb
- Date:
- Mon Oct 01 12:47:32 2018 +0000
- Revision:
- 8:9b517db94f49
- Parent:
- 7:e21056555296
- Child:
- 9:466dff9ae128
draaien van beide richtingen toegevoegd;
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 | |
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 | 4:651d06e860e7 | 9 | |
SimonRez | 5:f07bafaf11d7 | 10 | PwmOut pwmpin(PTA2); |
SimonRez | 5:f07bafaf11d7 | 11 | DigitalOut direct(PTB23); |
SimonRez | 6:1ee8795b7578 | 12 | AnalogIn pot1(A0); |
SimonRez | 6:1ee8795b7578 | 13 | |
SimonRez | 6:1ee8795b7578 | 14 | QEI encoder(D12,D13,NC,32); |
SimonRez | 5:f07bafaf11d7 | 15 | |
SimonRez | 4:651d06e860e7 | 16 | InterruptIn sw2(SW2); |
SimonRez | 4:651d06e860e7 | 17 | InterruptIn sw3(SW3); |
SimonRez | 2:52b3c0b95388 | 18 | |
vsluiter | 0:c8f15874531b | 19 | MODSERIAL pc(USBTX, USBRX); |
vsluiter | 0:c8f15874531b | 20 | |
SimonRez | 4:651d06e860e7 | 21 | |
vsluiter | 0:c8f15874531b | 22 | int main() |
vsluiter | 0:c8f15874531b | 23 | { |
SimonRez | 2:52b3c0b95388 | 24 | ledr = 1; |
SimonRez | 2:52b3c0b95388 | 25 | ledg = 1; |
SimonRez | 2:52b3c0b95388 | 26 | ledb = 1; |
SimonRez | 2:52b3c0b95388 | 27 | |
SimonRez | 4:651d06e860e7 | 28 | 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 | 29 | |
SimonRez | 5:f07bafaf11d7 | 30 | pwmpin.period_us(60); |
SimonRez | 5:f07bafaf11d7 | 31 | pwmpin = 0; |
SimonRez | 5:f07bafaf11d7 | 32 | |
SimonRez | 2:52b3c0b95388 | 33 | while (true) |
SimonRez | 2:52b3c0b95388 | 34 | { |
rachieldb | 8:9b517db94f49 | 35 | float pot1_float = pot1.read(); |
rachieldb | 8:9b517db94f49 | 36 | float pot1_motor = (pot1_float * 2.0f) - 1.0f; |
rachieldb | 8:9b517db94f49 | 37 | int mot1_direction = pot1_motor >= 0; |
rachieldb | 8:9b517db94f49 | 38 | pwmpin.write(fabs(pot1_motor)); |
rachieldb | 8:9b517db94f49 | 39 | direct = mot1_direction; |
rachieldb | 8:9b517db94f49 | 40 | pc.printf("potmeter: %f, encoder: %i \r\n", pot1_motor, encoder.getPulses()); |
SimonRez | 5:f07bafaf11d7 | 41 | wait(0.2f); |
vsluiter | 0:c8f15874531b | 42 | } |
vsluiter | 0:c8f15874531b | 43 | } |
SimonRez | 2:52b3c0b95388 | 44 | |
SimonRez | 2:52b3c0b95388 | 45 |