Procházet zdrojové kódy

Merge pull request #3939 from thinkyhead/rc_resume_get_position

set_current_position_from_planner() after stepper.quick_stop()
Scott Lahteine před 8 roky
rodič
revize
0d793fb2be
6 změnil soubory, kde provedl 54 přidání a 15 odebrání
  1. 5
    0
      Marlin/Marlin.h
  2. 35
    8
      Marlin/Marlin_main.cpp
  3. 3
    0
      Marlin/endstops.cpp
  4. 3
    3
      Marlin/planner.cpp
  5. 3
    3
      Marlin/planner.h
  6. 5
    1
      Marlin/ultralcd.cpp

+ 5
- 0
Marlin/Marlin.h Zobrazit soubor

@@ -227,6 +227,10 @@ void reset_bed_level();
227 227
 void prepare_move();
228 228
 void kill(const char*);
229 229
 
230
+#if DISABLED(DELTA) && DISABLED(SCARA)
231
+  void set_current_position_from_planner();
232
+#endif
233
+
230 234
 #if ENABLED(FILAMENT_RUNOUT_SENSOR)
231 235
   void handle_filament_runout();
232 236
 #endif
@@ -253,6 +257,7 @@ inline bool IsStopped() { return !Running; }
253 257
 bool enqueue_and_echo_command(const char* cmd, bool say_ok=false); //put a single ASCII command at the end of the current buffer or return false when it is full
254 258
 void enqueue_and_echo_command_now(const char* cmd); // enqueue now, only return when the command has been enqueued
255 259
 void enqueue_and_echo_commands_P(const char* cmd); //put one or many ASCII commands at the end of the current buffer, read from flash
260
+void clear_command_queue();
256 261
 
257 262
 void clamp_to_software_endstops(float target[3]);
258 263
 

+ 35
- 8
Marlin/Marlin_main.cpp Zobrazit soubor

@@ -552,7 +552,7 @@ static void report_current_position();
552 552
       if (DEBUGGING(LEVELING)) DEBUG_POS("sync_plan_position_delta", current_position);
553 553
     #endif
554 554
     calculate_delta(current_position);
555
-    planner.set_position(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS]);
555
+    planner.set_position_mm(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS]);
556 556
   }
557 557
 #endif
558 558
 
@@ -613,6 +613,11 @@ void enqueue_and_echo_commands_P(const char* pgcode) {
613 613
   drain_queued_commands_P(); // first command executed asap (when possible)
614 614
 }
615 615
 
616
+void clear_command_queue() {
617
+  cmd_queue_index_r = cmd_queue_index_w;
618
+  commands_in_queue = 0;
619
+}
620
+
616 621
 /**
617 622
  * Once a new command is in the ring buffer, call this to commit it
618 623
  */
