Library version for DC_Stepper_Controller_Lib with PWM speed control

Dependencies:   mbed QEI PID

Dependents:   DR-ArmServoTest Auto_DC_pick_class MBed_TR1 ros_button_2021

Committer:
stivending
Date:
Wed May 26 07:43:28 2021 +0000
Revision:
12:3949fd23be49
Parent:
11:e880912260b5
Child:
13:675456f1f401
add doc

Who changed what in which revision?

UserRevisionLine numberNew contents of line
stivending 12:3949fd23be49 1 /*******************************************************
stivending 12:3949fd23be49 2 DC MODOR CONTROLLER LIBRARY
stivending 12:3949fd23be49 3 *******************************************************
stivending 12:3949fd23be49 4 Important:
stivending 12:3949fd23be49 5 1) Enable / Disable DEBUG_MODE in DC_Motor_controller.cpp
stivending 12:3949fd23be49 6 (DEBUG_MODE affects accuracy in control!!!)
stivending 12:3949fd23be49 7 2) If compliation issue occurs, DELETE this file.
stivending 12:3949fd23be49 8 ********************************************************/
stivending 12:3949fd23be49 9
cheukming0607 2:6bc435f4ffec 10 #include "mbed.h"
aberk 0:bcff39fac858 11 #include "QEI.h"
stivending 5:c040faf21e07 12 #include "DC_Motor_Controller.h"
aberk 0:bcff39fac858 13
stivending 9:49b59b308767 14
stivending 10:fe56f6800a72 15 DC_Motor_Controller motor(D6,D3,D4,D5,792); //M1, M2, INA, INB, PPR
stivending 12:3949fd23be49 16 DigitalIn but(USER_BUTTON);
stivending 4:b242191ed0cf 17
stivending 12:3949fd23be49 18 // angle = 412 degree to move from one to another
stivending 12:3949fd23be49 19 // angle = 100 degree to
stivending 9:49b59b308767 20
stivending 12:3949fd23be49 21 int main() {
stivending 12:3949fd23be49 22
stivending 5:c040faf21e07 23 motor.reset();
stivending 12:3949fd23be49 24
stivending 12:3949fd23be49 25 Serial pc(USBTX, USBRX); // tx, rx
stivending 12:3949fd23be49 26 pc.baud(9600);
stivending 12:3949fd23be49 27
stivending 12:3949fd23be49 28 while(1)
stivending 12:3949fd23be49 29 {
stivending 12:3949fd23be49 30
stivending 12:3949fd23be49 31 while(!pc.readable())
stivending 12:3949fd23be49 32 if(but) { motor.set_out(0,0); pc.printf("\n now: %d \n", motor.get_pulse()); break;}
stivending 12:3949fd23be49 33 if(pc.readable()) {
stivending 12:3949fd23be49 34 if(pc.getc() == '1') motor.set_out(0.6,0);
stivending 12:3949fd23be49 35 else if(pc.getc() == '2') motor.set_out(0,0.6);
stivending 12:3949fd23be49 36 }
stivending 12:3949fd23be49 37 else break;
stivending 12:3949fd23be49 38 }
stivending 12:3949fd23be49 39
stivending 7:6e59ed00a6a9 40 /*
stivending 7:6e59ed00a6a9 41 motor.set_out(1,0);
stivending 7:6e59ed00a6a9 42 wait(5);
stivending 7:6e59ed00a6a9 43 motor.set_out(0,1);
stivending 12:3949fd23be49 44 wait(5);
stivending 12:3949fd23be49 45 */
stivending 12:3949fd23be49 46 wait(0.5);
stivending 12:3949fd23be49 47 motor.move_angle(412, 0.5); // speed, 0 to 1
stivending 12:3949fd23be49 48 wait(0.5);
stivending 12:3949fd23be49 49 motor.move_angle(412, 0.5); // speed, 0 to 1
stivending 12:3949fd23be49 50 wait(0.5);
stivending 12:3949fd23be49 51 motor.move_angle(412, 0.5); // speed, 0 to 1
stivending 12:3949fd23be49 52 wait(0.5);
stivending 12:3949fd23be49 53 motor.move_angle(412, 0.5); // speed, 0 to 1
stivending 12:3949fd23be49 54 wait(0.5);
stivending 12:3949fd23be49 55 motor.move_angle(120, 0.5); // speed, 0 to 1
stivending 10:fe56f6800a72 56
cheukming0607 2:6bc435f4ffec 57 }