![](/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
DC_Motor_Controller.h
- Committer:
- stivending
- Date:
- 2021-05-31
- Revision:
- 15:87df75ee8731
- Parent:
- 14:c9611cf036ad
File content as of revision 15:87df75ee8731:
#include "mbed.h" #include "QEI.h" #include "pid.h" #ifndef DC_MOTOR_CONTROLLER_H #define DC_MOTOR_CONTROLLER_H class DC_Motor_Controller { public: DC_Motor_Controller(PinName out_M1, PinName out_M2, PinName in_A, PinName in_B, int PPR); void goto_angle(int angle, float speed = 1); void reset(); void move_angle(int angle, float speed = 1); void set_out(float a, float b); int get_pulse(); protected: int _ppr; PwmOut out1, out2; QEI dc_motor; virtual void goto_pulse(int tar_pulse, float speed = 1) = 0; }; class DC_Motor_On_Off: public DC_Motor_Controller { public: 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){}; protected: void goto_pulse(int tar_pulse, float speed = 1); }; class DC_Motor_PID: public DC_Motor_Controller { private: PID* pid; protected: void goto_pulse(int tar_pulse, float placeholder = 0); public: 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){}; void set_pid(double Kp, double Ki, double Kd, double min); }; #endif