Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
motor.h
00001 #ifndef MOTOR_H 00002 #define MOTOR_H 00003 00004 #include "mbed.h" 00005 #include "PCA9555.h" 00006 #include "qed.h" 00007 /** Class for controlling motors trough PCA9555 */ 00008 class Motor { 00009 protected: 00010 FunctionPointer stallWarningCallback; 00011 FunctionPointer stallErrorCallback; 00012 public: 00013 /** Create an instance of the motor connected to specfied pins, and IO-expander. 00014 * 00015 * @param PWMpin Pin for PWM output 00016 * @param *ioExt Pointer to IO-expander object 00017 * @param dir1Pin Direction pin 1 number (on IO-expander) 00018 * @param dir2Pin Direction pin 2 number (on IO-expander) 00019 * @param encA Encoder pin 00020 * @param encB Encoder pin 00021 */ 00022 Motor(PinName PWMpin, PCA9555 *ioExt, unsigned int dir1Pin, unsigned int dir2Pin, PinName encA, PinName encB); 00023 00024 /** Set speed setpoint 00025 * 00026 * @param newSpeed New setpoint 00027 */ 00028 void setSpeed(int newSpeed); 00029 00030 /** Get current speed setpoint value */ 00031 int getSpeed(); 00032 00033 /**Method that calculates appropriate PWM values for keeping motor speed close to setpoint 00034 * This method shoud be called periodically (60Hz) 00035 */ 00036 void pid(); 00037 00038 void stallWarning(void (*function)(void)); 00039 00040 template<typename T> 00041 void stallWarning(T *object, void (T::*member)(void)) { 00042 stallWarningCallback.attach(object, member); 00043 } 00044 00045 void stallError(void (*function)(void)); 00046 00047 template<typename T> 00048 void stallError(T *object, void (T::*member)(void)) { 00049 stallErrorCallback.attach(object, member); 00050 } 00051 00052 private: 00053 PwmOut pwm; 00054 PCA9555 *extIO; 00055 unsigned int dir1; 00056 unsigned int dir2; 00057 QED qed; 00058 00059 int currentSpeed; 00060 int getDecoderCount(); 00061 00062 void resetPID(); 00063 00064 <<<<<<< local 00065 ======= 00066 /** Set pwm duty cycle 00067 * 00068 * @param newPWM Duty cycle 00069 */ 00070 void setPWM(int newPWM); 00071 00072 //void pid(); 00073 00074 >>>>>>> other 00075 int setPoint; 00076 int pMulti; 00077 int iDiv; 00078 int dMulti; 00079 int error; 00080 int prevError; 00081 int P; 00082 int I; 00083 int D; 00084 int minPwm; 00085 int pidMulti; 00086 int iMax; 00087 00088 int currentPWM; 00089 int stallCounter; 00090 int stallCounterLimit; 00091 }; 00092 00093 #endif
Generated on Sun Jul 17 2022 05:33:11 by
1.7.2