Bläddra i källkod

Merge pull request #8745 from thinkyhead/bf1_sync_M420_M852

[1.1.x] M852 skew changes position. And, position change reporting.
Scott Lahteine 7 år sedan
förälder
incheckning
db204c13f2
Inget konto är kopplat till bidragsgivarens mejladress
4 ändrade filer med 77 tillägg och 45 borttagningar
  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 Visa fil

373
 #endif
373
 #endif
374
 
374
 
375
 #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
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
 #endif
377
 #endif
378
 
378
 
379
 #if ENABLED(X_DUAL_ENDSTOPS)
379
 #if ENABLED(X_DUAL_ENDSTOPS)

+ 62
- 27
Marlin/Marlin_main.cpp Visa fil

340
   #include "ubl.h"
340
   #include "ubl.h"
341
   extern bool defer_return_to_status;
341
   extern bool defer_return_to_status;
342
   unified_bed_leveling ubl;
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
 #endif
343
 #endif
349
 
344
 
350
 #if ENABLED(CNC_COORDINATE_SYSTEMS)
345
 #if ENABLED(CNC_COORDINATE_SYSTEMS)
2469
           // so compensation will give the right stepper counts.
2464
           // so compensation will give the right stepper counts.
2470
           planner.unapply_leveling(current_position);
2465
           planner.unapply_leveling(current_position);
2471
 
2466
 
2467
+        SYNC_PLAN_POSITION_KINEMATIC();
2468
+
2472
       #endif // ABL
2469
       #endif // ABL
2473
     }
2470
     }
2474
   }
2471
   }
2475
 
2472
 
2476
   #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
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
       const bool level_active = planner.leveling_active;
2479
       const bool level_active = planner.leveling_active;
2481
 
2480
 
2486
       planner.set_z_fade_height(zfh);
2485
       planner.set_z_fade_height(zfh);
2487
 
2486
 
2488
       if (level_active) {
2487
       if (level_active) {
2488
+        const float oldpos[] = { current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] };
2489
         #if ENABLED(AUTO_BED_LEVELING_UBL)
2489
         #if ENABLED(AUTO_BED_LEVELING_UBL)
2490
           set_bed_leveling_enabled(true);  // turn back on after changing fade height
2490
           set_bed_leveling_enabled(true);  // turn back on after changing fade height
2491
         #else
2491
         #else
2496
               Z_AXIS
2496
               Z_AXIS
2497
             #endif
2497
             #endif
2498
           );
2498
           );
2499
+          SYNC_PLAN_POSITION_KINEMATIC();
2499
         #endif
2500
         #endif
2501
+        if (do_report && memcmp(oldpos, current_position, sizeof(oldpos)))
2502
+          report_current_position();
2500
       }
2503
       }
2501
     }
2504
     }
2502
 
2505
 
4625
               bed_level_virt_interpolate();
4628
               bed_level_virt_interpolate();
4626
             #endif
4629
             #endif
4627
             set_bed_leveling_enabled(abl_should_enable);
4630
             set_bed_leveling_enabled(abl_should_enable);
4631
+            report_current_position();
4628
           }
4632
           }
4629
           return;
4633
           return;
4630
         } // parser.seen('W')
4634
         } // parser.seen('W')
9604
    */
9608
    */
