浏览代码

Merge pull request #8745 from thinkyhead/bf1_sync_M420_M852

[1.1.x] M852 skew changes position. And, position change reporting.
Scott Lahteine 7 年前
父节点
当前提交
db204c13f2
没有帐户链接到提交者的电子邮件
共有 4 个文件被更改,包括 77 次插入45 次删除
  1. 1
    1
      Marlin/Marlin.h
  2. 62
    27
      Marlin/Marlin_main.cpp
  3. 11
    16
      Marlin/configuration_store.cpp
  4. 3
    1
      Marlin/ubl.cpp

+ 1
- 1
Marlin/Marlin.h 查看文件

@@ -373,7 +373,7 @@ void report_current_position();
373 373
 #endif
374 374
 
375 375
 #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
376
-  void set_z_fade_height(const float zfh);
376
+  void set_z_fade_height(const float zfh, const bool do_report=true);
377 377
 #endif
378 378
 
379 379
 #if ENABLED(X_DUAL_ENDSTOPS)

+ 62
- 27
Marlin/Marlin_main.cpp 查看文件

@@ -340,11 +340,6 @@
340 340
   #include "ubl.h"
341 341
   extern bool defer_return_to_status;
342 342
   unified_bed_leveling ubl;
343
-  #define UBL_MESH_VALID !( ( ubl.z_values[0][0] == ubl.z_values[0][1] && ubl.z_values[0][1] == ubl.z_values[0][2] \
344
-                           && ubl.z_values[1][0] == ubl.z_values[1][1] && ubl.z_values[1][1] == ubl.z_values[1][2] \
345
-                           && ubl.z_values[2][0] == ubl.z_values[2][1] && ubl.z_values[2][1] == ubl.z_values[2][2] \
346
-                           && ubl.z_values[0][0] == 0 && ubl.z_values[1][0] == 0 && ubl.z_values[2][0] == 0 )  \
347
-                           || isnan(ubl.z_values[0][0]))
348 343
 #endif
349 344
 
350 345
 #if ENABLED(CNC_COORDINATE_SYSTEMS)
@@ -2469,13 +2464,17 @@ static void clean_up_after_endstop_or_probe_move() {
2469 2464
           // so compensation will give the right stepper counts.
2470 2465
           planner.unapply_leveling(current_position);
2471 2466
 
2467
+        SYNC_PLAN_POSITION_KINEMATIC();
2468
+
2472 2469
       #endif // ABL
2473 2470
     }
2474 2471
   }
2475 2472
 
2476 2473
   #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
2477 2474
 
2478
-    void set_z_fade_height(const float zfh) {
2475
+    void set_z_fade_height(const float zfh, const bool do_report/*=true*/) {
2476
+
2477
+      if (planner.z_fade_height == zfh) return; // do nothing if no change
2479 2478
 
2480 2479
       const bool level_active = planner.leveling_active;
2481 2480
 
@@ -2486,6 +2485,7 @@ static void clean_up_after_endstop_or_probe_move() {
2486 2485
       planner.set_z_fade_height(zfh);
2487 2486
 
2488 2487
       if (level_active) {
2488
+        const float oldpos[] = { current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] };
2489 2489
         #if ENABLED(AUTO_BED_LEVELING_UBL)
2490 2490
           set_bed_leveling_enabled(true);  // turn back on after changing fade height
2491 2491
         #else
@@ -2496,7 +2496,10 @@ static void clean_up_after_endstop_or_probe_move() {
2496 2496
               Z_AXIS
2497 2497
             #endif
2498 2498
           );
2499
+          SYNC_PLAN_POSITION_KINEMATIC();
2499 2500
         #endif
2501
+        if (do_report && memcmp(oldpos, current_position, sizeof(oldpos)))
2502
+          report_current_position();
2500 2503
       }
2501 2504
     }
2502 2505
 
@@ -4625,6 +4628,7 @@ void home_all_axes() { gcode_G28(true); }
4625 4628
               bed_level_virt_interpolate();
4626 4629
             #endif
4627 4630
             set_bed_leveling_enabled(abl_should_enable);
4631
+            report_current_position();
4628 4632
           }
4629 4633
           return;
4630 4634
         } // parser.seen('W')
