Skip to content

Commit

Permalink
firmware: app: tasks: heater_controller: Add manual mode implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ramonborba committed Oct 25, 2022
1 parent dff96a1 commit c2555bf
Showing 1 changed file with 51 additions and 6 deletions.
57 changes: 51 additions & 6 deletions firmware/app/tasks/heater_controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include <system/sys_log/sys_log.h>
#include <structs/eps2_data.h>

// #include <devices/heater/heater.h>
#include <devices/heater/heater.h>
#include <devices/heater/heater_on_off.h>

#include "heater_controller.h"
Expand All @@ -62,13 +62,20 @@ xTaskHandle xTaskHeaterControllerHandle;
* .
* \endparblock
*
* \param[in] duty_cycle is the heater pwm duty cycle. It can be:
* \parblock
* - 1 to 100 (duty cycle percentage)
* .
* \endparblock
*
* \return None.
*/
void heater_control(int channel, uint32_t mode);
void heater_control(int channel, uint32_t mode, uint32_t duty_cycle);

void vTaskHeaterController(void)
{
uint32_t heater_mode = 0;
uint32_t heater_dt_cycle = 0;

/* Wait startup task to finish */
xEventGroupWaitBits(task_startup_status, TASK_STARTUP_DONE, pdFALSE, pdTRUE, pdMS_TO_TICKS(TASK_HEATER_CONTROLLER_INIT_TIMEOUT_MS));
Expand All @@ -79,25 +86,43 @@ void vTaskHeaterController(void)

/* Heater 1 */
eps_buffer_read(EPS2_PARAM_ID_BAT_HEATER_1_MODE, &heater_mode);
eps_buffer_read(EPS2_PARAM_ID_BAT_HEATER_1_DUTY_CYCLE, &heater_dt_cycle);

heater_control(HEATER_CONTROL_LOOP_CH_0, heater_mode);
heater_control(HEATER_CONTROL_LOOP_CH_0, heater_mode, heater_dt_cycle);

/* Heater 2 */
eps_buffer_read(EPS2_PARAM_ID_BAT_HEATER_2_MODE, &heater_mode);
eps_buffer_read(EPS2_PARAM_ID_BAT_HEATER_2_DUTY_CYCLE, &heater_dt_cycle);

heater_control(HEATER_CONTROL_LOOP_CH_1, heater_mode);
heater_control(HEATER_CONTROL_LOOP_CH_1, heater_mode, heater_dt_cycle);

vTaskDelayUntil(&last_cycle, pdMS_TO_TICKS(TASK_HEATER_CONTROLLER_PERIOD_MS));
}
}

void heater_control(int channel, uint32_t mode)
void heater_control(int channel, uint32_t mode, uint32_t duty_cycle)
{

static uint32_t last_mode = HEATER_AUTOMATIC_MODE;

switch(mode)
{
case HEATER_AUTOMATIC_MODE:
{
temperature_t temp = 0;

if (last_mode != HEATER_AUTOMATIC_MODE)
{
if (heater_on_off_init())
{
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 on/off initialization!");
sys_log_new_line();
}
last_mode = HEATER_AUTOMATIC_MODE;
}


if (heater_on_off_get_sensor(channel, &temp) == 0)
{
Expand All @@ -123,8 +148,28 @@ void heater_control(int channel, uint32_t mode)
break;
}
case HEATER_MANUAL_MODE:
/* TODO: Implement manual mode */
{
if (last_mode != HEATER_MANUAL_MODE)
{
if (heater_init())
{
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 manual mode initialization!");
sys_log_new_line();
}
last_mode = HEATER_MANUAL_MODE;
}
if (heater_set_actuator(channel, (float)duty_cycle) != 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();
}

break;
}
default:
sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_HEATER_CONTROLLER_NAME, "Invalid mode!");
sys_log_new_line();
Expand Down

0 comments on commit c2555bf

Please sign in to comment.