encoder verwerkt
Dependencies: MODSERIAL QEI mbed
Fork of motor_control by
main.cpp@7:27625939c4ed, 2016-10-07 (annotated)
- Committer:
- daniQQue
- Date:
- Fri Oct 07 08:18:44 2016 +0000
- Revision:
- 7:27625939c4ed
- Parent:
- 6:93a7d2989024
poging, met encoder naar revolutions door te delen door 3200;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
daniQQue | 2:80753272d9e4 | 1 | #include "mbed.h" //standaard bieb mbed |
daniQQue | 2:80753272d9e4 | 2 | #include "QEI.h" //bieb voor encoderfuncties in c++ |
daniQQue | 2:80753272d9e4 | 3 | #include "MODSERIAL.h" //bieb voor modserial |
daniQQue | 2:80753272d9e4 | 4 | //alle ingangen definieren |
daniQQue | 2:80753272d9e4 | 5 | DigitalIn encoder1A(D13); |
daniQQue | 2:80753272d9e4 | 6 | DigitalIn encoder1B(D12); |
daniQQue | 6:93a7d2989024 | 7 | DigitalIn button_cw(D11); |
daniQQue | 6:93a7d2989024 | 8 | DigitalIn button_ccw(D9); |
daniQQue | 6:93a7d2989024 | 9 | DigitalOut ledcw(D10); |
daniQQue | 6:93a7d2989024 | 10 | DigitalOut ledccw(D2); |
daniQQue | 2:80753272d9e4 | 11 | DigitalOut motor1(D4); |
daniQQue | 2:80753272d9e4 | 12 | PwmOut pwm_motor1(D5); |
daniQQue | 2:80753272d9e4 | 13 | MODSERIAL pc(USBTX, USBRX); |
FloorC | 1:e415c6eda278 | 14 | |
daniQQue | 2:80753272d9e4 | 15 | //constanten |
daniQQue | 6:93a7d2989024 | 16 | const int CW = 2.5; //definitie rechtsom 'lage waarde' |
daniQQue | 6:93a7d2989024 | 17 | const int CCW =0; //definitie linksom 'hoge waarde' |
FloorC | 0:8ed7e7bbc391 | 18 | |
daniQQue | 2:80753272d9e4 | 19 | //programma |
FloorC | 1:e415c6eda278 | 20 | int main () |
FloorC | 0:8ed7e7bbc391 | 21 | { |
daniQQue | 2:80753272d9e4 | 22 | pc.baud(115200); //contact maken met computer |
daniQQue | 6:93a7d2989024 | 23 | QEI Encoder(D12,D13, NC, 32); // maakt een encoder aan! |
daniQQue | 6:93a7d2989024 | 24 | int counts; //variabele counts aanmaken |
daniQQue | 4:d39f84608204 | 25 | while(true) |
daniQQue | 4:d39f84608204 | 26 | { |
daniQQue | 6:93a7d2989024 | 27 | if (button_cw==0) |
daniQQue | 4:d39f84608204 | 28 | { //als knop is aan dan |
daniQQue | 6:93a7d2989024 | 29 | ledcw=1; |
daniQQue | 6:93a7d2989024 | 30 | motor1= CW; |
daniQQue | 6:93a7d2989024 | 31 | pwm_motor1=2.5; |
daniQQue | 6:93a7d2989024 | 32 | counts = Encoder.getPulses(); |
daniQQue | 7:27625939c4ed | 33 | pc.printf("encoder pulses: %i \r\n", counts); |
daniQQue | 7:27625939c4ed | 34 | float rondjes=counts/3200; |
daniQQue | 7:27625939c4ed | 35 | pc.printf("encoder rondjes: %i \r\n", rondjes); |
daniQQue | 6:93a7d2989024 | 36 | } |
daniQQue | 6:93a7d2989024 | 37 | else if (button_ccw==0) |
daniQQue | 6:93a7d2989024 | 38 | { ledccw=1; |
daniQQue | 4:d39f84608204 | 39 | motor1= CCW; |
daniQQue | 3:a50f2ce05e1f | 40 | pwm_motor1=2.5; |
daniQQue | 2:80753272d9e4 | 41 | counts = Encoder.getPulses(); |
daniQQue | 7:27625939c4ed | 42 | pc.printf("encoder counts: %i \r\n", counts); |
daniQQue | 6:93a7d2989024 | 43 | } |
daniQQue | 6:93a7d2989024 | 44 | |
daniQQue | 6:93a7d2989024 | 45 | else { |
daniQQue | 6:93a7d2989024 | 46 | ledcw=0; ledccw=0; |
daniQQue | 4:d39f84608204 | 47 | pwm_motor1=0; |
daniQQue | 4:d39f84608204 | 48 | } |
daniQQue | 3:a50f2ce05e1f | 49 | } |
FloorC | 1:e415c6eda278 | 50 | } |