Dependents:   YMotor

Committer:
inst
Date:
Wed Oct 14 06:04:34 2015 +0000
Revision:
1:c8ed08beefb9
Parent:
0:a2bbf76ca734
Child:
2:871d1f6d311e

        

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 1:c8ed08beefb9 40 void updatePwmDuty();
inst 0:a2bbf76ca734 41
inst 0:a2bbf76ca734 42 I2CSlave* mI2C;
inst 0:a2bbf76ca734 43 DigitalOut* mLED;
inst 0:a2bbf76ca734 44
inst 0:a2bbf76ca734 45 private:
inst 1:c8ed08beefb9 46 virtual void updateI2CSlave();
inst 1:c8ed08beefb9 47 virtual void updateSpecial(){}
inst 0:a2bbf76ca734 48
inst 0:a2bbf76ca734 49 static float middle( float min, float d, float max ){
inst 0:a2bbf76ca734 50 if ( min > max ){
inst 0:a2bbf76ca734 51 float tmp = min;
inst 0:a2bbf76ca734 52 min = max;
inst 0:a2bbf76ca734 53 max = tmp;
inst 0:a2bbf76ca734 54 }
inst 0:a2bbf76ca734 55
inst 0:a2bbf76ca734 56 if ( d < min ){
inst 0:a2bbf76ca734 57 return min;
inst 0:a2bbf76ca734 58 } else if ( d > max ){
inst 0:a2bbf76ca734 59 return max;
inst 0:a2bbf76ca734 60 }
inst 0:a2bbf76ca734 61
inst 0:a2bbf76ca734 62 return d;
inst 0:a2bbf76ca734 63 }
inst 1:c8ed08beefb9 64
inst 1:c8ed08beefb9 65 void init();
inst 1:c8ed08beefb9 66
inst 1:c8ed08beefb9 67 PWMOut* mMotorDrivePwm;
inst 1:c8ed08beefb9 68 DigitalOut* mMotorDriveDout[ 4 ];
inst 1:c8ed08beefb9 69
inst 1:c8ed08beefb9 70 MotorAction mAction;
inst 1:c8ed08beefb9 71 float mDuty;
inst 1:c8ed08beefb9 72
inst 1:c8ed08beefb9 73 const char mAddress;
inst 1:c8ed08beefb9 74 int mID;
inst 1:c8ed08beefb9 75
inst 1:c8ed08beefb9 76 static const PinName mMotorDriveDoutPinName[ 4 ];
inst 1:c8ed08beefb9 77 static const PinName mMotorDrivePwmPinName;
inst 1:c8ed08beefb9 78 static const PinName mLEDPinName;
inst 1:c8ed08beefb9 79 static const PinName mSerialPinName[ 2 ];
inst 1:c8ed08beefb9 80 static const PinName mI2CPinName[ 2 ];
inst 1:c8ed08beefb9 81 static const int mPwmCycle_us;
inst 1:c8ed08beefb9 82 static const float mMaxDutyList[];
inst 1:c8ed08beefb9 83 static const float mMinDutyList[];
inst 1:c8ed08beefb9 84 float mMaxDuty;
inst 1:c8ed08beefb9 85 float mMinDuty;
inst 0:a2bbf76ca734 86 };
inst 0:a2bbf76ca734 87
inst 0:a2bbf76ca734 88 #endif