pid adjusts

master
Ondřej Hruška 2 years ago
parent 0d79379438
commit 39e143d186
  1. 4
      Core/Src/Gui/screen_calibration.c
  2. 2
      Core/Src/app_heater.c
  3. 2
      Core/Src/app_knob.c
  4. 17
      Core/Src/app_pid.c
  5. 3
      Core/Src/app_pid.h

@ -81,6 +81,7 @@ static void sample1_menu_cb(int opt) {
// Continue // Continue
next_phase(); next_phase();
request_paint(); request_paint();
s_calib.temp1 = 100;
s_calib.sample1 = app_temp_read_oven_raw(); s_calib.sample1 = app_temp_read_oven_raw();
app_heater_enable(false); app_heater_enable(false);
break; break;
@ -104,6 +105,7 @@ static void sample2_menu_cb(int opt) {
// Continue // Continue
next_phase(); next_phase();
request_paint(); request_paint();
s_calib.temp2 = 200;
s_calib.sample2 = app_temp_read_oven_raw(); s_calib.sample2 = app_temp_read_oven_raw();
app_heater_enable(false); app_heater_enable(false);
break; break;
@ -197,6 +199,8 @@ void screen_calibration(GuiEvent event)
next_phase(); next_phase();
request_paint(); request_paint();
PRINTF("KNOB_REL PH %d\r\n", s_calib.phase);
if (s_calib.phase == PH_DONE) { if (s_calib.phase == PH_DONE) {
app_heater_set_target(0); app_heater_set_target(0);
app_heater_enable(false); app_heater_enable(false);

@ -188,6 +188,8 @@ void app_task_heater(void *argument)
heaterEnterCritical(); heaterEnterCritical();
// TODO load from flash // TODO load from flash
PID_SetTunings(&state.pid, state.tuning_p, state.tuning_i, state.tuning_d); PID_SetTunings(&state.pid, state.tuning_p, state.tuning_i, state.tuning_d);
PID_SetOutputLimits(&state.pid, 0, 100);
PID_SetITermLimits(&state.pid, 0, 100);
PID_Initialize(&state.pid); PID_Initialize(&state.pid);
heaterExitCritical(); heaterExitCritical();

@ -71,7 +71,7 @@ bool app_knob_pushed() {
void app_knob_push_isr(bool push) void app_knob_push_isr(bool push)
{ {
PUTCHAR(push ? '#' : '.'); //PUTCHAR(push ? '#' : '.');
BaseType_t yield = pdFALSE; BaseType_t yield = pdFALSE;
if (push) { if (push) {

@ -13,8 +13,8 @@ static void clampOutput(struct PID *self)
static void clampIterm(struct PID *self) static void clampIterm(struct PID *self)
{ {
if (self->ITerm > self->outMax) { self->ITerm = self->outMax; } if (self->ITerm > self->iTermMax) { self->ITerm = self->iTermMax; }
else if (self->ITerm < self->outMin) { self->ITerm = self->outMin; } else if (self->ITerm < self->iTermMin) { self->ITerm = self->iTermMin; }
} }
void PID_Compute(struct PID *self, float input) void PID_Compute(struct PID *self, float input)
@ -32,6 +32,11 @@ void PID_Compute(struct PID *self, float input)
clampIterm(self); clampIterm(self);
// Shortcut to reduce overshoot
if (error < 0 && self->ITerm > 0) {
self->ITerm = 0;
}
float dInput = (input - self->lastInput); float dInput = (input - self->lastInput);
@ -91,6 +96,14 @@ void PID_SetOutputLimits(struct PID *self, float min, float max)
self->outMax = max; self->outMax = max;
clampOutput(self); clampOutput(self);
}
void PID_SetITermLimits(struct PID *self, float min, float max)
{
if (min > max) { return; }
self->iTermMin = min;
self->iTermMax = max;
clampIterm(self); clampIterm(self);
} }

@ -27,6 +27,7 @@ struct PID {
float kp, ki, kd; float kp, ki, kd;
uint32_t SampleTimeTicks; uint32_t SampleTimeTicks;
float outMin, outMax; float outMin, outMax;
float iTermMin, iTermMax;
enum PIDCtlMode ctlMode; // false enum PIDCtlMode ctlMode; // false
enum PIDDirection controllerDirection; enum PIDDirection controllerDirection;
}; };
@ -41,6 +42,8 @@ void PID_SetSampleTime(struct PID *self, uint32_t new_sample_time);
void PID_SetOutputLimits(struct PID *self, float min, float max); void PID_SetOutputLimits(struct PID *self, float min, float max);
void PID_SetITermLimits(struct PID *self, float min, float max);
void PID_SetCtlMode(struct PID *self, enum PIDCtlMode mode); void PID_SetCtlMode(struct PID *self, enum PIDCtlMode mode);
void PID_Initialize(struct PID *self); void PID_Initialize(struct PID *self);

Loading…
Cancel
Save