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@33:eb260dbfc22a, 2018-12-21 (annotated)
- Committer:
- MasashiNomura
- Date:
- Fri Dec 21 12:31:17 2018 +0000
- Revision:
- 33:eb260dbfc22a
- Parent:
- 31:56c554c560c1
- Child:
- 34:234b87f3e6ce
12/21 Add analog read for accel Motor
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 | 22:24c9c2dedca9 | 8 | } |
| MasashiNomura | 22:24c9c2dedca9 | 9 | |
| MasashiNomura | 22:24c9c2dedca9 | 10 | //========================================= |
| MasashiNomura | 22:24c9c2dedca9 | 11 | //デストラクタ |
| MasashiNomura | 22:24c9c2dedca9 | 12 | //========================================= |
| MasashiNomura | 22:24c9c2dedca9 | 13 | HbUserOpe::~HbUserOpe(){ |
| MasashiNomura | 22:24c9c2dedca9 | 14 | } |
| MasashiNomura | 22:24c9c2dedca9 | 15 | |
| MasashiNomura | 22:24c9c2dedca9 | 16 | typUserSw HbUserOpe::GetUserOpe() |
| MasashiNomura | 22:24c9c2dedca9 | 17 | { |
| MasashiNomura | 22:24c9c2dedca9 | 18 | oldOpe = curOpe; |
| MasashiNomura | 22:24c9c2dedca9 | 19 | curOpe.w = fpgaGetUserSw(); |
| MasashiNomura | 22:24c9c2dedca9 | 20 | return curOpe; |
| MasashiNomura | 23:79e20be4bc5b | 21 | } |
| MasashiNomura | 33:eb260dbfc22a | 22 | INT16 HbUserOpe::GetAinAccel() |
| MasashiNomura | 33:eb260dbfc22a | 23 | { |
| MasashiNomura | 33:eb260dbfc22a | 24 | // max rpm 8500 ユーザー使用分として7000をマックスとする |
| MasashiNomura | 33:eb260dbfc22a | 25 | // 0 ~ 1.00 -> 0.05 ~ 0.95を使用する(遊び分として) |
| MasashiNomura | 33:eb260dbfc22a | 26 | INT16 ret = 0; |
| MasashiNomura | 33:eb260dbfc22a | 27 | float anaval = AinAxl.read(); |
| MasashiNomura | 33:eb260dbfc22a | 28 | if(0.01 > anaval){ |
| MasashiNomura | 33:eb260dbfc22a | 29 | ret = 0; |
| MasashiNomura | 33:eb260dbfc22a | 30 | } else if(anaval >= 0.01 && anaval <= 0.97){ |
| MasashiNomura | 33:eb260dbfc22a | 31 | ret = 5500 * (anaval - 0.01) / 0.96 + 1500; |
| MasashiNomura | 33:eb260dbfc22a | 32 | } else if(anaval > 0.97){ |
| MasashiNomura | 33:eb260dbfc22a | 33 | ret = 7000; |
| MasashiNomura | 33:eb260dbfc22a | 34 | }else{ |
| MasashiNomura | 33:eb260dbfc22a | 35 | ret = 0; |
| MasashiNomura | 33:eb260dbfc22a | 36 | } |
| MasashiNomura | 33:eb260dbfc22a | 37 | if(gf_DbgPrint.bf.ana1 == true){ |
| MasashiNomura | 33:eb260dbfc22a | 38 | sp.printf("Axl Rpm=%d val=%f\r\n",ret,anaval); |
| MasashiNomura | 33:eb260dbfc22a | 39 | gf_DbgPrint.bf.ana1 = false; |
| MasashiNomura | 33:eb260dbfc22a | 40 | } |
| MasashiNomura | 33:eb260dbfc22a | 41 | //sp.printf("Axl Rpm=%d val=%f\r\n",ret,anaval); |
| MasashiNomura | 33:eb260dbfc22a | 42 | return ret; |
| MasashiNomura | 33:eb260dbfc22a | 43 | } |
| MasashiNomura | 30:13ada1a24c59 | 44 | // bool HbUserOpe::ChkCtrlSW(SW_TYPE styp) |
| MasashiNomura | 30:13ada1a24c59 | 45 | // { |
| MasashiNomura | 30:13ada1a24c59 | 46 | // if(styp == ACCEL_R){return curOpe.bf.brk_l;} |
| MasashiNomura | 30:13ada1a24c59 | 47 | // else if(styp == ACCEL_L){return curOpe.bf.axl_l;} |
| MasashiNomura | 30:13ada1a24c59 | 48 | // else if(styp == STOP){return curOpe.bf.stop;} |
| MasashiNomura | 30:13ada1a24c59 | 49 | // else if(styp == YAW_CTRL){return curOpe.bf.y_ctrl;} |
| MasashiNomura | 30:13ada1a24c59 | 50 | // else/*if(styp == ENG_STOP)*/{return curOpe.bf.eng_stop;} |
| MasashiNomura | 30:13ada1a24c59 | 51 | // // UINT16 mask = 0x1 << styp; |
| MasashiNomura | 30:13ada1a24c59 | 52 | // // return curOpe.w & mask; |
| MasashiNomura | 30:13ada1a24c59 | 53 | // } |
| MasashiNomura | 23:79e20be4bc5b | 54 | bool HbUserOpe::ChkCtrlSW(SW_TYPE styp) |
| MasashiNomura | 23:79e20be4bc5b | 55 | { |
| MasashiNomura | 30:13ada1a24c59 | 56 | if(styp == BRK_L) {return curOpe.bf.brk_l;} |
| MasashiNomura | 30:13ada1a24c59 | 57 | else if(styp == BRK_R) {return curOpe.bf.brk_r;} |
| MasashiNomura | 30:13ada1a24c59 | 58 | else if(styp == R_1) {return curOpe.bf.resv_1;} |
| MasashiNomura | 30:13ada1a24c59 | 59 | else if(styp == R_2) {return curOpe.bf.resv_2;} |
| MasashiNomura | 30:13ada1a24c59 | 60 | else if(styp == MOT_STOP){return curOpe.bf.mot_stop;} |
| MasashiNomura | 30:13ada1a24c59 | 61 | else if(styp == R_3) {return curOpe.bf.resv_3;} |
| MasashiNomura | 30:13ada1a24c59 | 62 | else if(styp == R_4) {return curOpe.bf.resv_4;} |
| MasashiNomura | 30:13ada1a24c59 | 63 | else if(styp == R_5) {return curOpe.bf.resv_5;} |
| MasashiNomura | 30:13ada1a24c59 | 64 | else if(styp == R_6) {return curOpe.bf.resv_6;} |
| MasashiNomura | 30:13ada1a24c59 | 65 | else if(styp == ALL_STOP){return curOpe.bf.all_stop;} |
| MasashiNomura | 31:56c554c560c1 | 66 | else {return false;} |
| MasashiNomura | 26:732bc37fbefd | 67 | } |
| MasashiNomura | 23:79e20be4bc5b | 68 | bool HbUserOpe::ChkCtrlSwAny() |
| MasashiNomura | 23:79e20be4bc5b | 69 | { |
| MasashiNomura | 23:79e20be4bc5b | 70 | UINT16 mask = 0x1; |
| MasashiNomura | 23:79e20be4bc5b | 71 | for(int i = 0; i < 5; ++i){ |
| MasashiNomura | 23:79e20be4bc5b | 72 | if(curOpe.w & mask){ |
| MasashiNomura | 23:79e20be4bc5b | 73 | return true; |
| MasashiNomura | 23:79e20be4bc5b | 74 | } |
| MasashiNomura | 23:79e20be4bc5b | 75 | mask = mask << 1; |
| MasashiNomura | 23:79e20be4bc5b | 76 | } |
| MasashiNomura | 23:79e20be4bc5b | 77 | return false; |
| MasashiNomura | 23:79e20be4bc5b | 78 | } |
| MasashiNomura | 30:13ada1a24c59 | 79 | bool HbUserOpe::ChkCtrlSwRiseEdge(SW_TYPE styp) |
| MasashiNomura | 26:732bc37fbefd | 80 | { |
| MasashiNomura | 30:13ada1a24c59 | 81 | if(styp == BRK_L) {return curOpe.bf.brk_l && !oldOpe.bf.brk_l;} |
| MasashiNomura | 30:13ada1a24c59 | 82 | else if(styp == BRK_R) {return curOpe.bf.brk_r && !oldOpe.bf.brk_r;} |
| MasashiNomura | 30:13ada1a24c59 | 83 | else if(styp == R_1) {return curOpe.bf.resv_1 && !oldOpe.bf.resv_1;} |
| MasashiNomura | 30:13ada1a24c59 | 84 | else if(styp == R_2) {return curOpe.bf.resv_2 && !oldOpe.bf.resv_2;} |
| MasashiNomura | 30:13ada1a24c59 | 85 | else if(styp == MOT_STOP){return curOpe.bf.mot_stop && !oldOpe.bf.mot_stop;} |
| MasashiNomura | 30:13ada1a24c59 | 86 | else if(styp == R_3) {return curOpe.bf.resv_3 && !oldOpe.bf.resv_3;} |
| MasashiNomura | 30:13ada1a24c59 | 87 | else if(styp == R_4) {return curOpe.bf.resv_4 && !oldOpe.bf.resv_4;} |
| MasashiNomura | 30:13ada1a24c59 | 88 | else if(styp == R_5) {return curOpe.bf.resv_5 && !oldOpe.bf.resv_5;} |
| MasashiNomura | 30:13ada1a24c59 | 89 | else if(styp == R_6) {return curOpe.bf.resv_6 && !oldOpe.bf.resv_6;} |
| MasashiNomura | 30:13ada1a24c59 | 90 | else if(styp == ALL_STOP){return curOpe.bf.all_stop && !oldOpe.bf.all_stop;} |
| MasashiNomura | 31:56c554c560c1 | 91 | else{return false;} |
| MasashiNomura | 26:732bc37fbefd | 92 | } |