@@ -534,10 +534,6 @@ PGMSTR(str_t_heating_failed, STR_T_HEATING_FAILED);
534
534
535
535
volatile bool Temperature::raw_temps_ready = false ;
536
536
537
- #if ENABLED(PID_EXTRUSION_SCALING)
538
- int32_t Temperature::pes_e_position, Temperature::lpq[LPQ_MAX_LEN];
539
- lpq_ptr_t Temperature::lpq_ptr = 0 ;
540
- #endif
541
537
542
538
#if ENABLED(MPCTEMP)
543
539
int32_t Temperature::mpc_e_position; // = 0
@@ -1338,50 +1334,33 @@ void Temperature::mintemp_error(const heater_id_t heater_id) {
1338
1334
1339
1335
#if HAS_PID_HEATING
1340
1336
1341
- template <typename TT, int MIN_POW, int MAX_POW >
1337
+ template <typename TT>
1342
1338
class PIDRunner {
1343
1339
public:
1344
1340
TT &tempinfo;
1345
- __typeof__ (TT::pid) work_pid{0 };
1346
- float temp_iState = 0 , temp_dState = 0 ;
1347
- bool pid_reset = true ;
1348
1341
1349
1342
PIDRunner (TT &t) : tempinfo(t) { }
1350
1343
1351
- float get_pid_output () {
1352
-
1344
+ float get_pid_output (const uint8_t extr=0 ) {
1353
1345
#if ENABLED(PID_OPENLOOP)
1354
1346
1355
1347
return constrain (tempinfo.target , 0 , MAX_POW);
1356
1348
1357
1349
#else // !PID_OPENLOOP
1358
1350
1359
- const float pid_error = tempinfo.target - tempinfo.celsius ;
1360
- if (!tempinfo.target || pid_error < -(PID_FUNCTIONAL_RANGE)) {
1361
- pid_reset = true ;
1362
- return 0 ;
1363
- }
1364
- else if (pid_error > PID_FUNCTIONAL_RANGE) {
1365
- pid_reset = true ;
1366
- return MAX_POW;
1367
- }
1351
+ float out = tempinfo.pid .get_pid_output (tempinfo.target , tempinfo.celsius );
1368
1352
1369
- if (pid_reset) {
1370
- pid_reset = false ;
1371
- temp_iState = 0.0 ;
1372
- work_pid.Kd = 0.0 ;
1373
- }
1374
-
1375
- const float max_power_over_i_gain = float (MAX_POW) / tempinfo.pid .Ki - float (MIN_POW);
1376
- temp_iState = constrain (temp_iState + pid_error, 0 , max_power_over_i_gain);
1377
-
1378
- work_pid.Kp = tempinfo.pid .Kp * pid_error;
1379
- work_pid.Ki = tempinfo.pid .Ki * temp_iState;
1380
- work_pid.Kd = work_pid.Kd + PID_K2 * (tempinfo.pid .Kd * (temp_dState - tempinfo.celsius ) - work_pid.Kd );
1353
+ #if ENABLED(PID_FAN_SCALING)
1354
+ out += tempinfo.pid .get_fan_scale_output (thermalManager.fan_speed [extr]);
1355
+ #endif
1381
1356
1382
- temp_dState = tempinfo.celsius ;
1357
+ #if ENABLED(PID_EXTRUSION_SCALING)
1358
+ out += tempinfo.pid .get_extrusion_scale_output (
1359
+ extr == active_extruder, stepper.position (E_AXIS), planner.mm_per_step [E_AXIS], thermalManager.lpq_len
1360
+ );
1361
+ #endif
1383
1362
1384
- return constrain (work_pid. Kp + work_pid. Ki + work_pid. Kd + float (MIN_POW ), 0 , MAX_POW );
1363
+ return constrain (out, tempinfo. pid . low ( ), tempinfo. pid . high () );
1385
1364
1386
1365
#endif // !PID_OPENLOOP
1387
1366
}
@@ -1395,7 +1374,8 @@ void Temperature::mintemp_error(const heater_id_t heater_id) {
1395
1374
STR_PID_DEBUG_INPUT, c,
1396
1375
STR_PID_DEBUG_OUTPUT, pid_out
1397
1376
#if DISABLED(PID_OPENLOOP)
1398
- , " pTerm " , work_pid.Kp , " iTerm " , work_pid.Ki , " dTerm " , work_pid.Kd
1377
+ , " pTerm " , tempinfo.pid .pTerm (), " iTerm " , tempinfo.pid .iTerm (), " dTerm " , tempinfo.pid .dTerm ()
1378
+ , " cTerm " , tempinfo.pid .cTerm (), " fTerm " , tempinfo.pid .fTerm ()
1399
1379
#endif
1400
1380
);
1401
1381
}
@@ -1413,14 +1393,14 @@ void Temperature::mintemp_error(const heater_id_t heater_id) {
1413
1393
1414
1394
#if ENABLED(PIDTEMP)
1415
1395
1416
- typedef PIDRunner<hotend_info_t , 0 , PID_MAX > PIDRunnerHotend;
1396
+ typedef PIDRunner<hotend_info_t > PIDRunnerHotend;
1417
1397
1418
1398
static PIDRunnerHotend hotend_pid[HOTENDS] = {
1419
1399
#define _HOTENDPID (E ) temp_hotend[E],
1420
1400
REPEAT (HOTENDS, _HOTENDPID)
1421
1401
};
1422
1402
1423
- const float pid_output = is_idling ? 0 : hotend_pid[ee].get_pid_output ();
1403
+ const float pid_output = is_idling ? 0 : hotend_pid[ee].get_pid_output (ee );
1424
1404
1425
1405
#if ENABLED(PID_DEBUG)
1426
1406
if (ee == active_extruder)
@@ -1521,7 +1501,7 @@ void Temperature::mintemp_error(const heater_id_t heater_id) {
1521
1501
#if ENABLED(PIDTEMPBED)
1522
1502
1523
1503
float Temperature::get_pid_output_bed () {
1524
- static PIDRunner<bed_info_t , MIN_BED_POWER, MAX_BED_POWER > bed_pid (temp_bed);
1504
+ static PIDRunner<bed_info_t > bed_pid (temp_bed);
1525
1505
const float pid_output = bed_pid.get_pid_output ();
1526
1506
TERN_ (PID_BED_DEBUG, bed_pid.debug (temp_bed.celsius , pid_output, F (" (Bed)" )));
1527
1507
return pid_output;
@@ -1532,7 +1512,7 @@ void Temperature::mintemp_error(const heater_id_t heater_id) {
1532
1512
#if ENABLED(PIDTEMPCHAMBER)
1533
1513
1534
1514
float Temperature::get_pid_output_chamber () {
1535
- static PIDRunner<chamber_info_t , MIN_CHAMBER_POWER, MAX_CHAMBER_POWER > chamber_pid (temp_chamber);
1515
+ static PIDRunner<chamber_info_t > chamber_pid (temp_chamber);
1536
1516
const float pid_output = chamber_pid.get_pid_output ();
1537
1517
TERN_ (PID_CHAMBER_DEBUG, chamber_pid.debug (temp_chamber.celsius , pid_output, F (" (Chamber)" )));
1538
1518
return pid_output;
@@ -2471,9 +2451,6 @@ void Temperature::init() {
2471
2451
2472
2452
TERN_ (PROBING_HEATERS_OFF, paused_for_probing = false );
2473
2453
2474
- #if BOTH(PIDTEMP, PID_EXTRUSION_SCALING)
2475
- pes_e_position = 0 ;
2476
- #endif
2477
2454
2478
2455
// Init (and disable) SPI thermocouples
2479
2456
#if TEMP_SENSOR_IS_ANY_MAX_TC(0) && PIN_EXISTS(TEMP_0_CS)
0 commit comments