-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
firmware: app: tasks: heater_controller: Improving the task implement…
…ation and increasing the period to 2 sec #142
- Loading branch information
Showing
3 changed files
with
63 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* heater_controller.c | ||
* | ||
* Copyright (C) 2021, SpaceLab. | ||
* Copyright The EPS 2.0 Contributors. | ||
* | ||
* This file is part of EPS 2.0. | ||
* | ||
|
@@ -16,16 +16,17 @@ | |
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with EPS 2.0. If not, see <http://www.gnu.org/licenses/>. | ||
* along with EPS 2.0. If not, see <http:/\/www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
/** | ||
* \brief Heater controller task implementation. | ||
* | ||
* \author André M. P. de Mattos <[email protected]> | ||
* \author Gabriel Mariano Marcelino <[email protected]> | ||
* | ||
* \version 0.2.23 | ||
* \version 0.2.36 | ||
* | ||
* \date 2021/08/04 | ||
* | ||
|
@@ -43,12 +44,9 @@ | |
|
||
xTaskHandle xTaskHeaterControllerHandle; | ||
|
||
void vTaskHeaterController(void *pvParameters) | ||
void vTaskHeaterController(void) | ||
{ | ||
uint32_t heater_mode = 0; | ||
uint32_t heater_duty_cyle = 0; | ||
temperature_t temp = 0; | ||
float actuator_output = 0; | ||
uint32_t heater_mode = 0; | ||
|
||
/* Wait startup task to finish */ | ||
xEventGroupWaitBits(task_startup_status, TASK_STARTUP_DONE, pdFALSE, pdTRUE, pdMS_TO_TICKS(TASK_HEATER_CONTROLLER_INIT_TIMEOUT_MS)); | ||
|
@@ -57,66 +55,57 @@ void vTaskHeaterController(void *pvParameters) | |
{ | ||
TickType_t last_cycle = xTaskGetTickCount(); | ||
|
||
eps_buffer_read(EPS2_PARAM_ID_BAT_HEATER_1_MODE, &heater_mode); | ||
switch(heater_mode) | ||
{ | ||
case HEATER_AUTOMATIC_MODE: | ||
if(heater_get_sensor(HEATER_CONTROL_LOOP_CH_0, &temp) != 0) | ||
{ | ||
sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_HEATER_CONTROLLER_NAME, "Heater channel 0 failed (get_sensor)!"); | ||
sys_log_new_line(); | ||
break; | ||
} | ||
|
||
actuator_output = heater_algorithm(PID_BASE_SET_POINT, temp); | ||
|
||
if(heater_set_actuator(HEATER_CONTROL_LOOP_CH_0, actuator_output) != 0) | ||
{ | ||
sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_HEATER_CONTROLLER_NAME, "Heater channel 0 failed (set_actuator)!"); | ||
sys_log_new_line(); | ||
break; | ||
} | ||
break; | ||
case HEATER_MANUAL_MODE: | ||
/* TODO: Implement manual mode */ | ||
break; | ||
default: | ||
sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_HEATER_CONTROLLER_NAME, "Invalid mode!"); | ||
sys_log_new_line(); | ||
break; | ||
} | ||
|
||
eps_buffer_read(EPS2_PARAM_ID_BAT_HEATER_2_MODE, &heater_mode); | ||
switch(heater_mode) | ||
{ | ||
case HEATER_AUTOMATIC_MODE: | ||
if(heater_get_sensor(HEATER_CONTROL_LOOP_CH_1, &temp) != 0) | ||
{ | ||
sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_HEATER_CONTROLLER_NAME, "Heater channel 1 failed (get_sensor)!"); | ||
sys_log_new_line(); | ||
break; | ||
} | ||
|
||
actuator_output = heater_algorithm(PID_BASE_SET_POINT, temp); | ||
|
||
if(heater_set_actuator(HEATER_CONTROL_LOOP_CH_1, actuator_output) != 0) | ||
{ | ||
sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_HEATER_CONTROLLER_NAME, "Heater channel 1 failed (set_actuator)!"); | ||
sys_log_new_line(); | ||
break; | ||
} | ||
break; | ||
case HEATER_MANUAL_MODE: | ||
/* TODO: Implement manual mode */ | ||
break; | ||
default: | ||
sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_HEATER_CONTROLLER_NAME, "Invalid mode!"); | ||
sys_log_new_line(); | ||
break; | ||
} | ||
/* Heater 1 */ | ||
eps_buffer_read(EPS2_PARAM_ID_BAT_HEATER_1_MODE, &heater_mode); | ||
|
||
heater_control(HEATER_CONTROL_LOOP_CH_0, heater_mode); | ||
|
||
/* Heater 2 */ | ||
eps_buffer_read(EPS2_PARAM_ID_BAT_HEATER_2_MODE, &heater_mode); | ||
|
||
heater_control(HEATER_CONTROL_LOOP_CH_1, heater_mode); | ||
|
||
vTaskDelayUntil(&last_cycle, pdMS_TO_TICKS(TASK_HEATER_CONTROLLER_PERIOD_MS)); | ||
} | ||
} | ||
|
||
void heater_control(int channel, uint32_t mode) | ||
{ | ||
switch(mode) | ||
{ | ||
case HEATER_AUTOMATIC_MODE: | ||
{ | ||
temperature_t temp = 0; | ||
|
||
if (heater_get_sensor(channel, &temp) == 0) | ||
{ | ||
if (heater_set_actuator(channel, heater_algorithm(PID_BASE_SET_POINT, temp)) != 0) | ||
{ | ||
sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_HEATER_CONTROLLER_NAME, "Heater channel "); | ||
sys_log_print_uint(channel); | ||
sys_log_print_msg(" failed! (set_actuator)"); | ||
sys_log_new_line(); | ||
} | ||
} | ||
else | ||
{ | ||
sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_HEATER_CONTROLLER_NAME, "Heater channel "); | ||
sys_log_print_uint(channel); | ||
sys_log_print_msg(" failed! (get_sensor)"); | ||
sys_log_new_line(); | ||
} | ||
|
||
break; | ||
} | ||
case HEATER_MANUAL_MODE: | ||
/* TODO: Implement manual mode */ | ||
break; | ||
default: | ||
sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_HEATER_CONTROLLER_NAME, "Invalid mode!"); | ||
sys_log_new_line(); | ||
|
||
break; | ||
} | ||
} | ||
|
||
/** \} End of heater_controller group */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* heater_controller.h | ||
* | ||
* Copyright (C) 2021, SpaceLab. | ||
* Copyright The EPS 2.0 Contributors. | ||
* | ||
* This file is part of EPS 2.0. | ||
* | ||
|
@@ -25,7 +25,7 @@ | |
* | ||
* \author André M. P. de Mattos <[email protected]> | ||
* | ||
* \version 0.2.12 | ||
* \version 0.2.36 | ||
* | ||
* \date 2021/08/04 | ||
* | ||
|
@@ -43,11 +43,12 @@ | |
#define TASK_HEATER_CONTROLLER_NAME "Heater Controller" /**< Task name. */ | ||
#define TASK_HEATER_CONTROLLER_STACK_SIZE 160 /**< Memory stack size in bytes. */ | ||
#define TASK_HEATER_CONTROLLER_PRIORITY 3 /**< Priority. */ | ||
#define TASK_HEATER_CONTROLLER_PERIOD_MS 500 /**< Period in milliseconds. */ | ||
#define TASK_HEATER_CONTROLLER_PERIOD_MS 2000 /**< Period in milliseconds. */ | ||
#define TASK_HEATER_CONTROLLER_INIT_TIMEOUT_MS 2000 /**< Wait time to initialize the task in milliseconds. */ | ||
|
||
#define HEATER_AUTOMATIC_MODE 0x00 | ||
#define HEATER_MANUAL_MODE 0x01 | ||
/* Heater modes */ | ||
#define HEATER_AUTOMATIC_MODE 0 | ||
#define HEATER_MANUAL_MODE 1 | ||
|
||
/** | ||
* \brief Heater controller task handle. | ||
|
@@ -57,11 +58,9 @@ extern xTaskHandle xTaskHeaterControllerHandle; | |
/** | ||
* \brief Heater controller task. | ||
* | ||
* \param[in] pvParameters is a value that will passed as the task's parameter. | ||
* | ||
* \return None. | ||
*/ | ||
void vTaskHeaterController(void *pvParameters); | ||
void vTaskHeaterController(void); | ||
|
||
#endif /* HEATER_CONTROLLER_H_ */ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ | |
* | ||
* \author Gabriel Mariano Marcelino <[email protected]> | ||
* | ||
* \version 0.2.35 | ||
* \version 0.2.36 | ||
* | ||
* \date 2020/10/21 | ||
* | ||
|
@@ -36,7 +36,7 @@ | |
#ifndef VERSION_H_ | ||
#define VERSION_H_ | ||
|
||
#define FIRMWARE_VERSION "0.2.35" | ||
#define FIRMWARE_VERSION "0.2.36" | ||
|
||
#define FIRMWARE_STATUS "Development" | ||
|
||
|