Motor
Fork of Motor by
motor.h
- Committer:
- mlaane
- Date:
- 2013-09-15
- Revision:
- 4:2b77f4656e92
- Parent:
- 3:94db629c0a83
- Child:
- 6:37199f371bf8
File content as of revision 4:2b77f4656e92:
#ifndef MOTOR_H #define MOTOR_H #include "mbed.h" #include "PCA9555.h" #include "qed.h" /** Class for controlling motors trough PCA9555 */ class Motor { public: /** Create an instance of the motor connected to specfied pins, and IO-expander. * * @param PWMpin Pin for PWM output * @param *ioExt Pointer to IO-expander object * @param dir1Pin Direction pin 1 number (on IO-expander) * @param dir2Pin Direction pin 2 number (on IO-expander) * @param encA Encoder pin * @param encB Encoder pin */ Motor(PinName PWMpin, PCA9555 *ioExt, unsigned int dir1Pin, unsigned int dir2Pin, PinName encA, PinName encB); /** Set speed setpoint * * @param newSpeed New setpoint */ void setSpeed(int newSpeed); /** Get current speed setpoint value */ int getSpeed(); /**Method that calculates appropriate PWM values for keeping motor speed close to setpoint * This method shoud be called periodically (60Hz) */ void pid(); private: PwmOut pwm; PCA9555 *extIO; unsigned int dir1; unsigned int dir2; QED qed; int currentSpeed; int getDecoderCount(); void resetPID(); /** Set pwm duty cycle * * @param newPWM Duty cycle */ void setPWM(int newPWM); //void pid(); int setPoint; int pMulti; int iDiv; int dMulti; int error; int prevError; int P; int I; int D; int minPwm; int pidMulti; int iMax; }; #endif