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.
a3930.h
00001 #ifndef A3930_H 00002 #define A3930_H 00003 00004 #include "mbed.h" 00005 #include "PCA9555.h" 00006 #include "PinDetect.h" 00007 00008 /** Class for controlling motors trough PCA9555 */ 00009 class A3930 { 00010 protected: 00011 FunctionPointer stallChangeCallback; 00012 FunctionPointer stallEndCallback; 00013 FunctionPointer stallWarningCallback; 00014 FunctionPointer stallErrorCallback; 00015 public: 00016 /** Create an instance of the motor connected to specfied pins, and IO-expander. 00017 * 00018 * @param PWMpin Pin for PWM output 00019 * @param *ioExt Pointer to IO-expander object 00020 * @param dir1Pin Direction pin 1 number (on IO-expander) 00021 * @param dir2Pin Direction pin 2 number (on IO-expander) 00022 * @param encA Encoder pin 00023 * @param encB Encoder pin 00024 */ 00025 A3930(PinName PWMpin, PCA9555 *ioExt, unsigned int dirPin, unsigned int brakePin, unsigned int coastPin, PinName tachoPin, PinName diroPin); 00026 00027 /** Set speed setpoint 00028 * 00029 * @param newSpeed New setpoint 00030 */ 00031 void setSpeed(int newSpeed); 00032 00033 /** Get current speed setpoint value */ 00034 int getSpeed(); 00035 00036 /**Method that calculates appropriate PWM values for keeping motor speed close to setpoint 00037 * This method shoud be called periodically (60Hz) 00038 */ 00039 void pid(); 00040 00041 /** Set pwm duty cycle 00042 * 00043 * @param newPWM Duty cycle 00044 */ 00045 void setPWM(float newPWM); 00046 00047 void setRawPWM(float newPWM); 00048 00049 int getStallLevel(); 00050 00051 void stallChange(void (*function)(void)); 00052 00053 template<typename T> 00054 void stallChange(T *object, void (T::*member)(void)) { 00055 stallChangeCallback.attach(object, member); 00056 } 00057 00058 void stallEnd(void (*function)(void)); 00059 00060 template<typename T> 00061 void stallEnd(T *object, void (T::*member)(void)) { 00062 stallEndCallback.attach(object, member); 00063 } 00064 00065 void stallWarning(void (*function)(void)); 00066 00067 template<typename T> 00068 void stallWarning(T *object, void (T::*member)(void)) { 00069 stallWarningCallback.attach(object, member); 00070 } 00071 00072 void stallError(void (*function)(void)); 00073 00074 template<typename T> 00075 void stallError(T *object, void (T::*member)(void)) { 00076 stallErrorCallback.attach(object, member); 00077 } 00078 00079 private: 00080 PwmOut pwm; 00081 PCA9555 *extIO; 00082 unsigned int dirPinNumber; 00083 unsigned int brakePinNumber; 00084 unsigned int coastPinNumber; 00085 00086 InterruptIn interruptTacho; 00087 //InterruptIn interruptDiro; 00088 00089 //PinDetect interruptTacho; 00090 PinDetect interruptDiro; 00091 00092 volatile int diro; 00093 volatile int pulses; 00094 00095 int currentSpeed; 00096 int getDecoderCount(); 00097 00098 void tachoChanged(); 00099 void diroRise(); 00100 void diroFall(); 00101 00102 void resetPID(); 00103 00104 int setPoint; 00105 float pMulti; 00106 float iMulti; 00107 float dMulti; 00108 int error; 00109 int prevError; 00110 float P; 00111 float I; 00112 float D; 00113 float minPwm; 00114 00115 float pwmPeriod; 00116 00117 float currentPWM; 00118 int stallCount; 00119 int prevStallCount; 00120 int stallWarningLimit; 00121 int stallErrorLimit; 00122 int stallLevel; 00123 }; 00124 00125 #endif
Generated on Sat Jul 16 2022 23:54:51 by
1.7.2