teamALI / Mbed 2 deprecated HB2018

Dependencies:   mbed FreeRTOS

Committer:
MasashiNomura
Date:
Mon Dec 17 13:25:00 2018 +0000
Revision:
29:eb3d72dd94aa
Parent:
28:fdb3b144e342
Child:
30:13ada1a24c59
2018/12/17 modify HbMotCtrl HbSubProp etc

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;
takeru0x1103 18:5aa48aec9cae 73 //
takeru0x1103 1:15ab74f0d0f1 74 while(1){
takeru0x1103 16:05b9e44889f1 75 led1=!led1;
MasashiNomura 23:79e20be4bc5b 76 bDoCtrlAtt = false;
MasashiNomura 23:79e20be4bc5b 77 bDoCtrlMot = false;
MasashiNomura 24:c5945aaae777 78
MasashiNomura 24:c5945aaae777 79 // PID係数アップデートチェック
MasashiNomura 24:c5945aaae777 80 if(gf_PidParaUpdate){
MasashiNomura 24:c5945aaae777 81 hb.setAttPara(g_PidPara);
MasashiNomura 24:c5945aaae777 82 sp.printf("Pp : [%f]\r\n",g_PidPara.PP);
MasashiNomura 24:c5945aaae777 83 sp.printf("P : [%f]\r\n",g_PidPara.P);
MasashiNomura 24:c5945aaae777 84 sp.printf("I : [%f]\r\n",g_PidPara.I);
MasashiNomura 24:c5945aaae777 85 sp.printf("D : [%f]\r\n",g_PidPara.D);
MasashiNomura 24:c5945aaae777 86 sp.printf("IMAX: [%f]\r\n",g_PidPara.IMax);
MasashiNomura 24:c5945aaae777 87 sp.printf("IMIN: [%f]\r\n",g_PidPara.IMin);
MasashiNomura 24:c5945aaae777 88 gf_PidParaUpdate = false;
MasashiNomura 24:c5945aaae777 89 }
MasashiNomura 25:f3a6e7eec9c3 90 for(int i = 0; i < 4; ++i){
MasashiNomura 25:f3a6e7eec9c3 91 if(gf_MotParaUpdate[i]){
MasashiNomura 25:f3a6e7eec9c3 92 hb.setMotPara((UCHAR)i, g_MotPara[i]);
MasashiNomura 25:f3a6e7eec9c3 93 sp.printf("num : [%d]\r\n",i);
MasashiNomura 25:f3a6e7eec9c3 94 //sp.printf("ofs : [%d]\r\n",g_MotPara[i].offset);
MasashiNomura 25:f3a6e7eec9c3 95 sp.printf("low : [%d]\r\n",g_MotPara[i].limit_low);
MasashiNomura 25:f3a6e7eec9c3 96 sp.printf("hi : [%d]\r\n",g_MotPara[i].limit_hi);
MasashiNomura 25:f3a6e7eec9c3 97 gf_MotParaUpdate[i] = false;
MasashiNomura 25:f3a6e7eec9c3 98 }
MasashiNomura 25:f3a6e7eec9c3 99 }
MasashiNomura 25:f3a6e7eec9c3 100 if(gf_StopMot){
MasashiNomura 29:eb3d72dd94aa 101 //setStateF(MOT_STOP);
MasashiNomura 29:eb3d72dd94aa 102 //hb.getCurMotVal();
MasashiNomura 29:eb3d72dd94aa 103 for(int i = 0; i < 4; ++i){
MasashiNomura 29:eb3d72dd94aa 104 gf_MtReq[i].bf.req = true;
MasashiNomura 29:eb3d72dd94aa 105 gf_MtReq[i].bf.val = 0;
MasashiNomura 29:eb3d72dd94aa 106 gf_MtReqOfs[i].bf.req = true;
MasashiNomura 29:eb3d72dd94aa 107 gf_MtReqOfs[i].bf.val = 0;
MasashiNomura 29:eb3d72dd94aa 108 }
MasashiNomura 25:f3a6e7eec9c3 109 gf_StopMot = false;
MasashiNomura 25:f3a6e7eec9c3 110 }
MasashiNomura 23:79e20be4bc5b 111
MasashiNomura 29:eb3d72dd94aa 112
takeru0x1103 21:78302ecdb661 113 //▼①状態読み出し系
MasashiNomura 22:24c9c2dedca9 114 hb.getAttitude(); //現在角度読み出し
MasashiNomura 22:24c9c2dedca9 115 hb.controlEngine(); //エンジン回転数読み出し
MasashiNomura 22:24c9c2dedca9 116 hb.getUserCommand(); //操作ボタン状態読み出し
takeru0x1103 18:5aa48aec9cae 117
MasashiNomura 29:eb3d72dd94aa 118
takeru0x1103 21:78302ecdb661 119 //▼②ステート遷移
MasashiNomura 22:24c9c2dedca9 120 switch(gf_State){
MasashiNomura 22:24c9c2dedca9 121 case SLEEP:
MasashiNomura 22:24c9c2dedca9 122 if(gf_Dbg){
MasashiNomura 24:c5945aaae777 123 gf_Dbg = false;
MasashiNomura 22:24c9c2dedca9 124 taskStart(2);
MasashiNomura 22:24c9c2dedca9 125 }
MasashiNomura 27:ff63c23bc689 126 for(int i = 0; i < 8; ++i){
MasashiNomura 27:ff63c23bc689 127 if(gf_MtReqDct[i].bf.req){
MasashiNomura 27:ff63c23bc689 128 hb.setMotFPGA(i, gf_MtReqDct[i].bf.val);
MasashiNomura 27:ff63c23bc689 129 gf_MtReqDct[i].bf.req = false;
MasashiNomura 27:ff63c23bc689 130 }
MasashiNomura 23:79e20be4bc5b 131 }
MasashiNomura 27:ff63c23bc689 132 //else if(gf_Armed){
MasashiNomura 27:ff63c23bc689 133 // gf_Armed = false;
MasashiNomura 27:ff63c23bc689 134 // // hb.initChkMotor();
MasashiNomura 27:ff63c23bc689 135 // setState(WAKEUP);
MasashiNomura 27:ff63c23bc689 136 //}
MasashiNomura 22:24c9c2dedca9 137 break;
MasashiNomura 22:24c9c2dedca9 138 case WAKEUP:
MasashiNomura 24:c5945aaae777 139 //各種モーター
MasashiNomura 24:c5945aaae777 140 //機材のチェック
MasashiNomura 24:c5945aaae777 141 // if(hb.chkMotor() == true){
MasashiNomura 25:f3a6e7eec9c3 142 hb.calAtt();
MasashiNomura 25:f3a6e7eec9c3 143 // STANDBYでモーター回転をオフセット値まで上げるためのフラグセット
MasashiNomura 25:f3a6e7eec9c3 144 //for(int i = 0; i < 4; ++i){
MasashiNomura 25:f3a6e7eec9c3 145 // gf_MtReq[i].bf.req = true;
MasashiNomura 25:f3a6e7eec9c3 146 // gf_MtReq[i].bf.val = 200;
MasashiNomura 25:f3a6e7eec9c3 147 //}
MasashiNomura 23:79e20be4bc5b 148 setState(STANDBY);
MasashiNomura 24:c5945aaae777 149 // }
MasashiNomura 22:24c9c2dedca9 150 break;
MasashiNomura 22:24c9c2dedca9 151 case STANDBY:
MasashiNomura 25:f3a6e7eec9c3 152 // モーター回転数のチェック→モーターの回転数をオフセット値まで上げる
MasashiNomura 25:f3a6e7eec9c3 153 //nxtStatFlg = true;
MasashiNomura 25:f3a6e7eec9c3 154 //for(int i = 0; i < 4; ++i){
MasashiNomura 25:f3a6e7eec9c3 155 // if(gf_MtReq[i].bf.req){
MasashiNomura 25:f3a6e7eec9c3 156 // bDoCtrlMot = true;
MasashiNomura 25:f3a6e7eec9c3 157 // }
MasashiNomura 25:f3a6e7eec9c3 158 //}
MasashiNomura 25:f3a6e7eec9c3 159 if(!bDoCtrlMot){
MasashiNomura 25:f3a6e7eec9c3 160 if(hb.chkInRangeIDLE()){
MasashiNomura 25:f3a6e7eec9c3 161 setState(IDLE);
MasashiNomura 25:f3a6e7eec9c3 162 }
MasashiNomura 25:f3a6e7eec9c3 163 else{
MasashiNomura 25:f3a6e7eec9c3 164 // デバッグのためここもスルー
MasashiNomura 25:f3a6e7eec9c3 165 setState(IDLE);
MasashiNomura 25:f3a6e7eec9c3 166 }
MasashiNomura 23:79e20be4bc5b 167 }
MasashiNomura 22:24c9c2dedca9 168 break;
MasashiNomura 22:24c9c2dedca9 169 case IDLE:
MasashiNomura 23:79e20be4bc5b 170 //SWのチェック
MasashiNomura 23:79e20be4bc5b 171 //離陸ボタン押下
MasashiNomura 23:79e20be4bc5b 172 //とりあえず、YawCtrlで代用
MasashiNomura 26:732bc37fbefd 173 //if(hb.chkSWUserOpe(HbUserOpe::YAW_CTRL))
MasashiNomura 26:732bc37fbefd 174 //{
MasashiNomura 26:732bc37fbefd 175 // // TODO IMU Cal
MasashiNomura 26:732bc37fbefd 176 // hb.calAtt();
MasashiNomura 26:732bc37fbefd 177 // setState(TAKE_OFF);
MasashiNomura 26:732bc37fbefd 178 //}
MasashiNomura 29:eb3d72dd94aa 179 //if(hb.chkSWUserOpeRE(HbUserOpe::F_L)){
MasashiNomura 26:732bc37fbefd 180 if(hb.chkSWUserOpe(HbUserOpe::F_L)){
MasashiNomura 26:732bc37fbefd 181 // Front Left
MasashiNomura 29:eb3d72dd94aa 182 //hb.addMotOfs(HbUserOpe::F_L);
MasashiNomura 29:eb3d72dd94aa 183 gf_MtReqOP[0].req=true; gf_MtReqOP[0].add_end=false; gf_MtReqOP[0].counter = 0; gf_MtReqOP[0].num = 20;
MasashiNomura 29:eb3d72dd94aa 184 gf_MtReqOP[0].addVal = 0;
MasashiNomura 26:732bc37fbefd 185 }
MasashiNomura 29:eb3d72dd94aa 186 //if(hb.chkSWUserOpeRE(HbUserOpe::F_R)){
MasashiNomura 26:732bc37fbefd 187 if(hb.chkSWUserOpe(HbUserOpe::F_R)){
MasashiNomura 26:732bc37fbefd 188 // Front Right
MasashiNomura 29:eb3d72dd94aa 189 //hb.addMotOfs(HbUserOpe::F_R);
MasashiNomura 29:eb3d72dd94aa 190 gf_MtReqOP[1].req=true; gf_MtReqOP[1].add_end=false; gf_MtReqOP[1].counter = 0; gf_MtReqOP[1].num = 20;
MasashiNomura 29:eb3d72dd94aa 191 gf_MtReqOP[1].addVal = 0;
MasashiNomura 23:79e20be4bc5b 192 }
MasashiNomura 26:732bc37fbefd 193 if(hb.chkSWUserOpe(HbUserOpe::R_L)){
MasashiNomura 26:732bc37fbefd 194 // Rear Left
MasashiNomura 29:eb3d72dd94aa 195 //hb.addMotOfs(HbUserOpe::R_L);
MasashiNomura 26:732bc37fbefd 196 }
MasashiNomura 26:732bc37fbefd 197 if(hb.chkSWUserOpe(HbUserOpe::R_R)){
MasashiNomura 26:732bc37fbefd 198 // Rear Right
MasashiNomura 29:eb3d72dd94aa 199 //hb.addMotOfs(HbUserOpe::R_R);
MasashiNomura 26:732bc37fbefd 200 }
MasashiNomura 26:732bc37fbefd 201 if(hb.chkSWUserOpeRE(HbUserOpe::EMG_STOP)){
MasashiNomura 26:732bc37fbefd 202 // EMG STOP だが、テスト用のため、モーターのオフセットを0にして回転を止める
MasashiNomura 26:732bc37fbefd 203 //sp.printf("RisingEdge!\r\n");
MasashiNomura 26:732bc37fbefd 204 for(int i = 0; i < 4; ++i){
MasashiNomura 29:eb3d72dd94aa 205 gf_MtReq[i].bf.req = true;
MasashiNomura 29:eb3d72dd94aa 206 gf_MtReq[i].bf.val = 0;
MasashiNomura 27:ff63c23bc689 207 gf_MtReqOfs[i].bf.req = true;
MasashiNomura 27:ff63c23bc689 208 gf_MtReqOfs[i].bf.val = 0;
MasashiNomura 26:732bc37fbefd 209 }
MasashiNomura 26:732bc37fbefd 210 }
MasashiNomura 26:732bc37fbefd 211
MasashiNomura 23:79e20be4bc5b 212 //else if(hb.chkSWUserOpe(HbUserOpe::ENG_STOP))
MasashiNomura 23:79e20be4bc5b 213 //{
MasashiNomura 23:79e20be4bc5b 214 // setState(SLEEP);
MasashiNomura 23:79e20be4bc5b 215 //}
MasashiNomura 26:732bc37fbefd 216 //if(hb.chkSWUserOpeAny()){
MasashiNomura 26:732bc37fbefd 217 // sp.printf("SW :[%X]\r\n",hb.getUserSw());
MasashiNomura 26:732bc37fbefd 218 //}
MasashiNomura 25:f3a6e7eec9c3 219 bDoCtrlMot = true;
MasashiNomura 22:24c9c2dedca9 220 break;
MasashiNomura 22:24c9c2dedca9 221 case TAKE_OFF:
MasashiNomura 23:79e20be4bc5b 222 // エンジン回転数のチェック
MasashiNomura 23:79e20be4bc5b 223 // 着陸ボタンが優先度が高いので先に判定、たが、まだ作ってないのでコメントアウト
MasashiNomura 23:79e20be4bc5b 224 // if(hb.chkSWUserOpe(HbUserOpe::STOP)){
MasashiNomura 23:79e20be4bc5b 225 // setState(GROUND);
MasashiNomura 23:79e20be4bc5b 226 // }
MasashiNomura 23:79e20be4bc5b 227 //else
MasashiNomura 23:79e20be4bc5b 228 bDoCtrlMot = true;
MasashiNomura 23:79e20be4bc5b 229 bDoCtrlAtt = true;
MasashiNomura 23:79e20be4bc5b 230 //if(hb.chkSWUserOpe(HbUserOpe::STOP)){
MasashiNomura 23:79e20be4bc5b 231 // setState(HOVER);
MasashiNomura 23:79e20be4bc5b 232 //}
MasashiNomura 23:79e20be4bc5b 233
MasashiNomura 22:24c9c2dedca9 234 break;
MasashiNomura 22:24c9c2dedca9 235 case GROUND:
MasashiNomura 23:79e20be4bc5b 236 // そのままスルー
MasashiNomura 23:79e20be4bc5b 237 setState(IDLE);
MasashiNomura 22:24c9c2dedca9 238 break;
MasashiNomura 22:24c9c2dedca9 239 case HOVER:
MasashiNomura 23:79e20be4bc5b 240 //
MasashiNomura 22:24c9c2dedca9 241 break;
MasashiNomura 22:24c9c2dedca9 242 case DRIVE:
MasashiNomura 22:24c9c2dedca9 243 break;
MasashiNomura 22:24c9c2dedca9 244 case EMGGND:
MasashiNomura 22:24c9c2dedca9 245 break;
MasashiNomura 23:79e20be4bc5b 246 case CHK_ENT: //チェックエンター
MasashiNomura 23:79e20be4bc5b 247 sp.printf("Check enter\r\n");
MasashiNomura 23:79e20be4bc5b 248 break;
MasashiNomura 23:79e20be4bc5b 249 case CHK_MOT: //モーターチェック
MasashiNomura 23:79e20be4bc5b 250 sp.printf("Check Motor\r\n");
MasashiNomura 23:79e20be4bc5b 251 bDoCtrlMot = true;
MasashiNomura 23:79e20be4bc5b 252 break;
MasashiNomura 23:79e20be4bc5b 253 case CHK_AXL: //アクセルサーボチェック
MasashiNomura 23:79e20be4bc5b 254 sp.printf("Check Accel Servo\r\n");
MasashiNomura 23:79e20be4bc5b 255 break;
MasashiNomura 23:79e20be4bc5b 256 case CHK_ATT: //姿勢制御チェック
MasashiNomura 23:79e20be4bc5b 257 sp.printf("Check Attitude\r\n");
MasashiNomura 23:79e20be4bc5b 258 bDoCtrlAtt = true;
MasashiNomura 23:79e20be4bc5b 259 break;
MasashiNomura 23:79e20be4bc5b 260 case CHK_EXIT: //チェックステート脱出
MasashiNomura 23:79e20be4bc5b 261 sp.printf("Check Exit\r\n");
MasashiNomura 23:79e20be4bc5b 262 break;
MasashiNomura 25:f3a6e7eec9c3 263 case MOT_STOP:
MasashiNomura 25:f3a6e7eec9c3 264 if(hb.stopMotor() == true){
MasashiNomura 25:f3a6e7eec9c3 265 hb.initMotVal();
MasashiNomura 25:f3a6e7eec9c3 266 setState(SLEEP);
MasashiNomura 25:f3a6e7eec9c3 267 sp.printf("MOTOR STOPPED!\r\n");
MasashiNomura 25:f3a6e7eec9c3 268 }
MasashiNomura 25:f3a6e7eec9c3 269 else{
MasashiNomura 25:f3a6e7eec9c3 270 //bDoCtrlMot = true;
MasashiNomura 25:f3a6e7eec9c3 271 sp.printf(".");
MasashiNomura 25:f3a6e7eec9c3 272 }
MasashiNomura 25:f3a6e7eec9c3 273 break;
MasashiNomura 22:24c9c2dedca9 274 }
takeru0x1103 21:78302ecdb661 275
takeru0x1103 21:78302ecdb661 276 //▼③各種設定
takeru0x1103 21:78302ecdb661 277 //hb.controlAttitude(); //姿勢制御
takeru0x1103 21:78302ecdb661 278 //hb.controlMotor();//モーター指令出し
MasashiNomura 23:79e20be4bc5b 279 if(bDoCtrlAtt)hb.controlAttitude(); //姿勢制御
MasashiNomura 23:79e20be4bc5b 280 if(bDoCtrlMot)hb.controlMotor();//モーター指令出し
takeru0x1103 18:5aa48aec9cae 281
MasashiNomura 23:79e20be4bc5b 282 if(gf_Print.bf.stat){
MasashiNomura 23:79e20be4bc5b 283 sp.printf("stat : [%X]\r\n",gf_State);
MasashiNomura 23:79e20be4bc5b 284 }
takeru0x1103 18:5aa48aec9cae 285 //表示フラグを落とす(けどモニタフラグが立ってる箇所は残る)
takeru0x1103 18:5aa48aec9cae 286 if(gf_Print.flg!=0){
takeru0x1103 18:5aa48aec9cae 287 gf_Print.flg=gf_Mon.flg;
takeru0x1103 18:5aa48aec9cae 288 sp.printf("\r\n");
takeru0x1103 18:5aa48aec9cae 289 }
MasashiNomura 26:732bc37fbefd 290 if(gf_DbgPrint.flg != 0){
MasashiNomura 26:732bc37fbefd 291 gf_DbgPrint.flg = 0;
MasashiNomura 26:732bc37fbefd 292 sp.printf("\r\n");
MasashiNomura 26:732bc37fbefd 293 }
takeru0x1103 1:15ab74f0d0f1 294
takeru0x1103 1:15ab74f0d0f1 295 //次の周期まで待つ
takeru0x1103 1:15ab74f0d0f1 296 vTaskDelayUntil(&xLastWakeTime, 20 / portTICK_RATE_MS );
takeru0x1103 1:15ab74f0d0f1 297 }
takeru0x1103 1:15ab74f0d0f1 298 }
takeru0x1103 18:5aa48aec9cae 299 //========================================================
takeru0x1103 21:78302ecdb661 300 //タスク2:デバッグ用タスク
takeru0x1103 18:5aa48aec9cae 301 //========================================================
takeru0x1103 18:5aa48aec9cae 302 void taskDebug(void *pvParameters){
takeru0x1103 21:78302ecdb661 303
takeru0x1103 21:78302ecdb661 304 taskStop(2);//自ら止めてレジュームされるまで待つ
MasashiNomura 24:c5945aaae777 305 UCHAR Num;
MasashiNomura 24:c5945aaae777 306 INT16 iVal;
MasashiNomura 25:f3a6e7eec9c3 307 //bool rvFlg;
MasashiNomura 24:c5945aaae777 308
takeru0x1103 21:78302ecdb661 309 //この関数をリターンしてしまうと他のタスクも止まるのでwhileで回すこと!
takeru0x1103 18:5aa48aec9cae 310 while(1){
MasashiNomura 24:c5945aaae777 311 for(Num = 0; Num < 8; ++Num){
MasashiNomura 24:c5945aaae777 312 for(iVal = 50; iVal < 300; ++iVal){
MasashiNomura 24:c5945aaae777 313 fpgaMotor(Num, iVal);
MasashiNomura 25:f3a6e7eec9c3 314 wait(0.002);
MasashiNomura 24:c5945aaae777 315 }
MasashiNomura 24:c5945aaae777 316 for(iVal = 300; iVal >= 50; --iVal){
MasashiNomura 24:c5945aaae777 317 fpgaMotor(Num, iVal);
MasashiNomura 25:f3a6e7eec9c3 318 wait(0.002);
MasashiNomura 24:c5945aaae777 319 }
MasashiNomura 24:c5945aaae777 320 }
MasashiNomura 23:79e20be4bc5b 321 //自タスク停止させて次の周期まで待つ
MasashiNomura 22:24c9c2dedca9 322 gf_Dbg = false;
MasashiNomura 23:79e20be4bc5b 323 sp.printf("Do DebugTask!");
takeru0x1103 18:5aa48aec9cae 324 taskStop(2);
takeru0x1103 18:5aa48aec9cae 325 }
takeru0x1103 18:5aa48aec9cae 326 }
takeru0x1103 17:f9610f3cfa1b 327
takeru0x1103 1:15ab74f0d0f1 328 //-------------------------------------------------------------
takeru0x1103 17:f9610f3cfa1b 329 //初期化:タスク登録
takeru0x1103 1:15ab74f0d0f1 330 //-------------------------------------------------------------
takeru0x1103 1:15ab74f0d0f1 331 void taskInit(){
takeru0x1103 21:78302ecdb661 332 portBASE_TYPE TaskRtn;//タスククリエイトの結果を受け取る型
takeru0x1103 18:5aa48aec9cae 333
takeru0x1103 21:78302ecdb661 334 //タスク0:コマンド解析タスク
MasashiNomura 26:732bc37fbefd 335 TaskRtn= xTaskCreate(taskCmdParser, (signed portCHAR *)"TaskCmd", 512, NULL, 1, &tskHandle[0]);
takeru0x1103 21:78302ecdb661 336 if(TaskRtn==pdTRUE){sp.printf("Task0 Set : Command parser\r\n");}
takeru0x1103 21:78302ecdb661 337
takeru0x1103 21:78302ecdb661 338 //タスク1:制御タスク
MasashiNomura 28:fdb3b144e342 339 TaskRtn= xTaskCreate(taskHbControl, (signed portCHAR *)"TaskHbCont", 1024, NULL, 2, &tskHandle[1]);
takeru0x1103 21:78302ecdb661 340 if(TaskRtn==pdTRUE){sp.printf("Task1 Set : Hoverbike Control\r\n");}
takeru0x1103 21:78302ecdb661 341
takeru0x1103 21:78302ecdb661 342 //タスク2:デバッグタスク
MasashiNomura 23:79e20be4bc5b 343 TaskRtn= xTaskCreate(taskDebug, (signed portCHAR *)"TaskDebug", 192, NULL, 0, &tskHandle[2]);
takeru0x1103 21:78302ecdb661 344 if(TaskRtn==pdTRUE){sp.printf("Task2 Set : Debug\r\n");}
takeru0x1103 8:1ca49cb18290 345
takeru0x1103 21:78302ecdb661 346 //RTOSカーネル起動(タスクが走り出す)
takeru0x1103 1:15ab74f0d0f1 347 vTaskStartScheduler();
takeru0x1103 1:15ab74f0d0f1 348 }
takeru0x1103 1:15ab74f0d0f1 349
takeru0x1103 1:15ab74f0d0f1 350