Issue #28: Write temperture ramp command
This commit is contained in:
parent
5ab911b4b6
commit
60104df30e
@ -115,9 +115,40 @@ static bool cmd_set_temp(struct pl_command *cmd, bool cmd_continue)
|
||||
|
||||
reactivate_pid_if_suspended();
|
||||
oven_pid_set_target_temperature(cmd->params[0]);
|
||||
state.setpoint = cmd->params[0];
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool cmd_ramp(struct pl_command *cmd, bool cmd_continue)
|
||||
{
|
||||
static uint64_t start_timestamp;
|
||||
static float start_temp;
|
||||
static float slope;
|
||||
float secs_passed;
|
||||
bool ret = false;
|
||||
|
||||
if (!cmd_continue) {
|
||||
/* Init of command */
|
||||
start_temp = state.setpoint;
|
||||
slope = (cmd->params[0] - start_temp) / cmd->params[1];
|
||||
reactivate_pid_if_suspended();
|
||||
oven_pid_set_target_temperature(start_temp);
|
||||
start_timestamp = systick_get_global_tick();
|
||||
} else {
|
||||
secs_passed = ((float)(systick_get_global_tick() - start_timestamp)) / 1000.0f;
|
||||
if ((state.setpoint <= cmd->params[0] && start_temp < cmd->params[0]) ||
|
||||
(state.setpoint >= cmd->params[0] && start_temp > cmd->params[0])) {
|
||||
state.setpoint = start_temp + secs_passed * slope;
|
||||
} else {
|
||||
state.setpoint = cmd->params[0];
|
||||
ret = true;
|
||||
}
|
||||
oven_pid_set_target_temperature(state.setpoint);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int temp_profile_executer_handle(void)
|
||||
{
|
||||
struct pl_command *current_cmd;
|
||||
@ -171,7 +202,7 @@ int temp_profile_executer_handle(void)
|
||||
pid_should_run = true;
|
||||
break;
|
||||
case PL_SET_RAMP:
|
||||
advance = true;
|
||||
advance = cmd_ramp(current_cmd, cmd_continue);
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
|
Loading…
Reference in New Issue
Block a user