teamALI / Mbed 2 deprecated HB2018

Dependencies:   mbed FreeRTOS

Committer:
MasashiNomura
Date:
Thu Dec 06 11:03:13 2018 +0000
Revision:
22:24c9c2dedca9
Parent:
21:78302ecdb661
Child:
23:79e20be4bc5b
Temp State Transfer

Who changed what in which revision?

UserRevisionLine numberNew 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 22:24c9c2dedca9 17 bool gf_Dbg ;//デバッグフラグ
takeru0x1103 19:4b0fe9a5ec38 18 typPrintFlag gf_Print ;//
takeru0x1103 19:4b0fe9a5ec38 19 typPrintFlag gf_Mon ;//
takeru0x1103 19:4b0fe9a5ec38 20 typCalFlag gf_Cal ;//
MasashiNomura 22:24c9c2dedca9 21 //typAccel gf_AxReq[2] ={0,} ;//アクセル更新
MasashiNomura 22:24c9c2dedca9 22 //typAccel gf_MtReq[4] ={0,} ;//モーター更新
MasashiNomura 22:24c9c2dedca9 23 typAccel gf_AxReq[2] ;//アクセル更新フラグ
MasashiNomura 22:24c9c2dedca9 24 typAccel gf_MtReq[4] ;//モーター更新フラグ
MasashiNomura 22:24c9c2dedca9 25
MasashiNomura 22:24c9c2dedca9 26 enmHbState gf_State = SLEEP;
takeru0x1103 19:4b0fe9a5ec38 27
takeru0x1103 20:0394e15412c3 28
MasashiNomura 22:24c9c2dedca9 29 void initFlags(){
MasashiNomura 22:24c9c2dedca9 30 memset(g_CmdBuf,0x0,sizeof(g_CmdBuf));
MasashiNomura 22:24c9c2dedca9 31 gf_CmdPrs = false;
MasashiNomura 22:24c9c2dedca9 32 gf_Armed = false;
MasashiNomura 22:24c9c2dedca9 33 gf_Dbg = false;
MasashiNomura 22:24c9c2dedca9 34 gf_Print.flg = 0;
MasashiNomura 22:24c9c2dedca9 35 gf_Mon.flg = 0;
MasashiNomura 22:24c9c2dedca9 36 gf_Cal.flg = 0;
MasashiNomura 22:24c9c2dedca9 37 gf_AxReq[0].dt = 0;
MasashiNomura 22:24c9c2dedca9 38 gf_AxReq[1].dt = 0;
MasashiNomura 22:24c9c2dedca9 39 gf_MtReq[0].dt = 0;
MasashiNomura 22:24c9c2dedca9 40 gf_MtReq[1].dt = 0;
MasashiNomura 22:24c9c2dedca9 41 gf_MtReq[2].dt = 0;
MasashiNomura 22:24c9c2dedca9 42 gf_MtReq[3].dt = 0;
MasashiNomura 22:24c9c2dedca9 43 gf_State = SLEEP;
MasashiNomura 22:24c9c2dedca9 44 }
MasashiNomura 22:24c9c2dedca9 45
MasashiNomura 22:24c9c2dedca9 46 void setState(enmHbState stat){
MasashiNomura 22:24c9c2dedca9 47 // ありえない遷移を排除
MasashiNomura 22:24c9c2dedca9 48 if(gf_State == SLEEP){if(stat != WAKEUP) return;}
MasashiNomura 22:24c9c2dedca9 49 if(gf_State == WAKEUP){if(stat != STANDBY) return;}
MasashiNomura 22:24c9c2dedca9 50 if(gf_State == STANDBY){if(stat !=IDLE) return;}
MasashiNomura 22:24c9c2dedca9 51 if(gf_State == IDLE){if(stat != TAKE_OFF || stat != SLEEP) return;}
MasashiNomura 22:24c9c2dedca9 52 if(gf_State == TAKE_OFF){if(stat != HOVER || stat != GROUND) return;}
MasashiNomura 22:24c9c2dedca9 53 if(gf_State == GROUND){if(stat != IDLE) return;}
MasashiNomura 22:24c9c2dedca9 54 if(gf_State == HOVER){if(stat != DRIVE && stat != GROUND) return;}
MasashiNomura 22:24c9c2dedca9 55 if(gf_State == DRIVE){if(stat != HOVER && stat != EMGGND) return;}
MasashiNomura 22:24c9c2dedca9 56 if(gf_State == EMGGND){if(stat != IDLE) return;}
MasashiNomura 22:24c9c2dedca9 57
MasashiNomura 22:24c9c2dedca9 58 gf_State = stat;
MasashiNomura 22:24c9c2dedca9 59 }
takeru0x1103 21:78302ecdb661 60 /*
takeru0x1103 19:4b0fe9a5ec38 61 //===========================================
takeru0x1103 19:4b0fe9a5ec38 62 //コンストラクタ
takeru0x1103 19:4b0fe9a5ec38 63 //===========================================
takeru0x1103 19:4b0fe9a5ec38 64 GlobalFlags::GlobalFlags(){
takeru0x1103 19:4b0fe9a5ec38 65 //初期ステート
takeru0x1103 21:78302ecdb661 66 state = SLEEP;
takeru0x1103 19:4b0fe9a5ec38 67 //ステートキュー初期化
takeru0x1103 19:4b0fe9a5ec38 68 for(int i=0; i<STATE_QUE_SIZ; i++){
takeru0x1103 19:4b0fe9a5ec38 69 stateQueue[i] = NONE;
takeru0x1103 19:4b0fe9a5ec38 70 }
takeru0x1103 19:4b0fe9a5ec38 71 rp = wp = 0;//先頭を指す
takeru0x1103 19:4b0fe9a5ec38 72 full = false;//最初はエンプティ
takeru0x1103 19:4b0fe9a5ec38 73 empty = true;
takeru0x1103 19:4b0fe9a5ec38 74 }
takeru0x1103 19:4b0fe9a5ec38 75
takeru0x1103 21:78302ecdb661 76
takeru0x1103 19:4b0fe9a5ec38 77 //-----------------------------------
takeru0x1103 19:4b0fe9a5ec38 78 //ステートのFIFOにプッシュする
takeru0x1103 19:4b0fe9a5ec38 79 //-----------------------------------
takeru0x1103 19:4b0fe9a5ec38 80 bool GlobalFlags::push(enmHbState iState){
takeru0x1103 19:4b0fe9a5ec38 81 if(full){
takeru0x1103 19:4b0fe9a5ec38 82 return false;//FFULLフラグが立ってら入力を受け付けない
takeru0x1103 19:4b0fe9a5ec38 83 }else{
takeru0x1103 19:4b0fe9a5ec38 84 stateQueue[wp] = iState;//キューに突っ込んで
takeru0x1103 19:4b0fe9a5ec38 85 wp = (wp==STATE_QUE_SIZ) ? 0 : wp+1;//ライトポインタを進める
takeru0x1103 19:4b0fe9a5ec38 86 full = (wp == rp)? true : false; //次ライト予定の場所がリードポインタに追いついたらFULLを立てる
takeru0x1103 19:4b0fe9a5ec38 87 empty = false;
takeru0x1103 19:4b0fe9a5ec38 88 return true;
takeru0x1103 19:4b0fe9a5ec38 89 }
takeru0x1103 19:4b0fe9a5ec38 90 }
takeru0x1103 19:4b0fe9a5ec38 91
takeru0x1103 19:4b0fe9a5ec38 92 //-----------------------------------
takeru0x1103 19:4b0fe9a5ec38 93 //ステートFIFOから次の予約ステートを引き抜く
takeru0x1103 19:4b0fe9a5ec38 94 //-----------------------------------
takeru0x1103 19:4b0fe9a5ec38 95 bool GlobalFlags::pull(){
takeru0x1103 19:4b0fe9a5ec38 96 if(empty){
takeru0x1103 19:4b0fe9a5ec38 97 return false;//EMPTYだったら引き抜けない
takeru0x1103 19:4b0fe9a5ec38 98 }else{
takeru0x1103 19:4b0fe9a5ec38 99 state = stateQueue[rp];//リードポインタの指すデータをステートに移す
takeru0x1103 19:4b0fe9a5ec38 100 stateQueue[rp] = NONE;//バッファを消す
takeru0x1103 19:4b0fe9a5ec38 101 rp = (rp==STATE_QUE_SIZ) ? 0 : rp+1;//リードポインタを進める
takeru0x1103 19:4b0fe9a5ec38 102 full = false; //フルではなくなる
takeru0x1103 19:4b0fe9a5ec38 103 empty = (stateQueue[rp] == NONE) ? true : false;//次にリードする場所がNONEだったらEMPTYを立てる
takeru0x1103 19:4b0fe9a5ec38 104 return true;
takeru0x1103 19:4b0fe9a5ec38 105 }
takeru0x1103 19:4b0fe9a5ec38 106 }
takeru0x1103 21:78302ecdb661 107 */
takeru0x1103 19:4b0fe9a5ec38 108
takeru0x1103 19:4b0fe9a5ec38 109