encoder verwerkt
Dependencies: MODSERIAL QEI mbed
Fork of motor_control by
main.cpp@6:93a7d2989024, 2016-09-30 (annotated)
- Committer:
- daniQQue
- Date:
- Fri Sep 30 12:36:20 2016 +0000
- Revision:
- 6:93a7d2989024
- Parent:
- 5:bb97950558bd
- Child:
- 7:27625939c4ed
werkend, met knopjes motor testen. Encoder telt plus en min kant op
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 | 6:93a7d2989024 | 33 | pc.printf("encoder counts: %i \r\n", counts); |
daniQQue | 6:93a7d2989024 | 34 | |
daniQQue | 6:93a7d2989024 | 35 | } |
daniQQue | 6:93a7d2989024 | 36 | else if (button_ccw==0) |
daniQQue | 6:93a7d2989024 | 37 | { ledccw=1; |
daniQQue | 4:d39f84608204 | 38 | motor1= CCW; |
daniQQue | 3:a50f2ce05e1f | 39 | pwm_motor1=2.5; |
daniQQue | 2:80753272d9e4 | 40 | counts = Encoder.getPulses(); |
daniQQue | 6:93a7d2989024 | 41 | pc.printf("encoder counts: %i \r\n", counts); |
daniQQue | 6:93a7d2989024 | 42 | } |
daniQQue | 6:93a7d2989024 | 43 | |
daniQQue | 6:93a7d2989024 | 44 | else { |
daniQQue | 6:93a7d2989024 | 45 | ledcw=0; ledccw=0; |
daniQQue | 4:d39f84608204 | 46 | pwm_motor1=0; |
daniQQue | 4:d39f84608204 | 47 | } |
daniQQue | 3:a50f2ce05e1f | 48 | } |
FloorC | 1:e415c6eda278 | 49 | } |