@@ -9604,6 +9608,8 @@ void quickstop_stepper() {
9604 9608
    */
9605 9609
   inline void gcode_M420() {
9606 9610
 
9611
+    const float oldpos[] = { current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] };
9612
+
9607 9613
     #if ENABLED(AUTO_BED_LEVELING_UBL)
9608 9614
 
9609 9615
       // L to load a mesh from the EEPROM
@@ -9638,7 +9644,7 @@ void quickstop_stepper() {
9638 9644
       // L to load a mesh from the EEPROM
9639 9645
       if (parser.seen('L') || parser.seen('V')) {
9640 9646
         ubl.display_map(0);  // Currently only supports one map type
9641
-        SERIAL_ECHOLNPAIR("UBL_MESH_VALID = ", UBL_MESH_VALID);
9647
+        SERIAL_ECHOLNPAIR("ubl.mesh_is_valid = ", ubl.mesh_is_valid());
9642 9648
         SERIAL_ECHOLNPAIR("ubl.storage_slot = ", ubl.storage_slot);
9643 9649
       }
9644 9650
 
@@ -9663,14 +9669,16 @@ void quickstop_stepper() {
9663 9669
       #endif
9664 9670
     }
9665 9671
 
9666
-    const bool to_enable = parser.boolval('S');
9667
-    if (parser.seen('S'))
9668
-      set_bed_leveling_enabled(to_enable);
9669
-
9670 9672
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
9671
-      if (parser.seen('Z')) set_z_fade_height(parser.value_linear_units());
9673
+      if (parser.seen('Z')) set_z_fade_height(parser.value_linear_units(), false);
9672 9674
     #endif
9673 9675
 
9676
+    bool to_enable = false;
9677
+    if (parser.seen('S')) {
9678
+      to_enable = parser.value_bool();
9679
+      set_bed_leveling_enabled(to_enable);
9680
+    }
9681
+
9674 9682
     const bool new_status = planner.leveling_active;
9675 9683
 
9676 9684
     if (to_enable && !new_status) {
@@ -9689,6 +9697,10 @@ void quickstop_stepper() {
9689 9697
       else
9690 9698
         SERIAL_ECHOLNPGM(MSG_OFF);
9691 9699
     #endif
9700
+
9701
+    // Report change in position
9702
+    if (memcmp(oldpos, current_position, sizeof(oldpos)))
9703
+      report_current_position();
9692 9704
   }
9693 9705
 #endif
9694 9706
 
@@ -9902,37 +9914,47 @@ inline void gcode_M502() {
9902 9914
    *  K[yz_factor] - New YZ skew factor
9903 9915
    */
9904 9916
   inline void gcode_M852() {
9905
-    const bool ijk = parser.seen('I') || parser.seen('S')
9906
-      #if ENABLED(SKEW_CORRECTION_FOR_Z)
9907
-        || parser.seen('J') || parser.seen('K')
9908
-      #endif
9909
-    ;
9910
-    bool badval = false;
9917
+    uint8_t ijk = 0, badval = 0, setval = 0;
9911 9918
 
9912 9919
     if (parser.seen('I') || parser.seen('S')) {
9920
+      ++ijk;
9913 9921
       const float value = parser.value_linear_units();
9914
-      if (WITHIN(value, SKEW_FACTOR_MIN, SKEW_FACTOR_MAX))
9915
-        planner.xy_skew_factor = value;
9922
+      if (WITHIN(value, SKEW_FACTOR_MIN, SKEW_FACTOR_MAX)) {
9923
+        if (planner.xy_skew_factor != value) {
9924
+          planner.xy_skew_factor = value;
9925
+          ++setval;
9926
+        }
9927
+      }
9916 9928
       else
9917
-        badval = true;
9929
+        ++badval;
9918 9930
     }
9919 9931
 
9920 9932
     #if ENABLED(SKEW_CORRECTION_FOR_Z)
9921 9933
 
9922 9934
       if (parser.seen('J')) {
9935
+        ++ijk;
9923 9936
         const float value = parser.value_linear_units();
9924
-        if (WITHIN(value, SKEW_FACTOR_MIN, SKEW_FACTOR_MAX))
9925
-          planner.xz_skew_factor = value;
9937
+        if (WITHIN(value, SKEW_FACTOR_MIN, SKEW_FACTOR_MAX)) {
9938
+          if (planner.xz_skew_factor != value) {
9939
+            planner.xz_skew_factor = value;
9940
+            ++setval;
9941
+          }
9942
+        }
9926 9943
         else
9927
-          badval = true;
9944
+          ++badval;
9928 9945
       }
9929 9946
 
9930 9947
       if (parser.seen('K')) {
9948
+        ++ijk;
9931 9949
         const float value = parser.value_linear_units();
9932
-        if (WITHIN(value, SKEW_FACTOR_MIN, SKEW_FACTOR_MAX))
9933
-          planner.yz_skew_factor = value;
9950
+        if (WITHIN(value, SKEW_FACTOR_MIN, SKEW_FACTOR_MAX)) {
9951
+          if (planner.yz_skew_factor != value) {
9952
+            planner.yz_skew_factor = value;
9953
+            ++setval;
9954
+          }
9955
+        }
9934 9956
         else
9935
-          badval = true;
9957
+          ++badval;
9936 9958
       }
9937 9959
 
9938 9960
     #endif
@@ -9940,6 +9962,13 @@ inline void gcode_M502() {
9940 9962
     if (badval)
9941 9963
       SERIAL_ECHOLNPGM(MSG_SKEW_MIN " " STRINGIFY(SKEW_FACTOR_MIN) " " MSG_SKEW_MAX " " STRINGIFY(SKEW_FACTOR_MAX));
9942 9964
 
9965
+    // When skew is changed the current position changes
9966
+    if (setval) {
9967
+      set_current_from_steppers_for_axis(ALL_AXES);
9968
+      SYNC_PLAN_POSITION_KINEMATIC();
9969
+      report_current_position();
9970
+    }
9971
+
9943 9972
     if (!ijk) {
9944 9973
       SERIAL_ECHO_START();
9945 9974
       SERIAL_ECHOPAIR(MSG_SKEW_FACTOR " XY: ", planner.xy_skew_factor);
@@ -12391,6 +12420,12 @@ void get_cartesian_from_steppers() {
12391 12420
  * Set the current_position for an axis based on
12392 12421
  * the stepper positions, removing any leveling that
12393 12422
  * may have been applied.
12423
+ *
12424
+ * To prevent small shifts in axis position always call
12425
+ * SYNC_PLAN_POSITION_KINEMATIC after updating axes with this.
12426
+ *
12427
+ * To keep hosts in sync, always call report_current_position
12428
+ * after updating the current_position.
12394 12429
  */
12395 12430
 void set_current_from_steppers_for_axis(const AxisEnum axis) {
12396 12431
   get_cartesian_from_steppers();

+ 11
- 16
Marlin/configuration_store.cpp 查看文件

@@ -215,14 +215,12 @@ MarlinSettings settings;
215 215
   float new_z_fade_height;
216 216
 #endif
217 217
 
218
-#if ENABLED(CNC_COORDINATE_SYSTEMS)
219
-  bool position_changed;
220
-#endif
221
-
222 218
 /**
223 219
  * Post-process after Retrieve or Reset
224 220
  */
225 221
 void MarlinSettings::postprocess() {
222
+  const float oldpos[] = { current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] };
223
+
226 224
   // steps per s2 needs to be updated to agree with units per s2
227 225
   planner.reset_acceleration_rates();
228 226
 
@@ -232,10 +230,6 @@ void MarlinSettings::postprocess() {
232 230
     recalc_delta_settings();
233 231
   #endif
234 232
 
235
-  // Refresh steps_to_mm with the reciprocal of axis_steps_per_mm
236
-  // and init stepper.count[], planner.position[] with current_position
237
-  planner.refresh_positioning();
238
-
239 233
   #if ENABLED(PIDTEMP)
240 234
     thermalManager.updatePID();
241 235
   #endif
@@ -248,7 +242,7 @@ void MarlinSettings::postprocess() {
248 242
   #endif
249 243
 
250 244
   #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
251
-    set_z_fade_height(new_z_fade_height);
245
+    set_z_fade_height(new_z_fade_height, false); // false = no report
252 246
   #endif
253 247
 
254 248
   #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
@@ -260,12 +254,13 @@ void MarlinSettings::postprocess() {
260 254
     stepper.refresh_motor_power();
261 255
   #endif
262 256
 
263
-  #if ENABLED(CNC_COORDINATE_SYSTEMS)
264
-    if (position_changed) {
265
-      report_current_position();
266
-      position_changed = false;
267
-    }
268
-  #endif
257
+  // Refresh steps_to_mm with the reciprocal of axis_steps_per_mm
258
+  // and init stepper.count[], planner.position[] with current_position
259
+  planner.refresh_positioning();
260
+
261
+  // Various factors can change the current position
262
+  if (memcmp(oldpos, current_position, sizeof(oldpos)))
263
+    report_current_position();
269 264
 }
270 265
 
271 266
 #if ENABLED(EEPROM_SETTINGS)
@@ -1121,7 +1116,7 @@ void MarlinSettings::postprocess() {
1121 1116
       //
1122 1117
 
1123 1118
       #if ENABLED(CNC_COORDINATE_SYSTEMS)
1124
-        position_changed = select_coordinate_system(-1); // Go back to machine space
1119
+        (void)select_coordinate_system(-1); // Go back to machine space
1125 1120
         EEPROM_READ(coordinate_system);                  // 27 floats
1126 1121
       #else
1127 1122
         for (uint8_t q = 27; q--;) EEPROM_READ(dummy);

+ 3
- 1
Marlin/ubl.cpp 查看文件

@@ -67,17 +67,19 @@
67 67
   volatile int unified_bed_leveling::encoder_diff;
68 68
 
69 69
   unified_bed_leveling::unified_bed_leveling() {
70
-    ubl_cnt++;  // Debug counter to insure we only have one UBL object present in memory.  We can eliminate this (and all references to ubl_cnt) very soon.
70
+    ubl_cnt++;  // Debug counter to ensure we only have one UBL object present in memory.  We can eliminate this (and all references to ubl_cnt) very soon.
71 71
     reset();
72 72
   }
73 73
 
74 74
   void unified_bed_leveling::reset() {
75
+    const bool was_enabled = planner.leveling_active;
75 76
     set_bed_leveling_enabled(false);
76 77
     storage_slot = -1;
77 78
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
78 79
       planner.set_z_fade_height(10.0);
79 80
     #endif
80 81
     ZERO(z_values);
82
+    if (was_enabled) report_current_position();
81 83
   }
82 84
 
83 85
   void unified_bed_leveling::invalidate() {

正在加载...
取消
保存