9605
   inline void gcode_M420() {
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
     #if ENABLED(AUTO_BED_LEVELING_UBL)
9613
     #if ENABLED(AUTO_BED_LEVELING_UBL)
9608
 
9614
 
9609
       // L to load a mesh from the EEPROM
9615
       // L to load a mesh from the EEPROM
9638
       // L to load a mesh from the EEPROM
9644
       // L to load a mesh from the EEPROM
9639
       if (parser.seen('L') || parser.seen('V')) {
9645
       if (parser.seen('L') || parser.seen('V')) {
9640
         ubl.display_map(0);  // Currently only supports one map type
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
         SERIAL_ECHOLNPAIR("ubl.storage_slot = ", ubl.storage_slot);
9648
         SERIAL_ECHOLNPAIR("ubl.storage_slot = ", ubl.storage_slot);
9643
       }
9649
       }
9644
 
9650
 
9663
       #endif
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
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
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
     #endif
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
     const bool new_status = planner.leveling_active;
9682
     const bool new_status = planner.leveling_active;
9675
 
9683
 
9676
     if (to_enable && !new_status) {
9684
     if (to_enable && !new_status) {
9689
       else
9697
       else
9690
         SERIAL_ECHOLNPGM(MSG_OFF);
9698
         SERIAL_ECHOLNPGM(MSG_OFF);
9691
     #endif
9699
     #endif
9700
+
9701
+    // Report change in position
9702
+    if (memcmp(oldpos, current_position, sizeof(oldpos)))
9703
+      report_current_position();
9692
   }
9704
   }
9693
 #endif
9705
 #endif
9694
 
9706
 
9902
    *  K[yz_factor] - New YZ skew factor
9914
    *  K[yz_factor] - New YZ skew factor
9903
    */
9915
    */
9904
   inline void gcode_M852() {
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
     if (parser.seen('I') || parser.seen('S')) {
9919
     if (parser.seen('I') || parser.seen('S')) {
9920
+      ++ijk;
9913
       const float value = parser.value_linear_units();
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
       else
9928
       else
9917
-        badval = true;
9929
+        ++badval;
9918
     }
9930
     }
9919
 
9931
 
9920
     #if ENABLED(SKEW_CORRECTION_FOR_Z)
9932
     #if ENABLED(SKEW_CORRECTION_FOR_Z)
9921
 
9933
 
9922
       if (parser.seen('J')) {
9934
       if (parser.seen('J')) {
9935
+        ++ijk;
9923
         const float value = parser.value_linear_units();
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
         else
9943
         else
9927
-          badval = true;
9944
+          ++badval;
9928
       }
9945
       }
9929
 
9946
 
9930
       if (parser.seen('K')) {
9947
       if (parser.seen('K')) {
9948
+        ++ijk;
9931
         const float value = parser.value_linear_units();
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
         else
9956
         else
9935
-          badval = true;
9957
+          ++badval;
9936
       }
9958
       }
9937
 
9959
 
9938
     #endif
9960
     #endif
9940
     if (badval)
9962
     if (badval)
9941
       SERIAL_ECHOLNPGM(MSG_SKEW_MIN " " STRINGIFY(SKEW_FACTOR_MIN) " " MSG_SKEW_MAX " " STRINGIFY(SKEW_FACTOR_MAX));
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
     if (!ijk) {
9972
     if (!ijk) {
9944
       SERIAL_ECHO_START();
9973
       SERIAL_ECHO_START();
9945
       SERIAL_ECHOPAIR(MSG_SKEW_FACTOR " XY: ", planner.xy_skew_factor);
9974
       SERIAL_ECHOPAIR(MSG_SKEW_FACTOR " XY: ", planner.xy_skew_factor);
12391
  * Set the current_position for an axis based on
12420
  * Set the current_position for an axis based on
12392
  * the stepper positions, removing any leveling that
12421
  * the stepper positions, removing any leveling that
12393
  * may have been applied.
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
 void set_current_from_steppers_for_axis(const AxisEnum axis) {
12430
 void set_current_from_steppers_for_axis(const AxisEnum axis) {
12396
   get_cartesian_from_steppers();
12431
   get_cartesian_from_steppers();

+ 11
- 16
Marlin/configuration_store.cpp Visa fil

215
   float new_z_fade_height;
215
   float new_z_fade_height;
216
 #endif
216
 #endif
217
 
217
 
218
-#if ENABLED(CNC_COORDINATE_SYSTEMS)
219
-  bool position_changed;
220
-#endif
221
-
222
 /**
218
 /**
223
  * Post-process after Retrieve or Reset
219
  * Post-process after Retrieve or Reset
224
  */
220
  */
225
 void MarlinSettings::postprocess() {
221
 void MarlinSettings::postprocess() {
222
+  const float oldpos[] = { current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] };
223
+
226
   // steps per s2 needs to be updated to agree with units per s2
224
   // steps per s2 needs to be updated to agree with units per s2
227
   planner.reset_acceleration_rates();
225
   planner.reset_acceleration_rates();
228
 
226
 
232
     recalc_delta_settings();
230
     recalc_delta_settings();
233
   #endif
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
   #if ENABLED(PIDTEMP)
233
   #if ENABLED(PIDTEMP)
240
     thermalManager.updatePID();
234
     thermalManager.updatePID();
241
   #endif
235
   #endif
248
   #endif
242
   #endif
249
 
243
 
250
   #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
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
   #endif
246
   #endif
253
 
247
 
254
   #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
248
   #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
260
     stepper.refresh_motor_power();
254
     stepper.refresh_motor_power();
261
   #endif
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
 #if ENABLED(EEPROM_SETTINGS)
266
 #if ENABLED(EEPROM_SETTINGS)
1121
       //
1116
       //
1122
 
1117
 
1123
       #if ENABLED(CNC_COORDINATE_SYSTEMS)
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
         EEPROM_READ(coordinate_system);                  // 27 floats
1120
         EEPROM_READ(coordinate_system);                  // 27 floats
1126
       #else
1121
       #else
1127
         for (uint8_t q = 27; q--;) EEPROM_READ(dummy);
1122
         for (uint8_t q = 27; q--;) EEPROM_READ(dummy);

+ 3
- 1
Marlin/ubl.cpp Visa fil

67
   volatile int unified_bed_leveling::encoder_diff;
67
   volatile int unified_bed_leveling::encoder_diff;
68
 
68
 
69
   unified_bed_leveling::unified_bed_leveling() {
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
     reset();
71
     reset();
72
   }
72
   }
73
 
73
 
74
   void unified_bed_leveling::reset() {
74
   void unified_bed_leveling::reset() {
75
+    const bool was_enabled = planner.leveling_active;
75
     set_bed_leveling_enabled(false);
76
     set_bed_leveling_enabled(false);
76
     storage_slot = -1;
77
     storage_slot = -1;
77
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
78
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
78
       planner.set_z_fade_height(10.0);
79
       planner.set_z_fade_height(10.0);
79
     #endif
80
     #endif
80
     ZERO(z_values);
81
     ZERO(z_values);
82
+    if (was_enabled) report_current_position();
81
   }
83
   }
82
 
84
 
83
   void unified_bed_leveling::invalidate() {
85
   void unified_bed_leveling::invalidate() {

Laddar…
Avbryt
Spara