Browse Source

Merge pull request #3525 from thinkyhead/rc_fix_pid_params_per_extruder

Fix broken PID_PARAMS_PER_EXTRUDER
Scott Lahteine 8 years ago
parent
commit
8429ae6beb
2 changed files with 37 additions and 31 deletions
  1. 29
    29
      Marlin/temperature.cpp
  2. 8
    2
      Marlin/temperature.h

+ 29
- 29
Marlin/temperature.cpp View File

231
 
231
 
232
   long bias, d;
232
   long bias, d;
233
   float Ku, Tu;
233
   float Ku, Tu;
234
-  float Kp = 0, Ki = 0, Kd = 0;
234
+  float workKp = 0, workKi = 0, workKd = 0;
235
   float max = 0, min = 10000;
235
   float max = 0, min = 10000;
236
 
236
 
237
   #if HAS_AUTO_FAN
237
   #if HAS_AUTO_FAN
309
               Tu = ((float)(t_low + t_high) / 1000.0);
309
               Tu = ((float)(t_low + t_high) / 1000.0);
310
               SERIAL_PROTOCOLPGM(MSG_KU); SERIAL_PROTOCOL(Ku);
310
               SERIAL_PROTOCOLPGM(MSG_KU); SERIAL_PROTOCOL(Ku);
311
               SERIAL_PROTOCOLPGM(MSG_TU); SERIAL_PROTOCOLLN(Tu);
311
               SERIAL_PROTOCOLPGM(MSG_TU); SERIAL_PROTOCOLLN(Tu);
312
-              Kp = 0.6 * Ku;
313
-              Ki = 2 * Kp / Tu;
314
-              Kd = Kp * Tu / 8;
312
+              workKp = 0.6 * Ku;
313
+              workKi = 2 * workKp / Tu;
314
+              workKd = workKp * Tu / 8;
315
               SERIAL_PROTOCOLLNPGM(MSG_CLASSIC_PID);
315
               SERIAL_PROTOCOLLNPGM(MSG_CLASSIC_PID);
316
-              SERIAL_PROTOCOLPGM(MSG_KP); SERIAL_PROTOCOLLN(Kp);
317
-              SERIAL_PROTOCOLPGM(MSG_KI); SERIAL_PROTOCOLLN(Ki);
318
-              SERIAL_PROTOCOLPGM(MSG_KD); SERIAL_PROTOCOLLN(Kd);
316
+              SERIAL_PROTOCOLPGM(MSG_KP); SERIAL_PROTOCOLLN(workKp);
317
+              SERIAL_PROTOCOLPGM(MSG_KI); SERIAL_PROTOCOLLN(workKi);
318
+              SERIAL_PROTOCOLPGM(MSG_KD); SERIAL_PROTOCOLLN(workKd);
319
               /**
319
               /**
320
-              Kp = 0.33*Ku;
321
-              Ki = Kp/Tu;
322
-              Kd = Kp*Tu/3;
320
+              workKp = 0.33*Ku;
321
+              workKi = workKp/Tu;
322
+              workKd = workKp*Tu/3;
323
               SERIAL_PROTOCOLLNPGM(" Some overshoot ");
323
               SERIAL_PROTOCOLLNPGM(" Some overshoot ");
324
-              SERIAL_PROTOCOLPGM(" Kp: "); SERIAL_PROTOCOLLN(Kp);
325
-              SERIAL_PROTOCOLPGM(" Ki: "); SERIAL_PROTOCOLLN(Ki);
326
-              SERIAL_PROTOCOLPGM(" Kd: "); SERIAL_PROTOCOLLN(Kd);
327
-              Kp = 0.2*Ku;
328
-              Ki = 2*Kp/Tu;
329
-              Kd = Kp*Tu/3;
324
+              SERIAL_PROTOCOLPGM(" Kp: "); SERIAL_PROTOCOLLN(workKp);
325
+              SERIAL_PROTOCOLPGM(" Ki: "); SERIAL_PROTOCOLLN(workKi);
326
+              SERIAL_PROTOCOLPGM(" Kd: "); SERIAL_PROTOCOLLN(workKd);
327
+              workKp = 0.2*Ku;
328
+              workKi = 2*workKp/Tu;
329
+              workKd = workKp*Tu/3;
330
               SERIAL_PROTOCOLLNPGM(" No overshoot ");
330
               SERIAL_PROTOCOLLNPGM(" No overshoot ");
331
-              SERIAL_PROTOCOLPGM(" Kp: "); SERIAL_PROTOCOLLN(Kp);
332
-              SERIAL_PROTOCOLPGM(" Ki: "); SERIAL_PROTOCOLLN(Ki);
333
-              SERIAL_PROTOCOLPGM(" Kd: "); SERIAL_PROTOCOLLN(Kd);
331
+              SERIAL_PROTOCOLPGM(" Kp: "); SERIAL_PROTOCOLLN(workKp);
332
+              SERIAL_PROTOCOLPGM(" Ki: "); SERIAL_PROTOCOLLN(workKi);
333
+              SERIAL_PROTOCOLPGM(" Kd: "); SERIAL_PROTOCOLLN(workKd);
334
               */
334
               */
335
             }
335
             }
336
           }
336
           }
