Ya kno it
Embed:
(wiki syntax)
Show/hide line numbers
Motor.h
00001 #include "mbed.h" 00002 #include "QEI.h" 00003 #include "PID.h" 00004 /** Motorclass 00005 Used to control Servo motors 00006 */ 00007 class Motor{ 00008 public: 00009 /** Motor class declaration 00010 @param PWM Pin 00011 @param Direction Pin 00012 @param Encoder Pin1 00013 @param Encoder Pin2 00014 @param Homingswitch 00015 @param controller Interval 00016 */ 00017 Motor(PinName PWM, PinName Direction, PinName Enc1,PinName Enc2,PinName HomingSW,float interval); 00018 00019 /** GotoPos function 00020 This function Sends the motor to the requested Position. 00021 This Function needs to be called repeadedly since it also 00022 triggers one tick of the PID controller 00023 @param The required Position in radians 00024 */ 00025 void GotoPos(float Rad); 00026 00027 /** Outputs the current motor position in radians, while keeping the gear ratio into account 00028 */ 00029 float GetPos(); 00030 00031 /** Homes the motor with the homing pin 00032 @param Direction 00033 @param PWM value 00034 @param HomingPosition in radians 00035 */ 00036 void Homing(bool direction, float PWM, float HomingPos); 00037 00038 /** Set the Pid values 00039 @param Pvalue 00040 @param Ti 00041 @param Td 00042 */ 00043 void SetPID(float P,float Ti,float Td); 00044 00045 /** Set the motor gear ratio 00046 */ 00047 void SetGearRatio(float GearRatio); 00048 00049 /** Set the inputlimits, or the allowed Position 00050 @param InputMinimum 00051 @param InputMaximum 00052 */ 00053 void SetInputLimits(float Imin, float Imax); 00054 00055 /** Set the output Limits of the PWM 00056 @param OutputMinimum 00057 @param OutputMaximum 00058 */ 00059 void SetOutputLimits(float Omin, float Omax); 00060 00061 /** Stops the motor 00062 */ 00063 void Stop(); 00064 00065 private: 00066 QEI encoder; 00067 float _GearRatio; 00068 00069 PwmOut MotorThrottle; 00070 DigitalOut MotorDirection; 00071 DigitalIn HomingSwitch; 00072 00073 PID controller; 00074 };
Generated on Fri Aug 5 2022 07:13:33 by
1.7.2