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.
globalFlags.cpp@35:3779201b4c73, 2018-12-25 (annotated)
- Committer:
- MasashiNomura
- Date:
- Tue Dec 25 08:20:17 2018 +0000
- Revision:
- 35:3779201b4c73
- Parent:
- 33:eb260dbfc22a
- Child:
- 36:2cc739c7e4cb
12/25 Remove no use commentout, add cchecking motAxl etc
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
takeru0x1103 | 19:4b0fe9a5ec38 | 1 | |
takeru0x1103 | 16:05b9e44889f1 | 2 | #include "globalFlags.h" |
takeru0x1103 | 16:05b9e44889f1 | 3 | |
MasashiNomura | 22:24c9c2dedca9 | 4 | //モニタ用LED |
takeru0x1103 | 16:05b9e44889f1 | 5 | DigitalOut led1(LED1); |
takeru0x1103 | 16:05b9e44889f1 | 6 | DigitalOut led2(LED2); |
takeru0x1103 | 16:05b9e44889f1 | 7 | DigitalOut led3(LED3); |
takeru0x1103 | 16:05b9e44889f1 | 8 | DigitalOut led4(LED4); |
takeru0x1103 | 8:1ca49cb18290 | 9 | |
MasashiNomura | 33:eb260dbfc22a | 10 | //モーターアクセル用アナログ入力 |
MasashiNomura | 33:eb260dbfc22a | 11 | AnalogIn AinAxl(p20); |
takeru0x1103 | 21:78302ecdb661 | 12 | |
takeru0x1103 | 19:4b0fe9a5ec38 | 13 | char g_CmdBuf[G_CMD_BUF_SIZ] ;// コマンド受け渡しバッファ |
MasashiNomura | 22:24c9c2dedca9 | 14 | bool gf_CmdPrs; |
takeru0x1103 | 19:4b0fe9a5ec38 | 15 | |
MasashiNomura | 22:24c9c2dedca9 | 16 | bool gf_Armed ;//アーミングフラグ |
MasashiNomura | 23:79e20be4bc5b | 17 | bool gf_Dbg ;//デバッグタスク起動フラグ |
MasashiNomura | 33:eb260dbfc22a | 18 | bool gf_fs_stat ;//強制遷移フラグ |
MasashiNomura | 25:f3a6e7eec9c3 | 19 | bool gf_StopMot ;//モーターの強制停止 |
MasashiNomura | 25:f3a6e7eec9c3 | 20 | |
takeru0x1103 | 19:4b0fe9a5ec38 | 21 | typPrintFlag gf_Print ;// |
takeru0x1103 | 19:4b0fe9a5ec38 | 22 | typPrintFlag gf_Mon ;// |
takeru0x1103 | 19:4b0fe9a5ec38 | 23 | typCalFlag gf_Cal ;// |
MasashiNomura | 26:732bc37fbefd | 24 | typDbgPrintFlg gf_DbgPrint ;//デバッグ用 |
MasashiNomura | 22:24c9c2dedca9 | 25 | typAccel gf_AxReq[2] ;//アクセル更新フラグ |
MasashiNomura | 32:7f4145cc3551 | 26 | typAxlRpm gf_MtReq[4] ;//モーター姿勢制御更新フラグ |
MasashiNomura | 29:eb3d72dd94aa | 27 | typAxlRpm gf_MtReqOfs[4] ;//モーターオフセット更新フラグ |
MasashiNomura | 29:eb3d72dd94aa | 28 | typAxlRpm gf_MtReqDct[8] ;//ダイレクト(FPGA関数直接呼び出し)モーター更新フラグ |
MasashiNomura | 32:7f4145cc3551 | 29 | typAxlRpm gf_MtReqU[4] ;//モーターユーザー更新フラグ |
MasashiNomura | 32:7f4145cc3551 | 30 | |
MasashiNomura | 22:24c9c2dedca9 | 31 | enmHbState gf_State = SLEEP; |
takeru0x1103 | 19:4b0fe9a5ec38 | 32 | |
MasashiNomura | 24:c5945aaae777 | 33 | bool gf_PidParaUpdate ;//PID Pp,P,I,Dの係数アップデートフラグ |
MasashiNomura | 24:c5945aaae777 | 34 | typPidPara g_PidPara ;//PID Pp,P,I,Dの係数の外部設定用 |
takeru0x1103 | 20:0394e15412c3 | 35 | |
MasashiNomura | 25:f3a6e7eec9c3 | 36 | bool gf_MotParaUpdate[4] ;//モーターのパラメータ値更新フラグ |
MasashiNomura | 25:f3a6e7eec9c3 | 37 | typMotPara g_MotPara[4]; |
MasashiNomura | 25:f3a6e7eec9c3 | 38 | |
MasashiNomura | 22:24c9c2dedca9 | 39 | void initFlags(){ |
MasashiNomura | 22:24c9c2dedca9 | 40 | memset(g_CmdBuf,0x0,sizeof(g_CmdBuf)); |
MasashiNomura | 22:24c9c2dedca9 | 41 | gf_CmdPrs = false; |
MasashiNomura | 22:24c9c2dedca9 | 42 | gf_Armed = false; |
MasashiNomura | 22:24c9c2dedca9 | 43 | gf_Dbg = false; |
MasashiNomura | 25:f3a6e7eec9c3 | 44 | gf_StopMot = false; |
MasashiNomura | 25:f3a6e7eec9c3 | 45 | |
MasashiNomura | 22:24c9c2dedca9 | 46 | gf_Print.flg = 0; |
MasashiNomura | 22:24c9c2dedca9 | 47 | gf_Mon.flg = 0; |
MasashiNomura | 22:24c9c2dedca9 | 48 | gf_Cal.flg = 0; |
MasashiNomura | 26:732bc37fbefd | 49 | |
MasashiNomura | 26:732bc37fbefd | 50 | gf_DbgPrint.flg = 0; |
MasashiNomura | 26:732bc37fbefd | 51 | |
MasashiNomura | 22:24c9c2dedca9 | 52 | gf_AxReq[0].dt = 0; |
MasashiNomura | 22:24c9c2dedca9 | 53 | gf_AxReq[1].dt = 0; |
MasashiNomura | 27:ff63c23bc689 | 54 | for(int i=0; i<4;++i){ |
MasashiNomura | 32:7f4145cc3551 | 55 | gf_MtReq[i].req = false; |
MasashiNomura | 32:7f4145cc3551 | 56 | gf_MtReq[i].val = 0; |
MasashiNomura | 32:7f4145cc3551 | 57 | gf_MtReqOfs[i].req = false; |
MasashiNomura | 32:7f4145cc3551 | 58 | gf_MtReqOfs[i].val = 0; |
MasashiNomura | 32:7f4145cc3551 | 59 | gf_MtReqU[i].req = false; |
MasashiNomura | 32:7f4145cc3551 | 60 | gf_MtReqU[i].val = 0; |
MasashiNomura | 27:ff63c23bc689 | 61 | } |
MasashiNomura | 27:ff63c23bc689 | 62 | for(int i = 0; i < 8; ++i){ |
MasashiNomura | 32:7f4145cc3551 | 63 | gf_MtReqDct[i].req = false; |
MasashiNomura | 32:7f4145cc3551 | 64 | gf_MtReqDct[i].val = 0; |
MasashiNomura | 27:ff63c23bc689 | 65 | } |
MasashiNomura | 22:24c9c2dedca9 | 66 | gf_State = SLEEP; |
MasashiNomura | 27:ff63c23bc689 | 67 | g_PidPara.PP = 2; |
MasashiNomura | 32:7f4145cc3551 | 68 | g_PidPara.P = 0; |
MasashiNomura | 25:f3a6e7eec9c3 | 69 | g_PidPara.I = 0; |
MasashiNomura | 24:c5945aaae777 | 70 | g_PidPara.D = 0; |
MasashiNomura | 24:c5945aaae777 | 71 | g_PidPara.IMax = 2000; |
MasashiNomura | 24:c5945aaae777 | 72 | g_PidPara.IMin = -2000; |
MasashiNomura | 25:f3a6e7eec9c3 | 73 | for(int i = 0; i < 4; ++i){ |
MasashiNomura | 25:f3a6e7eec9c3 | 74 | gf_MotParaUpdate[i] = false; |
MasashiNomura | 25:f3a6e7eec9c3 | 75 | g_MotPara[i].limit_hi = LIM_MOT_INP_MAX; |
MasashiNomura | 25:f3a6e7eec9c3 | 76 | g_MotPara[i].limit_low = LIM_MOT_INP_MIN; |
MasashiNomura | 25:f3a6e7eec9c3 | 77 | } |
MasashiNomura | 22:24c9c2dedca9 | 78 | } |
MasashiNomura | 35:3779201b4c73 | 79 | |
MasashiNomura | 22:24c9c2dedca9 | 80 | void setState(enmHbState stat){ |
MasashiNomura | 22:24c9c2dedca9 | 81 | // ありえない遷移を排除 |
MasashiNomura | 22:24c9c2dedca9 | 82 | if(gf_State == SLEEP){if(stat != WAKEUP) return;} |
MasashiNomura | 22:24c9c2dedca9 | 83 | if(gf_State == WAKEUP){if(stat != STANDBY) return;} |
MasashiNomura | 22:24c9c2dedca9 | 84 | if(gf_State == STANDBY){if(stat !=IDLE) return;} |
MasashiNomura | 23:79e20be4bc5b | 85 | if(gf_State == IDLE){if(stat != TAKE_OFF && stat != SLEEP) return;} |
MasashiNomura | 23:79e20be4bc5b | 86 | if(gf_State == TAKE_OFF){if(stat != HOVER && stat != GROUND) return;} |
MasashiNomura | 22:24c9c2dedca9 | 87 | if(gf_State == GROUND){if(stat != IDLE) return;} |
MasashiNomura | 22:24c9c2dedca9 | 88 | if(gf_State == HOVER){if(stat != DRIVE && stat != GROUND) return;} |
MasashiNomura | 22:24c9c2dedca9 | 89 | if(gf_State == DRIVE){if(stat != HOVER && stat != EMGGND) return;} |
MasashiNomura | 22:24c9c2dedca9 | 90 | if(gf_State == EMGGND){if(stat != IDLE) return;} |
MasashiNomura | 22:24c9c2dedca9 | 91 | |
MasashiNomura | 23:79e20be4bc5b | 92 | sp.printf("state: %d\r\n",stat); |
MasashiNomura | 22:24c9c2dedca9 | 93 | gf_State = stat; |
MasashiNomura | 22:24c9c2dedca9 | 94 | } |
MasashiNomura | 23:79e20be4bc5b | 95 | void setStateF(enmHbState stat){ |
MasashiNomura | 23:79e20be4bc5b | 96 | sp.printf("state: %d\r\n",stat); |
MasashiNomura | 23:79e20be4bc5b | 97 | enmHbState tmp; |
MasashiNomura | 25:f3a6e7eec9c3 | 98 | if((UINT16)stat > MOT_STOP){ |
MasashiNomura | 23:79e20be4bc5b | 99 | tmp = SLEEP; |
MasashiNomura | 23:79e20be4bc5b | 100 | } |
MasashiNomura | 23:79e20be4bc5b | 101 | else |
MasashiNomura | 23:79e20be4bc5b | 102 | { |
MasashiNomura | 23:79e20be4bc5b | 103 | tmp = stat; |
MasashiNomura | 23:79e20be4bc5b | 104 | } |
MasashiNomura | 23:79e20be4bc5b | 105 | gf_State = tmp; |
MasashiNomura | 23:79e20be4bc5b | 106 | } |
takeru0x1103 | 21:78302ecdb661 | 107 | /* |
takeru0x1103 | 19:4b0fe9a5ec38 | 108 | //=========================================== |
takeru0x1103 | 19:4b0fe9a5ec38 | 109 | //コンストラクタ |
takeru0x1103 | 19:4b0fe9a5ec38 | 110 | //=========================================== |
takeru0x1103 | 19:4b0fe9a5ec38 | 111 | GlobalFlags::GlobalFlags(){ |
takeru0x1103 | 19:4b0fe9a5ec38 | 112 | //初期ステート |
takeru0x1103 | 21:78302ecdb661 | 113 | state = SLEEP; |
takeru0x1103 | 19:4b0fe9a5ec38 | 114 | //ステートキュー初期化 |
takeru0x1103 | 19:4b0fe9a5ec38 | 115 | for(int i=0; i<STATE_QUE_SIZ; i++){ |
takeru0x1103 | 19:4b0fe9a5ec38 | 116 | stateQueue[i] = NONE; |
MasashiNomura | 33:eb260dbfc22a | 117 | } |
takeru0x1103 | 19:4b0fe9a5ec38 | 118 | rp = wp = 0;//先頭を指す |
takeru0x1103 | 19:4b0fe9a5ec38 | 119 | full = false;//最初はエンプティ |
takeru0x1103 | 19:4b0fe9a5ec38 | 120 | empty = true; |
takeru0x1103 | 19:4b0fe9a5ec38 | 121 | } |
takeru0x1103 | 19:4b0fe9a5ec38 | 122 | |
takeru0x1103 | 21:78302ecdb661 | 123 | |
takeru0x1103 | 19:4b0fe9a5ec38 | 124 | //----------------------------------- |
takeru0x1103 | 19:4b0fe9a5ec38 | 125 | //ステートのFIFOにプッシュする |
takeru0x1103 | 19:4b0fe9a5ec38 | 126 | //----------------------------------- |
takeru0x1103 | 19:4b0fe9a5ec38 | 127 | bool GlobalFlags::push(enmHbState iState){ |
takeru0x1103 | 19:4b0fe9a5ec38 | 128 | if(full){ |
takeru0x1103 | 19:4b0fe9a5ec38 | 129 | return false;//FFULLフラグが立ってら入力を受け付けない |
takeru0x1103 | 19:4b0fe9a5ec38 | 130 | }else{ |
takeru0x1103 | 19:4b0fe9a5ec38 | 131 | stateQueue[wp] = iState;//キューに突っ込んで |
takeru0x1103 | 19:4b0fe9a5ec38 | 132 | wp = (wp==STATE_QUE_SIZ) ? 0 : wp+1;//ライトポインタを進める |
takeru0x1103 | 19:4b0fe9a5ec38 | 133 | full = (wp == rp)? true : false; //次ライト予定の場所がリードポインタに追いついたらFULLを立てる |
takeru0x1103 | 19:4b0fe9a5ec38 | 134 | empty = false; |
takeru0x1103 | 19:4b0fe9a5ec38 | 135 | return true; |
takeru0x1103 | 19:4b0fe9a5ec38 | 136 | } |
takeru0x1103 | 19:4b0fe9a5ec38 | 137 | } |
takeru0x1103 | 19:4b0fe9a5ec38 | 138 | |
takeru0x1103 | 19:4b0fe9a5ec38 | 139 | //----------------------------------- |
takeru0x1103 | 19:4b0fe9a5ec38 | 140 | //ステートFIFOから次の予約ステートを引き抜く |
takeru0x1103 | 19:4b0fe9a5ec38 | 141 | //----------------------------------- |
takeru0x1103 | 19:4b0fe9a5ec38 | 142 | bool GlobalFlags::pull(){ |
takeru0x1103 | 19:4b0fe9a5ec38 | 143 | if(empty){ |
takeru0x1103 | 19:4b0fe9a5ec38 | 144 | return false;//EMPTYだったら引き抜けない |
takeru0x1103 | 19:4b0fe9a5ec38 | 145 | }else{ |
takeru0x1103 | 19:4b0fe9a5ec38 | 146 | state = stateQueue[rp];//リードポインタの指すデータをステートに移す |
takeru0x1103 | 19:4b0fe9a5ec38 | 147 | stateQueue[rp] = NONE;//バッファを消す |
takeru0x1103 | 19:4b0fe9a5ec38 | 148 | rp = (rp==STATE_QUE_SIZ) ? 0 : rp+1;//リードポインタを進める |
takeru0x1103 | 19:4b0fe9a5ec38 | 149 | full = false; //フルではなくなる |
takeru0x1103 | 19:4b0fe9a5ec38 | 150 | empty = (stateQueue[rp] == NONE) ? true : false;//次にリードする場所がNONEだったらEMPTYを立てる |
takeru0x1103 | 19:4b0fe9a5ec38 | 151 | return true; |
takeru0x1103 | 19:4b0fe9a5ec38 | 152 | } |
takeru0x1103 | 19:4b0fe9a5ec38 | 153 | } |
takeru0x1103 | 21:78302ecdb661 | 154 | */ |
takeru0x1103 | 19:4b0fe9a5ec38 | 155 | |
MasashiNomura | 33:eb260dbfc22a | 156 |