Skip to content

Commit f81634a

Browse files
committed
tweak
1 parent 3fc9f34 commit f81634a

File tree

3 files changed

+28
-51
lines changed

3 files changed

+28
-51
lines changed

Marlin/src/module/temperature.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -1341,21 +1341,27 @@ void Temperature::min_temp_error(const heater_id_t heater_id) {
13411341

13421342
PIDRunner(TT &t) : tempinfo(t) { }
13431343

1344-
float get_pid_output(int extr=0) {
1344+
float get_pid_output(const uint8_t extr=0) {
13451345
#if ENABLED(PID_OPENLOOP)
13461346

13471347
return constrain(tempinfo.target, 0, MAX_POW);
13481348

13491349
#else // !PID_OPENLOOP
1350+
13501351
float out = tempinfo.pid.get_pid_output(tempinfo.target, tempinfo.celsius);
1352+
13511353
#if ENABLED(PID_FAN_SCALING)
13521354
out += tempinfo.pid.get_fan_scale_output(thermalManager.fan_speed[extr]);
13531355
#endif
1356+
13541357
#if ENABLED(PID_EXTRUSION_SCALING)
13551358
out += tempinfo.pid.get_extrusion_scale_output(
1356-
extr == active_extruder, stepper.position(E_AXIS), planner.mm_per_step[E_AXIS], thermalManager.lpq_len);
1359+
extr == active_extruder, stepper.position(E_AXIS), planner.mm_per_step[E_AXIS], thermalManager.lpq_len
1360+
);
13571361
#endif
1362+
13581363
return constrain(out, tempinfo.pid.low(), tempinfo.pid.high());
1364+
13591365
#endif // !PID_OPENLOOP
13601366
}
13611367

@@ -1394,7 +1400,7 @@ void Temperature::min_temp_error(const heater_id_t heater_id) {
13941400
REPEAT(HOTENDS, _HOTENDPID)
13951401
};
13961402

1397-
const float pid_output = is_idling ? 0 : hotend_pid[ee].get_pid_output(HOTEND_INDEX);
1403+
const float pid_output = is_idling ? 0 : hotend_pid[ee].get_pid_output(ee);
13981404

13991405
#if ENABLED(PID_DEBUG)
14001406
if (ee == active_extruder)

Marlin/src/module/temperature.h

+16-40
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,7 @@ typedef struct { float p, i, d, c, f; } raw_pidcf_t;
169169
struct PID_t{
170170
protected:
171171
bool pid_reset = true;
172-
float temp_iState = 0.0f;
173-
float temp_dState = 0.0f;
172+
float temp_iState = 0.0f, temp_dState = 0.0f;
174173
float work_p = 0, work_i = 0, work_d = 0;
175174

176175
public:
@@ -192,25 +191,14 @@ typedef struct { float p, i, d, c, f; } raw_pidcf_t;
192191
void set_Kf(float) {}
193192
int low() const { return MIN_POW; }
194193
int high() const { return MAX_POW; }
195-
void reset() {
196-
pid_reset = true;
197-
}
194+
void reset() { pid_reset = true; }
198195
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); }
199196
void set(const raw_pid_t &raw) { set(raw.p, raw.i, raw.d); }
200197
void set(const raw_pidcf_t &raw) { set(raw.p, raw.i, raw.d, raw.c, raw.f); }
201198

202-
float get_fan_scale_output(const uint8_t fan_speed) {
203-
UNUSED(fan_speed);
204-
return 0;
205-
}
199+
float get_fan_scale_output(const uint8_t) { return 0; }
206200

207-
float get_extrusion_scale_output(const bool is_active, const long e_position, const float e_mm_per_step, const int16_t lpq_len) {
208-
UNUSED(is_active);
209-
UNUSED(e_position);
210-
UNUSED(e_mm_per_step);
211-
UNUSED(lpq_len);
212-
return 0;
213-
}
201+
float get_extrusion_scale_output(const bool, const int32_t, const float, const int16_t) { return 0; }
214202

215203
float get_pid_output(const float target, const float current) {
216204
const float pid_error = target - current;
@@ -274,29 +262,24 @@ typedef struct { float p, i, d, c, f; } raw_pidcf_t;
274262
base::reset();
275263
prev_e_pos = 0;
276264
lpq_ptr = 0;
277-
LOOP_L_N(i, LPQ_ARR_SZ) {
278-
lpq[i] = 0;
279-
}
265+
LOOP_L_N(i, LPQ_ARR_SZ) lpq[i] = 0;
280266
}
281267

