@@ -169,8 +169,7 @@ typedef struct { float p, i, d, c, f; } raw_pidcf_t;
169
169
struct PID_t{
170
170
protected:
171
171
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 ;
174
173
float work_p = 0 , work_i = 0 , work_d = 0 ;
175
174
176
175
public:
@@ -192,25 +191,14 @@ typedef struct { float p, i, d, c, f; } raw_pidcf_t;
192
191
void set_Kf (float ) {}
193
192
int low () const { return MIN_POW; }
194
193
int high () const { return MAX_POW; }
195
- void reset () {
196
- pid_reset = true ;
197
- }
194
+ void reset () { pid_reset = true ; }
198
195
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); }
199
196
void set (const raw_pid_t &raw) { set (raw.p , raw.i , raw.d ); }
200
197
void set (const raw_pidcf_t &raw) { set (raw.p , raw.i , raw.d , raw.c , raw.f ); }
201
198
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 ; }
206
200
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 ; }
214
202
215
203
float get_pid_output (const float target, const float current) {
216
204
const float pid_error = target - current;
@@ -274,29 +262,24 @@ typedef struct { float p, i, d, c, f; } raw_pidcf_t;
274
262
base::reset ();
275
263
prev_e_pos = 0 ;
276
264
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 ;
280
266
}
281
267
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) {
283
269
work_c = 0 ;
284
- if (!is_active) {
285
- return work_c; // 0
286
- }
270
+ if (!is_active) return work_c;
287
271
288
272
if (e_position > prev_e_pos) {
289
273
lpq[lpq_ptr] = e_position - prev_e_pos;
290
274
prev_e_pos = e_position;
291
275
}
292
- else {
276
+ else
293
277
lpq[lpq_ptr] = 0 ;
294
- }
295
278
296
279
++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)
298
282
lpq_ptr = 0 ;
299
- }
300
283
301
284
work_c = (lpq[lpq_ptr] * e_mm_per_step) * Kc;
302
285
@@ -331,9 +314,9 @@ typedef struct { float p, i, d, c, f; } raw_pidcf_t;
331
314
332
315
float get_fan_scale_output (const uint8_t fan_speed) {
333
316
work_f = 0 ;
334
- if (fan_speed > SCALE_MIN_SPEED) {
317
+ if (fan_speed > SCALE_MIN_SPEED)
335
318
work_f = Kf + (SCALE_LIN_FACTOR) * fan_speed;
336
- }
319
+
337
320
return work_f;
338
321
}
339
322
};
@@ -363,18 +346,13 @@ typedef struct { float p, i, d, c, f; } raw_pidcf_t;
363
346
void set (const raw_pid_t &raw) { set (raw.p , raw.i , raw.d ); }
364
347
void set (const raw_pidcf_t &raw) { set (raw.p , raw.i , raw.d , raw.c , raw.f ); }
365
348
366
- void reset () {
367
- cPID::reset ();
368
- }
349
+ void reset () { cPID::reset (); }
369
350
370
351
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 ;
375
353
return work_f;
376
354
}
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) {
378
356
return cPID::get_extrusion_scale_output (is_active, e_position, e_mm_per_step, lpq_len);
379
357
}
380
358
};
@@ -1174,9 +1152,7 @@ class Temperature {
1174
1152
1175
1153
// Update the temp manager when PID values change
1176
1154
#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 (); }
1180
1156
static void setPID (const uint8_t hotend, const_float_t p, const_float_t i, const_float_t d) {
1181
1157
#if ENABLED(PID_PARAMS_PER_HOTEND)
1182
1158
temp_hotend[hotend].pid .set (p, i, d);
0 commit comments