Browse Source

Discard all CONTINUED blocks on interrupted move

Scott Lahteine 7 years ago
parent
commit
75eb93140f
3 changed files with 34 additions and 14 deletions
  1. 4
    1
      Marlin/planner.cpp
  2. 19
    5
      Marlin/planner.h
  3. 11
    8
      Marlin/stepper.cpp

+ 4
- 1
Marlin/planner.cpp View File

778
   block_t* block = &block_buffer[block_buffer_head];
778
   block_t* block = &block_buffer[block_buffer_head];
779
 
779
 
780
   // Clear all flags, including the "busy" bit
780
   // Clear all flags, including the "busy" bit
781
-  block->flag = 0;
781
+  block->flag = 0x00;
782
 
782
 
783
   // Set direction bits
783
   // Set direction bits
784
   block->direction_bits = dm;
784
   block->direction_bits = dm;
1139
 
1139
 
1140
   float safe_speed = block->nominal_speed * min_axis_accel_ratio;
1140
   float safe_speed = block->nominal_speed * min_axis_accel_ratio;
1141
   static float previous_safe_speed;
1141
   static float previous_safe_speed;
1142
+
1142
   // Compute and limit the acceleration rate for the trapezoid generator.
1143
   // Compute and limit the acceleration rate for the trapezoid generator.
1143
   const float steps_per_mm = block->step_event_count * inverse_millimeters;
1144
   const float steps_per_mm = block->step_event_count * inverse_millimeters;
1144
   uint32_t accel;
1145
   uint32_t accel;
1423
     const int32_t between[XYZE] = { _BETWEEN(X), _BETWEEN(Y), _BETWEEN(Z), _BETWEEN(E) };
1424
     const int32_t between[XYZE] = { _BETWEEN(X), _BETWEEN(Y), _BETWEEN(Z), _BETWEEN(E) };
1424
     DISABLE_STEPPER_DRIVER_INTERRUPT();
1425
     DISABLE_STEPPER_DRIVER_INTERRUPT();
1425
     _buffer_steps(between, fr_mm_s, extruder);
1426
     _buffer_steps(between, fr_mm_s, extruder);
1427
+    const uint8_t next = block_buffer_head;
1426
     _buffer_steps(target, fr_mm_s, extruder);
1428
     _buffer_steps(target, fr_mm_s, extruder);
1429
+    SBI(block_buffer[next].flag, BLOCK_BIT_CONTINUED);
1427
     ENABLE_STEPPER_DRIVER_INTERRUPT();
1430
     ENABLE_STEPPER_DRIVER_INTERRUPT();
1428
   }
1431
   }
1429
   else
1432
   else

+ 19
- 5
Marlin/planner.h View File

53
   BLOCK_BIT_START_FROM_FULL_HALT,
53
   BLOCK_BIT_START_FROM_FULL_HALT,
54
 
54
 
55
   // The block is busy
55
   // The block is busy
56
-  BLOCK_BIT_BUSY
56
+  BLOCK_BIT_BUSY,
57
+
58
+  // The block is segment 2+ of a longer move
59
+  BLOCK_BIT_CONTINUED
57
 };
60
 };
58
 
61
 
59
 enum BlockFlag {
62
 enum BlockFlag {
60
   BLOCK_FLAG_RECALCULATE          = _BV(BLOCK_BIT_RECALCULATE),
63
   BLOCK_FLAG_RECALCULATE          = _BV(BLOCK_BIT_RECALCULATE),
61
   BLOCK_FLAG_NOMINAL_LENGTH       = _BV(BLOCK_BIT_NOMINAL_LENGTH),
64
   BLOCK_FLAG_NOMINAL_LENGTH       = _BV(BLOCK_BIT_NOMINAL_LENGTH),
62
   BLOCK_FLAG_START_FROM_FULL_HALT = _BV(BLOCK_BIT_START_FROM_FULL_HALT),
65
   BLOCK_FLAG_START_FROM_FULL_HALT = _BV(BLOCK_BIT_START_FROM_FULL_HALT),
63
-  BLOCK_FLAG_BUSY                 = _BV(BLOCK_BIT_BUSY)
66
+  BLOCK_FLAG_BUSY                 = _BV(BLOCK_BIT_BUSY),
67
+  BLOCK_FLAG_CONTINUED            = _BV(BLOCK_BIT_CONTINUED)
64
 };
68
 };
65
 
69
 
66
 /**
70
 /**
450
     static bool blocks_queued() { return (block_buffer_head != block_buffer_tail); }
454
     static bool blocks_queued() { return (block_buffer_head != block_buffer_tail); }
451
 
455
 
452
     /**
456
     /**
453
-     * "Discards" the block and "releases" the memory.
457
+     * "Discard" the block and "release" the memory.
454
      * Called when the current block is no longer needed.
458
      * Called when the current block is no longer needed.
455
      */
459
      */
