Bläddra i källkod

[2.0.x] Automatically reset stepper timeout (#10179)

* Automatically reset stepper timeout in manage_inactivity

Any code that adds moves to the planner can skip resetting the stepper timeout. We can let `idle` / `manage_inactivity` reset the timer whenever it detects any moves in the planner.

* blocks_queued => has_blocks_queued
Scott Lahteine 6 år sedan
förälder
incheckning
1cb810ff1c
Inget konto är kopplat till bidragsgivarens mejladress

+ 26
- 23
Marlin/src/Marlin.cpp Visa fil

@@ -336,7 +336,7 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) {
336 336
 
337 337
   const millis_t ms = millis();
338 338
 
339
-  if (max_inactive_time && ELAPSED(ms, gcode.previous_cmd_ms + max_inactive_time)) {
339
+  if (max_inactive_time && ELAPSED(ms, gcode.previous_move_ms + max_inactive_time)) {
340 340
     SERIAL_ERROR_START();
341 341
     SERIAL_ECHOLNPAIR(MSG_KILL_INACTIVE_TIME, parser.command_ptr);
342 342
     kill(PSTR(MSG_KILLED));
@@ -349,23 +349,26 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) {
349 349
     #define MOVE_AWAY_TEST true
350 350
   #endif
351 351
 
352
-  if (MOVE_AWAY_TEST && stepper_inactive_time && ELAPSED(ms, gcode.previous_cmd_ms + stepper_inactive_time)
353
-      && !ignore_stepper_queue && !planner.blocks_queued()) {
354
-    #if ENABLED(DISABLE_INACTIVE_X)
355
-      disable_X();
356
-    #endif
357
-    #if ENABLED(DISABLE_INACTIVE_Y)
358
-      disable_Y();
359
-    #endif
360
-    #if ENABLED(DISABLE_INACTIVE_Z)
361
-      disable_Z();
362
-    #endif
363
-    #if ENABLED(DISABLE_INACTIVE_E)
364
-      disable_e_steppers();
365
-    #endif
366
-    #if ENABLED(AUTO_BED_LEVELING_UBL) && ENABLED(ULTIPANEL)  // Only needed with an LCD
367
-      if (ubl.lcd_map_control) ubl.lcd_map_control = defer_return_to_status = false;
368
-    #endif
352
+  if (stepper_inactive_time) {
353
+    if (planner.has_blocks_queued())
354
+      gcode.previous_move_ms = ms; // reset_stepper_timeout to keep steppers powered
355
+    else if (MOVE_AWAY_TEST && !ignore_stepper_queue && ELAPSED(ms, gcode.previous_move_ms + stepper_inactive_time)) {
356
+      #if ENABLED(DISABLE_INACTIVE_X)
357
+        disable_X();
358
+      #endif
359
+      #if ENABLED(DISABLE_INACTIVE_Y)
360
+        disable_Y();
361
+      #endif
362
+      #if ENABLED(DISABLE_INACTIVE_Z)
363
+        disable_Z();
364
+      #endif
365
+      #if ENABLED(DISABLE_INACTIVE_E)
366
+        disable_e_steppers();
367
+      #endif
368
+      #if ENABLED(AUTO_BED_LEVELING_UBL) && ENABLED(ULTIPANEL)  // Only needed with an LCD
369
+        if (ubl.lcd_map_control) ubl.lcd_map_control = defer_return_to_status = false;
370
+      #endif
371
+    }
369 372
   }
370 373
 
371 374
   #ifdef CHDK // Check if pin should be set to LOW after M240 set it to HIGH
@@ -424,8 +427,8 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) {
424 427
 
425 428
   #if ENABLED(EXTRUDER_RUNOUT_PREVENT)
426 429
     if (thermalManager.degHotend(active_extruder) > EXTRUDER_RUNOUT_MINTEMP
427
-      && ELAPSED(ms, gcode.previous_cmd_ms + (EXTRUDER_RUNOUT_SECONDS) * 1000UL)
428
-      && !planner.blocks_queued()
430
+      && ELAPSED(ms, gcode.previous_move_ms + (EXTRUDER_RUNOUT_SECONDS) * 1000UL)
431
+      && !planner.has_blocks_queued()
429 432
     ) {
430 433
       #if ENABLED(SWITCHING_EXTRUDER)
431 434
         const bool oldstatus = E0_ENABLE_READ;
@@ -449,8 +452,6 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) {
449 452
         }
450 453
       #endif // !SWITCHING_EXTRUDER
451 454
 
452
-      gcode.refresh_cmd_timeout();
453
-
454 455
       const float olde = current_position[E_AXIS];
455 456
       current_position[E_AXIS] += EXTRUDER_RUNOUT_EXTRUDE;
456 457
       planner.buffer_line_kinematic(current_position, MMM_TO_MMS(EXTRUDER_RUNOUT_SPEED), active_extruder);
@@ -476,6 +477,8 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) {
476 477
           #endif // E_STEPPERS > 1
477 478
         }
478 479
       #endif // !SWITCHING_EXTRUDER
480
+
481
+      gcode.previous_move_ms = ms; // reset_stepper_timeout to keep steppers powered
479 482
     }
480 483
   #endif // EXTRUDER_RUNOUT_PREVENT
481 484
 
@@ -541,7 +544,7 @@ void idle(
541 544
 
542 545
   #if ENABLED(I2C_POSITION_ENCODERS)
543 546
     static millis_t i2cpem_next_update_ms;
544
-    if (planner.blocks_queued() && ELAPSED(millis(), i2cpem_next_update_ms)) {
547
+    if (planner.has_blocks_queued() && ELAPSED(millis(), i2cpem_next_update_ms)) {
545 548
       I2CPEM.update();
546 549
       i2cpem_next_update_ms = millis() + I2CPE_MIN_UPD_TIME_MS;
547 550
     }

+ 1
- 1
Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp Visa fil

@@ -779,7 +779,7 @@
779 779
       wait_for_release();
780 780
       while (!is_lcd_clicked()) {
781 781
         idle();
782
-        gcode.refresh_cmd_timeout();
782
+        gcode.reset_stepper_timeout(); // Keep steppers powered
783 783
         if (encoder_diff) {
784 784
           do_blocking_move_to_z(current_position[Z_AXIS] + float(encoder_diff) * multiplier);
785 785
           encoder_diff = 0;

+ 1
- 4
Marlin/src/gcode/config/M43.cpp Visa fil

@@ -155,8 +155,6 @@ inline void servo_probe_test() {
155 155
     } while (++i < 4);
156 156
     if (probe_inverting != deploy_state) SERIAL_PROTOCOLLNPGM("WARNING - INVERTING setting probably backwards");
157 157
 
158
-    gcode.refresh_cmd_timeout();
159
-
160 158
     if (deploy_state != stow_state) {
161 159
       SERIAL_PROTOCOLLNPGM("BLTouch clone detected");
162 160
       if (deploy_state) {
@@ -182,8 +180,7 @@ inline void servo_probe_test() {
182 180
 
183 181
         safe_delay(2);
184 182
 
185
-        if (0 == j % (500 * 1)) // keep cmd_timeout happy
186
-          gcode.refresh_cmd_timeout();
183
+        if (0 == j % (500 * 1)) gcode.reset_stepper_timeout(); // Keep steppers powered
187 184
 
188 185
         if (deploy_state != READ(PROBE_TEST_PIN)) { // probe triggered
189 186
 

+ 4
- 3
Marlin/src/gcode/gcode.cpp Visa fil

@@ -43,7 +43,7 @@ GcodeSuite gcode;
43 43
 #include "../Marlin.h" // for idle() and suspend_auto_report
44 44
 
45 45
 uint8_t GcodeSuite::target_extruder;
46
-millis_t GcodeSuite::previous_cmd_ms;
46
+millis_t GcodeSuite::previous_move_ms;
47 47
 
48 48
 bool GcodeSuite::axis_relative_modes[] = AXIS_RELATIVE_MODES;
49 49
 
@@ -121,8 +121,7 @@ void GcodeSuite::get_destination_from_command() {
121 121
  * Dwell waits immediately. It does not synchronize. Use M400 instead of G4
122 122
  */
123 123
 void GcodeSuite::dwell(millis_t time) {
124
-  refresh_cmd_timeout();
125
-  time += previous_cmd_ms;
124
+  time += millis();
126 125
   while (PENDING(millis(), time)) idle();
127 126
 }
128 127
 
@@ -735,6 +734,8 @@ void GcodeSuite::process_next_command() {
735 734
     #endif
736 735
   }
737 736
 
737
+  reset_stepper_timeout(); // Keep steppers powered
738
+
738 739
   // Parse the next command in the queue
739 740
   parser.parse(current_command);
740 741
   process_parsed_command();

+ 2
- 2
Marlin/src/gcode/gcode.h Visa fil

@@ -280,8 +280,8 @@ public:
280 280
     static bool select_coordinate_system(const int8_t _new);
281 281
   #endif
282 282
 
283
-  static millis_t previous_cmd_ms;
284
-  FORCE_INLINE static void refresh_cmd_timeout() { previous_cmd_ms = millis(); }
283
+  static millis_t previous_move_ms;
284
+  FORCE_INLINE static void reset_stepper_timeout() { previous_move_ms = millis(); }
285 285
 
286 286
   static bool get_target_extruder_from_command();
287 287
   static void get_destination_from_command();

+ 1
- 2
Marlin/src/gcode/lcd/M0_M1.cpp Visa fil

@@ -75,10 +75,9 @@ void GcodeSuite::M0_M1() {
75 75
   wait_for_user = true;
76 76
 
77 77
   stepper.synchronize();
78
-  refresh_cmd_timeout();
79 78
 
80 79
   if (ms > 0) {
81
-    ms += previous_cmd_ms;  // wait until this time for a click
80
+    ms += previous_move_ms;  // wait until this time for a click
82 81
     while (PENDING(millis(), ms) && wait_for_user) idle();
83 82
   }
84 83
   else {

+ 1
- 1
Marlin/src/gcode/motion/G2_G3.cpp Visa fil

@@ -269,7 +269,7 @@ void GcodeSuite::G2_G3(const bool clockwise) {
269 269
 
270 270
       // Send the arc to the planner
271 271
       plan_arc(destination, arc_offset, clockwise);
272
-      refresh_cmd_timeout();
272
+      reset_stepper_timeout();
273 273
     }
274 274
     else {
275 275
       // Bad arguments

+ 0
- 1
Marlin/src/gcode/queue.cpp Visa fil

@@ -204,7 +204,6 @@ void ok_to_send() {
204 204
     const int16_t port = command_queue_port[cmd_queue_index_r];
205 205
     if (port < 0) return;
206 206
   #endif
207
-  gcode.refresh_cmd_timeout();
208 207
   if (!send_ok[cmd_queue_index_r]) return;
209 208
   SERIAL_PROTOCOLPGM_P(port, MSG_OK);
210 209
   #if ENABLED(ADVANCED_OK)

+ 1
- 1
Marlin/src/gcode/temperature/M104_M109.cpp Visa fil

@@ -185,7 +185,7 @@ void GcodeSuite::M109() {
185 185
     }
186 186
 
187 187
     idle();
188
-    refresh_cmd_timeout(); // to prevent stepper_inactive_time from running out
188
+    reset_stepper_timeout(); // Keep steppers powered
189 189
 
190 190
     const float temp = thermalManager.degHotend(target_extruder);
191 191
 

+ 1
- 1
Marlin/src/gcode/temperature/M140_M190.cpp Visa fil

@@ -122,7 +122,7 @@ void GcodeSuite::M190() {
122 122
     }
123 123
 
124 124
     idle();
125
-    refresh_cmd_timeout(); // to prevent stepper_inactive_time from running out
125
+    reset_stepper_timeout(); // Keep steppers powered
126 126
 
127 127
     const float temp = thermalManager.degBed();
128 128
 

+ 1
- 7
Marlin/src/lcd/ultralcd.cpp Visa fil

@@ -1885,7 +1885,6 @@ void kill_screen(const char* lcd_msg) {
1885 1885
       // Encoder knob or keypad buttons adjust the Z position
1886 1886
       //
1887 1887
       if (encoderPosition) {
1888
-        gcode.refresh_cmd_timeout();
1889 1888
         const float z = current_position[Z_AXIS] + float((int32_t)encoderPosition) * (MBL_Z_STEP);
1890 1889
         line_to_z(constrain(z, -(LCD_PROBE_Z_RANGE) * 0.5, (LCD_PROBE_Z_RANGE) * 0.5));
1891 1890
         lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
@@ -2409,7 +2408,6 @@ void kill_screen(const char* lcd_msg) {
2409 2408
       stepper.cleaning_buffer_counter = 0;
2410 2409
       set_current_from_steppers_for_axis(ALL_AXES);
2411 2410
       sync_plan_position();
2412
-      gcode.refresh_cmd_timeout();
2413 2411
     }
2414 2412
 
2415 2413
     void _lcd_ubl_output_map_lcd() {
@@ -2424,10 +2422,7 @@ void kill_screen(const char* lcd_msg) {
2424 2422
       if (encoderPosition) {
2425 2423
         step_scaler += (int32_t)encoderPosition;
2426 2424
         x_plot += step_scaler / (ENCODER_STEPS_PER_MENU_ITEM);
2427
-        if (abs(step_scaler) >= ENCODER_STEPS_PER_MENU_ITEM)
2428
-          step_scaler = 0;
2429
-        gcode.refresh_cmd_timeout();
2430
-
2425
+        if (abs(step_scaler) >= ENCODER_STEPS_PER_MENU_ITEM) step_scaler = 0;
2431 2426
         encoderPosition = 0;
2432 2427
         lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
2433 2428
       }
@@ -2909,7 +2904,6 @@ void kill_screen(const char* lcd_msg) {
2909 2904
     if (use_click()) { return lcd_goto_previous_menu_no_defer(); }
2910 2905
     ENCODER_DIRECTION_NORMAL();
2911 2906
     if (encoderPosition && !processing_manual_move) {
2912
-      gcode.refresh_cmd_timeout();
2913 2907
 
2914 2908
       // Start with no limits to movement
2915 2909
       float min = current_position[axis] - 1000,

+ 0
- 5
Marlin/src/module/motion.cpp Visa fil

@@ -266,8 +266,6 @@ void buffer_line_to_destination(const float fr_mm_s) {
266 266
       if (DEBUGGING(LEVELING)) DEBUG_POS("prepare_uninterpolated_move_to_destination", destination);
267 267
     #endif
268 268
 
269
-    gcode.refresh_cmd_timeout();
270
-
271 269
     #if UBL_SEGMENTED
272 270
       // ubl segmented line will do z-only moves in single segment
273 271
       ubl.prepare_segmented_line_to(destination, MMS_SCALED(fr_mm_s ? fr_mm_s : feedrate_mm_s));
@@ -435,12 +433,10 @@ void bracket_probe_move(const bool before) {
435 433
     saved_feedrate_mm_s = feedrate_mm_s;
436 434
     saved_feedrate_percentage = feedrate_percentage;
437 435
     feedrate_percentage = 100;
438
-    gcode.refresh_cmd_timeout();
439 436
   }
440 437
   else {
441 438
     feedrate_mm_s = saved_feedrate_mm_s;
442 439
     feedrate_percentage = saved_feedrate_percentage;
443
-    gcode.refresh_cmd_timeout();
444 440
   }
445 441
 }
446 442
 
@@ -859,7 +855,6 @@ float soft_endstop_min[XYZ] = { X_MIN_BED, Y_MIN_BED, Z_MIN_POS },
859 855
  */
860 856
 void prepare_move_to_destination() {
861 857
   clamp_to_software_endstops(destination);
862
-  gcode.refresh_cmd_timeout();
863 858
 
864 859
   #if ENABLED(PREVENT_COLD_EXTRUSION) || ENABLED(PREVENT_LENGTHY_EXTRUDE)
865 860
 

+ 2
- 2
Marlin/src/module/planner.cpp Visa fil

@@ -468,7 +468,7 @@ void Planner::check_axes_activity() {
468 468
     #endif
469 469
   #endif
470 470
 
471
-  if (blocks_queued()) {
471
+  if (has_blocks_queued()) {
472 472
 
473 473
     #if FAN_COUNT > 0
474 474
       for (uint8_t i = 0; i < FAN_COUNT; i++)
@@ -1547,7 +1547,7 @@ void Planner::buffer_segment(const float &a, const float &b, const float &c, con
1547 1547
   //*/
1548 1548
 
1549 1549
   // Always split the first move into two (if not homing or probing)
1550
-  if (!blocks_queued()) {
1550
+  if (!has_blocks_queued()) {
1551 1551
 
1552 1552
     #define _BETWEEN(A) (position[A##_AXIS] + target[A##_AXIS]) >> 1
1553 1553
     const int32_t between[ABCE] = { _BETWEEN(A), _BETWEEN(B), _BETWEEN(C), _BETWEEN(E) };

+ 4
- 4
Marlin/src/module/planner.h Visa fil

@@ -512,14 +512,14 @@ class Planner {
512 512
     /**
513 513
      * Does the buffer have any blocks queued?
514 514
      */
515
-    static bool blocks_queued() { return (block_buffer_head != block_buffer_tail); }
515
+    static bool has_blocks_queued() { return (block_buffer_head != block_buffer_tail); }
516 516
 
517 517
     /**
518 518
      * "Discard" the block and "release" the memory.
519 519
      * Called when the current block is no longer needed.
520 520
      */
521 521
     FORCE_INLINE static void discard_current_block() {
522
-      if (blocks_queued())
522
+      if (has_blocks_queued())
523 523
         block_buffer_tail = BLOCK_MOD(block_buffer_tail + 1);
524 524
     }
525 525
 
@@ -528,7 +528,7 @@ class Planner {
528 528
      * Called after an interrupted move to throw away the rest of the move.
529 529
      */
530 530
     FORCE_INLINE static bool discard_continued_block() {
531
-      const bool discard = blocks_queued() && TEST(block_buffer[block_buffer_tail].flag, BLOCK_BIT_CONTINUED);
531
+      const bool discard = has_blocks_queued() && TEST(block_buffer[block_buffer_tail].flag, BLOCK_BIT_CONTINUED);
532 532
       if (discard) discard_current_block();
533 533
       return discard;
534 534
     }
@@ -539,7 +539,7 @@ class Planner {
539 539
      * WARNING: Called from Stepper ISR context!
540 540
      */
541 541
     static block_t* get_current_block() {
542
-      if (blocks_queued()) {
542
+      if (has_blocks_queued()) {
543 543
         block_t * const block = &block_buffer[block_buffer_tail];
544 544
 
545 545
         // If the block has no trapezoid calculated, it's unsafe to execute.

+ 0
- 3
Marlin/src/module/probe.cpp Visa fil

@@ -545,9 +545,6 @@ static float run_z_probe() {
545 545
     if (DEBUGGING(LEVELING)) DEBUG_POS(">>> run_z_probe", current_position);
546 546
   #endif
547 547
 
548
-  // Prevent stepper_inactive_time from running out and EXTRUDER_RUNOUT_PREVENT from extruding
549
-  gcode.refresh_cmd_timeout();
550
-
551 548
   // Double-probing does a fast probe followed by a slow probe
552 549
   #if MULTIPLE_PROBING == 2
553 550
 

+ 2
- 2
Marlin/src/module/stepper.cpp Visa fil

@@ -1091,7 +1091,7 @@ void Stepper::init() {
1091 1091
 /**
1092 1092
  * Block until all buffered steps are executed / cleaned
1093 1093
  */
1094
-void Stepper::synchronize() { while (planner.blocks_queued() || cleaning_buffer_counter) idle(); }
1094
+void Stepper::synchronize() { while (planner.has_blocks_queued() || cleaning_buffer_counter) idle(); }
1095 1095
 
1096 1096
 /**
1097 1097
  * Set the stepper positions directly in steps
@@ -1191,7 +1191,7 @@ void Stepper::finish_and_disable() {
1191 1191
 void Stepper::quick_stop() {
1192 1192
   cleaning_buffer_counter = 5000;
1193 1193
   DISABLE_STEPPER_DRIVER_INTERRUPT();
1194
-  while (planner.blocks_queued()) planner.discard_current_block();
1194
+  while (planner.has_blocks_queued()) planner.discard_current_block();
1195 1195
   current_block = NULL;
1196 1196
   ENABLE_STEPPER_DRIVER_INTERRUPT();
1197 1197
   #if ENABLED(ULTRA_LCD)

Laddar…
Avbryt
Spara