Dependents:   YMotor

Committer:
inst
Date:
Fri Nov 13 07:47:35 2015 +0000
Revision:
2:871d1f6d311e
Parent:
1:c8ed08beefb9
b

Who changed what in which revision?

UserRevisionLine numberNew contents of line
inst 0:a2bbf76ca734 1 #ifndef INCLUDED_YMOTOR_DRIVER_BASE_H
inst 0:a2bbf76ca734 2 #define INCLUDED_YMOTOR_DRIVER_BASE_H
inst 0:a2bbf76ca734 3
inst 0:a2bbf76ca734 4 #include "mbed.h"
inst 0:a2bbf76ca734 5 #include "PWMOut.h"
inst 0:a2bbf76ca734 6
inst 0:a2bbf76ca734 7 class YMotorDriverBase{
inst 0:a2bbf76ca734 8 public:
inst 0:a2bbf76ca734 9 enum MotorAction{
inst 0:a2bbf76ca734 10 FORWARD,
inst 0:a2bbf76ca734 11 REVERSE,
inst 0:a2bbf76ca734 12 BRAKE,
inst 0:a2bbf76ca734 13 RELEASE
inst 0:a2bbf76ca734 14 };
inst 0:a2bbf76ca734 15
inst 0:a2bbf76ca734 16 YMotorDriverBase( char address );
inst 1:c8ed08beefb9 17 YMotorDriverBase( char address, int id );
inst 1:c8ed08beefb9 18 YMotorDriverBase( char address, float maxDuty, float minDuty );
inst 0:a2bbf76ca734 19 ~YMotorDriverBase();
inst 0:a2bbf76ca734 20
inst 0:a2bbf76ca734 21 virtual void update();
inst 0:a2bbf76ca734 22
inst 0:a2bbf76ca734 23 void setMotorAction( MotorAction action ){
inst 0:a2bbf76ca734 24 mAction = action;
inst 0:a2bbf76ca734 25 }
inst 0:a2bbf76ca734 26 void setDuty( float d ){
inst 0:a2bbf76ca734 27 mDuty = middle( mMinDuty, d, mMaxDuty );
inst 0:a2bbf76ca734 28 }
inst 0:a2bbf76ca734 29 void setPercent( float p );
inst 0:a2bbf76ca734 30
inst 0:a2bbf76ca734 31 float getMinDuty(){
inst 0:a2bbf76ca734 32 return mMinDuty;
inst 0:a2bbf76ca734 33 }
inst 0:a2bbf76ca734 34 float getMaxDuty(){
inst 0:a2bbf76ca734 35 return mMaxDuty;
inst 0:a2bbf76ca734 36 }
inst 0:a2bbf76ca734 37
inst 0:a2bbf76ca734 38 protected:
inst 1:c8ed08beefb9 39 virtual void write();
inst 0:a2bbf76ca734 40
inst 0:a2bbf76ca734 41 I2CSlave* mI2C;
inst 0:a2bbf76ca734 42 DigitalOut* mLED;
inst 0:a2bbf76ca734 43
inst 0:a2bbf76ca734 44 private:
inst 1:c8ed08beefb9 45 virtual void updateI2CSlave();
inst 1:c8ed08beefb9 46 virtual void updateSpecial(){}
inst 0:a2bbf76ca734 47
inst 0:a2bbf76ca734 48 static float middle( float min, float d, float max ){
inst 0:a2bbf76ca734 49 if ( min > max ){
inst 0:a2bbf76ca734 50 float tmp = min;
inst 0:a2bbf76ca734 51 min = max;
inst 0:a2bbf76ca734 52 max = tmp;
inst 0:a2bbf76ca734 53 }
inst 0:a2bbf76ca734 54
inst 0:a2bbf76ca734 55 if ( d < min ){
inst 0:a2bbf76ca734 56 return min;
inst 0:a2bbf76ca734 57 } else if ( d > max ){
inst 0:a2bbf76ca734 58 return max;
inst 0:a2bbf76ca734 59 }
inst 0:a2bbf76ca734 60
inst 0:a2bbf76ca734 61 return d;
inst 0:a2bbf76ca734 62 }
inst 1:c8ed08beefb9 63
inst 1:c8ed08beefb9 64 void init();
inst 1:c8ed08beefb9 65
inst 1:c8ed08beefb9 66 PWMOut* mMotorDrivePwm;
inst 1:c8ed08beefb9 67 DigitalOut* mMotorDriveDout[ 4 ];
inst 1:c8ed08beefb9 68
inst 1:c8ed08beefb9 69 MotorAction mAction;
inst 1:c8ed08beefb9 70 float mDuty;
inst 1:c8ed08beefb9 71
inst 1:c8ed08beefb9 72 const char mAddress;
inst 1:c8ed08beefb9 73 int mID;
inst 1:c8ed08beefb9 74
inst 1:c8ed08beefb9 75 static const PinName mMotorDriveDoutPinName[ 4 ];
inst 1:c8ed08beefb9 76 static const PinName mMotorDrivePwmPinName;
inst 1:c8ed08beefb9 77 static const PinName mLEDPinName;
inst 1:c8ed08beefb9 78 static const PinName mSerialPinName[ 2 ];
inst 1:c8ed08beefb9 79 static const PinName mI2CPinName[ 2 ];
inst 1:c8ed08beefb9 80 static const int mPwmCycle_us;
inst 1:c8ed08beefb9 81 static const float mMaxDutyList[];
inst 1:c8ed08beefb9 82 static const float mMinDutyList[];
inst 1:c8ed08beefb9 83 float mMaxDuty;
inst 1:c8ed08beefb9 84 float mMinDuty;
inst 0:a2bbf76ca734 85 };
inst 0:a2bbf76ca734 86
inst 0:a2bbf76ca734 87 #endif