Skip to content

Commit

Permalink
tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Dec 17, 2022
1 parent 3fc9f34 commit e4d9b52
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 49 deletions.
8 changes: 7 additions & 1 deletion Marlin/src/module/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1347,15 +1347,21 @@ void Temperature::min_temp_error(const heater_id_t heater_id) {
return constrain(tempinfo.target, 0, MAX_POW);

#else // !PID_OPENLOOP

float out = tempinfo.pid.get_pid_output(tempinfo.target, tempinfo.celsius);

#if ENABLED(PID_FAN_SCALING)
out += tempinfo.pid.get_fan_scale_output(thermalManager.fan_speed[extr]);
#endif

#if ENABLED(PID_EXTRUSION_SCALING)
out += tempinfo.pid.get_extrusion_scale_output(
extr == active_extruder, stepper.position(E_AXIS), planner.mm_per_step[E_AXIS], thermalManager.lpq_len);
extr == active_extruder, stepper.position(E_AXIS), planner.mm_per_step[E_AXIS], thermalManager.lpq_len
);
#endif

return constrain(out, tempinfo.pid.low(), tempinfo.pid.high());

#endif // !PID_OPENLOOP
}

Expand Down
56 changes: 16 additions & 40 deletions Marlin/src/module/temperature.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ typedef struct { float p, i, d, c, f; } raw_pidcf_t;
struct PID_t{
protected:
bool pid_reset = true;
float temp_iState = 0.0f;
float temp_dState = 0.0f;
float temp_iState = 0.0f, temp_dState = 0.0f;
float work_p = 0, work_i = 0, work_d = 0;

public:
Expand All @@ -192,25 +191,14 @@ typedef struct { float p, i, d, c, f; } raw_pidcf_t;
void set_Kf(float) {}
int low() const { return MIN_POW; }
int high() const { return MAX_POW; }
void reset() {
pid_reset = true;
}
void reset() { pid_reset = true; }
void set(float p, float i, float d, float c=1, float f=0) { set_Kp(p); set_Ki(i); set_Kd(d); set_Kc(c); set_Kf(f); }
void set(const raw_pid_t &raw) { set(raw.p, raw.i, raw.d); }
void set(const raw_pidcf_t &raw) { set(raw.p, raw.i, raw.d, raw.c, raw.f); }

float get_fan_scale_output(const uint8_t fan_speed) {
UNUSED(fan_speed);
return 0;
}
float get_fan_scale_output(const uint8_t) { return 0; }

float get_extrusion_scale_output(const bool is_active, const long e_position, const float e_mm_per_step, const int16_t lpq_len) {
UNUSED(is_active);
UNUSED(e_position);
UNUSED(e_mm_per_step);
UNUSED(lpq_len);
return 0;
}
float get_extrusion_scale_output(const bool, const int32_t, const float, const int16_t) { return 0; }

float get_pid_output(const float target, const float current) {
const float pid_error = target - current;
Expand Down Expand Up @@ -274,29 +262,24 @@ typedef struct { float p, i, d, c, f; } raw_pidcf_t;
base::reset();
prev_e_pos = 0;
lpq_ptr = 0;
LOOP_L_N(i, LPQ_ARR_SZ) {
lpq[i] = 0;
}
LOOP_L_N(i, LPQ_ARR_SZ) lpq[i] = 0;
}

float get_extrusion_scale_output(const bool is_active, const long e_position, const float e_mm_per_step, const int16_t lpq_len) {
float get_extrusion_scale_output(const bool is_active, const int32_t e_position, const float e_mm_per_step, const int16_t lpq_len) {
work_c = 0;
if (!is_active) {
return work_c; // 0
}
if (!is_active) return work_c;

if (e_position > prev_e_pos) {
lpq[lpq_ptr] = e_position - prev_e_pos;
prev_e_pos = e_position;
}
else {
else
lpq[lpq_ptr] = 0;
}

++lpq_ptr;
if (lpq_ptr >= LPQ_ARR_SZ || lpq_ptr >= lpq_len) {

if (lpq_ptr >= LPQ_ARR_SZ || lpq_ptr >= lpq_len)
lpq_ptr = 0;
}

work_c = (lpq[lpq_ptr] * e_mm_per_step) * Kc;

Expand Down Expand Up @@ -331,9 +314,9 @@ typedef struct { float p, i, d, c, f; } raw_pidcf_t;

float get_fan_scale_output(const uint8_t fan_speed) {
work_f = 0;
if (fan_speed > SCALE_MIN_SPEED) {
if (fan_speed > SCALE_MIN_SPEED)
work_f = Kf + (SCALE_LIN_FACTOR) * fan_speed;
}

return work_f;
}
};
Expand Down Expand Up @@ -363,18 +346,13 @@ typedef struct { float p, i, d, c, f; } raw_pidcf_t;
void set(const raw_pid_t &raw) { set(raw.p, raw.i, raw.d); }
void set(const raw_pidcf_t &raw) { set(raw.p, raw.i, raw.d, raw.c, raw.f); }

void reset() {
cPID::reset();
}
void reset() { cPID::reset(); }

float get_fan_scale_output(const uint8_t fan_speed) {
work_f = 0;
if (fan_speed > SCALE_MIN_SPEED) {
work_f = Kf + (SCALE_LIN_FACTOR) * fan_speed;
}
work_f = fan_speed > (SCALE_MIN_SPEED) ? Kf + (SCALE_LIN_FACTOR) * fan_speed : 0;
return work_f;
}
float get_extrusion_scale_output(const bool is_active, const long e_position, const float e_mm_per_step, const int16_t lpq_len) {
float get_extrusion_scale_output(const bool is_active, const int32_t e_position, const float e_mm_per_step, const int16_t lpq_len) {
return cPID::get_extrusion_scale_output(is_active, e_position, e_mm_per_step, lpq_len);
}
};
Expand Down Expand Up @@ -1174,9 +1152,7 @@ class Temperature {

// Update the temp manager when PID values change
#if ENABLED(PIDTEMP)
static void updatePID() {
HOTEND_LOOP() temp_hotend[e].pid.reset();
}
static void updatePID() { HOTEND_LOOP() temp_hotend[e].pid.reset(); }
static void setPID(const uint8_t hotend, const_float_t p, const_float_t i, const_float_t d) {
#if ENABLED(PID_PARAMS_PER_HOTEND)
temp_hotend[hotend].pid.set(p, i, d);
Expand Down
11 changes: 3 additions & 8 deletions buildroot/tests/LPC1768
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,9 @@ opt_enable REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER ADAPTIVE_FAN_SLOWING NO
exec_test $1 $2 "Re-ARM with NOZZLE_AS_PROBE and many features." "$3"

restore_configs
opt_set MOTHERBOARD BOARD_BTT_SKR_V1_3 \
EXTRUDERS 2 \
TEMP_SENSOR_0 1 \
TEMP_SENSOR_1 1 \
TEMP_SENSOR_BED 1 \
TEMP_SENSOR_CHAMBER 1 \
TEMP_CHAMBER_PIN P1_30 \
HEATER_CHAMBER_PIN P0_28
opt_set MOTHERBOARD BOARD_BTT_SKR_V1_3 EXTRUDERS 2 \
TEMP_SENSOR_0 1 TEMP_SENSOR_1 1 TEMP_SENSOR_BED 1 TEMP_SENSOR_CHAMBER 1 \
TEMP_CHAMBER_PIN P1_30 HEATER_CHAMBER_PIN P0_28
opt_enable PIDTEMPBED PIDTEMPCHAMBER PID_EXTRUSION_SCALING PID_FAN_SCALING
exec_test $1 $2 "SKR v1.3 with 2*Extr, bed, chamber all PID." "$3"

Expand Down

0 comments on commit e4d9b52

Please sign in to comment.