Doesn't hit the ends
Dependencies: Motordriver QEI mbed
Revision 0:e881319cfd74, committed 2016-10-21
- Comitter:
- meikefrok
- Date:
- Fri Oct 21 11:28:55 2016 +0000
- Commit message:
- Encoder Cart
Changed in this revision
diff -r 000000000000 -r e881319cfd74 Motordriver.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Motordriver.lib Fri Oct 21 11:28:55 2016 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/littlexc/code/Motordriver/#3110b9209d3c
diff -r 000000000000 -r e881319cfd74 QEI.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QEI.lib Fri Oct 21 11:28:55 2016 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/aberk/code/QEI/#5c2ad81551aa
diff -r 000000000000 -r e881319cfd74 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Oct 21 11:28:55 2016 +0000 @@ -0,0 +1,76 @@ +#include "QEI.h" +#include "mbed.h" +#include "motordriver.h" + +//======== Serial Communication ================================================ +Serial pc(USBTX, USBRX); + + +//======== Motor and QEI ======================================================= +QEI wheel (D12, D13, NC, 62); + +//Safety for Motor +int Brakeable; +int sign; + +//Motor +Motor A(D6, D7, D7, Brakeable); // pwm, fwd, rev, brake LEFT + + +//======== Miscellaneous ======================================================= +AnalogIn pot(A1); //Potmeter +DigitalOut led(LED_GREEN); //Green LED +InterruptIn btn(SW2); //Button +InterruptIn btn2(SW3); //Button + + +//======== Variables =========================================================== +float factor = 0.03279; +int position; +float ain; /* Variable to store the analog input*/ + + + + +//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> +//======== Functions and main ================================================== +int main() { + while(1){ + + if(btn && btn2) { + A.speed(0)==0; + + }else if(btn && !btn2){ + if(position <= -105){ + A.speed(0.2)==0.2; + + }else{ + A.speed(-0.5)==-0.5; + } + + }else if(!btn && btn2){ + if(position >= 105){ + A.speed(-0.2)==-0.2; + + }else{ + A.speed(0.5)==0.5; + } + } + + else{ + A.speed(0)==0; + } + + position = (wheel.getPulses()*factor) ; // position of the motor + ain = pot.read(); + + if (ain == 0){ + wheel.reset(); + } + else {} + wait(0.1); + pc.baud(115200); + pc.printf("Afgelegde milimeters is: %i\n", position); + } + +}
diff -r 000000000000 -r e881319cfd74 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Oct 21 11:28:55 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/25aea2a3f4e3 \ No newline at end of file