Преглед на файлове

Merge pull request #8747 from thinkyhead/bf2_sync_M420_M852

[2.0.x] M852 changes position. Position change reporting.
Scott Lahteine преди 7 години
родител
ревизия
f53e0702fc
No account linked to committer's email address

+ 12
- 1
Marlin/src/feature/bedlevel/bedlevel.cpp Целия файл

@@ -128,13 +128,17 @@ void set_bed_leveling_enabled(const bool enable/*=true*/) {
128 128
         // so compensation will give the right stepper counts.
129 129
         planner.unapply_leveling(current_position);
130 130
 
131
+      SYNC_PLAN_POSITION_KINEMATIC();
132
+
131 133
     #endif // OLDSCHOOL_ABL
132 134
   }
133 135
 }
134 136
 
135 137
 #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
136 138
 
137
-  void set_z_fade_height(const float zfh) {
139
+  void set_z_fade_height(const float zfh, const bool do_report/*=true*/) {
140
+
141
+    if (planner.z_fade_height == zfh) return; // do nothing if no change
138 142
 
139 143
     const bool level_active = planner.leveling_active;
140 144
 
@@ -145,6 +149,10 @@ void set_bed_leveling_enabled(const bool enable/*=true*/) {
145 149
     planner.set_z_fade_height(zfh);
146 150
 
147 151
     if (level_active) {
152
+      const float oldpos[XYZE] = {
153
+        current_position[X_AXIS], current_position[Y_AXIS],
154
+        current_position[Z_AXIS], current_position[E_AXIS]
155
+      };
148 156
       #if ENABLED(AUTO_BED_LEVELING_UBL)
149 157
         set_bed_leveling_enabled(true);  // turn back on after changing fade height
150 158
       #else
@@ -155,7 +163,10 @@ void set_bed_leveling_enabled(const bool enable/*=true*/) {
155 163
             Z_AXIS
156 164
           #endif
157 165
         );
166
+        SYNC_PLAN_POSITION_KINEMATIC();
158 167
       #endif
168
+      if (do_report && memcmp(oldpos, current_position, sizeof(oldpos)))
169
+        report_current_position();
159 170
     }
160 171
   }
161 172
 

+ 1
- 1
Marlin/src/feature/bedlevel/bedlevel.h Целия файл

@@ -47,7 +47,7 @@ void set_bed_leveling_enabled(const bool enable=true);
47 47
 void reset_bed_level();
48 48
 
49 49
 #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
50
-  void set_z_fade_height(const float zfh);
50
+  void set_z_fade_height(const float zfh, const bool do_report=true);
51 51
 #endif
52 52
 
53 53
 #if ENABLED(AUTO_BED_LEVELING_BILINEAR) || ENABLED(MESH_BED_LEVELING)

+ 3
- 1
Marlin/src/feature/bedlevel/ubl/ubl.cpp Целия файл

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

+ 16
- 4
Marlin/src/gcode/bedlevel/M420.cpp Целия файл

@@ -45,6 +45,11 @@
45 45
  */
46 46
 void GcodeSuite::M420() {
47 47
 
48
+  const float oldpos[XYZE] = {
49
+    current_position[X_AXIS], current_position[Y_AXIS],
50
+    current_position[Z_AXIS], current_position[E_AXIS]
51
+  };
52
+
48 53
   #if ENABLED(AUTO_BED_LEVELING_UBL)
49 54
 
50 55
     // L to load a mesh from the EEPROM
@@ -104,13 +109,16 @@ void GcodeSuite::M420() {
104 109
     #endif
105 110
   }
106 111
 
107
-  const bool to_enable = parser.boolval('S');
108
-  if (parser.seen('S')) set_bed_leveling_enabled(to_enable);
109
-
110 112
   #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
111
-    if (parser.seen('Z')) set_z_fade_height(parser.value_linear_units());
113
+    if (parser.seen('Z')) set_z_fade_height(parser.value_linear_units(), false);
112 114
   #endif
113 115
 
116
+  bool to_enable = false;
117
+  if (parser.seen('S')) {
118
+    to_enable = parser.value_bool();
119
+    set_bed_leveling_enabled(to_enable);
120
+  }
121
+
114 122
   const bool new_status = planner.leveling_active;
115 123
 
116 124
   if (to_enable && !new_status) {
@@ -129,6 +137,10 @@ void GcodeSuite::M420() {
129 137
     else
130 138
       SERIAL_ECHOLNPGM(MSG_OFF);
131 139
   #endif
140
+
141
+  // Report change in position
142
+  if (memcmp(oldpos, current_position, sizeof(oldpos)))
143
+    report_current_position();
132 144
 }
133 145
 
134 146
 #endif // HAS_LEVELING

+ 1
- 0
Marlin/src/gcode/bedlevel/abl/G29.cpp Целия файл

@@ -285,6 +285,7 @@ void GcodeSuite::G29() {
285 285
             bed_level_virt_interpolate();
286 286
           #endif
287 287
           set_bed_leveling_enabled(abl_should_enable);
288
+          if (abl_should_enable) report_current_position();
288 289
         }
289 290
         return;
290 291
       } // parser.seen('W')

+ 32
- 15
Marlin/src/gcode/calibrate/M852.cpp Целия файл

@@ -36,37 +36,47 @@
36 36
  *  K[yz_factor] - New YZ skew factor
37 37
  */
38 38
 void GcodeSuite::M852() {
39
-  const bool ijk = parser.seen('I') || parser.seen('S')
40
-    #if ENABLED(SKEW_CORRECTION_FOR_Z)
41
-      || parser.seen('J') || parser.seen('K')
42
-    #endif
43
-  ;
44
-  bool badval = false;
39
+  uint8_t ijk = 0, badval = 0, setval = 0;
45 40
 
46 41
   if (parser.seen('I') || parser.seen('S')) {
42
+    ++ijk;
47 43
     const float value = parser.value_linear_units();
48
-    if (WITHIN(value, SKEW_FACTOR_MIN, SKEW_FACTOR_MAX))
49
-      planner.xy_skew_factor = value;
44
+    if (WITHIN(value, SKEW_FACTOR_MIN, SKEW_FACTOR_MAX)) {
45
+      if (planner.xy_skew_factor != value) {
46
+        planner.xy_skew_factor = value;
47
+        ++setval;
48
+      }
49
+    }
50 50
     else
51
-      badval = true;
51
+      ++badval;
52 52
   }
53 53
 
54 54
   #if ENABLED(SKEW_CORRECTION_FOR_Z)
55 55
 
56 56
     if (parser.seen('J')) {
57
+      ++ijk;
57 58
       const float value = parser.value_linear_units();
58
-      if (WITHIN(value, SKEW_FACTOR_MIN, SKEW_FACTOR_MAX))
59
-        planner.xz_skew_factor = value;
59
+      if (WITHIN(value, SKEW_FACTOR_MIN, SKEW_FACTOR_MAX)) {
60
+        if (planner.xz_skew_factor != value) {
61
+          planner.xz_skew_factor = value;
62
+          ++setval;
63
+        }
64
+      }
60 65
       else
61
-        badval = true;
66
+        ++badval;
62 67
     }
63 68
 
64 69
     if (parser.seen('K')) {
70
+      ++ijk;
65 71
       const float value = parser.value_linear_units();
66
-      if (WITHIN(value, SKEW_FACTOR_MIN, SKEW_FACTOR_MAX))
67
-        planner.yz_skew_factor = value;
72
+      if (WITHIN(value, SKEW_FACTOR_MIN, SKEW_FACTOR_MAX)) {
73
+        if (planner.yz_skew_factor != value) {
74
+          planner.yz_skew_factor = value;
75
+          ++setval;
76
+        }
77
+      }
68 78
       else
69
-        badval = true;
79
+        ++badval;
70 80
     }
71 81
 
72 82
   #endif
@@ -74,6 +84,13 @@ void GcodeSuite::M852() {
74 84
   if (badval)
75 85
     SERIAL_ECHOLNPGM(MSG_SKEW_MIN " " STRINGIFY(SKEW_FACTOR_MIN) " " MSG_SKEW_MAX " " STRINGIFY(SKEW_FACTOR_MAX));
76 86
 
87
+  // When skew is changed the current position changes
88
+  if (setval) {
89
+    set_current_from_steppers_for_axis(ALL_AXES);
90
+    SYNC_PLAN_POSITION_KINEMATIC();
91
+    report_current_position();
92
+  }
93
+
77 94
   if (!ijk) {
78 95
     SERIAL_ECHO_START();
79 96
     SERIAL_ECHOPAIR(MSG_SKEW_FACTOR " XY: ", planner.xy_skew_factor);

+ 17
- 20
Marlin/src/module/configuration_store.cpp Целия файл

@@ -216,14 +216,15 @@ MarlinSettings settings;
216 216
   float new_z_fade_height;
217 217
 #endif
218 218
 
219
-#if ENABLED(CNC_COORDINATE_SYSTEMS)
220
-  bool position_changed;
221
-#endif
222
-
223 219
 /**
224 220
  * Post-process after Retrieve or Reset
225 221
  */
226 222
 void MarlinSettings::postprocess() {
223
+  const float oldpos[XYZE] = {
224
+    current_position[X_AXIS], current_position[Y_AXIS],
225
+    current_position[Z_AXIS], current_position[E_AXIS]
226
+  };
227
+
227 228
   // steps per s2 needs to be updated to agree with units per s2
228 229
   planner.reset_acceleration_rates();
229 230
 
@@ -233,10 +234,6 @@ void MarlinSettings::postprocess() {
233 234
     recalc_delta_settings();
234 235
   #endif
235 236
 
236
-  // Refresh steps_to_mm with the reciprocal of axis_steps_per_mm
237
-  // and init stepper.count[], planner.position[] with current_position
238
-  planner.refresh_positioning();
239
-
240 237
   #if ENABLED(PIDTEMP)
241 238
     thermalManager.updatePID();
242 239
   #endif
@@ -249,7 +246,7 @@ void MarlinSettings::postprocess() {
249 246
   #endif
250 247
 
251 248
   #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
252
-    set_z_fade_height(new_z_fade_height);
249
+    set_z_fade_height(new_z_fade_height, false); // false = no report
253 250
   #endif
254 251
 
255 252
   #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
@@ -264,13 +261,14 @@ void MarlinSettings::postprocess() {
264 261
   #if ENABLED(FWRETRACT)
265 262
     fwretract.refresh_autoretract();
266 263
   #endif
264
+ 
265
+  // Refresh steps_to_mm with the reciprocal of axis_steps_per_mm
266
+  // and init stepper.count[], planner.position[] with current_position
267
+  planner.refresh_positioning();
267 268
 
268
-  #if ENABLED(CNC_COORDINATE_SYSTEMS)
269
-    if (position_changed) {
270
-      report_current_position();
271
-      position_changed = false;
272
-    }
273
-  #endif
269
+  // Various factors can change the current position
270
+  if (memcmp(oldpos, current_position, sizeof(oldpos)))
271
+    report_current_position();
274 272
 }
275 273
 
276 274
 #if ENABLED(EEPROM_SETTINGS)
@@ -308,7 +306,7 @@ void MarlinSettings::postprocess() {
308 306
     EEPROM_WRITE(ver);     // invalidate data first
309 307
     EEPROM_SKIP(working_crc); // Skip the checksum slot
310 308
 
311
-    working_crc = 0;  // Init to 0. Accumulated by EEPROM_READ
309
+    working_crc = 0; // clear before first "real data"
312 310
 
313 311
     const uint8_t esteppers = COUNT(planner.axis_steps_per_mm) - XYZ;
314 312
     EEPROM_WRITE(esteppers);
@@ -342,7 +340,7 @@ void MarlinSettings::postprocess() {
342 340
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
343 341
       const float zfh = planner.z_fade_height;
344 342
     #else
345
-      const float zfh = 0.0;
343
+      const float zfh = 10.0;
346 344
     #endif
347 345
     EEPROM_WRITE(zfh);
348 346
 
@@ -725,7 +723,7 @@ void MarlinSettings::postprocess() {
725 723
       float dummy = 0;
726 724
       bool dummyb;
727 725
 
728
-      working_crc = 0; //clear before reading first "real data"
726
+      working_crc = 0;  // Init to 0. Accumulated by EEPROM_READ
729 727
 
730 728
       // Number of esteppers may change
731 729
       uint8_t esteppers;
@@ -913,7 +911,6 @@ void MarlinSettings::postprocess() {
913 911
       #if DISABLED(ULTIPANEL)
914 912
         int lcd_preheat_hotend_temp[2], lcd_preheat_bed_temp[2], lcd_preheat_fan_speed[2];
915 913
       #endif
916
-
917 914
       EEPROM_READ(lcd_preheat_hotend_temp); // 2 floats
918 915
       EEPROM_READ(lcd_preheat_bed_temp);    // 2 floats
919 916
       EEPROM_READ(lcd_preheat_fan_speed);   // 2 floats
@@ -1094,7 +1091,7 @@ void MarlinSettings::postprocess() {
1094 1091
       //
1095 1092
 
1096 1093
       #if ENABLED(CNC_COORDINATE_SYSTEMS)
1097
-        position_changed = gcode.select_coordinate_system(-1); // Go back to machine space
1094
+        (void)gcode.select_coordinate_system(-1); // Go back to machine space
1098 1095
         EEPROM_READ(gcode.coordinate_system);                  // 27 floats
1099 1096
       #else
1100 1097
         for (uint8_t q = 27; q--;) EEPROM_READ(dummy);

+ 6
- 0
Marlin/src/module/motion.cpp Целия файл

@@ -211,6 +211,12 @@ void get_cartesian_from_steppers() {
211 211
  * Set the current_position for an axis based on
212 212
  * the stepper positions, removing any leveling that
213 213
  * may have been applied.
214
+ *
215
+ * To prevent small shifts in axis position always call
216
+ * SYNC_PLAN_POSITION_KINEMATIC after updating axes with this.
217
+ *
218
+ * To keep hosts in sync, always call report_current_position
219
+ * after updating the current_position.
214 220
  */
215 221
 void set_current_from_steppers_for_axis(const AxisEnum axis) {
216 222
   get_cartesian_from_steppers();

Loading…
Отказ
Запис