Library version for DC_Stepper_Controller_Lib with PWM speed control
Dependents: DR-ArmServoTest Auto_DC_pick_class MBed_TR1 ros_button_2021
DC_Motor_Controller.h@15:87df75ee8731, 2021-05-31 (annotated)
- Committer:
- stivending
- Date:
- Mon May 31 09:44:13 2021 +0000
- Revision:
- 15:87df75ee8731
- Parent:
- 14:c9611cf036ad
button to init;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
stivending | 5:c040faf21e07 | 1 | #include "mbed.h" |
stivending | 5:c040faf21e07 | 2 | #include "QEI.h" |
stivending | 13:675456f1f401 | 3 | #include "pid.h" |
stivending | 5:c040faf21e07 | 4 | |
stivending | 5:c040faf21e07 | 5 | #ifndef DC_MOTOR_CONTROLLER_H |
stivending | 5:c040faf21e07 | 6 | #define DC_MOTOR_CONTROLLER_H |
stivending | 5:c040faf21e07 | 7 | |
stivending | 13:675456f1f401 | 8 | class DC_Motor_Controller |
stivending | 13:675456f1f401 | 9 | { |
stivending | 5:c040faf21e07 | 10 | public: |
stivending | 10:fe56f6800a72 | 11 | DC_Motor_Controller(PinName out_M1, PinName out_M2, PinName in_A, PinName in_B, int PPR); |
stivending | 10:fe56f6800a72 | 12 | void goto_angle(int angle, float speed = 1); |
stivending | 9:49b59b308767 | 13 | void reset(); |
stivending | 10:fe56f6800a72 | 14 | void move_angle(int angle, float speed = 1); |
stivending | 10:fe56f6800a72 | 15 | void set_out(float a, float b); |
stivending | 9:49b59b308767 | 16 | int get_pulse(); |
stivending | 13:675456f1f401 | 17 | |
stivending | 13:675456f1f401 | 18 | protected: |
stivending | 14:c9611cf036ad | 19 | int _ppr; |
stivending | 13:675456f1f401 | 20 | PwmOut out1, out2; |
stivending | 13:675456f1f401 | 21 | QEI dc_motor; |
stivending | 13:675456f1f401 | 22 | virtual void goto_pulse(int tar_pulse, float speed = 1) = 0; |
stivending | 5:c040faf21e07 | 23 | }; |
stivending | 13:675456f1f401 | 24 | |
stivending | 13:675456f1f401 | 25 | class DC_Motor_On_Off: public DC_Motor_Controller |
stivending | 13:675456f1f401 | 26 | { |
stivending | 13:675456f1f401 | 27 | public: |
stivending | 13:675456f1f401 | 28 | DC_Motor_On_Off(PinName out_M1, PinName out_M2, PinName in_A, PinName in_B, int PPR):DC_Motor_Controller(out_M1, out_M2, in_A, in_B, PPR){}; |
stivending | 13:675456f1f401 | 29 | protected: |
stivending | 13:675456f1f401 | 30 | void goto_pulse(int tar_pulse, float speed = 1); |
stivending | 13:675456f1f401 | 31 | }; |
stivending | 13:675456f1f401 | 32 | |
stivending | 13:675456f1f401 | 33 | class DC_Motor_PID: public DC_Motor_Controller |
stivending | 13:675456f1f401 | 34 | { |
stivending | 13:675456f1f401 | 35 | private: |
stivending | 13:675456f1f401 | 36 | PID* pid; |
stivending | 13:675456f1f401 | 37 | protected: |
stivending | 13:675456f1f401 | 38 | void goto_pulse(int tar_pulse, float placeholder = 0); |
stivending | 13:675456f1f401 | 39 | public: |
stivending | 13:675456f1f401 | 40 | DC_Motor_PID(PinName out_M1, PinName out_M2, PinName in_A, PinName in_B, int PPR):DC_Motor_Controller(out_M1, out_M2, in_A, in_B, PPR){}; |
stivending | 15:87df75ee8731 | 41 | void set_pid(double Kp, double Ki, double Kd, double min); |
stivending | 13:675456f1f401 | 42 | }; |
stivending | 13:675456f1f401 | 43 | |
stivending | 13:675456f1f401 | 44 | |
stivending | 5:c040faf21e07 | 45 | #endif |