![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Library version for DC_Stepper_Controller_Lib with PWM speed control
Dependents: DR-ArmServoTest Auto_DC_pick_class MBed_TR1 ros_button_2021
Diff: sample_main.cpp
- Revision:
- 12:3949fd23be49
- Parent:
- 11:e880912260b5
- Child:
- 13:675456f1f401
--- a/sample_main.cpp Tue May 25 08:59:55 2021 +0000 +++ b/sample_main.cpp Wed May 26 07:43:28 2021 +0000 @@ -1,27 +1,57 @@ +/******************************************************* + DC MODOR CONTROLLER LIBRARY + ******************************************************* + Important: + 1) Enable / Disable DEBUG_MODE in DC_Motor_controller.cpp + (DEBUG_MODE affects accuracy in control!!!) + 2) If compliation issue occurs, DELETE this file. +********************************************************/ + #include "mbed.h" #include "QEI.h" #include "DC_Motor_Controller.h" DC_Motor_Controller motor(D6,D3,D4,D5,792); //M1, M2, INA, INB, PPR +DigitalIn but(USER_BUTTON); - +// angle = 412 degree to move from one to another +// angle = 100 degree to -int sample_main() { - +int main() { + motor.reset(); + + Serial pc(USBTX, USBRX); // tx, rx + pc.baud(9600); + + while(1) + { + + while(!pc.readable()) + if(but) { motor.set_out(0,0); pc.printf("\n now: %d \n", motor.get_pulse()); break;} + if(pc.readable()) { + if(pc.getc() == '1') motor.set_out(0.6,0); + else if(pc.getc() == '2') motor.set_out(0,0.6); + } + else break; + } + /* motor.set_out(1,0); wait(5); motor.set_out(0,1); - wait(5);*/ - - - motor.move_angle(-90, 0.5); // speed, 0 to 1 + wait(5); + */ + wait(0.5); + motor.move_angle(412, 0.5); // speed, 0 to 1 + wait(0.5); + motor.move_angle(412, 0.5); // speed, 0 to 1 + wait(0.5); + motor.move_angle(412, 0.5); // speed, 0 to 1 + wait(0.5); + motor.move_angle(412, 0.5); // speed, 0 to 1 + wait(0.5); + motor.move_angle(120, 0.5); // speed, 0 to 1 - wait(1.5); - - motor.move_angle(90, 0.3); - wait(1.5); - motor.goto_angle(0, 0.1); } \ No newline at end of file