Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
HbUserOpe.cpp@57:56b7e66a0c3d, 2019-03-07 (annotated)
- Committer:
- MasashiNomura
- Date:
- Thu Mar 07 04:01:10 2019 +0000
- Revision:
- 57:56b7e66a0c3d
- Parent:
- 54:283bb711e0fa
2019/03/07 add attitude controll ON/OFF Switch
Who changed what in which revision?
| User | Revision | Line number | New 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 | 53:b09c062cc31c | 9 | for(int i = 0; i < MAX_SW_TYPE; ++i){ |
| MasashiNomura | 53:b09c062cc31c | 10 | counter[i].w = 0; |
| MasashiNomura | 53:b09c062cc31c | 11 | } |
| MasashiNomura | 22:24c9c2dedca9 | 12 | } |
| MasashiNomura | 22:24c9c2dedca9 | 13 | |
| MasashiNomura | 22:24c9c2dedca9 | 14 | //========================================= |
| MasashiNomura | 22:24c9c2dedca9 | 15 | //デストラクタ |
| MasashiNomura | 22:24c9c2dedca9 | 16 | //========================================= |
| MasashiNomura | 22:24c9c2dedca9 | 17 | HbUserOpe::~HbUserOpe(){ |
| MasashiNomura | 22:24c9c2dedca9 | 18 | } |
| MasashiNomura | 22:24c9c2dedca9 | 19 | |
| MasashiNomura | 22:24c9c2dedca9 | 20 | typUserSw HbUserOpe::GetUserOpe() |
| MasashiNomura | 22:24c9c2dedca9 | 21 | { |
| MasashiNomura | 22:24c9c2dedca9 | 22 | oldOpe = curOpe; |
| MasashiNomura | 22:24c9c2dedca9 | 23 | curOpe.w = fpgaGetUserSw(); |
| MasashiNomura | 42:cc8501b824ba | 24 | if(gf_SwCmd.bf.req){ |
| MasashiNomura | 42:cc8501b824ba | 25 | if(gf_SwCmd.bf.req){ |
| MasashiNomura | 42:cc8501b824ba | 26 | UINT16 mask = 0x1; |
| MasashiNomura | 42:cc8501b824ba | 27 | mask = mask << gf_SwCmd.bf.val; |
| MasashiNomura | 42:cc8501b824ba | 28 | curOpe.w |= mask; |
| MasashiNomura | 42:cc8501b824ba | 29 | gf_SwCmd.bf.req = false; |
| MasashiNomura | 42:cc8501b824ba | 30 | } |
| MasashiNomura | 42:cc8501b824ba | 31 | } |
| MasashiNomura | 41:45c982b1c5b6 | 32 | if(gf_Print.d2.bf.sw){ |
| MasashiNomura | 57:56b7e66a0c3d | 33 | sp.printf("SW : %d%d%d%d%d%d%d%d%d%d ",curOpe.bf.brk_l,curOpe.bf.flt_off,curOpe.bf.r_eng_down,curOpe.bf.r_eng_up,curOpe.bf.ctrl_sw |
| MasashiNomura | 42:cc8501b824ba | 34 | ,curOpe.bf.brk_r,curOpe.bf.flt_on,curOpe.bf.f_eng_down,curOpe.bf.f_eng_up, curOpe.bf.all_stop); |
| MasashiNomura | 42:cc8501b824ba | 35 | //sp.printf("SW : [%04X] ", curOpe.w); |
| MasashiNomura | 41:45c982b1c5b6 | 36 | } |
| MasashiNomura | 22:24c9c2dedca9 | 37 | return curOpe; |
| MasashiNomura | 23:79e20be4bc5b | 38 | } |
| MasashiNomura | 38:24ee50452755 | 39 | float HbUserOpe::GetAinAccelRaw() |
| MasashiNomura | 38:24ee50452755 | 40 | { |
| MasashiNomura | 38:24ee50452755 | 41 | AinAxlVal = AinAxl.read(); |
| MasashiNomura | 38:24ee50452755 | 42 | return AinAxlVal; |
| MasashiNomura | 38:24ee50452755 | 43 | } |
| MasashiNomura | 33:eb260dbfc22a | 44 | INT16 HbUserOpe::GetAinAccel() |
| MasashiNomura | 33:eb260dbfc22a | 45 | { |
| MasashiNomura | 34:234b87f3e6ce | 46 | // max rpm 8500 ユーザー使用分として7000をマックスとする(仮) |
| MasashiNomura | 34:234b87f3e6ce | 47 | // 0 ~ 1.00 -> 0.01 ~ 0.97を使用する(遊び分として) |
| MasashiNomura | 33:eb260dbfc22a | 48 | INT16 ret = 0; |
| MasashiNomura | 34:234b87f3e6ce | 49 | AinAxlVal = AinAxl.read(); |
| MasashiNomura | 34:234b87f3e6ce | 50 | if(MIN_EFF_ANA_VAL > AinAxlVal){ |
| MasashiNomura | 33:eb260dbfc22a | 51 | ret = 0; |
| MasashiNomura | 34:234b87f3e6ce | 52 | } else if(AinAxlVal >= MIN_EFF_ANA_VAL && AinAxlVal <= MAX_EFF_ANA_VAL){ |
| MasashiNomura | 34:234b87f3e6ce | 53 | 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 | 54 | } else if(AinAxlVal > MAX_EFF_ANA_VAL){ |
| MasashiNomura | 34:234b87f3e6ce | 55 | ret = MAX_RPM_USERSET; |
| MasashiNomura | 33:eb260dbfc22a | 56 | }else{ |
| MasashiNomura | 33:eb260dbfc22a | 57 | ret = 0; |
| MasashiNomura | 33:eb260dbfc22a | 58 | } |
| MasashiNomura | 41:45c982b1c5b6 | 59 | if(gf_Print.d2.bf.ain == true){ |
| MasashiNomura | 41:45c982b1c5b6 | 60 | sp.printf("Axl Rpm=%d val=%f ",ret,AinAxlVal); |
| MasashiNomura | 33:eb260dbfc22a | 61 | } |
| MasashiNomura | 33:eb260dbfc22a | 62 | //sp.printf("Axl Rpm=%d val=%f\r\n",ret,anaval); |
| MasashiNomura | 33:eb260dbfc22a | 63 | return ret; |
| MasashiNomura | 33:eb260dbfc22a | 64 | } |
| MasashiNomura | 34:234b87f3e6ce | 65 | |
| MasashiNomura | 38:24ee50452755 | 66 | float HbUserOpe::GetAinThrottleRaw() |
| MasashiNomura | 38:24ee50452755 | 67 | { |
| MasashiNomura | 38:24ee50452755 | 68 | AinTrtlVal = AinAxl.read(); |
| MasashiNomura | 38:24ee50452755 | 69 | return AinTrtlVal; |
| MasashiNomura | 38:24ee50452755 | 70 | } |
| MasashiNomura | 38:24ee50452755 | 71 | |
| MasashiNomura | 36:2cc739c7e4cb | 72 | INT16 HbUserOpe::GetAinThrottle() |
| MasashiNomura | 36:2cc739c7e4cb | 73 | { |
| MasashiNomura | 36:2cc739c7e4cb | 74 | INT16 ret = 0; |
| MasashiNomura | 38:24ee50452755 | 75 | AinTrtlVal = AinAxl.read(); |
| MasashiNomura | 38:24ee50452755 | 76 | //AinTrtlVal = AinThrottle.read(); |
| MasashiNomura | 38:24ee50452755 | 77 | ret = (INT16)(MAX_VAL_12BIT * AinTrtlVal); |
| MasashiNomura | 41:45c982b1c5b6 | 78 | if(gf_Print.d2.bf.ain == true){ |
| MasashiNomura | 41:45c982b1c5b6 | 79 | sp.printf("Trottle Val=%d analog val=%f ",ret,AinTrtlVal); |
| MasashiNomura | 36:2cc739c7e4cb | 80 | } |
| MasashiNomura | 36:2cc739c7e4cb | 81 | return ret; |
| MasashiNomura | 36:2cc739c7e4cb | 82 | } |
| MasashiNomura | 36:2cc739c7e4cb | 83 | |
| MasashiNomura | 23:79e20be4bc5b | 84 | bool HbUserOpe::ChkCtrlSW(SW_TYPE styp) |
| MasashiNomura | 23:79e20be4bc5b | 85 | { |
| MasashiNomura | 36:2cc739c7e4cb | 86 | if(styp == BRK_L) {return curOpe.bf.brk_l;} |
| MasashiNomura | 36:2cc739c7e4cb | 87 | else if(styp == BRK_R) {return curOpe.bf.brk_r;} |
| MasashiNomura | 36:2cc739c7e4cb | 88 | else if(styp == FLT_ON) {return curOpe.bf.flt_on;} |
| MasashiNomura | 34:234b87f3e6ce | 89 | else if(styp == FLT_OFF) {return curOpe.bf.flt_off;} |
| MasashiNomura | 36:2cc739c7e4cb | 90 | else if(styp == F_ENG_UP) {return curOpe.bf.f_eng_up;} |
| MasashiNomura | 36:2cc739c7e4cb | 91 | else if(styp == F_ENG_DOWN) {return curOpe.bf.f_eng_down;} |
| MasashiNomura | 36:2cc739c7e4cb | 92 | else if(styp == R_ENG_UP) {return curOpe.bf.r_eng_up;} |
| MasashiNomura | 36:2cc739c7e4cb | 93 | else if(styp == R_ENG_DOWN) {return curOpe.bf.r_eng_down;} |
| MasashiNomura | 57:56b7e66a0c3d | 94 | else if(styp == CTRL_SW) {return curOpe.bf.ctrl_sw;} |
| MasashiNomura | 36:2cc739c7e4cb | 95 | else if(styp == ALL_STOP) {return curOpe.bf.all_stop;} |
| MasashiNomura | 31:56c554c560c1 | 96 | else {return false;} |
| MasashiNomura | 26:732bc37fbefd | 97 | } |
| MasashiNomura | 23:79e20be4bc5b | 98 | bool HbUserOpe::ChkCtrlSwAny() |
| MasashiNomura | 23:79e20be4bc5b | 99 | { |
| MasashiNomura | 23:79e20be4bc5b | 100 | UINT16 mask = 0x1; |
| MasashiNomura | 34:234b87f3e6ce | 101 | for(int i = 0; i < 10; ++i){ |
| MasashiNomura | 23:79e20be4bc5b | 102 | if(curOpe.w & mask){ |
| MasashiNomura | 23:79e20be4bc5b | 103 | return true; |
| MasashiNomura | 23:79e20be4bc5b | 104 | } |
| MasashiNomura | 23:79e20be4bc5b | 105 | mask = mask << 1; |
| MasashiNomura | 23:79e20be4bc5b | 106 | } |
| MasashiNomura | 23:79e20be4bc5b | 107 | return false; |
| MasashiNomura | 23:79e20be4bc5b | 108 | } |
| MasashiNomura | 36:2cc739c7e4cb | 109 | bool HbUserOpe::ChkCtrlSwBoth(SW_TYPE styp1,SW_TYPE styp2) |
| MasashiNomura | 36:2cc739c7e4cb | 110 | { |
| MasashiNomura | 36:2cc739c7e4cb | 111 | bool sw1,sw2; |
| MasashiNomura | 36:2cc739c7e4cb | 112 | sw1 = sw2 = false; |
| MasashiNomura | 36:2cc739c7e4cb | 113 | if(styp1 == BRK_L) {sw1 = curOpe.bf.brk_l;} |
| MasashiNomura | 36:2cc739c7e4cb | 114 | else if(styp1 == BRK_R) {sw1 = curOpe.bf.brk_r;} |
| MasashiNomura | 36:2cc739c7e4cb | 115 | else if(styp1 == FLT_ON) {sw1 = curOpe.bf.flt_on;} |
| MasashiNomura | 36:2cc739c7e4cb | 116 | else if(styp1 == FLT_OFF) {sw1 = curOpe.bf.flt_off;} |
| MasashiNomura | 36:2cc739c7e4cb | 117 | else if(styp1 == F_ENG_UP) {sw1 = curOpe.bf.f_eng_up;} |
| MasashiNomura | 36:2cc739c7e4cb | 118 | else if(styp1 == F_ENG_DOWN) {sw1 = curOpe.bf.f_eng_down;} |
| MasashiNomura | 36:2cc739c7e4cb | 119 | else if(styp1 == R_ENG_UP) {sw1 = curOpe.bf.r_eng_up;} |
| MasashiNomura | 36:2cc739c7e4cb | 120 | else if(styp1 == R_ENG_DOWN) {sw1 = curOpe.bf.r_eng_down;} |
| MasashiNomura | 57:56b7e66a0c3d | 121 | else if(styp1 == CTRL_SW) {sw1 = curOpe.bf.ctrl_sw;} |
| MasashiNomura | 36:2cc739c7e4cb | 122 | else if(styp1 == ALL_STOP) {sw1 = curOpe.bf.all_stop;} |
| MasashiNomura | 36:2cc739c7e4cb | 123 | else {sw1 = false;} |
| MasashiNomura | 36:2cc739c7e4cb | 124 | if(styp2 == BRK_L) {sw2 = curOpe.bf.brk_l;} |
| MasashiNomura | 36:2cc739c7e4cb | 125 | else if(styp2 == BRK_R) {sw2 = curOpe.bf.brk_r;} |
| MasashiNomura | 36:2cc739c7e4cb | 126 | else if(styp2 == FLT_ON) {sw2 = curOpe.bf.flt_on;} |
| MasashiNomura | 36:2cc739c7e4cb | 127 | else if(styp2 == FLT_OFF) {sw2 = curOpe.bf.flt_off;} |
| MasashiNomura | 36:2cc739c7e4cb | 128 | else if(styp2 == F_ENG_UP) {sw2 = curOpe.bf.f_eng_up;} |
| MasashiNomura | 36:2cc739c7e4cb | 129 | else if(styp2 == F_ENG_DOWN) {sw2 = curOpe.bf.f_eng_down;} |
| MasashiNomura | 36:2cc739c7e4cb | 130 | else if(styp2 == R_ENG_UP) {sw2 = curOpe.bf.r_eng_up;} |
| MasashiNomura | 36:2cc739c7e4cb | 131 | else if(styp2 == R_ENG_DOWN) {sw2 = curOpe.bf.r_eng_down;} |
| MasashiNomura | 57:56b7e66a0c3d | 132 | else if(styp2 == CTRL_SW) {sw2 = curOpe.bf.ctrl_sw;} |
| MasashiNomura | 36:2cc739c7e4cb | 133 | else if(styp2 == ALL_STOP) {sw2 = curOpe.bf.all_stop;} |
| MasashiNomura | 36:2cc739c7e4cb | 134 | else {sw2 = false;} |
| MasashiNomura | 36:2cc739c7e4cb | 135 | |
| MasashiNomura | 36:2cc739c7e4cb | 136 | return sw1 && sw2; |
| MasashiNomura | 36:2cc739c7e4cb | 137 | } |
| MasashiNomura | 36:2cc739c7e4cb | 138 | |
| MasashiNomura | 30:13ada1a24c59 | 139 | bool HbUserOpe::ChkCtrlSwRiseEdge(SW_TYPE styp) |
| MasashiNomura | 26:732bc37fbefd | 140 | { |
| MasashiNomura | 54:283bb711e0fa | 141 | // if(counter[styp].bf.flg){ |
| MasashiNomura | 54:283bb711e0fa | 142 | // ++counter[styp].bf.cnt; |
| MasashiNomura | 54:283bb711e0fa | 143 | // if(styp == BRK_L){ if(!curOpe.bf.brk_l && oldOpe.bf.brk_l){ counter[styp].bf.cnt = 0; } } |
| MasashiNomura | 54:283bb711e0fa | 144 | // if(styp == BRK_R){ if(!curOpe.bf.brk_r && oldOpe.bf.brk_r){ counter[styp].bf.cnt = 0; } } |
| MasashiNomura | 54:283bb711e0fa | 145 | // if(styp == FLT_ON){ if(!curOpe.bf.flt_on && oldOpe.bf.flt_on){ counter[styp].bf.cnt = 0; } } |
| MasashiNomura | 54:283bb711e0fa | 146 | // if(styp == FLT_OFF){ if(!curOpe.bf.flt_off && oldOpe.bf.flt_off){ counter[styp].bf.cnt = 0; } } |
| MasashiNomura | 54:283bb711e0fa | 147 | // if(styp == F_ENG_UP){ if(!curOpe.bf.f_eng_up && oldOpe.bf.f_eng_up){ counter[styp].bf.cnt = 0; } } |
| MasashiNomura | 54:283bb711e0fa | 148 | // if(styp == F_ENG_DOWN){ if(!curOpe.bf.f_eng_down && oldOpe.bf.f_eng_down){ counter[styp].bf.cnt = 0; } } |
| MasashiNomura | 54:283bb711e0fa | 149 | // if(styp == R_ENG_UP){ if(!curOpe.bf.r_eng_up && oldOpe.bf.r_eng_up){ counter[styp].bf.cnt = 0; } } |
| MasashiNomura | 54:283bb711e0fa | 150 | // if(styp == R_ENG_DOWN){ if(!curOpe.bf.r_eng_down && oldOpe.bf.r_eng_down){ counter[styp].bf.cnt = 0; } } |
| MasashiNomura | 57:56b7e66a0c3d | 151 | // if(styp == CTRL_SW){ if(!curOpe.bf.ctrl_sw && oldOpe.bf.ctrl_sw){ counter[styp].bf.cnt = 0; } } |
| MasashiNomura | 54:283bb711e0fa | 152 | // if(styp == ALL_STOP){ if(!curOpe.bf.all_stop && oldOpe.bf.all_stop){ counter[styp].bf.cnt = 0; } } |
| MasashiNomura | 54:283bb711e0fa | 153 | // if(counter[styp].bf.cnt > CNT_NUM_RE){ |
| MasashiNomura | 54:283bb711e0fa | 154 | // counter[styp].bf.cnt = 0; |
| MasashiNomura | 54:283bb711e0fa | 155 | // counter[styp].bf.flg = false; |
| MasashiNomura | 54:283bb711e0fa | 156 | // } |
| MasashiNomura | 54:283bb711e0fa | 157 | // return false; |
| MasashiNomura | 54:283bb711e0fa | 158 | // } else{ |
| MasashiNomura | 54:283bb711e0fa | 159 | // if(styp == BRK_L) return counter[BRK_L].bf.flg = curOpe.bf.brk_l && !oldOpe.bf.brk_l; |
| MasashiNomura | 54:283bb711e0fa | 160 | // if(styp == BRK_R) return counter[BRK_R].bf.flg = curOpe.bf.brk_r && !oldOpe.bf.brk_r; |
| MasashiNomura | 54:283bb711e0fa | 161 | // if(styp == FLT_ON) return counter[FLT_ON].bf.flg = curOpe.bf.flt_on && !oldOpe.bf.flt_on; |
| MasashiNomura | 54:283bb711e0fa | 162 | // if(styp == FLT_OFF) return counter[FLT_OFF].bf.flg = curOpe.bf.flt_off && !oldOpe.bf.flt_off; |
| MasashiNomura | 54:283bb711e0fa | 163 | // if(styp == F_ENG_UP) return counter[F_ENG_UP].bf.flg = curOpe.bf.f_eng_up && !oldOpe.bf.f_eng_up; |
| MasashiNomura | 54:283bb711e0fa | 164 | // if(styp == F_ENG_DOWN) return counter[F_ENG_DOWN].bf.flg = curOpe.bf.f_eng_down && !oldOpe.bf.f_eng_down; |
| MasashiNomura | 54:283bb711e0fa | 165 | // if(styp == R_ENG_UP) return counter[R_ENG_UP].bf.flg = curOpe.bf.r_eng_up && !oldOpe.bf.r_eng_up; |
| MasashiNomura | 54:283bb711e0fa | 166 | // if(styp == R_ENG_DOWN) return counter[R_ENG_DOWN].bf.flg = curOpe.bf.r_eng_down && !oldOpe.bf.r_eng_down; |
| MasashiNomura | 57:56b7e66a0c3d | 167 | // if(styp == CTRL_SW) return counter[CTRL_SW].bf.flg = curOpe.bf.ctrl_sw && !oldOpe.bf.ctrl_sw; |
| MasashiNomura | 54:283bb711e0fa | 168 | // if(styp == ALL_STOP) return counter[ALL_STOP].bf.flg = curOpe.bf.all_stop && !oldOpe.bf.all_stop; |
| MasashiNomura | 53:b09c062cc31c | 169 | // return false; |
| MasashiNomura | 53:b09c062cc31c | 170 | // } |
| MasashiNomura | 54:283bb711e0fa | 171 | |
| MasashiNomura | 54:283bb711e0fa | 172 | if (styp == BRK_L) { return curOpe.bf.brk_l && !oldOpe.bf.brk_l; } |
| MasashiNomura | 54:283bb711e0fa | 173 | else if(styp == BRK_R) { return curOpe.bf.brk_r && !oldOpe.bf.brk_r; } |
| MasashiNomura | 54:283bb711e0fa | 174 | else if(styp == FLT_ON) { return curOpe.bf.flt_on && !oldOpe.bf.flt_on; } |
| MasashiNomura | 54:283bb711e0fa | 175 | else if(styp == FLT_OFF) { return curOpe.bf.flt_off && !oldOpe.bf.flt_off; } |
| MasashiNomura | 54:283bb711e0fa | 176 | else if(styp == F_ENG_UP) { return curOpe.bf.f_eng_up && !oldOpe.bf.f_eng_up; } |
| MasashiNomura | 54:283bb711e0fa | 177 | else if(styp == F_ENG_DOWN) { return curOpe.bf.f_eng_down && !oldOpe.bf.f_eng_down; } |
| MasashiNomura | 54:283bb711e0fa | 178 | else if(styp == R_ENG_UP) { return curOpe.bf.r_eng_up && !oldOpe.bf.r_eng_up; } |
| MasashiNomura | 54:283bb711e0fa | 179 | else if(styp == R_ENG_DOWN) { return curOpe.bf.r_eng_down && !oldOpe.bf.r_eng_down; } |
| MasashiNomura | 57:56b7e66a0c3d | 180 | else if(styp == CTRL_SW) { return curOpe.bf.ctrl_sw && !oldOpe.bf.ctrl_sw; } |
| MasashiNomura | 54:283bb711e0fa | 181 | else if(styp == ALL_STOP) { return curOpe.bf.all_stop && !oldOpe.bf.all_stop; } |
| MasashiNomura | 54:283bb711e0fa | 182 | else { return false; } |
| MasashiNomura | 26:732bc37fbefd | 183 | } |