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@24:c5945aaae777, 2018-12-10 (annotated)
- Committer:
- MasashiNomura
- Date:
- Mon Dec 10 12:29:37 2018 +0000
- Revision:
- 24:c5945aaae777
- Parent:
- 23:79e20be4bc5b
- Child:
- 25:f3a6e7eec9c3
2018/12/10 dbg 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" |
MasashiNomura | 22:24c9c2dedca9 | 3 | //#define STATE_BUF_SIZ 8 |
takeru0x1103 | 16:05b9e44889f1 | 4 | |
MasashiNomura | 22:24c9c2dedca9 | 5 | //モニタ用LED |
takeru0x1103 | 16:05b9e44889f1 | 6 | DigitalOut led1(LED1); |
takeru0x1103 | 16:05b9e44889f1 | 7 | DigitalOut led2(LED2); |
takeru0x1103 | 16:05b9e44889f1 | 8 | DigitalOut led3(LED3); |
takeru0x1103 | 16:05b9e44889f1 | 9 | DigitalOut led4(LED4); |
takeru0x1103 | 8:1ca49cb18290 | 10 | |
takeru0x1103 | 21:78302ecdb661 | 11 | //GlobalFlags gf; |
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 | 23:79e20be4bc5b | 18 | bool gf_fs_stat ;//強制遷移フラグ |
takeru0x1103 | 19:4b0fe9a5ec38 | 19 | typPrintFlag gf_Print ;// |
takeru0x1103 | 19:4b0fe9a5ec38 | 20 | typPrintFlag gf_Mon ;// |
takeru0x1103 | 19:4b0fe9a5ec38 | 21 | typCalFlag gf_Cal ;// |
MasashiNomura | 22:24c9c2dedca9 | 22 | //typAccel gf_AxReq[2] ={0,} ;//アクセル更新 |
MasashiNomura | 22:24c9c2dedca9 | 23 | //typAccel gf_MtReq[4] ={0,} ;//モーター更新 |
MasashiNomura | 22:24c9c2dedca9 | 24 | typAccel gf_AxReq[2] ;//アクセル更新フラグ |
MasashiNomura | 22:24c9c2dedca9 | 25 | typAccel gf_MtReq[4] ;//モーター更新フラグ |
MasashiNomura | 22:24c9c2dedca9 | 26 | |
MasashiNomura | 22:24c9c2dedca9 | 27 | enmHbState gf_State = SLEEP; |
takeru0x1103 | 19:4b0fe9a5ec38 | 28 | |
MasashiNomura | 24:c5945aaae777 | 29 | bool gf_PidParaUpdate ;//PID Pp,P,I,Dの係数アップデートフラグ |
MasashiNomura | 24:c5945aaae777 | 30 | typPidPara g_PidPara ;//PID Pp,P,I,Dの係数の外部設定用 |
takeru0x1103 | 20:0394e15412c3 | 31 | |
MasashiNomura | 22:24c9c2dedca9 | 32 | void initFlags(){ |
MasashiNomura | 22:24c9c2dedca9 | 33 | memset(g_CmdBuf,0x0,sizeof(g_CmdBuf)); |
MasashiNomura | 22:24c9c2dedca9 | 34 | gf_CmdPrs = false; |
MasashiNomura | 22:24c9c2dedca9 | 35 | gf_Armed = false; |
MasashiNomura | 22:24c9c2dedca9 | 36 | gf_Dbg = false; |
MasashiNomura | 22:24c9c2dedca9 | 37 | gf_Print.flg = 0; |
MasashiNomura | 22:24c9c2dedca9 | 38 | gf_Mon.flg = 0; |
MasashiNomura | 22:24c9c2dedca9 | 39 | gf_Cal.flg = 0; |
MasashiNomura | 22:24c9c2dedca9 | 40 | gf_AxReq[0].dt = 0; |
MasashiNomura | 22:24c9c2dedca9 | 41 | gf_AxReq[1].dt = 0; |
MasashiNomura | 22:24c9c2dedca9 | 42 | gf_MtReq[0].dt = 0; |
MasashiNomura | 22:24c9c2dedca9 | 43 | gf_MtReq[1].dt = 0; |
MasashiNomura | 22:24c9c2dedca9 | 44 | gf_MtReq[2].dt = 0; |
MasashiNomura | 22:24c9c2dedca9 | 45 | gf_MtReq[3].dt = 0; |
MasashiNomura | 22:24c9c2dedca9 | 46 | gf_State = SLEEP; |
MasashiNomura | 24:c5945aaae777 | 47 | g_PidPara.PP = 4; |
MasashiNomura | 24:c5945aaae777 | 48 | g_PidPara.P = 4; |
MasashiNomura | 24:c5945aaae777 | 49 | g_PidPara.I = 0.02; |
MasashiNomura | 24:c5945aaae777 | 50 | g_PidPara.D = 0; |
MasashiNomura | 24:c5945aaae777 | 51 | g_PidPara.IMax = 2000; |
MasashiNomura | 24:c5945aaae777 | 52 | g_PidPara.IMin = -2000; |
MasashiNomura | 22:24c9c2dedca9 | 53 | } |
MasashiNomura | 22:24c9c2dedca9 | 54 | |
MasashiNomura | 22:24c9c2dedca9 | 55 | void setState(enmHbState stat){ |
MasashiNomura | 22:24c9c2dedca9 | 56 | // ありえない遷移を排除 |
MasashiNomura | 22:24c9c2dedca9 | 57 | if(gf_State == SLEEP){if(stat != WAKEUP) return;} |
MasashiNomura | 22:24c9c2dedca9 | 58 | if(gf_State == WAKEUP){if(stat != STANDBY) return;} |
MasashiNomura | 22:24c9c2dedca9 | 59 | if(gf_State == STANDBY){if(stat !=IDLE) return;} |
MasashiNomura | 23:79e20be4bc5b | 60 | if(gf_State == IDLE){if(stat != TAKE_OFF && stat != SLEEP) return;} |
MasashiNomura | 23:79e20be4bc5b | 61 | if(gf_State == TAKE_OFF){if(stat != HOVER && stat != GROUND) return;} |
MasashiNomura | 22:24c9c2dedca9 | 62 | if(gf_State == GROUND){if(stat != IDLE) return;} |
MasashiNomura | 22:24c9c2dedca9 | 63 | if(gf_State == HOVER){if(stat != DRIVE && stat != GROUND) return;} |
MasashiNomura | 22:24c9c2dedca9 | 64 | if(gf_State == DRIVE){if(stat != HOVER && stat != EMGGND) return;} |
MasashiNomura | 22:24c9c2dedca9 | 65 | if(gf_State == EMGGND){if(stat != IDLE) return;} |
MasashiNomura | 22:24c9c2dedca9 | 66 | |
MasashiNomura | 23:79e20be4bc5b | 67 | sp.printf("state: %d\r\n",stat); |
MasashiNomura | 22:24c9c2dedca9 | 68 | gf_State = stat; |
MasashiNomura | 22:24c9c2dedca9 | 69 | } |
MasashiNomura | 23:79e20be4bc5b | 70 | void setStateF(enmHbState stat){ |
MasashiNomura | 23:79e20be4bc5b | 71 | sp.printf("state: %d\r\n",stat); |
MasashiNomura | 23:79e20be4bc5b | 72 | enmHbState tmp; |
MasashiNomura | 23:79e20be4bc5b | 73 | if((UINT16)stat > CHK_EXIT){ |
MasashiNomura | 23:79e20be4bc5b | 74 | tmp = SLEEP; |
MasashiNomura | 23:79e20be4bc5b | 75 | } |
MasashiNomura | 23:79e20be4bc5b | 76 | else |
MasashiNomura | 23:79e20be4bc5b | 77 | { |
MasashiNomura | 23:79e20be4bc5b | 78 | tmp = stat; |
MasashiNomura | 23:79e20be4bc5b | 79 | } |
MasashiNomura | 23:79e20be4bc5b | 80 | gf_State = tmp; |
MasashiNomura | 23:79e20be4bc5b | 81 | } |
takeru0x1103 | 21:78302ecdb661 | 82 | /* |
takeru0x1103 | 19:4b0fe9a5ec38 | 83 | //=========================================== |
takeru0x1103 | 19:4b0fe9a5ec38 | 84 | //コンストラクタ |
takeru0x1103 | 19:4b0fe9a5ec38 | 85 | //=========================================== |
takeru0x1103 | 19:4b0fe9a5ec38 | 86 | GlobalFlags::GlobalFlags(){ |
takeru0x1103 | 19:4b0fe9a5ec38 | 87 | //初期ステート |
takeru0x1103 | 21:78302ecdb661 | 88 | state = SLEEP; |
takeru0x1103 | 19:4b0fe9a5ec38 | 89 | //ステートキュー初期化 |
takeru0x1103 | 19:4b0fe9a5ec38 | 90 | for(int i=0; i<STATE_QUE_SIZ; i++){ |
takeru0x1103 | 19:4b0fe9a5ec38 | 91 | stateQueue[i] = NONE; |
takeru0x1103 | 19:4b0fe9a5ec38 | 92 | } |
takeru0x1103 | 19:4b0fe9a5ec38 | 93 | rp = wp = 0;//先頭を指す |
takeru0x1103 | 19:4b0fe9a5ec38 | 94 | full = false;//最初はエンプティ |
takeru0x1103 | 19:4b0fe9a5ec38 | 95 | empty = true; |
takeru0x1103 | 19:4b0fe9a5ec38 | 96 | } |
takeru0x1103 | 19:4b0fe9a5ec38 | 97 | |
takeru0x1103 | 21:78302ecdb661 | 98 | |
takeru0x1103 | 19:4b0fe9a5ec38 | 99 | //----------------------------------- |
takeru0x1103 | 19:4b0fe9a5ec38 | 100 | //ステートのFIFOにプッシュする |
takeru0x1103 | 19:4b0fe9a5ec38 | 101 | //----------------------------------- |
takeru0x1103 | 19:4b0fe9a5ec38 | 102 | bool GlobalFlags::push(enmHbState iState){ |
takeru0x1103 | 19:4b0fe9a5ec38 | 103 | if(full){ |
takeru0x1103 | 19:4b0fe9a5ec38 | 104 | return false;//FFULLフラグが立ってら入力を受け付けない |
takeru0x1103 | 19:4b0fe9a5ec38 | 105 | }else{ |
takeru0x1103 | 19:4b0fe9a5ec38 | 106 | stateQueue[wp] = iState;//キューに突っ込んで |
takeru0x1103 | 19:4b0fe9a5ec38 | 107 | wp = (wp==STATE_QUE_SIZ) ? 0 : wp+1;//ライトポインタを進める |
takeru0x1103 | 19:4b0fe9a5ec38 | 108 | full = (wp == rp)? true : false; //次ライト予定の場所がリードポインタに追いついたらFULLを立てる |
takeru0x1103 | 19:4b0fe9a5ec38 | 109 | empty = false; |
takeru0x1103 | 19:4b0fe9a5ec38 | 110 | return true; |
takeru0x1103 | 19:4b0fe9a5ec38 | 111 | } |
takeru0x1103 | 19:4b0fe9a5ec38 | 112 | } |
takeru0x1103 | 19:4b0fe9a5ec38 | 113 | |
takeru0x1103 | 19:4b0fe9a5ec38 | 114 | //----------------------------------- |
takeru0x1103 | 19:4b0fe9a5ec38 | 115 | //ステートFIFOから次の予約ステートを引き抜く |
takeru0x1103 | 19:4b0fe9a5ec38 | 116 | //----------------------------------- |
takeru0x1103 | 19:4b0fe9a5ec38 | 117 | bool GlobalFlags::pull(){ |
takeru0x1103 | 19:4b0fe9a5ec38 | 118 | if(empty){ |
takeru0x1103 | 19:4b0fe9a5ec38 | 119 | return false;//EMPTYだったら引き抜けない |
takeru0x1103 | 19:4b0fe9a5ec38 | 120 | }else{ |
takeru0x1103 | 19:4b0fe9a5ec38 | 121 | state = stateQueue[rp];//リードポインタの指すデータをステートに移す |
takeru0x1103 | 19:4b0fe9a5ec38 | 122 | stateQueue[rp] = NONE;//バッファを消す |
takeru0x1103 | 19:4b0fe9a5ec38 | 123 | rp = (rp==STATE_QUE_SIZ) ? 0 : rp+1;//リードポインタを進める |
takeru0x1103 | 19:4b0fe9a5ec38 | 124 | full = false; //フルではなくなる |
takeru0x1103 | 19:4b0fe9a5ec38 | 125 | empty = (stateQueue[rp] == NONE) ? true : false;//次にリードする場所がNONEだったらEMPTYを立てる |
takeru0x1103 | 19:4b0fe9a5ec38 | 126 | return true; |
takeru0x1103 | 19:4b0fe9a5ec38 | 127 | } |
takeru0x1103 | 19:4b0fe9a5ec38 | 128 | } |
takeru0x1103 | 21:78302ecdb661 | 129 | */ |
takeru0x1103 | 19:4b0fe9a5ec38 | 130 | |
takeru0x1103 | 19:4b0fe9a5ec38 | 131 |