456
-    static void discard_current_block() {
460
+    FORCE_INLINE static void discard_current_block() {
457
       if (blocks_queued())
461
       if (blocks_queued())
458
         block_buffer_tail = BLOCK_MOD(block_buffer_tail + 1);
462
         block_buffer_tail = BLOCK_MOD(block_buffer_tail + 1);
459
     }
463
     }
460
 
464
 
461
     /**
465
     /**
466
+     * "Discard" the next block if it's continued.
467
+     * Called after an interrupted move to throw away the rest of the move.
468
+     */
469
+    FORCE_INLINE static bool discard_continued_block() {
470
+      const bool discard = blocks_queued() && TEST(block_buffer[block_buffer_tail].flag, BLOCK_BIT_CONTINUED);
471
+      if (discard) discard_current_block();
472
+      return discard;
473
+    }
474
+
475
+    /**
462
      * The current block. NULL if the buffer is empty.
476
      * The current block. NULL if the buffer is empty.
463
      * This also marks the block as busy.
477
      * This also marks the block as busy.
464
      * WARNING: Called from Stepper ISR context!
478
      * WARNING: Called from Stepper ISR context!
465
      */
479
      */
466
     static block_t* get_current_block() {
480
     static block_t* get_current_block() {
467
       if (blocks_queued()) {
481
       if (blocks_queued()) {
468
-        block_t* block = &block_buffer[block_buffer_tail];
482
+        block_t * const block = &block_buffer[block_buffer_tail];
469
         #if ENABLED(ULTRA_LCD)
483
         #if ENABLED(ULTRA_LCD)
470
           block_buffer_runtime_us -= block->segment_time_us; // We can't be sure how long an active block will take, so don't count it.
484
           block_buffer_runtime_us -= block->segment_time_us; // We can't be sure how long an active block will take, so don't count it.
471
         #endif
485
         #endif

+ 11
- 8
Marlin/stepper.cpp View File

427
   // When cleaning, discard the current block and run fast
427
   // When cleaning, discard the current block and run fast
428
   //
428
   //
429
   if (cleaning_buffer_counter) {
429
   if (cleaning_buffer_counter) {
430
-    current_block = NULL;
431
-    planner.discard_current_block();
432
-    if (cleaning_buffer_counter < 0)
433
-      ++cleaning_buffer_counter;            // Count up for endstop hit
430
+    if (cleaning_buffer_counter < 0) {          // Count up for endstop hit
431
+      if (current_block) planner.discard_current_block(); // Discard the active block that led to the trigger
432
+      if (!planner.discard_continued_block())   // Discard next CONTINUED block
433
+        cleaning_buffer_counter = 0;            // Keep discarding until non-CONTINUED
434
+    }
434
     else {
435
     else {
435
-      --cleaning_buffer_counter;            // Count down for abort print
436
+      planner.discard_current_block();
437
+      --cleaning_buffer_counter;                // Count down for abort print
436
       #ifdef SD_FINISHED_RELEASECOMMAND
438
       #ifdef SD_FINISHED_RELEASECOMMAND
437
         if (!cleaning_buffer_counter && (SD_FINISHED_STEPPERRELEASE)) enqueue_and_echo_commands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
439
         if (!cleaning_buffer_counter && (SD_FINISHED_STEPPERRELEASE)) enqueue_and_echo_commands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
438
       #endif
440
       #endif
439
     }
441
     }
442
+    current_block = NULL;                       // Prep to get a new block after cleaning
440
     _NEXT_ISR(200);                             // Run at max speed - 10 KHz
443
     _NEXT_ISR(200);                             // Run at max speed - 10 KHz
441
     _ENABLE_ISRs();
444
     _ENABLE_ISRs();
442
     return;
445
     return;
1124
 
1127
 
1125
 
1128
 
1126
 /**
1129
 /**
1127
- * Block until all buffered steps are executed
1130
+ * Block until all buffered steps are executed / cleaned
1128
  */
1131
  */
1129
-void Stepper::synchronize() { while (planner.blocks_queued()) idle(); }
1132
+void Stepper::synchronize() { while (planner.blocks_queued() || cleaning_buffer_counter) idle(); }
1130
 
1133
 
1131
 /**
1134
 /**
1132
  * Set the stepper positions directly in steps
1135
  * Set the stepper positions directly in steps
1250
   #endif // !COREXY && !COREXZ && !COREYZ
1253
   #endif // !COREXY && !COREXZ && !COREYZ
1251
 
1254
 
1252
   kill_current_block();
1255
   kill_current_block();
1253
-  cleaning_buffer_counter = -(BLOCK_BUFFER_SIZE - 1); // Ignore remaining blocks
1256
+  cleaning_buffer_counter = -1; // Discard the rest of the move
1254
 }
1257
 }
1255
 
1258
 
1256
 void Stepper::report_positions() {
1259
 void Stepper::report_positions() {

Loading…
Cancel
Save