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.
Diff: userTask.cpp
- Revision:
- 21:78302ecdb661
- Parent:
- 20:0394e15412c3
- Child:
- 22:24c9c2dedca9
--- a/userTask.cpp Wed Dec 05 01:43:55 2018 +0000 +++ b/userTask.cpp Thu Dec 06 01:50:17 2018 +0000 @@ -1,16 +1,18 @@ -//RTOS関連 +//RTOS関連------------------ #include "FreeRTOS.h" #include "task.h" -#include "queue.h" +//#include "queue.h" +//------------------RTOS関連 + #include "globalFlags.h" #include "HbManager.h" #include "hbCommand.h" #include "uart.h" -#include "fpga.h" //タスクハンドル(停止とか再開に必要) static xTaskHandle tskHandle[3]={NULL,}; +//------------------ //タスク停止 //------------------ static void taskStop(int iId){ @@ -18,6 +20,7 @@ vTaskSuspend(tskHandle[iId]);//タスクを止める } +//------------------ //タスク再開 //------------------ static void taskStart(int iId){ @@ -26,24 +29,55 @@ } //======================================================== +//コマンド解析タスク +//======================================================== +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; - portTickType xLastWakeTime; +// int8_t *pcTaskName = (int8_t *) pvParameters;; + portTickType xLastWakeTime = xTaskGetTickCount(); + HbManager hb; - pcTaskName = (int8_t *) pvParameters; - xLastWakeTime = xTaskGetTickCount(); - // while(1){ led1=!led1; + //▼①状態読み出し系 + //hb.getAttitude(); //現在角度読み出し + //hb.controlEngine(); //エンジン回転数読み出し + //操作ボタン状態読み出し - hb.getAttitude();//現在角度読み出し - hb.controlAttitude();//姿勢制御 - hb.controlMotor();//モーター指令出し - hb.controlEngine();//エンジン回転数読み出し + //▼②ステート遷移 + + + //▼③各種設定 + //hb.controlAttitude(); //姿勢制御 + //hb.controlMotor();//モーター指令出し //表示フラグを落とす(けどモニタフラグが立ってる箇所は残る) @@ -57,61 +91,17 @@ } } //======================================================== -//コマンド解析タスク -//======================================================== -void taskCmdParser(void *pvParameters){ - int8_t *pcTaskName; - portTickType xLastWakeTime; - - pcTaskName = (int8_t *) pvParameters; - xLastWakeTime = xTaskGetTickCount(); - - vTaskDelay(300);//制御タスクを先に走らせたいので待たす - - while(1){ - led2=!led2; - //コマンド解釈 - commandParse(); - - // - switch(gf.state){ - CHK_ENT: //チェックエンター - taskStop(0);//制御タスクを止める - taskStart(2);//デバッグタスク再開 - break; - CHK_EXIT: //チェックステート脱出 - taskStop(2);//デバッグタスクを止める - taskStart(0);//制御タスク再開 - break; - default: - break; - }//switch - - //次の周期まで待つ - vTaskDelayUntil(&xLastWakeTime, 100 / portTICK_RATE_MS ); - } -} -//======================================================== -//デバッグ用タスク +//タスク2:デバッグ用タスク //======================================================== void taskDebug(void *pvParameters){ - int8_t *pcTaskName; - portTickType xLastWakeTime; + + taskStop(2);//自ら止めてレジュームされるまで待つ - pcTaskName = (int8_t *) pvParameters; - xLastWakeTime = xTaskGetTickCount(); - - taskStop(2); - + //この関数をリターンしてしまうと他のタスクも止まるのでwhileで回すこと! while(1){ - switch(gf.state){ - CHK_MOT://モーターチェック - //hb. - //CHK_MOT:fpgaMotorChk(); - break; - } + - //自らタスク停止させて次の周期まで待つ + //自タスク停止させて次の周期まで待つ taskStop(2); } } @@ -120,21 +110,21 @@ //初期化:タスク登録 //------------------------------------------------------------- void taskInit(){ - portBASE_TYPE TaskRtn; - - //制御タスク - TaskRtn= xTaskCreate(taskHbControl, (signed portCHAR *)"Task50Hz", 192, NULL, 2, &tskHandle[0]); - if(TaskRtn==pdTRUE){printf("Hoverbike Control task Set\r\n");} + portBASE_TYPE TaskRtn;//タスククリエイトの結果を受け取る型 - //コマンド解析タスク - TaskRtn= xTaskCreate(taskCmdParser, (signed portCHAR *)"TaskParser", 192, NULL, 1, &tskHandle[1]); - if(TaskRtn==pdTRUE){printf("Command Parser task Set\r\n");} + //タスク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");} - //デバッグタスク - TaskRtn= xTaskCreate(taskDebug, (signed portCHAR *)"TaskDebug", 192, NULL, 0, &tskHandle[2]); - if(TaskRtn==pdTRUE){printf("Debug Parser task Set\r\n");} - - //RTOSカーネルの起動 + //RTOSカーネル起動(タスクが走り出す) vTaskStartScheduler(); }