Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
userTask.cpp@35:3779201b4c73, 2018-12-25 (annotated)
- Committer:
- MasashiNomura
- Date:
- Tue Dec 25 08:20:17 2018 +0000
- Revision:
- 35:3779201b4c73
- Parent:
- 34:234b87f3e6ce
- Child:
- 36:2cc739c7e4cb
12/25 Remove no use commentout, add cchecking motAxl etc
Who changed what in which revision?
| User | Revision | Line number | New 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 | 31:56c554c560c1 | 74 | //INT16 tmpRpm, difRpm; |
| MasashiNomura | 33:eb260dbfc22a | 75 | INT16 AxlRpm; |
| takeru0x1103 | 1:15ab74f0d0f1 | 76 | while(1){ |
| takeru0x1103 | 16:05b9e44889f1 | 77 | led1=!led1; |
| MasashiNomura | 23:79e20be4bc5b | 78 | bDoCtrlAtt = false; |
| MasashiNomura | 23:79e20be4bc5b | 79 | bDoCtrlMot = false; |
| MasashiNomura | 31:56c554c560c1 | 80 | bDoCtrlEng = false; |
| MasashiNomura | 24:c5945aaae777 | 81 | // PID係数アップデートチェック |
| MasashiNomura | 24:c5945aaae777 | 82 | if(gf_PidParaUpdate){ |
| MasashiNomura | 24:c5945aaae777 | 83 | hb.setAttPara(g_PidPara); |
| MasashiNomura | 24:c5945aaae777 | 84 | sp.printf("Pp : [%f]\r\n",g_PidPara.PP); |
| MasashiNomura | 24:c5945aaae777 | 85 | sp.printf("P : [%f]\r\n",g_PidPara.P); |
| MasashiNomura | 24:c5945aaae777 | 86 | sp.printf("I : [%f]\r\n",g_PidPara.I); |
| MasashiNomura | 24:c5945aaae777 | 87 | sp.printf("D : [%f]\r\n",g_PidPara.D); |
| MasashiNomura | 24:c5945aaae777 | 88 | sp.printf("IMAX: [%f]\r\n",g_PidPara.IMax); |
| MasashiNomura | 24:c5945aaae777 | 89 | sp.printf("IMIN: [%f]\r\n",g_PidPara.IMin); |
| MasashiNomura | 31:56c554c560c1 | 90 | sp.printf("V : [%f]\r\n",g_PidPara.V); |
| MasashiNomura | 24:c5945aaae777 | 91 | gf_PidParaUpdate = false; |
| MasashiNomura | 24:c5945aaae777 | 92 | } |
| MasashiNomura | 25:f3a6e7eec9c3 | 93 | for(int i = 0; i < 4; ++i){ |
| MasashiNomura | 25:f3a6e7eec9c3 | 94 | if(gf_MotParaUpdate[i]){ |
| MasashiNomura | 32:7f4145cc3551 | 95 | // hb.setMotPara((UCHAR)i, g_MotPara[i]); |
| MasashiNomura | 32:7f4145cc3551 | 96 | // sp.printf("num : [%d]\r\n",i); |
| MasashiNomura | 32:7f4145cc3551 | 97 | // //sp.printf("ofs : [%d]\r\n",g_MotPara[i].offset); |
| MasashiNomura | 32:7f4145cc3551 | 98 | // sp.printf("low : [%d]\r\n",g_MotPara[i].limit_low); |
| MasashiNomura | 32:7f4145cc3551 | 99 | // sp.printf("hi : [%d]\r\n",g_MotPara[i].limit_hi); |
| MasashiNomura | 25:f3a6e7eec9c3 | 100 | gf_MotParaUpdate[i] = false; |
| MasashiNomura | 25:f3a6e7eec9c3 | 101 | } |
| MasashiNomura | 25:f3a6e7eec9c3 | 102 | } |
| MasashiNomura | 25:f3a6e7eec9c3 | 103 | if(gf_StopMot){ |
| MasashiNomura | 29:eb3d72dd94aa | 104 | //setStateF(MOT_STOP); |
| MasashiNomura | 29:eb3d72dd94aa | 105 | //hb.getCurMotVal(); |
| MasashiNomura | 29:eb3d72dd94aa | 106 | for(int i = 0; i < 4; ++i){ |
| MasashiNomura | 32:7f4145cc3551 | 107 | gf_MtReq[i].req = true; |
| MasashiNomura | 32:7f4145cc3551 | 108 | gf_MtReq[i].val = 0; |
| MasashiNomura | 32:7f4145cc3551 | 109 | gf_MtReqOfs[i].req = true; |
| MasashiNomura | 32:7f4145cc3551 | 110 | gf_MtReqOfs[i].val = 0; |
| MasashiNomura | 29:eb3d72dd94aa | 111 | } |
| MasashiNomura | 25:f3a6e7eec9c3 | 112 | gf_StopMot = false; |
| MasashiNomura | 25:f3a6e7eec9c3 | 113 | } |
| MasashiNomura | 23:79e20be4bc5b | 114 | |
| MasashiNomura | 29:eb3d72dd94aa | 115 | |
| takeru0x1103 | 21:78302ecdb661 | 116 | //▼①状態読み出し系 |
| MasashiNomura | 22:24c9c2dedca9 | 117 | hb.getAttitude(); //現在角度読み出し |
| MasashiNomura | 22:24c9c2dedca9 | 118 | hb.controlEngine(); //エンジン回転数読み出し |
| MasashiNomura | 22:24c9c2dedca9 | 119 | hb.getUserCommand(); //操作ボタン状態読み出し |
| MasashiNomura | 29:eb3d72dd94aa | 120 | |
| takeru0x1103 | 21:78302ecdb661 | 121 | //▼②ステート遷移 |
| MasashiNomura | 22:24c9c2dedca9 | 122 | switch(gf_State){ |
| MasashiNomura | 22:24c9c2dedca9 | 123 | case SLEEP: |
| MasashiNomura | 22:24c9c2dedca9 | 124 | if(gf_Dbg){ |
| MasashiNomura | 24:c5945aaae777 | 125 | gf_Dbg = false; |
| MasashiNomura | 22:24c9c2dedca9 | 126 | taskStart(2); |
| MasashiNomura | 22:24c9c2dedca9 | 127 | } |
| MasashiNomura | 22:24c9c2dedca9 | 128 | break; |
| MasashiNomura | 22:24c9c2dedca9 | 129 | case WAKEUP: |
| MasashiNomura | 24:c5945aaae777 | 130 | //各種モーター |
| MasashiNomura | 24:c5945aaae777 | 131 | //機材のチェック |
| MasashiNomura | 35:3779201b4c73 | 132 | hb.calAtt(); |
| MasashiNomura | 35:3779201b4c73 | 133 | AxlRpm = hb.getUserMotAxl(); |
| MasashiNomura | 35:3779201b4c73 | 134 | if(AxlRpm > 0){ |
| MasashiNomura | 35:3779201b4c73 | 135 | // 将来的に警告音等 |
| MasashiNomura | 35:3779201b4c73 | 136 | sp.printf("Warning!! Motor Accel Opened!!\r\n"); |
| MasashiNomura | 35:3779201b4c73 | 137 | setStateF(SLEEP); |
| MasashiNomura | 35:3779201b4c73 | 138 | } else { |
| MasashiNomura | 23:79e20be4bc5b | 139 | setState(STANDBY); |
| MasashiNomura | 35:3779201b4c73 | 140 | } |
| MasashiNomura | 22:24c9c2dedca9 | 141 | break; |
| MasashiNomura | 22:24c9c2dedca9 | 142 | case STANDBY: |
| MasashiNomura | 25:f3a6e7eec9c3 | 143 | // モーター回転数のチェック→モーターの回転数をオフセット値まで上げる |
| MasashiNomura | 25:f3a6e7eec9c3 | 144 | //nxtStatFlg = true; |
| MasashiNomura | 25:f3a6e7eec9c3 | 145 | //for(int i = 0; i < 4; ++i){ |
| MasashiNomura | 25:f3a6e7eec9c3 | 146 | // if(gf_MtReq[i].bf.req){ |
| MasashiNomura | 25:f3a6e7eec9c3 | 147 | // bDoCtrlMot = true; |
| MasashiNomura | 25:f3a6e7eec9c3 | 148 | // } |
| MasashiNomura | 25:f3a6e7eec9c3 | 149 | //} |
| MasashiNomura | 25:f3a6e7eec9c3 | 150 | if(!bDoCtrlMot){ |
| MasashiNomura | 25:f3a6e7eec9c3 | 151 | if(hb.chkInRangeIDLE()){ |
| MasashiNomura | 25:f3a6e7eec9c3 | 152 | setState(IDLE); |
| MasashiNomura | 25:f3a6e7eec9c3 | 153 | } |
| MasashiNomura | 25:f3a6e7eec9c3 | 154 | else{ |
| MasashiNomura | 25:f3a6e7eec9c3 | 155 | // デバッグのためここもスルー |
| MasashiNomura | 25:f3a6e7eec9c3 | 156 | setState(IDLE); |
| MasashiNomura | 25:f3a6e7eec9c3 | 157 | } |
| MasashiNomura | 23:79e20be4bc5b | 158 | } |
| MasashiNomura | 22:24c9c2dedca9 | 159 | break; |
| MasashiNomura | 22:24c9c2dedca9 | 160 | case IDLE: |
| MasashiNomura | 23:79e20be4bc5b | 161 | //SWのチェック |
| MasashiNomura | 31:56c554c560c1 | 162 | hb.chkSW(IDLE); |
| MasashiNomura | 33:eb260dbfc22a | 163 | AxlRpm = hb.getUserMotAxl(); |
| MasashiNomura | 33:eb260dbfc22a | 164 | hb.setMotVal(R_L,AxlRpm); |
| MasashiNomura | 33:eb260dbfc22a | 165 | hb.setMotVal(R_R,AxlRpm); |
| MasashiNomura | 31:56c554c560c1 | 166 | bDoCtrlEng = true; |
| MasashiNomura | 25:f3a6e7eec9c3 | 167 | bDoCtrlMot = true; |
| MasashiNomura | 32:7f4145cc3551 | 168 | //bDoCtrlAtt = true; |
| MasashiNomura | 22:24c9c2dedca9 | 169 | break; |
| MasashiNomura | 22:24c9c2dedca9 | 170 | case TAKE_OFF: |
| MasashiNomura | 23:79e20be4bc5b | 171 | // エンジン回転数のチェック |
| MasashiNomura | 23:79e20be4bc5b | 172 | // 着陸ボタンが優先度が高いので先に判定、たが、まだ作ってないのでコメントアウト |
| MasashiNomura | 23:79e20be4bc5b | 173 | // if(hb.chkSWUserOpe(HbUserOpe::STOP)){ |
| MasashiNomura | 23:79e20be4bc5b | 174 | // setState(GROUND); |
| MasashiNomura | 23:79e20be4bc5b | 175 | // } |
| MasashiNomura | 23:79e20be4bc5b | 176 | //else |
| MasashiNomura | 34:234b87f3e6ce | 177 | hb.chkSW(TAKE_OFF); |
| MasashiNomura | 34:234b87f3e6ce | 178 | AxlRpm = hb.getUserMotAxl(); |
| MasashiNomura | 34:234b87f3e6ce | 179 | hb.setMotVal(R_L,AxlRpm); |
| MasashiNomura | 34:234b87f3e6ce | 180 | hb.setMotVal(R_R,AxlRpm); |
| MasashiNomura | 31:56c554c560c1 | 181 | bDoCtrlEng = true; |
| MasashiNomura | 23:79e20be4bc5b | 182 | bDoCtrlMot = true; |
| MasashiNomura | 23:79e20be4bc5b | 183 | bDoCtrlAtt = true; |
| MasashiNomura | 23:79e20be4bc5b | 184 | //if(hb.chkSWUserOpe(HbUserOpe::STOP)){ |
| MasashiNomura | 23:79e20be4bc5b | 185 | // setState(HOVER); |
| MasashiNomura | 23:79e20be4bc5b | 186 | //} |
| MasashiNomura | 23:79e20be4bc5b | 187 | |
| MasashiNomura | 22:24c9c2dedca9 | 188 | break; |
| MasashiNomura | 22:24c9c2dedca9 | 189 | case GROUND: |
| MasashiNomura | 23:79e20be4bc5b | 190 | // そのままスルー |
| MasashiNomura | 23:79e20be4bc5b | 191 | setState(IDLE); |
| MasashiNomura | 22:24c9c2dedca9 | 192 | break; |
| MasashiNomura | 22:24c9c2dedca9 | 193 | case HOVER: |
| MasashiNomura | 23:79e20be4bc5b | 194 | // |
| MasashiNomura | 22:24c9c2dedca9 | 195 | break; |
| MasashiNomura | 22:24c9c2dedca9 | 196 | case DRIVE: |
| MasashiNomura | 22:24c9c2dedca9 | 197 | break; |
| MasashiNomura | 22:24c9c2dedca9 | 198 | case EMGGND: |
| MasashiNomura | 22:24c9c2dedca9 | 199 | break; |
| MasashiNomura | 23:79e20be4bc5b | 200 | case CHK_ENT: //チェックエンター |
| MasashiNomura | 23:79e20be4bc5b | 201 | sp.printf("Check enter\r\n"); |
| MasashiNomura | 23:79e20be4bc5b | 202 | break; |
| MasashiNomura | 23:79e20be4bc5b | 203 | case CHK_MOT: //モーターチェック |
| MasashiNomura | 23:79e20be4bc5b | 204 | sp.printf("Check Motor\r\n"); |
| MasashiNomura | 23:79e20be4bc5b | 205 | bDoCtrlMot = true; |
| MasashiNomura | 23:79e20be4bc5b | 206 | break; |
| MasashiNomura | 23:79e20be4bc5b | 207 | case CHK_AXL: //アクセルサーボチェック |
| MasashiNomura | 23:79e20be4bc5b | 208 | sp.printf("Check Accel Servo\r\n"); |
| MasashiNomura | 23:79e20be4bc5b | 209 | break; |
| MasashiNomura | 23:79e20be4bc5b | 210 | case CHK_ATT: //姿勢制御チェック |
| MasashiNomura | 23:79e20be4bc5b | 211 | sp.printf("Check Attitude\r\n"); |
| MasashiNomura | 23:79e20be4bc5b | 212 | bDoCtrlAtt = true; |
| MasashiNomura | 23:79e20be4bc5b | 213 | break; |
| MasashiNomura | 23:79e20be4bc5b | 214 | case CHK_EXIT: //チェックステート脱出 |
| MasashiNomura | 23:79e20be4bc5b | 215 | sp.printf("Check Exit\r\n"); |
| MasashiNomura | 23:79e20be4bc5b | 216 | break; |
| MasashiNomura | 25:f3a6e7eec9c3 | 217 | case MOT_STOP: |
| MasashiNomura | 32:7f4145cc3551 | 218 | // if(hb.stopMotor() == true){ |
| MasashiNomura | 32:7f4145cc3551 | 219 | // hb.initMotVal(); |
| MasashiNomura | 32:7f4145cc3551 | 220 | // setState(SLEEP); |
| MasashiNomura | 32:7f4145cc3551 | 221 | // sp.printf("MOTOR STOPPED!\r\n"); |
| MasashiNomura | 32:7f4145cc3551 | 222 | // } |
| MasashiNomura | 32:7f4145cc3551 | 223 | // else{ |
| MasashiNomura | 32:7f4145cc3551 | 224 | // //bDoCtrlMot = true; |
| MasashiNomura | 32:7f4145cc3551 | 225 | // sp.printf("."); |
| MasashiNomura | 32:7f4145cc3551 | 226 | // } |
| MasashiNomura | 25:f3a6e7eec9c3 | 227 | break; |
| MasashiNomura | 22:24c9c2dedca9 | 228 | } |
| takeru0x1103 | 21:78302ecdb661 | 229 | |
| takeru0x1103 | 21:78302ecdb661 | 230 | //▼③各種設定 |
| takeru0x1103 | 21:78302ecdb661 | 231 | //hb.controlAttitude(); //姿勢制御 |
| takeru0x1103 | 21:78302ecdb661 | 232 | //hb.controlMotor();//モーター指令出し |
| MasashiNomura | 23:79e20be4bc5b | 233 | if(bDoCtrlAtt)hb.controlAttitude(); //姿勢制御 |
| MasashiNomura | 23:79e20be4bc5b | 234 | if(bDoCtrlMot)hb.controlMotor();//モーター指令出し |
| MasashiNomura | 31:56c554c560c1 | 235 | //if(bDoCtrlEng)hb.controlEngine();//エンジン指令出し |
| MasashiNomura | 31:56c554c560c1 | 236 | |
| MasashiNomura | 23:79e20be4bc5b | 237 | if(gf_Print.bf.stat){ |
| MasashiNomura | 23:79e20be4bc5b | 238 | sp.printf("stat : [%X]\r\n",gf_State); |
| MasashiNomura | 23:79e20be4bc5b | 239 | } |
| takeru0x1103 | 18:5aa48aec9cae | 240 | //表示フラグを落とす(けどモニタフラグが立ってる箇所は残る) |
| takeru0x1103 | 18:5aa48aec9cae | 241 | if(gf_Print.flg!=0){ |
| takeru0x1103 | 18:5aa48aec9cae | 242 | gf_Print.flg=gf_Mon.flg; |
| takeru0x1103 | 18:5aa48aec9cae | 243 | sp.printf("\r\n"); |
| takeru0x1103 | 18:5aa48aec9cae | 244 | } |
| MasashiNomura | 26:732bc37fbefd | 245 | if(gf_DbgPrint.flg != 0){ |
| MasashiNomura | 26:732bc37fbefd | 246 | gf_DbgPrint.flg = 0; |
| MasashiNomura | 26:732bc37fbefd | 247 | sp.printf("\r\n"); |
| MasashiNomura | 26:732bc37fbefd | 248 | } |
| takeru0x1103 | 1:15ab74f0d0f1 | 249 | |
| takeru0x1103 | 1:15ab74f0d0f1 | 250 | //次の周期まで待つ |
| takeru0x1103 | 1:15ab74f0d0f1 | 251 | vTaskDelayUntil(&xLastWakeTime, 20 / portTICK_RATE_MS ); |
| takeru0x1103 | 1:15ab74f0d0f1 | 252 | } |
| takeru0x1103 | 1:15ab74f0d0f1 | 253 | } |
| takeru0x1103 | 18:5aa48aec9cae | 254 | //======================================================== |
| takeru0x1103 | 21:78302ecdb661 | 255 | //タスク2:デバッグ用タスク |
| takeru0x1103 | 18:5aa48aec9cae | 256 | //======================================================== |
| takeru0x1103 | 18:5aa48aec9cae | 257 | void taskDebug(void *pvParameters){ |
| takeru0x1103 | 21:78302ecdb661 | 258 | |
| takeru0x1103 | 21:78302ecdb661 | 259 | taskStop(2);//自ら止めてレジュームされるまで待つ |
| MasashiNomura | 24:c5945aaae777 | 260 | UCHAR Num; |
| MasashiNomura | 24:c5945aaae777 | 261 | INT16 iVal; |
| MasashiNomura | 25:f3a6e7eec9c3 | 262 | //bool rvFlg; |
| MasashiNomura | 24:c5945aaae777 | 263 | |
| takeru0x1103 | 21:78302ecdb661 | 264 | //この関数をリターンしてしまうと他のタスクも止まるのでwhileで回すこと! |
| takeru0x1103 | 18:5aa48aec9cae | 265 | while(1){ |
| MasashiNomura | 24:c5945aaae777 | 266 | for(Num = 0; Num < 8; ++Num){ |
| MasashiNomura | 24:c5945aaae777 | 267 | for(iVal = 50; iVal < 300; ++iVal){ |
| MasashiNomura | 24:c5945aaae777 | 268 | fpgaMotor(Num, iVal); |
| MasashiNomura | 25:f3a6e7eec9c3 | 269 | wait(0.002); |
| MasashiNomura | 24:c5945aaae777 | 270 | } |
| MasashiNomura | 24:c5945aaae777 | 271 | for(iVal = 300; iVal >= 50; --iVal){ |
| MasashiNomura | 24:c5945aaae777 | 272 | fpgaMotor(Num, iVal); |
| MasashiNomura | 25:f3a6e7eec9c3 | 273 | wait(0.002); |
| MasashiNomura | 24:c5945aaae777 | 274 | } |
| MasashiNomura | 24:c5945aaae777 | 275 | } |
| MasashiNomura | 23:79e20be4bc5b | 276 | //自タスク停止させて次の周期まで待つ |
| MasashiNomura | 22:24c9c2dedca9 | 277 | gf_Dbg = false; |
| MasashiNomura | 23:79e20be4bc5b | 278 | sp.printf("Do DebugTask!"); |
| takeru0x1103 | 18:5aa48aec9cae | 279 | taskStop(2); |
| takeru0x1103 | 18:5aa48aec9cae | 280 | } |
| takeru0x1103 | 18:5aa48aec9cae | 281 | } |
| takeru0x1103 | 17:f9610f3cfa1b | 282 | |
| takeru0x1103 | 1:15ab74f0d0f1 | 283 | //------------------------------------------------------------- |
| takeru0x1103 | 17:f9610f3cfa1b | 284 | //初期化:タスク登録 |
| takeru0x1103 | 1:15ab74f0d0f1 | 285 | //------------------------------------------------------------- |
| takeru0x1103 | 1:15ab74f0d0f1 | 286 | void taskInit(){ |
| takeru0x1103 | 21:78302ecdb661 | 287 | portBASE_TYPE TaskRtn;//タスククリエイトの結果を受け取る型 |
| takeru0x1103 | 18:5aa48aec9cae | 288 | |
| takeru0x1103 | 21:78302ecdb661 | 289 | //タスク0:コマンド解析タスク |
| MasashiNomura | 26:732bc37fbefd | 290 | TaskRtn= xTaskCreate(taskCmdParser, (signed portCHAR *)"TaskCmd", 512, NULL, 1, &tskHandle[0]); |
| takeru0x1103 | 21:78302ecdb661 | 291 | if(TaskRtn==pdTRUE){sp.printf("Task0 Set : Command parser\r\n");} |
| takeru0x1103 | 21:78302ecdb661 | 292 | |
| takeru0x1103 | 21:78302ecdb661 | 293 | //タスク1:制御タスク |
| MasashiNomura | 28:fdb3b144e342 | 294 | TaskRtn= xTaskCreate(taskHbControl, (signed portCHAR *)"TaskHbCont", 1024, NULL, 2, &tskHandle[1]); |
| takeru0x1103 | 21:78302ecdb661 | 295 | if(TaskRtn==pdTRUE){sp.printf("Task1 Set : Hoverbike Control\r\n");} |
| takeru0x1103 | 21:78302ecdb661 | 296 | |
| takeru0x1103 | 21:78302ecdb661 | 297 | //タスク2:デバッグタスク |
| MasashiNomura | 23:79e20be4bc5b | 298 | TaskRtn= xTaskCreate(taskDebug, (signed portCHAR *)"TaskDebug", 192, NULL, 0, &tskHandle[2]); |
| takeru0x1103 | 21:78302ecdb661 | 299 | if(TaskRtn==pdTRUE){sp.printf("Task2 Set : Debug\r\n");} |
| takeru0x1103 | 8:1ca49cb18290 | 300 | |
| takeru0x1103 | 21:78302ecdb661 | 301 | //RTOSカーネル起動(タスクが走り出す) |
| takeru0x1103 | 1:15ab74f0d0f1 | 302 | vTaskStartScheduler(); |
| takeru0x1103 | 1:15ab74f0d0f1 | 303 | } |
| takeru0x1103 | 1:15ab74f0d0f1 | 304 | |
| takeru0x1103 | 1:15ab74f0d0f1 | 305 |