365
     if (cycles > ncycles) {
365
     if (cycles > ncycles) {
366
       SERIAL_PROTOCOLLNPGM(MSG_PID_AUTOTUNE_FINISHED);
366
       SERIAL_PROTOCOLLNPGM(MSG_PID_AUTOTUNE_FINISHED);
367
       const char* estring = extruder < 0 ? "bed" : "";
367
       const char* estring = extruder < 0 ? "bed" : "";
368
-      SERIAL_PROTOCOLPGM("#define  DEFAULT_"); SERIAL_PROTOCOL(estring); SERIAL_PROTOCOLPGM("Kp "); SERIAL_PROTOCOLLN(Kp);
369
-      SERIAL_PROTOCOLPGM("#define  DEFAULT_"); SERIAL_PROTOCOL(estring); SERIAL_PROTOCOLPGM("Ki "); SERIAL_PROTOCOLLN(Ki);
370
-      SERIAL_PROTOCOLPGM("#define  DEFAULT_"); SERIAL_PROTOCOL(estring); SERIAL_PROTOCOLPGM("Kd "); SERIAL_PROTOCOLLN(Kd);
368
+      SERIAL_PROTOCOLPGM("#define  DEFAULT_"); SERIAL_PROTOCOL(estring); SERIAL_PROTOCOLPGM("Kp "); SERIAL_PROTOCOLLN(workKp);
369
+      SERIAL_PROTOCOLPGM("#define  DEFAULT_"); SERIAL_PROTOCOL(estring); SERIAL_PROTOCOLPGM("Ki "); SERIAL_PROTOCOLLN(workKi);
370
+      SERIAL_PROTOCOLPGM("#define  DEFAULT_"); SERIAL_PROTOCOL(estring); SERIAL_PROTOCOLPGM("Kd "); SERIAL_PROTOCOLLN(workKd);
371
 
371
 
372
       // Use the result? (As with "M303 U1")
372
       // Use the result? (As with "M303 U1")
373
       if (set_result) {
373
       if (set_result) {
374
         if (extruder < 0) {
374
         if (extruder < 0) {
375
           #if ENABLED(PIDTEMPBED)
375
           #if ENABLED(PIDTEMPBED)
376
-            bedKp = Kp;
377
-            bedKi = scalePID_i(Ki);
378
-            bedKd = scalePID_d(Kd);
376
+            bedKp = workKp;
377
+            bedKi = scalePID_i(workKi);
378
+            bedKd = scalePID_d(workKd);
379
             updatePID();
379
             updatePID();
380
           #endif
380
           #endif
381
         }
381
         }
382
         else {
382
         else {
383
-          PID_PARAM(Kp, extruder) = Kp;
384
-          PID_PARAM(Ki, e) = scalePID_i(Ki);
385
-          PID_PARAM(Kd, e) = scalePID_d(Kd);
383
+          PID_PARAM(Kp, extruder) = workKp;
384
+          PID_PARAM(Ki, extruder) = scalePID_i(workKi);
385
+          PID_PARAM(Kd, extruder) = scalePID_d(workKd);
386
           updatePID();
386
           updatePID();
387
         }
387
         }
388
       }
388
       }
395
 void updatePID() {
395
 void updatePID() {
396
   #if ENABLED(PIDTEMP)
396
   #if ENABLED(PIDTEMP)
397
     for (int e = 0; e < EXTRUDERS; e++) {
397
     for (int e = 0; e < EXTRUDERS; e++) {
398
-      temp_iState_max[e] = (PID_INTEGRAL_DRIVE_MAX) / PID_PARAM(Ki,e);
398
+      temp_iState_max[e] = (PID_INTEGRAL_DRIVE_MAX) / PID_PARAM(Ki, e);
399
       #if ENABLED(PID_ADD_EXTRUSION_RATE)
399
       #if ENABLED(PID_ADD_EXTRUSION_RATE)
400
         last_position[e] = 0;
400
         last_position[e] = 0;
401
       #endif
401
       #endif

+ 8
- 2
Marlin/temperature.h View File

82
 #if ENABLED(PIDTEMP)
82
 #if ENABLED(PIDTEMP)
83
 
83
 
84
   #if ENABLED(PID_PARAMS_PER_EXTRUDER)
84
   #if ENABLED(PID_PARAMS_PER_EXTRUDER)
85
-    extern float Kp[EXTRUDERS], Ki[EXTRUDERS], Kd[EXTRUDERS], Kc[EXTRUDERS]; // one param per extruder
85
+    extern float Kp[EXTRUDERS], Ki[EXTRUDERS], Kd[EXTRUDERS];  // one param per extruder
86
+    #if ENABLED(PID_ADD_EXTRUSION_RATE)
87
+      extern float Kc[EXTRUDERS];
88
+    #endif
86
     #define PID_PARAM(param, e) param[e] // use macro to point to array value
89
     #define PID_PARAM(param, e) param[e] // use macro to point to array value
87
   #else
90
   #else
88
-    extern float Kp, Ki, Kd, Kc; // one param per extruder - saves 20 or 36 bytes of ram (inc array pointer)
91
+    extern float Kp, Ki, Kd;  // one param per extruder - saves 20 or 36 bytes of ram (inc array pointer)
92
+    #if ENABLED(PID_ADD_EXTRUSION_RATE)
93
+      extern float Kc;
94
+    #endif
89
     #define PID_PARAM(param, e) param // use macro to point directly to value
95
     #define PID_PARAM(param, e) param // use macro to point directly to value
90
   #endif // PID_PARAMS_PER_EXTRUDER
96
   #endif // PID_PARAMS_PER_EXTRUDER
91
   float scalePID_i(float i);
97
   float scalePID_i(float i);

Loading…
Cancel
Save