From 652647fc87ab8f8138d29896bce17b8346fc9f0b Mon Sep 17 00:00:00 2001 From: James Cotton Date: Wed, 1 Aug 2012 11:04:37 -0500 Subject: [PATCH] Make autotuning module optional --- flight/Modules/Autotune/autotune.c | 29 ++++++++++++++++++----- flight/PiOS/Boards/STM32103CB_CC_Rev1.h | 1 + shared/uavobjectdefinition/hwsettings.xml | 2 +- shared/uavobjectdefinition/taskinfo.xml | 6 ++--- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/flight/Modules/Autotune/autotune.c b/flight/Modules/Autotune/autotune.c index 776e9b842..ec44a7b72 100644 --- a/flight/Modules/Autotune/autotune.c +++ b/flight/Modules/Autotune/autotune.c @@ -50,6 +50,7 @@ #include "pios.h" #include "flightstatus.h" +#include "hwsettings.h" #include "manualcontrolcommand.h" #include "manualcontrolsettings.h" #include "relaytuning.h" @@ -67,6 +68,7 @@ enum AUTOTUNE_STATE {AT_INIT, AT_START, AT_ROLL, AT_PITCH, AT_FINISHED, AT_SET}; // Private variables static xTaskHandle taskHandle; +static bool autotuneEnabled; // Private functions static void AutotuneTask(void *parameters); @@ -79,6 +81,19 @@ static void update_stabilization_settings(); int32_t AutotuneInitialize(void) { // Create a queue, connect to manual control command and flightstatus +#ifdef MODULE_AUTOTUNE_BUILTIN + autotuneEnabled = true; +#else + HwSettingsInitialize(); + uint8_t optionalModules[HWSETTINGS_OPTIONALMODULES_NUMELEM]; + + HwSettingsOptionalModulesGet(optionalModules); + + if (optionalModules[HWSETTINGS_OPTIONALMODULES_AUTOTUNE] == HWSETTINGS_OPTIONALMODULES_ENABLED) + autotuneEnabled = true; + else + autotuneEnabled = false; +#endif return 0; } @@ -89,13 +104,13 @@ int32_t AutotuneInitialize(void) */ int32_t AutotuneStart(void) { - - // Start main task - xTaskCreate(AutotuneTask, (signed char *)"Autotune", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &taskHandle); + // Start main task if it is enabled + if(autotuneEnabled) { + xTaskCreate(AutotuneTask, (signed char *)"Autotune", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &taskHandle); - //TaskMonitorAdd(TASKINFO_RUNNING_ATTITUDE, taskHandle); - //PIOS_WDG_RegisterFlag(PIOS_WDG_ATTITUDE); - + TaskMonitorAdd(TASKINFO_RUNNING_AUTOTUNE, taskHandle); + PIOS_WDG_RegisterFlag(PIOS_WDG_AUTOTUNE); + } return 0; } @@ -113,6 +128,8 @@ static void AutotuneTask(void *parameters) portTickType lastUpdateTime = xTaskGetTickCount(); while(1) { + + PIOS_WDG_UpdateFlag(PIOS_WDG_AUTOTUNE); // TODO: // 1. get from queue // 2. based on whether it is flightstatus or manualcontrol diff --git a/flight/PiOS/Boards/STM32103CB_CC_Rev1.h b/flight/PiOS/Boards/STM32103CB_CC_Rev1.h index 10a7a41cd..85143fc17 100644 --- a/flight/PiOS/Boards/STM32103CB_CC_Rev1.h +++ b/flight/PiOS/Boards/STM32103CB_CC_Rev1.h @@ -74,6 +74,7 @@ TIM4 | RC In 1 | Servo 3 | Servo 2 | Servo 1 #define PIOS_WDG_STABILIZATION 0x0002 #define PIOS_WDG_ATTITUDE 0x0004 #define PIOS_WDG_MANUAL 0x0008 +#define PIOS_WDG_AUTOTUNE 0x0010 //------------------------ // TELEMETRY diff --git a/shared/uavobjectdefinition/hwsettings.xml b/shared/uavobjectdefinition/hwsettings.xml index 0cee2a6d9..0a09a7620 100644 --- a/shared/uavobjectdefinition/hwsettings.xml +++ b/shared/uavobjectdefinition/hwsettings.xml @@ -18,7 +18,7 @@ - + diff --git a/shared/uavobjectdefinition/taskinfo.xml b/shared/uavobjectdefinition/taskinfo.xml index 40f0d4bdf..97582f7e5 100644 --- a/shared/uavobjectdefinition/taskinfo.xml +++ b/shared/uavobjectdefinition/taskinfo.xml @@ -1,9 +1,9 @@ Task information - - - + + +