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
- Committer:
- takeru0x1103
- Date:
- 2018-12-06
- Revision:
- 21:78302ecdb661
- Parent:
- 20:0394e15412c3
- Child:
- 22:24c9c2dedca9
File content as of revision 21:78302ecdb661:
//RTOS関連------------------ #include "FreeRTOS.h" #include "task.h" //#include "queue.h" //------------------RTOS関連 #include "globalFlags.h" #include "HbManager.h" #include "hbCommand.h" #include "uart.h" //タスクハンドル(停止とか再開に必要) static xTaskHandle tskHandle[3]={NULL,}; //------------------ //タスク停止 //------------------ static void taskStop(int iId){ sp.printf("Task[%d] Stop\r\n" , iId); vTaskSuspend(tskHandle[iId]);//タスクを止める } //------------------ //タスク再開 //------------------ static void taskStart(int iId){ sp.printf("Task[%d] Start!!\r\n" , iId); vTaskResume(tskHandle[iId]);//タスク再開 } //======================================================== //コマンド解析タスク //======================================================== void taskCmdParser(void *pvParameters){ // int8_t *pcTaskName = (int8_t *) pvParameters;; portTickType xLastWakeTime = xTaskGetTickCount(); // vTaskDelay(300);//制御タスクを先に走らせたいので待たす while(1){ led2=!led2; //コマンド解釈 commandParse(); // if(gf_Armed){ taskStop(0);//制御タスクを止める taskStart(2);//デバッグタスク再開 }else{ taskStop(2);//デバッグタスクを止める taskStart(0);//制御タスク再開 }//switch //次の周期まで待つ vTaskDelayUntil(&xLastWakeTime, 50 / portTICK_RATE_MS ); } } //======================================================== //ホバーバイク制御タスク //======================================================== void taskHbControl(void *pvParameters){ // int8_t *pcTaskName = (int8_t *) pvParameters;; portTickType xLastWakeTime = xTaskGetTickCount(); HbManager hb; // while(1){ led1=!led1; //▼①状態読み出し系 //hb.getAttitude(); //現在角度読み出し //hb.controlEngine(); //エンジン回転数読み出し //操作ボタン状態読み出し //▼②ステート遷移 //▼③各種設定 //hb.controlAttitude(); //姿勢制御 //hb.controlMotor();//モーター指令出し //表示フラグを落とす(けどモニタフラグが立ってる箇所は残る) if(gf_Print.flg!=0){ gf_Print.flg=gf_Mon.flg; sp.printf("\r\n"); } //次の周期まで待つ vTaskDelayUntil(&xLastWakeTime, 20 / portTICK_RATE_MS ); } } //======================================================== //タスク2:デバッグ用タスク //======================================================== void taskDebug(void *pvParameters){ taskStop(2);//自ら止めてレジュームされるまで待つ //この関数をリターンしてしまうと他のタスクも止まるのでwhileで回すこと! while(1){ //自タスク停止させて次の周期まで待つ taskStop(2); } } //------------------------------------------------------------- //初期化:タスク登録 //------------------------------------------------------------- void taskInit(){ portBASE_TYPE TaskRtn;//タスククリエイトの結果を受け取る型 //タスク0:コマンド解析タスク TaskRtn= xTaskCreate(taskCmdParser, (signed portCHAR *)"TaskCmd", 32, NULL, 1, &tskHandle[0]); if(TaskRtn==pdTRUE){sp.printf("Task0 Set : Command parser\r\n");} //タスク1:制御タスク TaskRtn= xTaskCreate(taskHbControl, (signed portCHAR *)"TaskHbCont", 192, NULL, 2, &tskHandle[1]); if(TaskRtn==pdTRUE){sp.printf("Task1 Set : Hoverbike Control\r\n");} //タスク2:デバッグタスク TaskRtn= xTaskCreate(taskDebug, (signed portCHAR *)"TaskDebug", 64, NULL, 0, &tskHandle[2]); if(TaskRtn==pdTRUE){sp.printf("Task2 Set : Debug\r\n");} //RTOSカーネル起動(タスクが走り出す) vTaskStartScheduler(); }