teamALI / Mbed 2 deprecated HB2018

Dependencies:   mbed FreeRTOS

Committer:
MasashiNomura
Date:
Sat Jan 19 12:35:23 2019 +0000
Revision:
39:1b76f7df8804
Parent:
38:24ee50452755
Child:
40:debe99e228d3
20190119 Modify for 45inc; Checking User SW and sequence

Who changed what in which revision?

UserRevisionLine numberNew 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
MasashiNomura 38:24ee50452755 13 // //エンジンスロットル用アナログ入力
MasashiNomura 38:24ee50452755 14 // AnalogIn AinThrottle(p19);
MasashiNomura 36:2cc739c7e4cb 15
takeru0x1103 19:4b0fe9a5ec38 16 char g_CmdBuf[G_CMD_BUF_SIZ] ;// コマンド受け渡しバッファ
MasashiNomura 22:24c9c2dedca9 17 bool gf_CmdPrs;
takeru0x1103 19:4b0fe9a5ec38 18
MasashiNomura 22:24c9c2dedca9 19 bool gf_Armed ;//アーミングフラグ
MasashiNomura 23:79e20be4bc5b 20 bool gf_Dbg ;//デバッグタスク起動フラグ
MasashiNomura 37:d51dacb4c30f 21 //bool gf_fs_stat ;//強制遷移フラグ
MasashiNomura 37:d51dacb4c30f 22 bool gf_StopMot ;//モーターの強制停止 サーボ全閉
MasashiNomura 37:d51dacb4c30f 23 bool gf_FromActiveStat ;//モーターの強制停止 サーボ全閉が動作時に発生したかどうか
MasashiNomura 25:f3a6e7eec9c3 24
takeru0x1103 19:4b0fe9a5ec38 25 typPrintFlag gf_Print ;//
takeru0x1103 19:4b0fe9a5ec38 26 typPrintFlag gf_Mon ;//
MasashiNomura 39:1b76f7df8804 27 typPrintFlg gf_Prt1 ;
MasashiNomura 39:1b76f7df8804 28 typPrintFlg gf_Mon1 ;
takeru0x1103 19:4b0fe9a5ec38 29 typCalFlag gf_Cal ;//
MasashiNomura 26:732bc37fbefd 30 typDbgPrintFlg gf_DbgPrint ;//デバッグ用
MasashiNomura 22:24c9c2dedca9 31 typAccel gf_AxReq[2] ;//アクセル更新フラグ
MasashiNomura 32:7f4145cc3551 32 typAxlRpm gf_MtReq[4] ;//モーター姿勢制御更新フラグ
MasashiNomura 29:eb3d72dd94aa 33 typAxlRpm gf_MtReqOfs[4] ;//モーターオフセット更新フラグ
MasashiNomura 29:eb3d72dd94aa 34 typAxlRpm gf_MtReqDct[8] ;//ダイレクト(FPGA関数直接呼び出し)モーター更新フラグ
MasashiNomura 32:7f4145cc3551 35 typAxlRpm gf_MtReqU[4] ;//モーターユーザー更新フラグ
MasashiNomura 32:7f4145cc3551 36
MasashiNomura 22:24c9c2dedca9 37 enmHbState gf_State = SLEEP;
MasashiNomura 36:2cc739c7e4cb 38 bool gf_StateEnt ;//状態遷移後、最初であることを示す
takeru0x1103 19:4b0fe9a5ec38 39
MasashiNomura 24:c5945aaae777 40 bool gf_PidParaUpdate ;//PID Pp,P,I,Dの係数アップデートフラグ
MasashiNomura 24:c5945aaae777 41 typPidPara g_PidPara ;//PID Pp,P,I,Dの係数の外部設定用
takeru0x1103 20:0394e15412c3 42
MasashiNomura 36:2cc739c7e4cb 43 // bool gf_MotParaUpdate[4] ;//モーターのパラメータ値更新フラグ
MasashiNomura 36:2cc739c7e4cb 44 // typMotPara g_MotPara[4];
MasashiNomura 25:f3a6e7eec9c3 45
MasashiNomura 22:24c9c2dedca9 46 void initFlags(){
MasashiNomura 22:24c9c2dedca9 47 memset(g_CmdBuf,0x0,sizeof(g_CmdBuf));
MasashiNomura 22:24c9c2dedca9 48 gf_CmdPrs = false;
MasashiNomura 22:24c9c2dedca9 49 gf_Armed = false;
MasashiNomura 22:24c9c2dedca9 50 gf_Dbg = false;
MasashiNomura 25:f3a6e7eec9c3 51 gf_StopMot = false;
MasashiNomura 25:f3a6e7eec9c3 52
MasashiNomura 22:24c9c2dedca9 53 gf_Print.flg = 0;
MasashiNomura 22:24c9c2dedca9 54 gf_Mon.flg = 0;
MasashiNomura 39:1b76f7df8804 55 gf_Prt1.d1.flg = 0;
MasashiNomura 39:1b76f7df8804 56 gf_Prt1.d2.flg = 0;
MasashiNomura 39:1b76f7df8804 57
MasashiNomura 22:24c9c2dedca9 58 gf_Cal.flg = 0;
MasashiNomura 26:732bc37fbefd 59
MasashiNomura 26:732bc37fbefd 60 gf_DbgPrint.flg = 0;
MasashiNomura 26:732bc37fbefd 61
MasashiNomura 22:24c9c2dedca9 62 gf_AxReq[0].dt = 0;
MasashiNomura 22:24c9c2dedca9 63 gf_AxReq[1].dt = 0;
MasashiNomura 27:ff63c23bc689 64 for(int i=0; i<4;++i){
MasashiNomura 32:7f4145cc3551 65 gf_MtReq[i].req = false;
MasashiNomura 32:7f4145cc3551 66 gf_MtReq[i].val = 0;
MasashiNomura 32:7f4145cc3551 67 gf_MtReqOfs[i].req = false;
MasashiNomura 32:7f4145cc3551 68 gf_MtReqOfs[i].val = 0;
MasashiNomura 32:7f4145cc3551 69 gf_MtReqU[i].req = false;
MasashiNomura 32:7f4145cc3551 70 gf_MtReqU[i].val = 0;
MasashiNomura 27:ff63c23bc689 71 }
MasashiNomura 27:ff63c23bc689 72 for(int i = 0; i < 8; ++i){
MasashiNomura 32:7f4145cc3551 73 gf_MtReqDct[i].req = false;
MasashiNomura 32:7f4145cc3551 74 gf_MtReqDct[i].val = 0;
MasashiNomura 27:ff63c23bc689 75 }
MasashiNomura 22:24c9c2dedca9 76 gf_State = SLEEP;
MasashiNomura 36:2cc739c7e4cb 77 gf_StateEnt = false;
MasashiNomura 27:ff63c23bc689 78 g_PidPara.PP = 2;
MasashiNomura 32:7f4145cc3551 79 g_PidPara.P = 0;
MasashiNomura 25:f3a6e7eec9c3 80 g_PidPara.I = 0;
MasashiNomura 24:c5945aaae777 81 g_PidPara.D = 0;
MasashiNomura 24:c5945aaae777 82 g_PidPara.IMax = 2000;
MasashiNomura 24:c5945aaae777 83 g_PidPara.IMin = -2000;
MasashiNomura 36:2cc739c7e4cb 84 // for(int i = 0; i < 4; ++i){
MasashiNomura 36:2cc739c7e4cb 85 // gf_MotParaUpdate[i] = false;
MasashiNomura 36:2cc739c7e4cb 86 // g_MotPara[i].limit_hi = LIM_MOT_INP_MAX;
MasashiNomura 36:2cc739c7e4cb 87 // g_MotPara[i].limit_low = LIM_MOT_INP_MIN;
MasashiNomura 36:2cc739c7e4cb 88 // }
MasashiNomura 22:24c9c2dedca9 89 }
MasashiNomura 35:3779201b4c73 90
MasashiNomura 22:24c9c2dedca9 91 void setState(enmHbState stat){
MasashiNomura 22:24c9c2dedca9 92 // ありえない遷移を排除
MasashiNomura 22:24c9c2dedca9 93 if(gf_State == SLEEP){if(stat != WAKEUP) return;}
MasashiNomura 22:24c9c2dedca9 94 if(gf_State == WAKEUP){if(stat != STANDBY) return;}
MasashiNomura 22:24c9c2dedca9 95 if(gf_State == STANDBY){if(stat !=IDLE) return;}
MasashiNomura 23:79e20be4bc5b 96 if(gf_State == IDLE){if(stat != TAKE_OFF && stat != SLEEP) return;}
MasashiNomura 23:79e20be4bc5b 97 if(gf_State == TAKE_OFF){if(stat != HOVER && stat != GROUND) return;}
MasashiNomura 22:24c9c2dedca9 98 if(gf_State == GROUND){if(stat != IDLE) return;}
MasashiNomura 22:24c9c2dedca9 99 if(gf_State == HOVER){if(stat != DRIVE && stat != GROUND) return;}
MasashiNomura 22:24c9c2dedca9 100 if(gf_State == DRIVE){if(stat != HOVER && stat != EMGGND) return;}
MasashiNomura 22:24c9c2dedca9 101 if(gf_State == EMGGND){if(stat != IDLE) return;}
MasashiNomura 22:24c9c2dedca9 102
MasashiNomura 23:79e20be4bc5b 103 sp.printf("state: %d\r\n",stat);
MasashiNomura 22:24c9c2dedca9 104 gf_State = stat;
MasashiNomura 36:2cc739c7e4cb 105 gf_StateEnt = true;
MasashiNomura 22:24c9c2dedca9 106 }
MasashiNomura 23:79e20be4bc5b 107 void setStateF(enmHbState stat){
MasashiNomura 23:79e20be4bc5b 108 sp.printf("state: %d\r\n",stat);
MasashiNomura 23:79e20be4bc5b 109 enmHbState tmp;
MasashiNomura 25:f3a6e7eec9c3 110 if((UINT16)stat > MOT_STOP){
MasashiNomura 23:79e20be4bc5b 111 tmp = SLEEP;
MasashiNomura 23:79e20be4bc5b 112 }
MasashiNomura 23:79e20be4bc5b 113 else
MasashiNomura 23:79e20be4bc5b 114 {
MasashiNomura 23:79e20be4bc5b 115 tmp = stat;
MasashiNomura 23:79e20be4bc5b 116 }
MasashiNomura 23:79e20be4bc5b 117 gf_State = tmp;
MasashiNomura 36:2cc739c7e4cb 118 gf_StateEnt = true;
MasashiNomura 23:79e20be4bc5b 119 }
MasashiNomura 37:d51dacb4c30f 120
MasashiNomura 37:d51dacb4c30f 121 bool isActiveState(){
MasashiNomura 37:d51dacb4c30f 122 if(gf_State >= IDLE && gf_State <= EMGGND){
MasashiNomura 37:d51dacb4c30f 123 return true;
MasashiNomura 37:d51dacb4c30f 124 }
MasashiNomura 37:d51dacb4c30f 125 else {
MasashiNomura 37:d51dacb4c30f 126 return false;
MasashiNomura 37:d51dacb4c30f 127 }
MasashiNomura 37:d51dacb4c30f 128 }
MasashiNomura 37:d51dacb4c30f 129
takeru0x1103 21:78302ecdb661 130 /*
takeru0x1103 19:4b0fe9a5ec38 131 //===========================================
takeru0x1103 19:4b0fe9a5ec38 132 //コンストラクタ
takeru0x1103 19:4b0fe9a5ec38 133 //===========================================
takeru0x1103 19:4b0fe9a5ec38 134 GlobalFlags::GlobalFlags(){
takeru0x1103 19:4b0fe9a5ec38 135 //初期ステート
takeru0x1103 21:78302ecdb661 136 state = SLEEP;
takeru0x1103 19:4b0fe9a5ec38 137 //ステートキュー初期化
takeru0x1103 19:4b0fe9a5ec38 138 for(int i=0; i<STATE_QUE_SIZ; i++){
takeru0x1103 19:4b0fe9a5ec38 139 stateQueue[i] = NONE;
MasashiNomura 33:eb260dbfc22a 140 }
takeru0x1103 19:4b0fe9a5ec38 141 rp = wp = 0;//先頭を指す
takeru0x1103 19:4b0fe9a5ec38 142 full = false;//最初はエンプティ
takeru0x1103 19:4b0fe9a5ec38 143 empty = true;
takeru0x1103 19:4b0fe9a5ec38 144 }
takeru0x1103 19:4b0fe9a5ec38 145
takeru0x1103 21:78302ecdb661 146
takeru0x1103 19:4b0fe9a5ec38 147 //-----------------------------------
takeru0x1103 19:4b0fe9a5ec38 148 //ステートのFIFOにプッシュする
takeru0x1103 19:4b0fe9a5ec38 149 //-----------------------------------
takeru0x1103 19:4b0fe9a5ec38 150 bool GlobalFlags::push(enmHbState iState){
takeru0x1103 19:4b0fe9a5ec38 151 if(full){
takeru0x1103 19:4b0fe9a5ec38 152 return false;//FFULLフラグが立ってら入力を受け付けない
takeru0x1103 19:4b0fe9a5ec38 153 }else{
takeru0x1103 19:4b0fe9a5ec38 154 stateQueue[wp] = iState;//キューに突っ込んで
takeru0x1103 19:4b0fe9a5ec38 155 wp = (wp==STATE_QUE_SIZ) ? 0 : wp+1;//ライトポインタを進める
takeru0x1103 19:4b0fe9a5ec38 156 full = (wp == rp)? true : false; //次ライト予定の場所がリードポインタに追いついたらFULLを立てる
takeru0x1103 19:4b0fe9a5ec38 157 empty = false;
takeru0x1103 19:4b0fe9a5ec38 158 return true;
takeru0x1103 19:4b0fe9a5ec38 159 }
takeru0x1103 19:4b0fe9a5ec38 160 }
takeru0x1103 19:4b0fe9a5ec38 161
takeru0x1103 19:4b0fe9a5ec38 162 //-----------------------------------
takeru0x1103 19:4b0fe9a5ec38 163 //ステートFIFOから次の予約ステートを引き抜く
takeru0x1103 19:4b0fe9a5ec38 164 //-----------------------------------
takeru0x1103 19:4b0fe9a5ec38 165 bool GlobalFlags::pull(){
takeru0x1103 19:4b0fe9a5ec38 166 if(empty){
takeru0x1103 19:4b0fe9a5ec38 167 return false;//EMPTYだったら引き抜けない
takeru0x1103 19:4b0fe9a5ec38 168 }else{
takeru0x1103 19:4b0fe9a5ec38 169 state = stateQueue[rp];//リードポインタの指すデータをステートに移す
takeru0x1103 19:4b0fe9a5ec38 170 stateQueue[rp] = NONE;//バッファを消す
takeru0x1103 19:4b0fe9a5ec38 171 rp = (rp==STATE_QUE_SIZ) ? 0 : rp+1;//リードポインタを進める
takeru0x1103 19:4b0fe9a5ec38 172 full = false; //フルではなくなる
takeru0x1103 19:4b0fe9a5ec38 173 empty = (stateQueue[rp] == NONE) ? true : false;//次にリードする場所がNONEだったらEMPTYを立てる
takeru0x1103 19:4b0fe9a5ec38 174 return true;
takeru0x1103 19:4b0fe9a5ec38 175 }
takeru0x1103 19:4b0fe9a5ec38 176 }
takeru0x1103 21:78302ecdb661 177 */
takeru0x1103 19:4b0fe9a5ec38 178
MasashiNomura 33:eb260dbfc22a 179