282-
float get_extrusion_scale_output(const bool is_active, const long e_position, const float e_mm_per_step, const int16_t lpq_len) {
268+
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) {
283269
work_c = 0;
284-
if (!is_active) {
285-
return work_c; // 0
286-
}
270+
if (!is_active) return work_c;
287271

288272
if (e_position > prev_e_pos) {
289273
lpq[lpq_ptr] = e_position - prev_e_pos;
290274
prev_e_pos = e_position;
291275
}
292-
else {
276+
else
293277
lpq[lpq_ptr] = 0;
294-
}
295278

296279
++lpq_ptr;
297-
if (lpq_ptr >= LPQ_ARR_SZ || lpq_ptr >= lpq_len) {
280+
281+
if (lpq_ptr >= LPQ_ARR_SZ || lpq_ptr >= lpq_len)
298282
lpq_ptr = 0;
299-
}
300283

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

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

332315
float get_fan_scale_output(const uint8_t fan_speed) {
333316
work_f = 0;
334-
if (fan_speed > SCALE_MIN_SPEED) {
317+
if (fan_speed > SCALE_MIN_SPEED)
335318
work_f = Kf + (SCALE_LIN_FACTOR) * fan_speed;
336-
}
319+
337320
return work_f;
338321
}
339322
};
@@ -363,18 +346,13 @@ typedef struct { float p, i, d, c, f; } raw_pidcf_t;
363346
void set(const raw_pid_t &raw) { set(raw.p, raw.i, raw.d); }
364347
void set(const raw_pidcf_t &raw) { set(raw.p, raw.i, raw.d, raw.c, raw.f); }
365348

366-
void reset() {
367-
cPID::reset();
368-
}
349+
void reset() { cPID::reset(); }
369350

370351
float get_fan_scale_output(const uint8_t fan_speed) {
371-
work_f = 0;
372-
if (fan_speed > SCALE_MIN_SPEED) {
373-
work_f = Kf + (SCALE_LIN_FACTOR) * fan_speed;
374-
}
352+
work_f = fan_speed > (SCALE_MIN_SPEED) ? Kf + (SCALE_LIN_FACTOR) * fan_speed : 0;
375353
return work_f;
376354
}
377-
float get_extrusion_scale_output(const bool is_active, const long e_position, const float e_mm_per_step, const int16_t lpq_len) {
355+
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) {
378356
return cPID::get_extrusion_scale_output(is_active, e_position, e_mm_per_step, lpq_len);
379357
}
380358
};
@@ -1174,9 +1152,7 @@ class Temperature {
11741152

11751153
// Update the temp manager when PID values change
11761154
#if ENABLED(PIDTEMP)
1177-
static void updatePID() {
1178-
HOTEND_LOOP() temp_hotend[e].pid.reset();
1179-
}
1155+
static void updatePID() { HOTEND_LOOP() temp_hotend[e].pid.reset(); }
11801156
static void setPID(const uint8_t hotend, const_float_t p, const_float_t i, const_float_t d) {
11811157
#if ENABLED(PID_PARAMS_PER_HOTEND)
11821158
temp_hotend[hotend].pid.set(p, i, d);

buildroot/tests/LPC1768

+3-8
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,9 @@ opt_enable REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER ADAPTIVE_FAN_SLOWING NO
5353
exec_test $1 $2 "Re-ARM with NOZZLE_AS_PROBE and many features." "$3"
5454

5555
restore_configs
56-
opt_set MOTHERBOARD BOARD_BTT_SKR_V1_3 \
57-
EXTRUDERS 2 \
58-
TEMP_SENSOR_0 1 \
59-
TEMP_SENSOR_1 1 \
60-
TEMP_SENSOR_BED 1 \
61-
TEMP_SENSOR_CHAMBER 1 \
62-
TEMP_CHAMBER_PIN P1_30 \
63-
HEATER_CHAMBER_PIN P0_28
56+
opt_set MOTHERBOARD BOARD_BTT_SKR_V1_3 EXTRUDERS 2 \
57+
TEMP_SENSOR_0 1 TEMP_SENSOR_1 1 TEMP_SENSOR_BED 1 TEMP_SENSOR_CHAMBER 1 \
58+
TEMP_CHAMBER_PIN P1_30 HEATER_CHAMBER_PIN P0_28
6459
opt_enable PIDTEMPBED PIDTEMPCHAMBER PID_EXTRUSION_SCALING PID_FAN_SCALING
6560
exec_test $1 $2 "SKR v1.3 with 2*Extr, bed, chamber all PID." "$3"
6661

0 commit comments

Comments
 (0)