teamALI / Mbed 2 deprecated HB2018

Dependencies:   mbed FreeRTOS

Committer:
MasashiNomura
Date:
Fri Jan 18 11:52:00 2019 +0000
Revision:
38:24ee50452755
Parent:
37:d51dacb4c30f
Child:
39:1b76f7df8804
20190118 Modify for 45inc. check User SW (include analogIn)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
takeru0x1103 21:78302ecdb661 1 //RTOS関連------------------
takeru0x1103 1:15ab74f0d0f1 2 #include "FreeRTOS.h"
takeru0x1103 1:15ab74f0d0f1 3 #include "task.h"
takeru0x1103 21:78302ecdb661 4 //#include "queue.h"
takeru0x1103 21:78302ecdb661 5 //------------------RTOS関連
takeru0x1103 21:78302ecdb661 6
takeru0x1103 17:f9610f3cfa1b 7 #include "globalFlags.h"
takeru0x1103 17:f9610f3cfa1b 8 #include "HbManager.h"
takeru0x1103 18:5aa48aec9cae 9 #include "hbCommand.h"
takeru0x1103 18:5aa48aec9cae 10 #include "uart.h"
MasashiNomura 24:c5945aaae777 11 #include "fpga.h"
takeru0x1103 1:15ab74f0d0f1 12
takeru0x1103 18:5aa48aec9cae 13 //タスクハンドル(停止とか再開に必要)
takeru0x1103 18:5aa48aec9cae 14 static xTaskHandle tskHandle[3]={NULL,};
takeru0x1103 1:15ab74f0d0f1 15
takeru0x1103 21:78302ecdb661 16 //------------------
takeru0x1103 18:5aa48aec9cae 17 //タスク停止
takeru0x1103 18:5aa48aec9cae 18 //------------------
takeru0x1103 18:5aa48aec9cae 19 static void taskStop(int iId){
takeru0x1103 18:5aa48aec9cae 20 sp.printf("Task[%d] Stop\r\n" , iId);
takeru0x1103 18:5aa48aec9cae 21 vTaskSuspend(tskHandle[iId]);//タスクを止める
takeru0x1103 18:5aa48aec9cae 22 }
takeru0x1103 18:5aa48aec9cae 23
takeru0x1103 21:78302ecdb661 24 //------------------
takeru0x1103 18:5aa48aec9cae 25 //タスク再開
takeru0x1103 18:5aa48aec9cae 26 //------------------
takeru0x1103 18:5aa48aec9cae 27 static void taskStart(int iId){
takeru0x1103 18:5aa48aec9cae 28 sp.printf("Task[%d] Start!!\r\n" , iId);
takeru0x1103 18:5aa48aec9cae 29 vTaskResume(tskHandle[iId]);//タスク再開
takeru0x1103 18:5aa48aec9cae 30 }
takeru0x1103 18:5aa48aec9cae 31
takeru0x1103 18:5aa48aec9cae 32 //========================================================
takeru0x1103 21:78302ecdb661 33 //コマンド解析タスク
takeru0x1103 21:78302ecdb661 34 //========================================================
takeru0x1103 21:78302ecdb661 35 void taskCmdParser(void *pvParameters){
takeru0x1103 21:78302ecdb661 36 // int8_t *pcTaskName = (int8_t *) pvParameters;;
takeru0x1103 21:78302ecdb661 37 portTickType xLastWakeTime = xTaskGetTickCount();
takeru0x1103 21:78302ecdb661 38
takeru0x1103 21:78302ecdb661 39 // vTaskDelay(300);//制御タスクを先に走らせたいので待たす
takeru0x1103 21:78302ecdb661 40
takeru0x1103 21:78302ecdb661 41 while(1){
takeru0x1103 21:78302ecdb661 42 led2=!led2;
takeru0x1103 21:78302ecdb661 43 //コマンド解釈
takeru0x1103 21:78302ecdb661 44 commandParse();
takeru0x1103 21:78302ecdb661 45
takeru0x1103 21:78302ecdb661 46 //
MasashiNomura 24:c5945aaae777 47 // if(gf_Armed){
MasashiNomura 24:c5945aaae777 48 // setState(WAKEUP);
MasashiNomura 24:c5945aaae777 49 // gf_Armed = false;
MasashiNomura 24:c5945aaae777 50 // // taskStop(0);//制御タスクを止める
MasashiNomura 24:c5945aaae777 51 // // taskStart(2);//デバッグタスク再開
MasashiNomura 24:c5945aaae777 52 // }
MasashiNomura 22:24c9c2dedca9 53 // else{
MasashiNomura 22:24c9c2dedca9 54 // taskStop(2);//デバッグタスクを止める
MasashiNomura 22:24c9c2dedca9 55 // taskStart(0);//制御タスク再開
MasashiNomura 22:24c9c2dedca9 56 // }//switch
takeru0x1103 21:78302ecdb661 57
takeru0x1103 21:78302ecdb661 58 //次の周期まで待つ
takeru0x1103 21:78302ecdb661 59 vTaskDelayUntil(&xLastWakeTime, 50 / portTICK_RATE_MS );
takeru0x1103 21:78302ecdb661 60 }
takeru0x1103 21:78302ecdb661 61 }
takeru0x1103 21:78302ecdb661 62 //========================================================
takeru0x1103 17:f9610f3cfa1b 63 //ホバーバイク制御タスク
takeru0x1103 18:5aa48aec9cae 64 //========================================================
takeru0x1103 17:f9610f3cfa1b 65 void taskHbControl(void *pvParameters){
takeru0x1103 21:78302ecdb661 66 // int8_t *pcTaskName = (int8_t *) pvParameters;;
takeru0x1103 21:78302ecdb661 67 portTickType xLastWakeTime = xTaskGetTickCount();
takeru0x1103 21:78302ecdb661 68
takeru0x1103 17:f9610f3cfa1b 69 HbManager hb;
takeru0x1103 8:1ca49cb18290 70
MasashiNomura 23:79e20be4bc5b 71 bool bDoCtrlAtt;
MasashiNomura 23:79e20be4bc5b 72 bool bDoCtrlMot;
MasashiNomura 31:56c554c560c1 73 bool bDoCtrlEng;
MasashiNomura 37:d51dacb4c30f 74 bool bTmp;
MasashiNomura 31:56c554c560c1 75 //INT16 tmpRpm, difRpm;
MasashiNomura 36:2cc739c7e4cb 76 INT16 cntSW1 = 0;
MasashiNomura 36:2cc739c7e4cb 77 INT16 cntSW2 = 0;
MasashiNomura 33:eb260dbfc22a 78 INT16 AxlRpm;
MasashiNomura 36:2cc739c7e4cb 79 INT16 TrtlVal;
MasashiNomura 38:24ee50452755 80 float AxlRow;
MasashiNomura 38:24ee50452755 81 float TrtlRow;
takeru0x1103 1:15ab74f0d0f1 82 while(1){
takeru0x1103 16:05b9e44889f1 83 led1=!led1;
MasashiNomura 23:79e20be4bc5b 84 bDoCtrlAtt = false;
MasashiNomura 23:79e20be4bc5b 85 bDoCtrlMot = false;
MasashiNomura 31:56c554c560c1 86 bDoCtrlEng = false;
MasashiNomura 24:c5945aaae777 87 // PID係数アップデートチェック
MasashiNomura 24:c5945aaae777 88 if(gf_PidParaUpdate){
MasashiNomura 24:c5945aaae777 89 hb.setAttPara(g_PidPara);
MasashiNomura 24:c5945aaae777 90 sp.printf("Pp : [%f]\r\n",g_PidPara.PP);
MasashiNomura 24:c5945aaae777 91 sp.printf("P : [%f]\r\n",g_PidPara.P);
MasashiNomura 24:c5945aaae777 92 sp.printf("I : [%f]\r\n",g_PidPara.I);
MasashiNomura 24:c5945aaae777 93 sp.printf("D : [%f]\r\n",g_PidPara.D);
MasashiNomura 24:c5945aaae777 94 sp.printf("IMAX: [%f]\r\n",g_PidPara.IMax);
MasashiNomura 24:c5945aaae777 95 sp.printf("IMIN: [%f]\r\n",g_PidPara.IMin);
MasashiNomura 31:56c554c560c1 96 sp.printf("V : [%f]\r\n",g_PidPara.V);
MasashiNomura 24:c5945aaae777 97 gf_PidParaUpdate = false;
MasashiNomura 24:c5945aaae777 98 }
MasashiNomura 37:d51dacb4c30f 99 // 確実にモーター等を止めるため
MasashiNomura 25:f3a6e7eec9c3 100 if(gf_StopMot){
MasashiNomura 29:eb3d72dd94aa 101 for(int i = 0; i < 4; ++i){
MasashiNomura 32:7f4145cc3551 102 gf_MtReq[i].req = true;
MasashiNomura 32:7f4145cc3551 103 gf_MtReq[i].val = 0;
MasashiNomura 32:7f4145cc3551 104 gf_MtReqOfs[i].req = true;
MasashiNomura 32:7f4145cc3551 105 gf_MtReqOfs[i].val = 0;
MasashiNomura 29:eb3d72dd94aa 106 }
MasashiNomura 37:d51dacb4c30f 107 for(int i = 0; i < 2; ++i){
MasashiNomura 37:d51dacb4c30f 108 gf_AxReq[i].bf.req = true;
MasashiNomura 37:d51dacb4c30f 109 gf_AxReq[i].bf.val = 0;
MasashiNomura 37:d51dacb4c30f 110 }
MasashiNomura 37:d51dacb4c30f 111 gf_FromActiveStat = isActiveState();
MasashiNomura 37:d51dacb4c30f 112 setStateF(MOT_STOP);
MasashiNomura 25:f3a6e7eec9c3 113 gf_StopMot = false;
MasashiNomura 25:f3a6e7eec9c3 114 }
MasashiNomura 23:79e20be4bc5b 115
MasashiNomura 29:eb3d72dd94aa 116
takeru0x1103 21:78302ecdb661 117 //▼①状態読み出し系
MasashiNomura 22:24c9c2dedca9 118 hb.getAttitude(); //現在角度読み出し
MasashiNomura 22:24c9c2dedca9 119 hb.controlEngine(); //エンジン回転数読み出し
MasashiNomura 22:24c9c2dedca9 120 hb.getUserCommand(); //操作ボタン状態読み出し
MasashiNomura 29:eb3d72dd94aa 121
takeru0x1103 21:78302ecdb661 122 //▼②ステート遷移
MasashiNomura 22:24c9c2dedca9 123 switch(gf_State){
MasashiNomura 22:24c9c2dedca9 124 case SLEEP:
MasashiNomura 36:2cc739c7e4cb 125 if(gf_StateEnt){
MasashiNomura 36:2cc739c7e4cb 126 sp.printf("SLEEP state\r\n");
MasashiNomura 36:2cc739c7e4cb 127 gf_StateEnt = false;
MasashiNomura 36:2cc739c7e4cb 128 }
MasashiNomura 36:2cc739c7e4cb 129 // DEBUGタスクスタートフラグの監視
MasashiNomura 22:24c9c2dedca9 130 if(gf_Dbg){
MasashiNomura 24:c5945aaae777 131 gf_Dbg = false;
MasashiNomura 22:24c9c2dedca9 132 taskStart(2);
MasashiNomura 22:24c9c2dedca9 133 }
MasashiNomura 37:d51dacb4c30f 134 if(hb.chkSWUserOpeAny()){
MasashiNomura 37:d51dacb4c30f 135 typUserSw sw = hb.getUserSw();
MasashiNomura 37:d51dacb4c30f 136 sp.printf("%d%d%d%d%d%d%d%d%d%d\r\n",sw.bf.brk_r,sw.bf.brk_l,sw.bf.flt_on,sw.bf.flt_off,
MasashiNomura 37:d51dacb4c30f 137 sw.bf.f_eng_up,sw.bf.f_eng_down,sw.bf.r_eng_up,sw.bf.r_eng_down,
MasashiNomura 37:d51dacb4c30f 138 sw.bf.rsv_1, sw.bf.all_stop);
MasashiNomura 38:24ee50452755 139 } else {
MasashiNomura 38:24ee50452755 140 AxlRow = hb.getUserMotAxlRaw();
MasashiNomura 38:24ee50452755 141 //TrtlRow = hb.getUserEngTrottleRaw();
MasashiNomura 38:24ee50452755 142 if(gf_Print.bf.ain){
MasashiNomura 38:24ee50452755 143 sp.printf("MotAxl:%f\r\n",AxlRow);
MasashiNomura 38:24ee50452755 144 }
MasashiNomura 37:d51dacb4c30f 145 }
MasashiNomura 36:2cc739c7e4cb 146 // 浮上(離陸)ボタン、着陸ボタンの同時長押し監視
MasashiNomura 36:2cc739c7e4cb 147 if(hb.chkSWUserOpeBoth(HbUserOpe::FLT_ON,HbUserOpe::FLT_OFF)){
MasashiNomura 36:2cc739c7e4cb 148 ++cntSW1;
MasashiNomura 36:2cc739c7e4cb 149 if(cntSW1 > 30){
MasashiNomura 36:2cc739c7e4cb 150 cntSW1 = 0;
MasashiNomura 36:2cc739c7e4cb 151 setStateF(CHK_EG_ENT);
MasashiNomura 36:2cc739c7e4cb 152 }
MasashiNomura 36:2cc739c7e4cb 153 }
MasashiNomura 36:2cc739c7e4cb 154 else {
MasashiNomura 36:2cc739c7e4cb 155 cntSW1 = 0;
MasashiNomura 36:2cc739c7e4cb 156 }
MasashiNomura 36:2cc739c7e4cb 157 if(hb.chkSWUserOpeBoth(HbUserOpe::BRK_L, HbUserOpe::BRK_R)){
MasashiNomura 36:2cc739c7e4cb 158 ++cntSW2;
MasashiNomura 36:2cc739c7e4cb 159 if(cntSW2 > 30){
MasashiNomura 36:2cc739c7e4cb 160 cntSW2 = 0;
MasashiNomura 36:2cc739c7e4cb 161 setStateF(WAKEUP);
MasashiNomura 36:2cc739c7e4cb 162 }
MasashiNomura 36:2cc739c7e4cb 163 }
MasashiNomura 36:2cc739c7e4cb 164 else {
MasashiNomura 36:2cc739c7e4cb 165 cntSW2 = 0;
MasashiNomura 36:2cc739c7e4cb 166 }
MasashiNomura 22:24c9c2dedca9 167 break;
MasashiNomura 22:24c9c2dedca9 168 case WAKEUP:
MasashiNomura 36:2cc739c7e4cb 169 if(gf_StateEnt){
MasashiNomura 36:2cc739c7e4cb 170 //スイッチが何も押されていないことの確認
MasashiNomura 36:2cc739c7e4cb 171 if(!hb.chkSWUserOpeAny()){
MasashiNomura 36:2cc739c7e4cb 172 sp.printf("WAKEUP state\r\n");
MasashiNomura 36:2cc739c7e4cb 173 gf_StateEnt = false;
MasashiNomura 36:2cc739c7e4cb 174 }
MasashiNomura 36:2cc739c7e4cb 175 }
MasashiNomura 36:2cc739c7e4cb 176 else
MasashiNomura 36:2cc739c7e4cb 177 {
MasashiNomura 36:2cc739c7e4cb 178 //各種モーター
MasashiNomura 36:2cc739c7e4cb 179 //機材のチェック
MasashiNomura 36:2cc739c7e4cb 180 hb.calAtt();//現在値でヨー角校正
MasashiNomura 36:2cc739c7e4cb 181 //モーター用のアナログ入力が下げられているかの確認
MasashiNomura 36:2cc739c7e4cb 182 AxlRpm = hb.getUserMotAxl();
MasashiNomura 36:2cc739c7e4cb 183 if(AxlRpm > 0){
MasashiNomura 36:2cc739c7e4cb 184 // 将来的に警告音等
MasashiNomura 38:24ee50452755 185 sp.printf("Warning!! Motor Accel Opened!![%d]\r\n",AxlRpm);
MasashiNomura 36:2cc739c7e4cb 186 setStateF(SLEEP);
MasashiNomura 36:2cc739c7e4cb 187 } else {
MasashiNomura 36:2cc739c7e4cb 188 setState(STANDBY);
MasashiNomura 36:2cc739c7e4cb 189 }
MasashiNomura 35:3779201b4c73 190 }
MasashiNomura 22:24c9c2dedca9 191 break;
MasashiNomura 22:24c9c2dedca9 192 case STANDBY:
MasashiNomura 36:2cc739c7e4cb 193 bDoCtrlMot = true;
MasashiNomura 36:2cc739c7e4cb 194 if(gf_StateEnt){
MasashiNomura 36:2cc739c7e4cb 195 // モーター回転数のチェック→モーターの回転数をオフセット値まで上げる
MasashiNomura 36:2cc739c7e4cb 196 // TODO
MasashiNomura 36:2cc739c7e4cb 197 sp.printf("STANDBY state\r\n");
MasashiNomura 36:2cc739c7e4cb 198 gf_StateEnt = false;
MasashiNomura 36:2cc739c7e4cb 199 }
MasashiNomura 36:2cc739c7e4cb 200 else {
MasashiNomura 36:2cc739c7e4cb 201
MasashiNomura 25:f3a6e7eec9c3 202 if(hb.chkInRangeIDLE()){
MasashiNomura 36:2cc739c7e4cb 203 hb.calAtt();//現在値でヨー角校正
MasashiNomura 25:f3a6e7eec9c3 204 setState(IDLE);
MasashiNomura 25:f3a6e7eec9c3 205 }
MasashiNomura 25:f3a6e7eec9c3 206 else{
MasashiNomura 25:f3a6e7eec9c3 207 // デバッグのためここもスルー
MasashiNomura 36:2cc739c7e4cb 208 hb.calAtt();//現在値でヨー角校正
MasashiNomura 25:f3a6e7eec9c3 209 setState(IDLE);
MasashiNomura 25:f3a6e7eec9c3 210 }
MasashiNomura 23:79e20be4bc5b 211 }
MasashiNomura 22:24c9c2dedca9 212 break;
MasashiNomura 22:24c9c2dedca9 213 case IDLE:
MasashiNomura 36:2cc739c7e4cb 214 if(gf_StateEnt){
MasashiNomura 36:2cc739c7e4cb 215 sp.printf("IDLE state\r\n");
MasashiNomura 36:2cc739c7e4cb 216 gf_StateEnt = false;
MasashiNomura 36:2cc739c7e4cb 217 }
MasashiNomura 23:79e20be4bc5b 218 //SWのチェック
MasashiNomura 31:56c554c560c1 219 hb.chkSW(IDLE);
MasashiNomura 33:eb260dbfc22a 220 AxlRpm = hb.getUserMotAxl();
MasashiNomura 33:eb260dbfc22a 221 hb.setMotVal(R_L,AxlRpm);
MasashiNomura 33:eb260dbfc22a 222 hb.setMotVal(R_R,AxlRpm);
MasashiNomura 31:56c554c560c1 223 bDoCtrlEng = true;
MasashiNomura 25:f3a6e7eec9c3 224 bDoCtrlMot = true;
MasashiNomura 32:7f4145cc3551 225 //bDoCtrlAtt = true;
MasashiNomura 22:24c9c2dedca9 226 break;
MasashiNomura 22:24c9c2dedca9 227 case TAKE_OFF:
MasashiNomura 36:2cc739c7e4cb 228 if(gf_StateEnt){
MasashiNomura 36:2cc739c7e4cb 229 sp.printf("TAKE_OFF state\r\n");
MasashiNomura 36:2cc739c7e4cb 230 gf_StateEnt = false;
MasashiNomura 36:2cc739c7e4cb 231 }
MasashiNomura 23:79e20be4bc5b 232 // エンジン回転数のチェック
MasashiNomura 23:79e20be4bc5b 233 // 着陸ボタンが優先度が高いので先に判定、たが、まだ作ってないのでコメントアウト
MasashiNomura 23:79e20be4bc5b 234 // if(hb.chkSWUserOpe(HbUserOpe::STOP)){
MasashiNomura 23:79e20be4bc5b 235 // setState(GROUND);
MasashiNomura 23:79e20be4bc5b 236 // }
MasashiNomura 23:79e20be4bc5b 237 //else
MasashiNomura 34:234b87f3e6ce 238 hb.chkSW(TAKE_OFF);
MasashiNomura 34:234b87f3e6ce 239 AxlRpm = hb.getUserMotAxl();
MasashiNomura 34:234b87f3e6ce 240 hb.setMotVal(R_L,AxlRpm);
MasashiNomura 34:234b87f3e6ce 241 hb.setMotVal(R_R,AxlRpm);
MasashiNomura 31:56c554c560c1 242 bDoCtrlEng = true;
MasashiNomura 23:79e20be4bc5b 243 bDoCtrlMot = true;
MasashiNomura 23:79e20be4bc5b 244 bDoCtrlAtt = true;
MasashiNomura 22:24c9c2dedca9 245 break;
MasashiNomura 22:24c9c2dedca9 246 case GROUND:
MasashiNomura 36:2cc739c7e4cb 247 if(gf_StateEnt){
MasashiNomura 36:2cc739c7e4cb 248 sp.printf("GROUND state\r\n");
MasashiNomura 36:2cc739c7e4cb 249 gf_StateEnt = false;
MasashiNomura 36:2cc739c7e4cb 250 }
MasashiNomura 23:79e20be4bc5b 251 // そのままスルー
MasashiNomura 36:2cc739c7e4cb 252 // TODO エンジン回転数が一定以下になることを確認する
MasashiNomura 23:79e20be4bc5b 253 setState(IDLE);
MasashiNomura 22:24c9c2dedca9 254 break;
MasashiNomura 22:24c9c2dedca9 255 case HOVER:
MasashiNomura 36:2cc739c7e4cb 256 gf_StateEnt = false;
MasashiNomura 23:79e20be4bc5b 257 //
MasashiNomura 22:24c9c2dedca9 258 break;
MasashiNomura 22:24c9c2dedca9 259 case DRIVE:
MasashiNomura 36:2cc739c7e4cb 260 gf_StateEnt = false;
MasashiNomura 22:24c9c2dedca9 261 break;
MasashiNomura 22:24c9c2dedca9 262 case EMGGND:
MasashiNomura 36:2cc739c7e4cb 263 gf_StateEnt = false;
MasashiNomura 36:2cc739c7e4cb 264 break;
MasashiNomura 36:2cc739c7e4cb 265 case CHK_EG_ENT:
MasashiNomura 36:2cc739c7e4cb 266 if(gf_StateEnt){
MasashiNomura 36:2cc739c7e4cb 267 sp.printf("Check Engine enter\r\n");
MasashiNomura 36:2cc739c7e4cb 268 gf_StateEnt = false;
MasashiNomura 36:2cc739c7e4cb 269 }
MasashiNomura 36:2cc739c7e4cb 270 if(!hb.chkSWUserOpeAny()){
MasashiNomura 36:2cc739c7e4cb 271 AxlRpm = hb.getUserMotAxl();
MasashiNomura 36:2cc739c7e4cb 272 TrtlVal = hb.getUserEngTrottle();
MasashiNomura 38:24ee50452755 273 //if(AxlRpm > 0 || TrtlVal > 40){
MasashiNomura 38:24ee50452755 274 if(AxlRpm > 0 || TrtlVal > 400){//暫定的に400
MasashiNomura 38:24ee50452755 275 sp.printf("Throttle Val:%d\r\n",TrtlVal);
MasashiNomura 36:2cc739c7e4cb 276 break;
MasashiNomura 36:2cc739c7e4cb 277 } else {
MasashiNomura 38:24ee50452755 278 hb.clearHvAxl();
MasashiNomura 36:2cc739c7e4cb 279 setState(CHK_EG_F);
MasashiNomura 36:2cc739c7e4cb 280 }
MasashiNomura 36:2cc739c7e4cb 281 }
MasashiNomura 36:2cc739c7e4cb 282 break;
MasashiNomura 36:2cc739c7e4cb 283 case CHK_EG_F:
MasashiNomura 36:2cc739c7e4cb 284 if(gf_StateEnt){
MasashiNomura 36:2cc739c7e4cb 285 sp.printf("Check Engine Front\r\n");
MasashiNomura 36:2cc739c7e4cb 286 gf_StateEnt = false;
MasashiNomura 36:2cc739c7e4cb 287 }
MasashiNomura 36:2cc739c7e4cb 288 TrtlVal = hb.getUserEngTrottle();
MasashiNomura 36:2cc739c7e4cb 289 hb.setAccelVal(FRONT, TrtlVal);
MasashiNomura 36:2cc739c7e4cb 290 if(hb.chkSWUserOpe(HbUserOpe::F_ENG_UP)){
MasashiNomura 38:24ee50452755 291 sp.printf("FRONT Throttle Val:%d\r\n",TrtlVal);
MasashiNomura 36:2cc739c7e4cb 292 hb.setHvAxl(FRONT, TrtlVal);
MasashiNomura 36:2cc739c7e4cb 293 }
MasashiNomura 36:2cc739c7e4cb 294 if(hb.chkSWUserOpe(HbUserOpe::R_ENG_UP)){
MasashiNomura 36:2cc739c7e4cb 295 if(hb.chkSetHvAxl(FRONT)){
MasashiNomura 36:2cc739c7e4cb 296 setState(CHK_EG_MID);
MasashiNomura 36:2cc739c7e4cb 297 }
MasashiNomura 36:2cc739c7e4cb 298 }
MasashiNomura 36:2cc739c7e4cb 299 break;
MasashiNomura 36:2cc739c7e4cb 300 case CHK_EG_MID:
MasashiNomura 36:2cc739c7e4cb 301 if(gf_StateEnt){
MasashiNomura 36:2cc739c7e4cb 302 sp.printf("Check Engine MIDDLE\r\n");
MasashiNomura 36:2cc739c7e4cb 303 gf_StateEnt = false;
MasashiNomura 36:2cc739c7e4cb 304 }
MasashiNomura 36:2cc739c7e4cb 305 if(!hb.chkSWUserOpeAny()){
MasashiNomura 36:2cc739c7e4cb 306 AxlRpm = hb.getUserMotAxl();
MasashiNomura 36:2cc739c7e4cb 307 TrtlVal = hb.getUserEngTrottle();
MasashiNomura 38:24ee50452755 308 if(AxlRpm > 0 || TrtlVal > 400){
MasashiNomura 36:2cc739c7e4cb 309 break;
MasashiNomura 36:2cc739c7e4cb 310 } else {
MasashiNomura 36:2cc739c7e4cb 311 setState(CHK_EG_R);
MasashiNomura 36:2cc739c7e4cb 312 }
MasashiNomura 36:2cc739c7e4cb 313 }
MasashiNomura 36:2cc739c7e4cb 314 break;
MasashiNomura 36:2cc739c7e4cb 315 case CHK_EG_R:
MasashiNomura 36:2cc739c7e4cb 316 if(gf_StateEnt){
MasashiNomura 36:2cc739c7e4cb 317 sp.printf("Check Engine Rear\r\n");
MasashiNomura 36:2cc739c7e4cb 318 gf_StateEnt = false;
MasashiNomura 36:2cc739c7e4cb 319 }
MasashiNomura 36:2cc739c7e4cb 320 TrtlVal = hb.getUserEngTrottle();
MasashiNomura 36:2cc739c7e4cb 321 hb.setAccelVal(REAR, TrtlVal);
MasashiNomura 36:2cc739c7e4cb 322 if(hb.chkSWUserOpe(HbUserOpe::F_ENG_UP)){
MasashiNomura 38:24ee50452755 323 sp.printf("REAR Throttle Val:%d\r\n",TrtlVal);
MasashiNomura 36:2cc739c7e4cb 324 hb.setHvAxl(REAR, TrtlVal);
MasashiNomura 36:2cc739c7e4cb 325 }
MasashiNomura 36:2cc739c7e4cb 326 if(hb.chkSWUserOpe(HbUserOpe::R_ENG_UP)){
MasashiNomura 36:2cc739c7e4cb 327 if(hb.chkSetHvAxl(REAR)){
MasashiNomura 36:2cc739c7e4cb 328 setState(CHK_EG_EXIT);
MasashiNomura 36:2cc739c7e4cb 329 }
MasashiNomura 36:2cc739c7e4cb 330 }
MasashiNomura 36:2cc739c7e4cb 331 break;
MasashiNomura 36:2cc739c7e4cb 332 case CHK_EG_EXIT:
MasashiNomura 36:2cc739c7e4cb 333 if(gf_StateEnt){
MasashiNomura 36:2cc739c7e4cb 334 sp.printf("Check Engine Exit\r\n");
MasashiNomura 36:2cc739c7e4cb 335 gf_StateEnt = false;
MasashiNomura 36:2cc739c7e4cb 336 }
MasashiNomura 36:2cc739c7e4cb 337 if(!hb.chkSWUserOpeAny()){
MasashiNomura 36:2cc739c7e4cb 338 AxlRpm = hb.getUserMotAxl();
MasashiNomura 36:2cc739c7e4cb 339 TrtlVal = hb.getUserEngTrottle();
MasashiNomura 38:24ee50452755 340 if(AxlRpm > 0 || TrtlVal > 400){
MasashiNomura 36:2cc739c7e4cb 341 break;
MasashiNomura 36:2cc739c7e4cb 342 } else {
MasashiNomura 36:2cc739c7e4cb 343 setState(SLEEP);
MasashiNomura 36:2cc739c7e4cb 344 }
MasashiNomura 36:2cc739c7e4cb 345 }
MasashiNomura 22:24c9c2dedca9 346 break;
MasashiNomura 23:79e20be4bc5b 347 case CHK_ENT: //チェックエンター
MasashiNomura 36:2cc739c7e4cb 348 if(gf_StateEnt){
MasashiNomura 36:2cc739c7e4cb 349 sp.printf("Check enter\r\n");
MasashiNomura 36:2cc739c7e4cb 350 gf_StateEnt = false;
MasashiNomura 36:2cc739c7e4cb 351 }
MasashiNomura 38:24ee50452755 352 //setStateF(CHK_MOT);
MasashiNomura 23:79e20be4bc5b 353 break;
MasashiNomura 23:79e20be4bc5b 354 case CHK_MOT: //モーターチェック
MasashiNomura 36:2cc739c7e4cb 355 if(gf_StateEnt){
MasashiNomura 36:2cc739c7e4cb 356 sp.printf("Check Motor\r\n");
MasashiNomura 36:2cc739c7e4cb 357 gf_StateEnt = false;
MasashiNomura 36:2cc739c7e4cb 358 }
MasashiNomura 38:24ee50452755 359 //AxlRpm = hb.getUserMotAxl();
MasashiNomura 23:79e20be4bc5b 360 bDoCtrlMot = true;
MasashiNomura 23:79e20be4bc5b 361 break;
MasashiNomura 23:79e20be4bc5b 362 case CHK_AXL: //アクセルサーボチェック
MasashiNomura 36:2cc739c7e4cb 363 if(gf_StateEnt){
MasashiNomura 36:2cc739c7e4cb 364 sp.printf("Check Accel Servo\r\n");
MasashiNomura 36:2cc739c7e4cb 365 gf_StateEnt = false;
MasashiNomura 36:2cc739c7e4cb 366 }
MasashiNomura 38:24ee50452755 367 //TrtlVal = hb.getUserEngTrottle();
MasashiNomura 23:79e20be4bc5b 368 break;
MasashiNomura 23:79e20be4bc5b 369 case CHK_ATT: //姿勢制御チェック
MasashiNomura 36:2cc739c7e4cb 370 if(gf_StateEnt){
MasashiNomura 36:2cc739c7e4cb 371 sp.printf("Check Attitude\r\n");
MasashiNomura 36:2cc739c7e4cb 372 gf_StateEnt = false;
MasashiNomura 36:2cc739c7e4cb 373 }
MasashiNomura 23:79e20be4bc5b 374 bDoCtrlAtt = true;
MasashiNomura 23:79e20be4bc5b 375 break;
MasashiNomura 23:79e20be4bc5b 376 case CHK_EXIT: //チェックステート脱出
MasashiNomura 36:2cc739c7e4cb 377 if(gf_StateEnt){
MasashiNomura 36:2cc739c7e4cb 378 sp.printf("Check Exit\r\n");
MasashiNomura 36:2cc739c7e4cb 379 gf_StateEnt = false;
MasashiNomura 36:2cc739c7e4cb 380 }
MasashiNomura 23:79e20be4bc5b 381 break;
MasashiNomura 25:f3a6e7eec9c3 382 case MOT_STOP:
MasashiNomura 36:2cc739c7e4cb 383 if(gf_StateEnt){
MasashiNomura 36:2cc739c7e4cb 384 sp.printf("Motor Stop\r\n");
MasashiNomura 36:2cc739c7e4cb 385 gf_StateEnt = false;
MasashiNomura 36:2cc739c7e4cb 386 }
MasashiNomura 37:d51dacb4c30f 387 bDoCtrlAtt = false;
MasashiNomura 37:d51dacb4c30f 388 bDoCtrlMot = true;
MasashiNomura 37:d51dacb4c30f 389 bTmp = true;
MasashiNomura 37:d51dacb4c30f 390 for(int i = 0; i < 4; ++i){
MasashiNomura 37:d51dacb4c30f 391 if(gf_MtReq[i].req){
MasashiNomura 37:d51dacb4c30f 392 bTmp = false;
MasashiNomura 37:d51dacb4c30f 393 break;
MasashiNomura 37:d51dacb4c30f 394 }
MasashiNomura 37:d51dacb4c30f 395 if(gf_MtReqOfs[i].req){
MasashiNomura 37:d51dacb4c30f 396 bTmp = false;
MasashiNomura 37:d51dacb4c30f 397 break;
MasashiNomura 37:d51dacb4c30f 398 }
MasashiNomura 37:d51dacb4c30f 399 }
MasashiNomura 37:d51dacb4c30f 400 if(!bTmp)break;
MasashiNomura 37:d51dacb4c30f 401 for(int i = 0; i < 2; ++i){
MasashiNomura 37:d51dacb4c30f 402 if(gf_AxReq[i].bf.req){
MasashiNomura 37:d51dacb4c30f 403 bTmp = false;
MasashiNomura 37:d51dacb4c30f 404 break;
MasashiNomura 37:d51dacb4c30f 405 }
MasashiNomura 37:d51dacb4c30f 406 }
MasashiNomura 37:d51dacb4c30f 407 if(bTmp){
MasashiNomura 37:d51dacb4c30f 408 if(gf_FromActiveStat){
MasashiNomura 37:d51dacb4c30f 409 setStateF(IDLE);
MasashiNomura 37:d51dacb4c30f 410 }
MasashiNomura 37:d51dacb4c30f 411 else{
MasashiNomura 37:d51dacb4c30f 412 setStateF(SLEEP);
MasashiNomura 37:d51dacb4c30f 413 }
MasashiNomura 37:d51dacb4c30f 414 }
MasashiNomura 37:d51dacb4c30f 415
MasashiNomura 32:7f4145cc3551 416 // if(hb.stopMotor() == true){
MasashiNomura 32:7f4145cc3551 417 // hb.initMotVal();
MasashiNomura 32:7f4145cc3551 418 // setState(SLEEP);
MasashiNomura 32:7f4145cc3551 419 // sp.printf("MOTOR STOPPED!\r\n");
MasashiNomura 32:7f4145cc3551 420 // }
MasashiNomura 32:7f4145cc3551 421 // else{
MasashiNomura 32:7f4145cc3551 422 // //bDoCtrlMot = true;
MasashiNomura 32:7f4145cc3551 423 // sp.printf(".");
MasashiNomura 32:7f4145cc3551 424 // }
MasashiNomura 25:f3a6e7eec9c3 425 break;
MasashiNomura 22:24c9c2dedca9 426 }
takeru0x1103 21:78302ecdb661 427
takeru0x1103 21:78302ecdb661 428 //▼③各種設定
takeru0x1103 21:78302ecdb661 429 //hb.controlAttitude(); //姿勢制御
takeru0x1103 21:78302ecdb661 430 //hb.controlMotor();//モーター指令出し
MasashiNomura 23:79e20be4bc5b 431 if(bDoCtrlAtt)hb.controlAttitude(); //姿勢制御
MasashiNomura 23:79e20be4bc5b 432 if(bDoCtrlMot)hb.controlMotor();//モーター指令出し
MasashiNomura 31:56c554c560c1 433 //if(bDoCtrlEng)hb.controlEngine();//エンジン指令出し
MasashiNomura 31:56c554c560c1 434
MasashiNomura 23:79e20be4bc5b 435 if(gf_Print.bf.stat){
MasashiNomura 23:79e20be4bc5b 436 sp.printf("stat : [%X]\r\n",gf_State);
MasashiNomura 23:79e20be4bc5b 437 }
takeru0x1103 18:5aa48aec9cae 438 //表示フラグを落とす(けどモニタフラグが立ってる箇所は残る)
takeru0x1103 18:5aa48aec9cae 439 if(gf_Print.flg!=0){
takeru0x1103 18:5aa48aec9cae 440 gf_Print.flg=gf_Mon.flg;
takeru0x1103 18:5aa48aec9cae 441 sp.printf("\r\n");
takeru0x1103 18:5aa48aec9cae 442 }
MasashiNomura 26:732bc37fbefd 443 if(gf_DbgPrint.flg != 0){
MasashiNomura 26:732bc37fbefd 444 gf_DbgPrint.flg = 0;
MasashiNomura 26:732bc37fbefd 445 sp.printf("\r\n");
MasashiNomura 26:732bc37fbefd 446 }
takeru0x1103 1:15ab74f0d0f1 447
takeru0x1103 1:15ab74f0d0f1 448 //次の周期まで待つ
takeru0x1103 1:15ab74f0d0f1 449 vTaskDelayUntil(&xLastWakeTime, 20 / portTICK_RATE_MS );
takeru0x1103 1:15ab74f0d0f1 450 }
takeru0x1103 1:15ab74f0d0f1 451 }
takeru0x1103 18:5aa48aec9cae 452 //========================================================
takeru0x1103 21:78302ecdb661 453 //タスク2:デバッグ用タスク
takeru0x1103 18:5aa48aec9cae 454 //========================================================
takeru0x1103 18:5aa48aec9cae 455 void taskDebug(void *pvParameters){
takeru0x1103 21:78302ecdb661 456
takeru0x1103 21:78302ecdb661 457 taskStop(2);//自ら止めてレジュームされるまで待つ
MasashiNomura 24:c5945aaae777 458 UCHAR Num;
MasashiNomura 24:c5945aaae777 459 INT16 iVal;
MasashiNomura 25:f3a6e7eec9c3 460 //bool rvFlg;
MasashiNomura 24:c5945aaae777 461
takeru0x1103 21:78302ecdb661 462 //この関数をリターンしてしまうと他のタスクも止まるのでwhileで回すこと!
takeru0x1103 18:5aa48aec9cae 463 while(1){
MasashiNomura 24:c5945aaae777 464 for(Num = 0; Num < 8; ++Num){
MasashiNomura 24:c5945aaae777 465 for(iVal = 50; iVal < 300; ++iVal){
MasashiNomura 24:c5945aaae777 466 fpgaMotor(Num, iVal);
MasashiNomura 25:f3a6e7eec9c3 467 wait(0.002);
MasashiNomura 24:c5945aaae777 468 }
MasashiNomura 24:c5945aaae777 469 for(iVal = 300; iVal >= 50; --iVal){
MasashiNomura 24:c5945aaae777 470 fpgaMotor(Num, iVal);
MasashiNomura 25:f3a6e7eec9c3 471 wait(0.002);
MasashiNomura 24:c5945aaae777 472 }
MasashiNomura 24:c5945aaae777 473 }
MasashiNomura 23:79e20be4bc5b 474 //自タスク停止させて次の周期まで待つ
MasashiNomura 22:24c9c2dedca9 475 gf_Dbg = false;
MasashiNomura 23:79e20be4bc5b 476 sp.printf("Do DebugTask!");
takeru0x1103 18:5aa48aec9cae 477 taskStop(2);
takeru0x1103 18:5aa48aec9cae 478 }
takeru0x1103 18:5aa48aec9cae 479 }
takeru0x1103 17:f9610f3cfa1b 480
takeru0x1103 1:15ab74f0d0f1 481 //-------------------------------------------------------------
takeru0x1103 17:f9610f3cfa1b 482 //初期化:タスク登録
takeru0x1103 1:15ab74f0d0f1 483 //-------------------------------------------------------------
takeru0x1103 1:15ab74f0d0f1 484 void taskInit(){
takeru0x1103 21:78302ecdb661 485 portBASE_TYPE TaskRtn;//タスククリエイトの結果を受け取る型
takeru0x1103 18:5aa48aec9cae 486
takeru0x1103 21:78302ecdb661 487 //タスク0:コマンド解析タスク
MasashiNomura 26:732bc37fbefd 488 TaskRtn= xTaskCreate(taskCmdParser, (signed portCHAR *)"TaskCmd", 512, NULL, 1, &tskHandle[0]);
takeru0x1103 21:78302ecdb661 489 if(TaskRtn==pdTRUE){sp.printf("Task0 Set : Command parser\r\n");}
takeru0x1103 21:78302ecdb661 490
takeru0x1103 21:78302ecdb661 491 //タスク1:制御タスク
MasashiNomura 28:fdb3b144e342 492 TaskRtn= xTaskCreate(taskHbControl, (signed portCHAR *)"TaskHbCont", 1024, NULL, 2, &tskHandle[1]);
takeru0x1103 21:78302ecdb661 493 if(TaskRtn==pdTRUE){sp.printf("Task1 Set : Hoverbike Control\r\n");}
takeru0x1103 21:78302ecdb661 494
takeru0x1103 21:78302ecdb661 495 //タスク2:デバッグタスク
MasashiNomura 23:79e20be4bc5b 496 TaskRtn= xTaskCreate(taskDebug, (signed portCHAR *)"TaskDebug", 192, NULL, 0, &tskHandle[2]);
takeru0x1103 21:78302ecdb661 497 if(TaskRtn==pdTRUE){sp.printf("Task2 Set : Debug\r\n");}
takeru0x1103 8:1ca49cb18290 498
takeru0x1103 21:78302ecdb661 499 //RTOSカーネル起動(タスクが走り出す)
takeru0x1103 1:15ab74f0d0f1 500 vTaskStartScheduler();
takeru0x1103 1:15ab74f0d0f1 501 }
takeru0x1103 1:15ab74f0d0f1 502
takeru0x1103 1:15ab74f0d0f1 503