|
@@ -99,6 +99,12 @@ static volatile bool temp_meas_ready = false;
|
99
|
99
|
static float pTerm[EXTRUDERS];
|
100
|
100
|
static float iTerm[EXTRUDERS];
|
101
|
101
|
static float dTerm[EXTRUDERS];
|
|
102
|
+ #if ENABLED(PID_ADD_EXTRUSION_RATE)
|
|
103
|
+ static float cTerm[EXTRUDERS];
|
|
104
|
+ static long last_position[EXTRUDERS];
|
|
105
|
+ static long lpq[LPQ_MAX_LEN];
|
|
106
|
+ static int lpq_ptr = 0;
|
|
107
|
+ #endif
|
102
|
108
|
//int output;
|
103
|
109
|
static float pid_error[EXTRUDERS];
|
104
|
110
|
static float temp_iState_min[EXTRUDERS];
|
|
@@ -357,6 +363,9 @@ void updatePID() {
|
357
|
363
|
#if ENABLED(PIDTEMP)
|
358
|
364
|
for (int e = 0; e < EXTRUDERS; e++) {
|
359
|
365
|
temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / PID_PARAM(Ki,e);
|
|
366
|
+ #if ENABLED(PID_ADD_EXTRUSION_RATE)
|
|
367
|
+ last_position[e] = 0;
|
|
368
|
+ #endif
|
360
|
369
|
}
|
361
|
370
|
#endif
|
362
|
371
|
#if ENABLED(PIDTEMPBED)
|
|
@@ -497,6 +506,23 @@ float get_pid_output(int e) {
|
497
|
506
|
iTerm[e] = PID_PARAM(Ki,e) * temp_iState[e];
|
498
|
507
|
|
499
|
508
|
pid_output = pTerm[e] + iTerm[e] - dTerm[e];
|
|
509
|
+
|
|
510
|
+ #if ENABLED(PID_ADD_EXTRUSION_RATE)
|
|
511
|
+ cTerm[e] = 0;
|
|
512
|
+ if (e == active_extruder) {
|
|
513
|
+ long e_position = st_get_position(E_AXIS);
|
|
514
|
+ if (e_position > last_position[e]) {
|
|
515
|
+ lpq[lpq_ptr++] = e_position - last_position[e];
|
|
516
|
+ last_position[e] = e_position;
|
|
517
|
+ } else {
|
|
518
|
+ lpq[lpq_ptr++] = 0;
|
|
519
|
+ }
|
|
520
|
+ if (lpq_ptr >= lpq_len) lpq_ptr = 0;
|
|
521
|
+ cTerm[e] = (lpq[lpq_ptr] / axis_steps_per_unit[E_AXIS]) * Kc;
|
|
522
|
+ pid_output += cTerm[e];
|
|
523
|
+ }
|
|
524
|
+ #endif //PID_ADD_EXTRUSION_RATE
|
|
525
|
+
|
500
|
526
|
if (pid_output > PID_MAX) {
|
501
|
527
|
if (pid_error[e] > 0) temp_iState[e] -= pid_error[e]; // conditional un-integration
|
502
|
528
|
pid_output = PID_MAX;
|
|
@@ -512,18 +538,16 @@ float get_pid_output(int e) {
|
512
|
538
|
|
513
|
539
|
#if ENABLED(PID_DEBUG)
|
514
|
540
|
SERIAL_ECHO_START;
|
515
|
|
- SERIAL_ECHO(MSG_PID_DEBUG);
|
516
|
|
- SERIAL_ECHO(e);
|
517
|
|
- SERIAL_ECHO(MSG_PID_DEBUG_INPUT);
|
518
|
|
- SERIAL_ECHO(current_temperature[e]);
|
519
|
|
- SERIAL_ECHO(MSG_PID_DEBUG_OUTPUT);
|
520
|
|
- SERIAL_ECHO(pid_output);
|
521
|
|
- SERIAL_ECHO(MSG_PID_DEBUG_PTERM);
|
522
|
|
- SERIAL_ECHO(pTerm[e]);
|
523
|
|
- SERIAL_ECHO(MSG_PID_DEBUG_ITERM);
|
524
|
|
- SERIAL_ECHO(iTerm[e]);
|
525
|
|
- SERIAL_ECHO(MSG_PID_DEBUG_DTERM);
|
526
|
|
- SERIAL_ECHOLN(dTerm[e]);
|
|
541
|
+ SERIAL_ECHOPAIR(MSG_PID_DEBUG, e);
|
|
542
|
+ SERIAL_ECHOPAIR(MSG_PID_DEBUG_INPUT, current_temperature[e]);
|
|
543
|
+ SERIAL_ECHOPAIR(MSG_PID_DEBUG_OUTPUT, pid_output);
|
|
544
|
+ SERIAL_ECHOPAIR(MSG_PID_DEBUG_PTERM, pTerm[e]);
|
|
545
|
+ SERIAL_ECHOPAIR(MSG_PID_DEBUG_ITERM, iTerm[e]);
|
|
546
|
+ SERIAL_ECHOPAIR(MSG_PID_DEBUG_DTERM, dTerm[e]);
|
|
547
|
+ #if ENABLED(PID_ADD_EXTRUSION_RATE)
|
|
548
|
+ SERIAL_ECHOPAIR(MSG_PID_DEBUG_CTERM, cTerm[e]);
|
|
549
|
+ #endif
|
|
550
|
+ SERIAL_EOL;
|
527
|
551
|
#endif //PID_DEBUG
|
528
|
552
|
|
529
|
553
|
#else /* PID off */
|
|
@@ -837,6 +861,9 @@ void tp_init() {
|
837
|
861
|
#if ENABLED(PIDTEMP)
|
838
|
862
|
temp_iState_min[e] = 0.0;
|
839
|
863
|
temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / PID_PARAM(Ki,e);
|
|
864
|
+ #if ENABLED(PID_ADD_EXTRUSION_RATE)
|
|
865
|
+ last_position[e] = 0;
|
|
866
|
+ #endif
|
840
|
867
|
#endif //PIDTEMP
|
841
|
868
|
#if ENABLED(PIDTEMPBED)
|
842
|
869
|
temp_iState_min_bed = 0.0;
|