瀏覽代碼

Apply indentation to gcode_M303, PID_autotune

Scott Lahteine 9 年之前
父節點
當前提交
a26d70e932
共有 2 個文件被更改,包括 158 次插入158 次删除
  1. 14
    14
      Marlin/Marlin_main.cpp
  2. 144
    144
      Marlin/temperature.cpp

+ 14
- 14
Marlin/Marlin_main.cpp 查看文件

@@ -5559,25 +5559,25 @@ inline void gcode_M226() {
5559 5559
  *       U<bool> with a non-zero value will apply the result to current settings
5560 5560
  */
5561 5561
 inline void gcode_M303() {
5562
-#if ENABLED(PIDTEMP)
5563
-  int e = code_seen('E') ? code_value_short() : 0;
5564
-  int c = code_seen('C') ? code_value_short() : 5;
5565
-  bool u = code_seen('U') && code_value_short() != 0;
5562
+  #if ENABLED(PIDTEMP)
5563
+    int e = code_seen('E') ? code_value_short() : 0;
5564
+    int c = code_seen('C') ? code_value_short() : 5;
5565
+    bool u = code_seen('U') && code_value_short() != 0;
5566 5566
 
5567
-  float temp = code_seen('S') ? code_value() : (e < 0 ? 70.0 : 150.0);
5567
+    float temp = code_seen('S') ? code_value() : (e < 0 ? 70.0 : 150.0);
5568 5568
 
5569
-  if (e >= 0 && e < EXTRUDERS)
5570
-    target_extruder = e;
5569
+    if (e >= 0 && e < EXTRUDERS)
5570
+      target_extruder = e;
5571 5571
 
5572
-  KEEPALIVE_STATE(NOT_BUSY); // don't send "busy: processing" messages during autotune output
5572
+    KEEPALIVE_STATE(NOT_BUSY); // don't send "busy: processing" messages during autotune output
5573 5573
 
5574
-  PID_autotune(temp, e, c, u);
5574
+    PID_autotune(temp, e, c, u);
5575 5575
 
5576
-  KEEPALIVE_STATE(IN_HANDLER);
5577
-#else
5578
-  SERIAL_ERROR_START;
5579
-  SERIAL_ERRORLNPGM(MSG_ERR_M303_DISABLED);
5580
-#endif
5576
+    KEEPALIVE_STATE(IN_HANDLER);
5577
+  #else
5578
+    SERIAL_ERROR_START;
5579
+    SERIAL_ERRORLNPGM(MSG_ERR_M303_DISABLED);
5580
+  #endif
5581 5581
 }
5582 5582
 
5583 5583
 #if ENABLED(SCARA)

+ 144
- 144
Marlin/temperature.cpp 查看文件

@@ -223,176 +223,176 @@ static void updateTemperaturesFromRawValues();
223 223
 
224 224
 #if ENABLED(PIDTEMP)
225 225
 
226
-void PID_autotune(float temp, int extruder, int ncycles, bool set_result/*=false*/) {
227
-  float input = 0.0;
228
-  int cycles = 0;
229
-  bool heating = true;
226
+  void PID_autotune(float temp, int extruder, int ncycles, bool set_result/*=false*/) {
227
+    float input = 0.0;
228
+    int cycles = 0;
229
+    bool heating = true;
230 230
 
231
-  millis_t temp_ms = millis(), t1 = temp_ms, t2 = temp_ms;
232
-  long t_high = 0, t_low = 0;
231
+    millis_t temp_ms = millis(), t1 = temp_ms, t2 = temp_ms;
232
+    long t_high = 0, t_low = 0;
233 233
 
234
-  long bias, d;
235
-  float Ku, Tu;
236
-  float workKp = 0, workKi = 0, workKd = 0;
237
-  float max = 0, min = 10000;
234
+    long bias, d;
235
+    float Ku, Tu;
236
+    float workKp = 0, workKi = 0, workKd = 0;
237
+    float max = 0, min = 10000;
238 238
 
239
-  #if HAS_AUTO_FAN
240
-    millis_t next_auto_fan_check_ms = temp_ms + 2500UL;
241
-  #endif
242
-
243
-  if (extruder >= EXTRUDERS
244
-    #if !HAS_TEMP_BED
245
-       || extruder < 0
239
+    #if HAS_AUTO_FAN
240
+      millis_t next_auto_fan_check_ms = temp_ms + 2500UL;
246 241
     #endif
247
-  ) {
248
-    SERIAL_ECHOLN(MSG_PID_BAD_EXTRUDER_NUM);
249
-    return;
250
-  }
251 242
 
252
-  SERIAL_ECHOLN(MSG_PID_AUTOTUNE_START);
243
+    if (extruder >= EXTRUDERS
244
+      #if !HAS_TEMP_BED
245
+         || extruder < 0
246
+      #endif
247
+    ) {
248
+      SERIAL_ECHOLN(MSG_PID_BAD_EXTRUDER_NUM);
249
+      return;
250
+    }
253 251
 
254
-  disable_all_heaters(); // switch off all heaters.
252
+    SERIAL_ECHOLN(MSG_PID_AUTOTUNE_START);
255 253
 
256
-  if (extruder < 0)
257
-    soft_pwm_bed = bias = d = (MAX_BED_POWER) / 2;
258
-  else
259
-    soft_pwm[extruder] = bias = d = (PID_MAX) / 2;
254
+    disable_all_heaters(); // switch off all heaters.
260 255
 
261
-  // PID Tuning loop
262
-  for (;;) {
256
+    if (extruder < 0)
257
+      soft_pwm_bed = bias = d = (MAX_BED_POWER) / 2;
258
+    else
259
+      soft_pwm[extruder] = bias = d = (PID_MAX) / 2;
263 260
 
264
-    millis_t ms = millis();
261
+    // PID Tuning loop
262
+    for (;;) {
265 263
 
266
-    if (temp_meas_ready) { // temp sample ready
267
-      updateTemperaturesFromRawValues();
264
+      millis_t ms = millis();
268 265
 
269
-      input = (extruder < 0) ? current_temperature_bed : current_temperature[extruder];
266
+      if (temp_meas_ready) { // temp sample ready
267
+        updateTemperaturesFromRawValues();
270 268
 
271
-      max = max(max, input);
272
-      min = min(min, input);
269
+        input = (extruder < 0) ? current_temperature_bed : current_temperature[extruder];
273 270
 
274
-      #if HAS_AUTO_FAN
275
-        if (ELAPSED(ms, next_auto_fan_check_ms)) {
276
-          checkExtruderAutoFans();
277
-          next_auto_fan_check_ms = ms + 2500UL;
278
-        }
279
-      #endif
271
+        max = max(max, input);
272
+        min = min(min, input);
273
+
274
+        #if HAS_AUTO_FAN
275
+          if (ELAPSED(ms, next_auto_fan_check_ms)) {
276
+            checkExtruderAutoFans();
277
+            next_auto_fan_check_ms = ms + 2500UL;
278
+          }
279
+        #endif
280 280
 
281
-      if (heating && input > temp) {
282
-        if (ELAPSED(ms, t2 + 5000UL)) {
283
-          heating = false;
284
-          if (extruder < 0)
285
-            soft_pwm_bed = (bias - d) >> 1;
286
-          else
287
-            soft_pwm[extruder] = (bias - d) >> 1;
288
-          t1 = ms;
289
-          t_high = t1 - t2;
290
-          max = temp;
281
+        if (heating && input > temp) {
282
+          if (ELAPSED(ms, t2 + 5000UL)) {
283
+            heating = false;
284
+            if (extruder < 0)
285
+              soft_pwm_bed = (bias - d) >> 1;
286
+            else
287
+              soft_pwm[extruder] = (bias - d) >> 1;
288
+            t1 = ms;
289
+            t_high = t1 - t2;
290
+            max = temp;
291
+          }
291 292
         }
292
-      }
293 293
 
294
-      if (!heating && input < temp) {
295
-        if (ELAPSED(ms, t1 + 5000UL)) {
296
-          heating = true;
297
-          t2 = ms;
298
-          t_low = t2 - t1;
299
-          if (cycles > 0) {
300
-            long max_pow = extruder < 0 ? MAX_BED_POWER : PID_MAX;
301
-            bias += (d * (t_high - t_low)) / (t_low + t_high);
302
-            bias = constrain(bias, 20, max_pow - 20);
303
-            d = (bias > max_pow / 2) ? max_pow - 1 - bias : bias;
304
-
305
-            SERIAL_PROTOCOLPGM(MSG_BIAS); SERIAL_PROTOCOL(bias);
306
-            SERIAL_PROTOCOLPGM(MSG_D);    SERIAL_PROTOCOL(d);
307
-            SERIAL_PROTOCOLPGM(MSG_T_MIN);  SERIAL_PROTOCOL(min);
308
-            SERIAL_PROTOCOLPGM(MSG_T_MAX);  SERIAL_PROTOCOLLN(max);
309
-            if (cycles > 2) {
310
-              Ku = (4.0 * d) / (3.14159265 * (max - min) / 2.0);
311
-              Tu = ((float)(t_low + t_high) / 1000.0);
312
-              SERIAL_PROTOCOLPGM(MSG_KU); SERIAL_PROTOCOL(Ku);
313
-              SERIAL_PROTOCOLPGM(MSG_TU); SERIAL_PROTOCOLLN(Tu);
314
-              workKp = 0.6 * Ku;
315
-              workKi = 2 * workKp / Tu;
316
-              workKd = workKp * Tu / 8;
317
-              SERIAL_PROTOCOLLNPGM(MSG_CLASSIC_PID);
318
-              SERIAL_PROTOCOLPGM(MSG_KP); SERIAL_PROTOCOLLN(workKp);
319
-              SERIAL_PROTOCOLPGM(MSG_KI); SERIAL_PROTOCOLLN(workKi);
320
-              SERIAL_PROTOCOLPGM(MSG_KD); SERIAL_PROTOCOLLN(workKd);
321
-              /**
322
-              workKp = 0.33*Ku;
323
-              workKi = workKp/Tu;
324
-              workKd = workKp*Tu/3;
325
-              SERIAL_PROTOCOLLNPGM(" Some overshoot ");
326
-              SERIAL_PROTOCOLPGM(" Kp: "); SERIAL_PROTOCOLLN(workKp);
327
-              SERIAL_PROTOCOLPGM(" Ki: "); SERIAL_PROTOCOLLN(workKi);
328
-              SERIAL_PROTOCOLPGM(" Kd: "); SERIAL_PROTOCOLLN(workKd);
329
-              workKp = 0.2*Ku;
330
-              workKi = 2*workKp/Tu;
331
-              workKd = workKp*Tu/3;
332
-              SERIAL_PROTOCOLLNPGM(" No overshoot ");
333
-              SERIAL_PROTOCOLPGM(" Kp: "); SERIAL_PROTOCOLLN(workKp);
334
-              SERIAL_PROTOCOLPGM(" Ki: "); SERIAL_PROTOCOLLN(workKi);
335
-              SERIAL_PROTOCOLPGM(" Kd: "); SERIAL_PROTOCOLLN(workKd);
336
-              */
294
+        if (!heating && input < temp) {
295
+          if (ELAPSED(ms, t1 + 5000UL)) {
296
+            heating = true;
297
+            t2 = ms;
298
+            t_low = t2 - t1;
299
+            if (cycles > 0) {
300
+              long max_pow = extruder < 0 ? MAX_BED_POWER : PID_MAX;
301
+              bias += (d * (t_high - t_low)) / (t_low + t_high);
302
+              bias = constrain(bias, 20, max_pow - 20);
303
+              d = (bias > max_pow / 2) ? max_pow - 1 - bias : bias;
304
+
305
+              SERIAL_PROTOCOLPGM(MSG_BIAS); SERIAL_PROTOCOL(bias);
306
+              SERIAL_PROTOCOLPGM(MSG_D);    SERIAL_PROTOCOL(d);
307
+              SERIAL_PROTOCOLPGM(MSG_T_MIN);  SERIAL_PROTOCOL(min);
308
+              SERIAL_PROTOCOLPGM(MSG_T_MAX);  SERIAL_PROTOCOLLN(max);
309
+              if (cycles > 2) {
310
+                Ku = (4.0 * d) / (3.14159265 * (max - min) / 2.0);
311
+                Tu = ((float)(t_low + t_high) / 1000.0);
312
+                SERIAL_PROTOCOLPGM(MSG_KU); SERIAL_PROTOCOL(Ku);
313
+                SERIAL_PROTOCOLPGM(MSG_TU); SERIAL_PROTOCOLLN(Tu);
314
+                workKp = 0.6 * Ku;
315
+                workKi = 2 * workKp / Tu;
316
+                workKd = workKp * Tu / 8;
317
+                SERIAL_PROTOCOLLNPGM(MSG_CLASSIC_PID);
318
+                SERIAL_PROTOCOLPGM(MSG_KP); SERIAL_PROTOCOLLN(workKp);
319
+                SERIAL_PROTOCOLPGM(MSG_KI); SERIAL_PROTOCOLLN(workKi);
320
+                SERIAL_PROTOCOLPGM(MSG_KD); SERIAL_PROTOCOLLN(workKd);
321
+                /**
322
+                workKp = 0.33*Ku;
323
+                workKi = workKp/Tu;
324
+                workKd = workKp*Tu/3;
325
+                SERIAL_PROTOCOLLNPGM(" Some overshoot ");
326
+                SERIAL_PROTOCOLPGM(" Kp: "); SERIAL_PROTOCOLLN(workKp);
327
+                SERIAL_PROTOCOLPGM(" Ki: "); SERIAL_PROTOCOLLN(workKi);
328
+                SERIAL_PROTOCOLPGM(" Kd: "); SERIAL_PROTOCOLLN(workKd);
329
+                workKp = 0.2*Ku;
330
+                workKi = 2*workKp/Tu;
331
+                workKd = workKp*Tu/3;
332
+                SERIAL_PROTOCOLLNPGM(" No overshoot ");
333
+                SERIAL_PROTOCOLPGM(" Kp: "); SERIAL_PROTOCOLLN(workKp);
334
+                SERIAL_PROTOCOLPGM(" Ki: "); SERIAL_PROTOCOLLN(workKi);
335
+                SERIAL_PROTOCOLPGM(" Kd: "); SERIAL_PROTOCOLLN(workKd);
336
+                */
337
+              }
337 338
             }
339
+            if (extruder < 0)
340
+              soft_pwm_bed = (bias + d) >> 1;
341
+            else
342
+              soft_pwm[extruder] = (bias + d) >> 1;
343
+            cycles++;
344
+            min = temp;
338 345
           }
339
-          if (extruder < 0)
340
-            soft_pwm_bed = (bias + d) >> 1;
341
-          else
342
-            soft_pwm[extruder] = (bias + d) >> 1;
343
-          cycles++;
344
-          min = temp;
345 346
         }
346 347
       }
347
-    }
348
-    #define MAX_OVERSHOOT_PID_AUTOTUNE 20
349
-    if (input > temp + MAX_OVERSHOOT_PID_AUTOTUNE) {
350
-      SERIAL_PROTOCOLLNPGM(MSG_PID_TEMP_TOO_HIGH);
351
-      return;
352
-    }
353
-    // Every 2 seconds...
354
-    if (ELAPSED(ms, temp_ms + 2000UL)) {
355
-      #if HAS_TEMP_HOTEND || HAS_TEMP_BED
356
-        print_heaterstates();
357
-        SERIAL_EOL;
358
-      #endif
348
+      #define MAX_OVERSHOOT_PID_AUTOTUNE 20
349
+      if (input > temp + MAX_OVERSHOOT_PID_AUTOTUNE) {
350
+        SERIAL_PROTOCOLLNPGM(MSG_PID_TEMP_TOO_HIGH);
351
+        return;
352
+      }
353
+      // Every 2 seconds...
354
+      if (ELAPSED(ms, temp_ms + 2000UL)) {
355
+        #if HAS_TEMP_HOTEND || HAS_TEMP_BED
356
+          print_heaterstates();
357
+          SERIAL_EOL;
358
+        #endif
359 359
 
360
-      temp_ms = ms;
361
-    } // every 2 seconds
362
-    // Over 2 minutes?
363
-    if (((ms - t1) + (ms - t2)) > (10L * 60L * 1000L * 2L)) {
364
-      SERIAL_PROTOCOLLNPGM(MSG_PID_TIMEOUT);
365
-      return;
366
-    }
367
-    if (cycles > ncycles) {
368
-      SERIAL_PROTOCOLLNPGM(MSG_PID_AUTOTUNE_FINISHED);
369
-      const char* estring = extruder < 0 ? "bed" : "";
370
-      SERIAL_PROTOCOLPGM("#define  DEFAULT_"); SERIAL_PROTOCOL(estring); SERIAL_PROTOCOLPGM("Kp "); SERIAL_PROTOCOLLN(workKp);
371
-      SERIAL_PROTOCOLPGM("#define  DEFAULT_"); SERIAL_PROTOCOL(estring); SERIAL_PROTOCOLPGM("Ki "); SERIAL_PROTOCOLLN(workKi);
372
-      SERIAL_PROTOCOLPGM("#define  DEFAULT_"); SERIAL_PROTOCOL(estring); SERIAL_PROTOCOLPGM("Kd "); SERIAL_PROTOCOLLN(workKd);
373
-
374
-      // Use the result? (As with "M303 U1")
375
-      if (set_result) {
376
-        if (extruder < 0) {
377
-          #if ENABLED(PIDTEMPBED)
378
-            bedKp = workKp;
379
-            bedKi = scalePID_i(workKi);
380
-            bedKd = scalePID_d(workKd);
360
+        temp_ms = ms;
361
+      } // every 2 seconds
362
+      // Over 2 minutes?
363
+      if (((ms - t1) + (ms - t2)) > (10L * 60L * 1000L * 2L)) {
364
+        SERIAL_PROTOCOLLNPGM(MSG_PID_TIMEOUT);
365
+        return;
366
+      }
367
+      if (cycles > ncycles) {
368
+        SERIAL_PROTOCOLLNPGM(MSG_PID_AUTOTUNE_FINISHED);
369
+        const char* estring = extruder < 0 ? "bed" : "";
370
+        SERIAL_PROTOCOLPGM("#define  DEFAULT_"); SERIAL_PROTOCOL(estring); SERIAL_PROTOCOLPGM("Kp "); SERIAL_PROTOCOLLN(workKp);
371
+        SERIAL_PROTOCOLPGM("#define  DEFAULT_"); SERIAL_PROTOCOL(estring); SERIAL_PROTOCOLPGM("Ki "); SERIAL_PROTOCOLLN(workKi);
372
+        SERIAL_PROTOCOLPGM("#define  DEFAULT_"); SERIAL_PROTOCOL(estring); SERIAL_PROTOCOLPGM("Kd "); SERIAL_PROTOCOLLN(workKd);
373
+
374
+        // Use the result? (As with "M303 U1")
375
+        if (set_result) {
376
+          if (extruder < 0) {
377
+            #if ENABLED(PIDTEMPBED)
378
+              bedKp = workKp;
379
+              bedKi = scalePID_i(workKi);
380
+              bedKd = scalePID_d(workKd);
381
+              updatePID();
382
+            #endif
383
+          }
384
+          else {
385
+            PID_PARAM(Kp, extruder) = workKp;
386
+            PID_PARAM(Ki, extruder) = scalePID_i(workKi);
387
+            PID_PARAM(Kd, extruder) = scalePID_d(workKd);
381 388
             updatePID();
382
-          #endif
383
-        }
384
-        else {
385
-          PID_PARAM(Kp, extruder) = workKp;
386
-          PID_PARAM(Ki, extruder) = scalePID_i(workKi);
387
-          PID_PARAM(Kd, extruder) = scalePID_d(workKd);
388
-          updatePID();
389
+          }
389 390
         }
391
+        return;
390 392
       }
391
-      return;
393
+      lcd_update();
392 394
     }
393
-    lcd_update();
394 395
   }
395
-}
396 396
 
397 397
 #endif // PIDTEMP
398 398
 

Loading…
取消
儲存