![](/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
sample_main.cpp@13:675456f1f401, 2021-05-27 (annotated)
- Committer:
- stivending
- Date:
- Thu May 27 05:43:48 2021 +0000
- Revision:
- 13:675456f1f401
- Parent:
- 12:3949fd23be49
- Child:
- 14:c9611cf036ad
PID supported, read manual first
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
stivending | 12:3949fd23be49 | 1 | /******************************************************* |
stivending | 12:3949fd23be49 | 2 | DC MODOR CONTROLLER LIBRARY |
stivending | 12:3949fd23be49 | 3 | ******************************************************* |
stivending | 13:675456f1f401 | 4 | IMPORTANT: GO TO README FOR DOCUMENT! |
stivending | 12:3949fd23be49 | 5 | ********************************************************/ |
stivending | 12:3949fd23be49 | 6 | |
cheukming0607 | 2:6bc435f4ffec | 7 | #include "mbed.h" |
aberk | 0:bcff39fac858 | 8 | #include "QEI.h" |
stivending | 5:c040faf21e07 | 9 | #include "DC_Motor_Controller.h" |
aberk | 0:bcff39fac858 | 10 | |
stivending | 9:49b59b308767 | 11 | |
stivending | 13:675456f1f401 | 12 | DC_Motor_PID motor(D6,D3,D4,D5,792); //M1, M2, INA, INB, PPR |
stivending | 12:3949fd23be49 | 13 | DigitalIn but(USER_BUTTON); |
stivending | 4:b242191ed0cf | 14 | |
stivending | 12:3949fd23be49 | 15 | // angle = 412 degree to move from one to another |
stivending | 12:3949fd23be49 | 16 | // angle = 100 degree to |
stivending | 9:49b59b308767 | 17 | |
stivending | 12:3949fd23be49 | 18 | int main() { |
stivending | 12:3949fd23be49 | 19 | |
stivending | 13:675456f1f401 | 20 | motor.set_pid(0.008, 0, 0); |
stivending | 12:3949fd23be49 | 21 | |
stivending | 12:3949fd23be49 | 22 | Serial pc(USBTX, USBRX); // tx, rx |
stivending | 12:3949fd23be49 | 23 | pc.baud(9600); |
stivending | 12:3949fd23be49 | 24 | |
stivending | 12:3949fd23be49 | 25 | while(1) |
stivending | 12:3949fd23be49 | 26 | { |
stivending | 12:3949fd23be49 | 27 | |
stivending | 12:3949fd23be49 | 28 | while(!pc.readable()) |
stivending | 12:3949fd23be49 | 29 | if(but) { motor.set_out(0,0); pc.printf("\n now: %d \n", motor.get_pulse()); break;} |
stivending | 12:3949fd23be49 | 30 | if(pc.readable()) { |
stivending | 12:3949fd23be49 | 31 | if(pc.getc() == '1') motor.set_out(0.6,0); |
stivending | 12:3949fd23be49 | 32 | else if(pc.getc() == '2') motor.set_out(0,0.6); |
stivending | 12:3949fd23be49 | 33 | } |
stivending | 12:3949fd23be49 | 34 | else break; |
stivending | 12:3949fd23be49 | 35 | } |
stivending | 12:3949fd23be49 | 36 | |
stivending | 7:6e59ed00a6a9 | 37 | /* |
stivending | 7:6e59ed00a6a9 | 38 | motor.set_out(1,0); |
stivending | 7:6e59ed00a6a9 | 39 | wait(5); |
stivending | 7:6e59ed00a6a9 | 40 | motor.set_out(0,1); |
stivending | 12:3949fd23be49 | 41 | wait(5); |
stivending | 12:3949fd23be49 | 42 | */ |
stivending | 12:3949fd23be49 | 43 | wait(0.5); |
stivending | 13:675456f1f401 | 44 | motor.move_angle(412); // speed, 0 to 1 |
stivending | 12:3949fd23be49 | 45 | wait(0.5); |
stivending | 13:675456f1f401 | 46 | motor.move_angle(-412); // speed, 0 to 1 |
stivending | 12:3949fd23be49 | 47 | wait(0.5); |
stivending | 13:675456f1f401 | 48 | motor.move_angle(412); // speed, 0 to 1 |
stivending | 12:3949fd23be49 | 49 | wait(0.5); |
stivending | 13:675456f1f401 | 50 | motor.move_angle(412); // speed, 0 to 1 |
stivending | 12:3949fd23be49 | 51 | wait(0.5); |
stivending | 13:675456f1f401 | 52 | motor.move_angle(120); // speed, 0 to 1 |
stivending | 10:fe56f6800a72 | 53 | |
cheukming0607 | 2:6bc435f4ffec | 54 | } |