@@ -1448,9 +1453,9 @@ inline void sync_plan_position() {
1448 1453
   #if ENABLED(DEBUG_LEVELING_FEATURE)
1449 1454
     if (DEBUGGING(LEVELING)) DEBUG_POS("sync_plan_position", current_position);
1450 1455
   #endif
1451
-  planner.set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
1456
+  planner.set_position_mm(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
1452 1457
 }
1453
-inline void sync_plan_position_e() { planner.set_e_position(current_position[E_AXIS]); }
1458
+inline void sync_plan_position_e() { planner.set_e_position_mm(current_position[E_AXIS]); }
1454 1459
 inline void set_current_to_destination() { memcpy(current_position, destination, sizeof(current_position)); }
1455 1460
 inline void set_destination_to_current() { memcpy(destination, current_position, sizeof(destination)); }
1456 1461
 
@@ -1607,7 +1612,7 @@ static void setup_for_endstop_move() {
1607 1612
 
1608 1613
       // Tell the planner where we ended up - Get this from the stepper handler
1609 1614
       zPosition = stepper.get_axis_position_mm(Z_AXIS);
1610
-      planner.set_position(
1615
+      planner.set_position_mm(
1611 1616
         current_position[X_AXIS], current_position[Y_AXIS], zPosition,
1612 1617
         current_position[E_AXIS]
1613 1618
       );
@@ -3593,7 +3598,7 @@ inline void gcode_G28() {
3593 3598
          * Get the current Z position and send it to the planner.
3594 3599
          *
3595 3600
          * >> (z_tmp - real_z) : The rotated current Z minus the uncorrected Z
3596
-         * (most recent planner.set_position/sync_plan_position)
3601
+         * (most recent planner.set_position_mm/sync_plan_position)
3597 3602
          *
3598 3603
          * >> zprobe_zoffset : Z distance from nozzle to Z probe
3599 3604
          * (set by default, M851, EEPROM, or Menu)
@@ -5889,13 +5894,35 @@ inline void gcode_M400() { stepper.synchronize(); }
5889 5894
 
5890 5895
 #endif // FILAMENT_WIDTH_SENSOR
5891 5896
 
5897
+#if DISABLED(DELTA) && DISABLED(SCARA)
5898
+  void set_current_position_from_planner() {
5899
+    stepper.synchronize();
5900
+    #if ENABLED(AUTO_BED_LEVELING_FEATURE)
5901
+      vector_3 pos = planner.adjusted_position(); // values directly from steppers...
5902
+      current_position[X_AXIS] = pos.x;
5903
+      current_position[Y_AXIS] = pos.y;
5904
+      current_position[Z_AXIS] = pos.z;
5905
+    #else
5906
+      current_position[X_AXIS] = stepper.get_axis_position_mm(X_AXIS);
5907
+      current_position[Y_AXIS] = stepper.get_axis_position_mm(Y_AXIS);
5908
+      current_position[Z_AXIS] = stepper.get_axis_position_mm(Z_AXIS);
5909
+    #endif
5910
+    sync_plan_position();                       // ...re-apply to planner position
5911
+  }
5912
+#endif
5913
+
5892 5914
 /**
5893 5915
  * M410: Quickstop - Abort all planned moves
5894 5916
  *
5895 5917
  * This will stop the carriages mid-move, so most likely they
5896 5918
  * will be out of sync with the stepper position after this.
5897 5919
  */
5898
-inline void gcode_M410() { stepper.quick_stop(); }
5920
+inline void gcode_M410() {
5921
+  stepper.quick_stop();
5922
+  #if DISABLED(DELTA) && DISABLED(SCARA)
5923
+    set_current_position_from_planner();
5924
+  #endif
5925
+}
5899 5926
 
5900 5927
 
5901 5928
 #if ENABLED(MESH_BED_LEVELING)
@@ -7436,7 +7463,7 @@ void mesh_buffer_line(float x, float y, float z, const float e, float feed_rate,
7436 7463
     if (active_extruder_parked) {
7437 7464
       if (dual_x_carriage_mode == DXC_DUPLICATION_MODE && active_extruder == 0) {
7438 7465
         // move duplicate extruder into correct duplication position.
7439
-        planner.set_position(inactive_extruder_x_pos, current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
7466
+        planner.set_position_mm(inactive_extruder_x_pos, current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
7440 7467
         planner.buffer_line(current_position[X_AXIS] + duplicate_extruder_x_offset,
7441 7468
                          current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], planner.max_feedrate[X_AXIS], 1);
7442 7469
         sync_plan_position();
@@ -7989,7 +8016,7 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) {
7989 8016
                          (EXTRUDER_RUNOUT_SPEED) / 60. * (EXTRUDER_RUNOUT_ESTEPS) / planner.axis_steps_per_unit[E_AXIS], active_extruder);
7990 8017
       current_position[E_AXIS] = oldepos;
7991 8018
       destination[E_AXIS] = oldedes;
7992
-      planner.set_e_position(oldepos);
8019
+      planner.set_e_position_mm(oldepos);
7993 8020
       previous_cmd_ms = ms; // refresh_cmd_timeout()
7994 8021
       stepper.synchronize();
7995 8022
       switch (active_extruder) {

+ 3
- 0
Marlin/endstops.cpp Zobrazit soubor

@@ -187,6 +187,9 @@ void Endstops::report_state() {
187 187
         card.sdprinting = false;
188 188
         card.closefile();
189 189
         stepper.quick_stop();
190
+        #if DISABLED(DELTA) && DISABLED(SCARA)
191
+          set_current_position_from_planner();
192
+        #endif
190 193
         thermalManager.disable_all_heaters(); // switch off all heaters.
191 194
       }
192 195
     #endif

+ 3
- 3
Marlin/planner.cpp Zobrazit soubor

@@ -1114,9 +1114,9 @@ void Planner::check_axes_activity() {
1114 1114
  * On CORE machines stepper ABC will be translated from the given XYZ.
1115 1115
  */
1116 1116
 #if ENABLED(AUTO_BED_LEVELING_FEATURE) || ENABLED(MESH_BED_LEVELING)
1117
-  void Planner::set_position(float x, float y, float z, const float& e)
1117
+  void Planner::set_position_mm(float x, float y, float z, const float& e)
1118 1118
 #else
1119
-  void Planner::set_position(const float& x, const float& y, const float& z, const float& e)
1119
+  void Planner::set_position_mm(const float& x, const float& y, const float& z, const float& e)
1120 1120
 #endif // AUTO_BED_LEVELING_FEATURE || MESH_BED_LEVELING
1121 1121
   {
1122 1122
     #if ENABLED(MESH_BED_LEVELING)
@@ -1138,7 +1138,7 @@ void Planner::check_axes_activity() {
1138 1138
 /**
1139 1139
  * Directly set the planner E position (hence the stepper E position).
1140 1140
  */
1141
-void Planner::set_e_position(const float& e) {
1141
+void Planner::set_e_position_mm(const float& e) {
1142 1142
   position[E_AXIS] = lround(e * axis_steps_per_unit[E_AXIS]);
1143 1143
   stepper.set_e_position(position[E_AXIS]);
1144 1144
 }

+ 3
- 3
Marlin/planner.h Zobrazit soubor

@@ -216,19 +216,19 @@ class Planner {
216 216
        *
217 217
        * Clears previous speed values.
218 218
        */
219
-      static void set_position(float x, float y, float z, const float& e);
219
+      static void set_position_mm(float x, float y, float z, const float& e);
220 220
 
221 221
     #else
222 222
 
223 223
       static void buffer_line(const float& x, const float& y, const float& z, const float& e, float feed_rate, const uint8_t extruder);
224
-      static void set_position(const float& x, const float& y, const float& z, const float& e);
224
+      static void set_position_mm(const float& x, const float& y, const float& z, const float& e);
225 225
 
226 226
     #endif // AUTO_BED_LEVELING_FEATURE || MESH_BED_LEVELING
227 227
 
228 228
     /**
229 229
      * Set the E position (mm) of the planner (and the E stepper)
230 230
      */
231
-    static void set_e_position(const float& e);
231
+    static void set_e_position_mm(const float& e);
232 232
 
233 233
     /**
234 234
      * Does the buffer have any blocks queued?

+ 5
- 1
Marlin/ultralcd.cpp Zobrazit soubor

@@ -482,6 +482,10 @@ inline void line_to_current(AxisEnum axis) {
482 482
 
483 483
   static void lcd_sdcard_stop() {
484 484
     stepper.quick_stop();
485
+    #if DISABLED(DELTA) && DISABLED(SCARA)
486
+      set_current_position_from_planner();
487
+    #endif
488
+    clear_command_queue();
485 489
     card.sdprinting = false;
486 490
     card.closefile();
487 491
     print_job_timer.stop();
@@ -1037,7 +1041,7 @@ void lcd_cooldown() {
1037 1041
     if (LCD_CLICKED) {
1038 1042
       _lcd_level_bed_position = 0;
1039 1043
       current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
1040
-      planner.set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
1044
+      planner.set_position_mm(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
1041 1045
       lcd_goto_menu(_lcd_level_goto_next_point, true);
1042 1046
     }
1043 1047
   }

Loading…
Zrušit
Uložit