Library version for DC_Stepper_Controller_Lib with PWM speed control
Dependents: DR-ArmServoTest Auto_DC_pick_class MBed_TR1 ros_button_2021
Diff: main.cpp
- Revision:
- 2:6bc435f4ffec
- Parent:
- 1:30696e4d196b
- Child:
- 3:1229fe22fdcd
--- a/main.cpp Wed Aug 11 09:15:10 2010 +0000 +++ b/main.cpp Fri Mar 12 09:42:14 2021 +0000 @@ -1,16 +1,53 @@ +#include "mbed.h" #include "QEI.h" + +DigitalOut out1(D2); +DigitalOut out2(D4); +DigitalIn home_button(D13); +QEI dc_motor (D8,D7,NC,792); +int counter = 0; -Serial pc(USBTX, USBRX); -//Use X4 encoding. -//QEI wheel(p29, p30, NC, 624, QEI::X4_ENCODING); -//Use X2 encoding by default. -QEI wheel (p29, p30, NC, 624); +void reset(){ + while (home_button == 0){ + out1 = 1; + out2 = 0; + } + out1 = 0; + dc_motor.reset(); + wait(1); + }; + + void go_angle(int angle){ + int tar_pulse = ((double) angle / 360.0)* (2.0 * 792.0); + int cur_pulse = dc_motor.getPulses(); + + while ( tar_pulse != cur_pulse ){ + if (tar_pulse > cur_pulse){ + out1 = 1; + out2 = 0; + } + else { + out1 = 0; + out2 = 1; + } + cur_pulse = dc_motor.getPulses(); + } + out1 = 0; + out2 = 0; +}; + int main() { + reset(); + go_angle(90); + wait(1); + go_angle(180); + wait(1); + go_angle(45); + wait(1); + go_angle(30); + wait(1); + go_angle(1); + wait(1); - while(1){ - wait(0.1); - pc.printf("Pulses is: %i\n", wheel.getPulses()); - } - -} +} \ No newline at end of file