LHI Brushless

Committer:
lordofthestorm12
Date:
Wed Mar 13 18:18:12 2019 +0000
Revision:
1:f1cd988f3eea
Parent:
0:50babc482989
Brushless-Lib for LHI-Brushless Motors

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lordofthestorm12 0:50babc482989 1 #include "Brushless_DC_LIB.h"
lordofthestorm12 0:50babc482989 2
lordofthestorm12 0:50babc482989 3 Motor_obj::Motor_obj(PinName mLF, PinName mRF, PinName mLB, PinName mRB): _MotorLF(mLF), _MotorRF(mRF), _MotorLB(mLB), _MotorRB(mRB){
lordofthestorm12 1:f1cd988f3eea 4 _MotorLF.period_us(2000); _MotorLF.pulsewidth_us(1000);_CurrentPPW[0] = 1000;
lordofthestorm12 1:f1cd988f3eea 5 _MotorRF.period_us(2000); _MotorRF.pulsewidth_us(1000);_CurrentPPW[1] = 1000;
lordofthestorm12 1:f1cd988f3eea 6 _MotorLB.period_us(2000); _MotorLB.pulsewidth_us(1000);_CurrentPPW[2] = 1000;
lordofthestorm12 1:f1cd988f3eea 7 _MotorRB.period_us(2000); _MotorRB.pulsewidth_us(1000);_CurrentPPW[3] = 1000;
lordofthestorm12 0:50babc482989 8 }
lordofthestorm12 0:50babc482989 9
lordofthestorm12 0:50babc482989 10 int Motor_obj:: getMotorVal(MOTOR mMotor){
lordofthestorm12 0:50babc482989 11
lordofthestorm12 0:50babc482989 12 switch (mMotor){
lordofthestorm12 0:50babc482989 13 case LeftFront: return _CurrentPPW[0];
lordofthestorm12 0:50babc482989 14 case RightFront: return _CurrentPPW[1];
lordofthestorm12 0:50babc482989 15 case LeftBack: return _CurrentPPW[2];
lordofthestorm12 0:50babc482989 16 case RightBack: return _CurrentPPW[3];
lordofthestorm12 0:50babc482989 17 }
lordofthestorm12 0:50babc482989 18 return 0;
lordofthestorm12 0:50babc482989 19
lordofthestorm12 0:50babc482989 20 }
lordofthestorm12 0:50babc482989 21 void Motor_obj:: getAllMotorVal(int mAry[4]){
lordofthestorm12 0:50babc482989 22
lordofthestorm12 0:50babc482989 23 for(int i = 0; i <=4; i++) mAry[i] = _CurrentPPW[i];
lordofthestorm12 0:50babc482989 24 }
lordofthestorm12 0:50babc482989 25
lordofthestorm12 0:50babc482989 26 void Motor_obj:: setMotor(MOTOR mMotor, int mMotorVal){
lordofthestorm12 0:50babc482989 27
lordofthestorm12 0:50babc482989 28 switch (mMotor){
lordofthestorm12 0:50babc482989 29
lordofthestorm12 0:50babc482989 30 case LeftFront:{_MotorLF.pulsewidth_us(mMotorVal); _CurrentPPW[0] = mMotorVal ;break;}
lordofthestorm12 0:50babc482989 31 case RightFront:{_MotorRF.pulsewidth_us(mMotorVal); _CurrentPPW[1] = mMotorVal ; break;}
lordofthestorm12 0:50babc482989 32 case LeftBack:{_MotorLB.pulsewidth_us(mMotorVal); _CurrentPPW[2] = mMotorVal ; break;}
lordofthestorm12 0:50babc482989 33 case RightBack:{_MotorRB.pulsewidth_us(mMotorVal); _CurrentPPW[3] = mMotorVal ; break;}
lordofthestorm12 0:50babc482989 34
lordofthestorm12 0:50babc482989 35 }
lordofthestorm12 0:50babc482989 36
lordofthestorm12 0:50babc482989 37 }
lordofthestorm12 0:50babc482989 38
lordofthestorm12 0:50babc482989 39 void Motor_obj:: setAllMotor(int mMotorLF, int mMotorRF, int mMotorLB, int mMotorRB){
lordofthestorm12 0:50babc482989 40
lordofthestorm12 0:50babc482989 41 _MotorLF.pulsewidth_us(mMotorLF); _CurrentPPW[0] = mMotorLF;
lordofthestorm12 0:50babc482989 42 _MotorRF.pulsewidth_us(mMotorRF); _CurrentPPW[1] = mMotorRF;
lordofthestorm12 0:50babc482989 43 _MotorLB.pulsewidth_us(mMotorLB); _CurrentPPW[2] = mMotorLB;
lordofthestorm12 0:50babc482989 44 _MotorRB.pulsewidth_us(mMotorRB); _CurrentPPW[3] = mMotorRB;
lordofthestorm12 0:50babc482989 45
lordofthestorm12 0:50babc482989 46 }
lordofthestorm12 0:50babc482989 47
lordofthestorm12 0:50babc482989 48 void Motor_obj:: setAllZero(void){
lordofthestorm12 0:50babc482989 49 _MotorRF.pulsewidth_us(0); _MotorLB.pulsewidth_us(0); _MotorRB.pulsewidth_us(0);_MotorLF.pulsewidth_us(0);
lordofthestorm12 0:50babc482989 50 _MotorLF = 0; _MotorRF = 0; _MotorLB = 0; _MotorRB = 0;
lordofthestorm12 0:50babc482989 51
lordofthestorm12 0:50babc482989 52
lordofthestorm12 0:50babc482989 53 }
lordofthestorm12 0:50babc482989 54