teamALI / Mbed 2 deprecated HB2018

Dependencies:   mbed FreeRTOS

Committer:
MasashiNomura
Date:
Sat Dec 15 14:20:04 2018 +0000
Revision:
28:fdb3b144e342
Parent:
27:ff63c23bc689
Child:
29:eb3d72dd94aa
2018/12/15 modify HbMotorClass -> HbSubProp&HbMotCtrl

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