teamALI / Mbed 2 deprecated HB2018

Dependencies:   mbed FreeRTOS

Committer:
MasashiNomura
Date:
Mon Jan 21 11:57:35 2019 +0000
Revision:
41:45c982b1c5b6
Parent:
38:24ee50452755
Child:
42:cc8501b824ba
20190121 Modify for 45inc. HbMotor,HbManager,GF etc

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MasashiNomura 22:24c9c2dedca9 1 #include "HbUserOpe.h"
MasashiNomura 22:24c9c2dedca9 2 #include "fpga.h"
MasashiNomura 22:24c9c2dedca9 3 //=========================================
MasashiNomura 22:24c9c2dedca9 4 //コンストラクタ
MasashiNomura 22:24c9c2dedca9 5 //=========================================
MasashiNomura 22:24c9c2dedca9 6 HbUserOpe::HbUserOpe(){
MasashiNomura 22:24c9c2dedca9 7 oldOpe.w = curOpe.w = 0;
MasashiNomura 36:2cc739c7e4cb 8 AinAxlVal = AinTrtlVal = 0;
MasashiNomura 22:24c9c2dedca9 9 }
MasashiNomura 22:24c9c2dedca9 10
MasashiNomura 22:24c9c2dedca9 11 //=========================================
MasashiNomura 22:24c9c2dedca9 12 //デストラクタ
MasashiNomura 22:24c9c2dedca9 13 //=========================================
MasashiNomura 22:24c9c2dedca9 14 HbUserOpe::~HbUserOpe(){
MasashiNomura 22:24c9c2dedca9 15 }
MasashiNomura 22:24c9c2dedca9 16
MasashiNomura 22:24c9c2dedca9 17 typUserSw HbUserOpe::GetUserOpe()
MasashiNomura 22:24c9c2dedca9 18 {
MasashiNomura 22:24c9c2dedca9 19 oldOpe = curOpe;
MasashiNomura 22:24c9c2dedca9 20 curOpe.w = fpgaGetUserSw();
MasashiNomura 41:45c982b1c5b6 21 if(gf_Print.d2.bf.sw){
MasashiNomura 41:45c982b1c5b6 22 sp.printf("SW : [%04X] ", curOpe.w);
MasashiNomura 41:45c982b1c5b6 23 }
MasashiNomura 22:24c9c2dedca9 24 return curOpe;
MasashiNomura 23:79e20be4bc5b 25 }
MasashiNomura 38:24ee50452755 26 float HbUserOpe::GetAinAccelRaw()
MasashiNomura 38:24ee50452755 27 {
MasashiNomura 38:24ee50452755 28 AinAxlVal = AinAxl.read();
MasashiNomura 38:24ee50452755 29 return AinAxlVal;
MasashiNomura 38:24ee50452755 30 }
MasashiNomura 33:eb260dbfc22a 31 INT16 HbUserOpe::GetAinAccel()
MasashiNomura 33:eb260dbfc22a 32 {
MasashiNomura 34:234b87f3e6ce 33 // max rpm 8500 ユーザー使用分として7000をマックスとする(仮)
MasashiNomura 34:234b87f3e6ce 34 // 0 ~ 1.00 -> 0.01 ~ 0.97を使用する(遊び分として)
MasashiNomura 33:eb260dbfc22a 35 INT16 ret = 0;
MasashiNomura 34:234b87f3e6ce 36 AinAxlVal = AinAxl.read();
MasashiNomura 34:234b87f3e6ce 37 if(MIN_EFF_ANA_VAL > AinAxlVal){
MasashiNomura 33:eb260dbfc22a 38 ret = 0;
MasashiNomura 34:234b87f3e6ce 39 } else if(AinAxlVal >= MIN_EFF_ANA_VAL && AinAxlVal <= MAX_EFF_ANA_VAL){
MasashiNomura 34:234b87f3e6ce 40 ret = (MAX_RPM_USERSET - MIN_RPM_TOTAL) * (AinAxlVal - MIN_EFF_ANA_VAL) / (MAX_EFF_ANA_VAL - MIN_EFF_ANA_VAL) + MIN_RPM_TOTAL;
MasashiNomura 34:234b87f3e6ce 41 } else if(AinAxlVal > MAX_EFF_ANA_VAL){
MasashiNomura 34:234b87f3e6ce 42 ret = MAX_RPM_USERSET;
MasashiNomura 33:eb260dbfc22a 43 }else{
MasashiNomura 33:eb260dbfc22a 44 ret = 0;
MasashiNomura 33:eb260dbfc22a 45 }
MasashiNomura 41:45c982b1c5b6 46 if(gf_Print.d2.bf.ain == true){
MasashiNomura 41:45c982b1c5b6 47 sp.printf("Axl Rpm=%d val=%f ",ret,AinAxlVal);
MasashiNomura 33:eb260dbfc22a 48 }
MasashiNomura 33:eb260dbfc22a 49 //sp.printf("Axl Rpm=%d val=%f\r\n",ret,anaval);
MasashiNomura 33:eb260dbfc22a 50 return ret;
MasashiNomura 33:eb260dbfc22a 51 }
MasashiNomura 34:234b87f3e6ce 52
MasashiNomura 38:24ee50452755 53 float HbUserOpe::GetAinThrottleRaw()
MasashiNomura 38:24ee50452755 54 {
MasashiNomura 38:24ee50452755 55 AinTrtlVal = AinAxl.read();
MasashiNomura 38:24ee50452755 56 return AinTrtlVal;
MasashiNomura 38:24ee50452755 57 }
MasashiNomura 38:24ee50452755 58
MasashiNomura 36:2cc739c7e4cb 59 INT16 HbUserOpe::GetAinThrottle()
MasashiNomura 36:2cc739c7e4cb 60 {
MasashiNomura 36:2cc739c7e4cb 61 INT16 ret = 0;
MasashiNomura 38:24ee50452755 62 AinTrtlVal = AinAxl.read();
MasashiNomura 38:24ee50452755 63 //AinTrtlVal = AinThrottle.read();
MasashiNomura 38:24ee50452755 64 ret = (INT16)(MAX_VAL_12BIT * AinTrtlVal);
MasashiNomura 41:45c982b1c5b6 65 if(gf_Print.d2.bf.ain == true){
MasashiNomura 41:45c982b1c5b6 66 sp.printf("Trottle Val=%d analog val=%f ",ret,AinTrtlVal);
MasashiNomura 36:2cc739c7e4cb 67 }
MasashiNomura 36:2cc739c7e4cb 68 return ret;
MasashiNomura 36:2cc739c7e4cb 69 }
MasashiNomura 36:2cc739c7e4cb 70
MasashiNomura 23:79e20be4bc5b 71 bool HbUserOpe::ChkCtrlSW(SW_TYPE styp)
MasashiNomura 23:79e20be4bc5b 72 {
MasashiNomura 36:2cc739c7e4cb 73 if(styp == BRK_L) {return curOpe.bf.brk_l;}
MasashiNomura 36:2cc739c7e4cb 74 else if(styp == BRK_R) {return curOpe.bf.brk_r;}
MasashiNomura 36:2cc739c7e4cb 75 else if(styp == FLT_ON) {return curOpe.bf.flt_on;}
MasashiNomura 34:234b87f3e6ce 76 else if(styp == FLT_OFF) {return curOpe.bf.flt_off;}
MasashiNomura 36:2cc739c7e4cb 77 else if(styp == F_ENG_UP) {return curOpe.bf.f_eng_up;}
MasashiNomura 36:2cc739c7e4cb 78 else if(styp == F_ENG_DOWN) {return curOpe.bf.f_eng_down;}
MasashiNomura 36:2cc739c7e4cb 79 else if(styp == R_ENG_UP) {return curOpe.bf.r_eng_up;}
MasashiNomura 36:2cc739c7e4cb 80 else if(styp == R_ENG_DOWN) {return curOpe.bf.r_eng_down;}
MasashiNomura 36:2cc739c7e4cb 81 else if(styp == R_1) {return curOpe.bf.rsv_1;}
MasashiNomura 36:2cc739c7e4cb 82 else if(styp == ALL_STOP) {return curOpe.bf.all_stop;}
MasashiNomura 31:56c554c560c1 83 else {return false;}
MasashiNomura 26:732bc37fbefd 84 }
MasashiNomura 23:79e20be4bc5b 85 bool HbUserOpe::ChkCtrlSwAny()
MasashiNomura 23:79e20be4bc5b 86 {
MasashiNomura 23:79e20be4bc5b 87 UINT16 mask = 0x1;
MasashiNomura 34:234b87f3e6ce 88 for(int i = 0; i < 10; ++i){
MasashiNomura 23:79e20be4bc5b 89 if(curOpe.w & mask){
MasashiNomura 23:79e20be4bc5b 90 return true;
MasashiNomura 23:79e20be4bc5b 91 }
MasashiNomura 23:79e20be4bc5b 92 mask = mask << 1;
MasashiNomura 23:79e20be4bc5b 93 }
MasashiNomura 23:79e20be4bc5b 94 return false;
MasashiNomura 23:79e20be4bc5b 95 }
MasashiNomura 36:2cc739c7e4cb 96 bool HbUserOpe::ChkCtrlSwBoth(SW_TYPE styp1,SW_TYPE styp2)
MasashiNomura 36:2cc739c7e4cb 97 {
MasashiNomura 36:2cc739c7e4cb 98 bool sw1,sw2;
MasashiNomura 36:2cc739c7e4cb 99 sw1 = sw2 = false;
MasashiNomura 36:2cc739c7e4cb 100 if(styp1 == BRK_L) {sw1 = curOpe.bf.brk_l;}
MasashiNomura 36:2cc739c7e4cb 101 else if(styp1 == BRK_R) {sw1 = curOpe.bf.brk_r;}
MasashiNomura 36:2cc739c7e4cb 102 else if(styp1 == FLT_ON) {sw1 = curOpe.bf.flt_on;}
MasashiNomura 36:2cc739c7e4cb 103 else if(styp1 == FLT_OFF) {sw1 = curOpe.bf.flt_off;}
MasashiNomura 36:2cc739c7e4cb 104 else if(styp1 == F_ENG_UP) {sw1 = curOpe.bf.f_eng_up;}
MasashiNomura 36:2cc739c7e4cb 105 else if(styp1 == F_ENG_DOWN) {sw1 = curOpe.bf.f_eng_down;}
MasashiNomura 36:2cc739c7e4cb 106 else if(styp1 == R_ENG_UP) {sw1 = curOpe.bf.r_eng_up;}
MasashiNomura 36:2cc739c7e4cb 107 else if(styp1 == R_ENG_DOWN) {sw1 = curOpe.bf.r_eng_down;}
MasashiNomura 36:2cc739c7e4cb 108 else if(styp1 == R_1) {sw1 = curOpe.bf.rsv_1;}
MasashiNomura 36:2cc739c7e4cb 109 else if(styp1 == ALL_STOP) {sw1 = curOpe.bf.all_stop;}
MasashiNomura 36:2cc739c7e4cb 110 else {sw1 = false;}
MasashiNomura 36:2cc739c7e4cb 111 if(styp2 == BRK_L) {sw2 = curOpe.bf.brk_l;}
MasashiNomura 36:2cc739c7e4cb 112 else if(styp2 == BRK_R) {sw2 = curOpe.bf.brk_r;}
MasashiNomura 36:2cc739c7e4cb 113 else if(styp2 == FLT_ON) {sw2 = curOpe.bf.flt_on;}
MasashiNomura 36:2cc739c7e4cb 114 else if(styp2 == FLT_OFF) {sw2 = curOpe.bf.flt_off;}
MasashiNomura 36:2cc739c7e4cb 115 else if(styp2 == F_ENG_UP) {sw2 = curOpe.bf.f_eng_up;}
MasashiNomura 36:2cc739c7e4cb 116 else if(styp2 == F_ENG_DOWN) {sw2 = curOpe.bf.f_eng_down;}
MasashiNomura 36:2cc739c7e4cb 117 else if(styp2 == R_ENG_UP) {sw2 = curOpe.bf.r_eng_up;}
MasashiNomura 36:2cc739c7e4cb 118 else if(styp2 == R_ENG_DOWN) {sw2 = curOpe.bf.r_eng_down;}
MasashiNomura 36:2cc739c7e4cb 119 else if(styp2 == R_1) {sw2 = curOpe.bf.rsv_1;}
MasashiNomura 36:2cc739c7e4cb 120 else if(styp2 == ALL_STOP) {sw2 = curOpe.bf.all_stop;}
MasashiNomura 36:2cc739c7e4cb 121 else {sw2 = false;}
MasashiNomura 36:2cc739c7e4cb 122
MasashiNomura 36:2cc739c7e4cb 123 return sw1 && sw2;
MasashiNomura 36:2cc739c7e4cb 124 }
MasashiNomura 36:2cc739c7e4cb 125
MasashiNomura 30:13ada1a24c59 126 bool HbUserOpe::ChkCtrlSwRiseEdge(SW_TYPE styp)
MasashiNomura 26:732bc37fbefd 127 {
MasashiNomura 34:234b87f3e6ce 128 if(styp == BRK_L) {return curOpe.bf.brk_l && !oldOpe.bf.brk_l;}
MasashiNomura 34:234b87f3e6ce 129 else if(styp == BRK_R) {return curOpe.bf.brk_r && !oldOpe.bf.brk_r;}
MasashiNomura 34:234b87f3e6ce 130 else if(styp == FLT_ON) {return curOpe.bf.flt_on && !oldOpe.bf.flt_on;}
MasashiNomura 34:234b87f3e6ce 131 else if(styp == FLT_OFF) {return curOpe.bf.flt_off && !oldOpe.bf.flt_off;}
MasashiNomura 36:2cc739c7e4cb 132 else if(styp == F_ENG_UP) {return curOpe.bf.f_eng_up && !oldOpe.bf.f_eng_up;}
MasashiNomura 36:2cc739c7e4cb 133 else if(styp == F_ENG_DOWN) {return curOpe.bf.f_eng_down && !oldOpe.bf.f_eng_down;}
MasashiNomura 36:2cc739c7e4cb 134 else if(styp == R_ENG_UP) {return curOpe.bf.r_eng_up && !oldOpe.bf.r_eng_up;}
MasashiNomura 36:2cc739c7e4cb 135 else if(styp == R_ENG_DOWN) {return curOpe.bf.r_eng_down && !oldOpe.bf.r_eng_down;}
MasashiNomura 36:2cc739c7e4cb 136 else if(styp == R_1) {return curOpe.bf.rsv_1 && !oldOpe.bf.rsv_1;}
MasashiNomura 34:234b87f3e6ce 137 else if(styp == ALL_STOP) {return curOpe.bf.all_stop && !oldOpe.bf.all_stop;}
MasashiNomura 31:56c554c560c1 138 else{return false;}
MasashiNomura 26:732bc37fbefd 139 }