Browse Source

Merge pull request #6245 from thinkyhead/rc_babystep_zprobe

BABYSTEPPING updates Z probe offset
Scott Lahteine 8 years ago
parent
commit
972c9655e9
4 changed files with 85 additions and 32 deletions
  1. 1
    0
      Marlin/Marlin.h
  2. 37
    25
      Marlin/Marlin_main.cpp
  3. 6
    2
      Marlin/configuration_store.cpp
  4. 41
    5
      Marlin/ultralcd.cpp

+ 1
- 0
Marlin/Marlin.h View File

@@ -317,6 +317,7 @@ float code_value_temp_diff();
317 317
 
318 318
 #if HAS_BED_PROBE
319 319
   extern float zprobe_zoffset;
320
+  void refresh_zprobe_zoffset(const bool no_babystep=false);
320 321
   #define DEPLOY_PROBE() set_probe_deployed(true)
321 322
   #define STOW_PROBE() set_probe_deployed(false)
322 323
 #endif

+ 37
- 25
Marlin/Marlin_main.cpp View File

@@ -7968,41 +7968,53 @@ inline void gcode_M503() {
7968 7968
 
7969 7969
 #if HAS_BED_PROBE
7970 7970
 
7971
-  inline void gcode_M851() {
7971
+  void refresh_zprobe_zoffset(const bool no_babystep/*=false*/) {
7972
+    static float last_zoffset = NAN;
7972 7973
 
7973
-    SERIAL_ECHO_START;
7974
-    SERIAL_ECHOPGM(MSG_ZPROBE_ZOFFSET);
7975
-    SERIAL_CHAR(' ');
7974
+    if (!isnan(last_zoffset)) {
7976 7975
 
7977
-    if (code_seen('Z')) {
7978
-      float value = code_value_axis_units(Z_AXIS);
7979
-      if (WITHIN(value, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) {
7976
+      #if ENABLED(AUTO_BED_LEVELING_BILINEAR) || ENABLED(BABYSTEPPING)
7977
+        const float diff = zprobe_zoffset - last_zoffset;
7978
+      #endif
7980 7979
 
7981
-        #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
7982
-          // Correct bilinear grid for new probe offset
7983
-          const float diff = value - zprobe_zoffset;
7984
-          if (diff) {
7985
-            for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
7986
-              for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
7987
-                bed_level_grid[x][y] += diff;
7988
-          }
7989
-          #if ENABLED(ABL_BILINEAR_SUBDIVISION)
7990
-            bed_level_virt_interpolate();
7991
-          #endif
7980
+      #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
7981
+        // Correct bilinear grid for new probe offset
7982
+        if (diff) {
7983
+          for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
7984
+            for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
7985
+              bed_level_grid[x][y] -= diff;
7986
+        }
7987
+        #if ENABLED(ABL_BILINEAR_SUBDIVISION)
7988
+          bed_level_virt_interpolate();
7992 7989
         #endif
7990
+      #endif
7993 7991
 
7992
+      #if ENABLED(BABYSTEPPING)
7993
+        if (!no_babystep && planner.abl_enabled)
7994
+          thermalManager.babystep_axis(Z_AXIS, -lround(diff * planner.axis_steps_per_mm[Z_AXIS]));
7995
+      #else
7996
+        UNUSED(no_babystep);
7997
+      #endif
7998
+    }
7999
+
8000
+    last_zoffset = zprobe_zoffset;
8001
+  }
8002
+
8003
+  inline void gcode_M851() {
8004
+    SERIAL_ECHO_START;
8005
+    SERIAL_ECHOPGM(MSG_ZPROBE_ZOFFSET " ");
8006
+    if (code_seen('Z')) {
8007
+      const float value = code_value_axis_units(Z_AXIS);
8008
+      if (WITHIN(value, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) {
7994 8009
         zprobe_zoffset = value;
8010
+        refresh_zprobe_zoffset();
7995 8011
         SERIAL_ECHO(zprobe_zoffset);
7996 8012
       }
7997
-      else {
7998
-        SERIAL_ECHOPAIR(MSG_Z_MIN, Z_PROBE_OFFSET_RANGE_MIN);
7999
-        SERIAL_CHAR(' ');
8000
-        SERIAL_ECHOPAIR(MSG_Z_MAX, Z_PROBE_OFFSET_RANGE_MAX);
8001
-      }
8013
+      else
8014
+        SERIAL_ECHOPGM(MSG_Z_MIN " " STRINGIFY(Z_PROBE_OFFSET_RANGE_MIN) " " MSG_Z_MAX " " STRINGIFY(Z_PROBE_OFFSET_RANGE_MAX));
8002 8015
     }
8003
-    else {
8016
+    else
8004 8017
       SERIAL_ECHOPAIR(": ", zprobe_zoffset);
8005
-    }
8006 8018
 
8007 8019
     SERIAL_EOL;
8008 8020
   }

+ 6
- 2
Marlin/configuration_store.cpp View File

@@ -216,6 +216,10 @@ void MarlinSettings::postprocess() {
216 216
       //#endif
217 217
     );
218 218
   #endif
219
+
220
+  #if HAS_BED_PROBE
221
+    refresh_zprobe_zoffset();
222
+  #endif
219 223
 }
220 224
 
221 225
 #if ENABLED(EEPROM_SETTINGS)
@@ -344,7 +348,7 @@ void MarlinSettings::postprocess() {
344 348
     #endif // MESH_BED_LEVELING
345 349
 
346 350
     #if !HAS_BED_PROBE
347
-      float zprobe_zoffset = 0;
351
+      const float zprobe_zoffset = 0;
348 352
     #endif
349 353
     EEPROM_WRITE(zprobe_zoffset);
350 354
 
@@ -685,7 +689,7 @@ void MarlinSettings::postprocess() {
685 689
       #endif // MESH_BED_LEVELING
686 690
 
687 691
       #if !HAS_BED_PROBE
688
-        float zprobe_zoffset = 0;
692
+        float zprobe_zoffset;
689 693
       #endif
690 694
       EEPROM_READ(zprobe_zoffset);
691 695
 

+ 41
- 5
Marlin/ultralcd.cpp View File

@@ -834,7 +834,7 @@ void kill_screen(const char* lcd_msg) {
834 834
       if (lcd_clicked) { defer_return_to_status = false; return lcd_goto_previous_menu(); }
835 835
       ENCODER_DIRECTION_NORMAL();
836 836
       if (encoderPosition) {
837
-        int babystep_increment = (int32_t)encoderPosition * (BABYSTEP_MULTIPLICATOR);
837
+        const int babystep_increment = (int32_t)encoderPosition * (BABYSTEP_MULTIPLICATOR);
838 838
         encoderPosition = 0;
839 839
         lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
840 840
         thermalManager.babystep_axis(axis, babystep_increment);
@@ -850,8 +850,38 @@ void kill_screen(const char* lcd_msg) {
850 850
       void lcd_babystep_x() { lcd_goto_screen(_lcd_babystep_x); babysteps_done = 0; defer_return_to_status = true; }
851 851
       void lcd_babystep_y() { lcd_goto_screen(_lcd_babystep_y); babysteps_done = 0; defer_return_to_status = true; }
852 852
     #endif
853
-    void _lcd_babystep_z() { _lcd_babystep(Z_AXIS, PSTR(MSG_BABYSTEPPING_Z)); }
854
-    void lcd_babystep_z() { lcd_goto_screen(_lcd_babystep_z); babysteps_done = 0; defer_return_to_status = true; }
853
+
854
+    #if HAS_BED_PROBE
855
+
856
+      void lcd_babystep_zoffset() {
857
+        if (lcd_clicked) { defer_return_to_status = false; return lcd_goto_previous_menu(); }
858
+        defer_return_to_status = true;
859
+        ENCODER_DIRECTION_NORMAL();
860
+        if (encoderPosition) {
861
+          const int babystep_increment = (int32_t)encoderPosition * (BABYSTEP_MULTIPLICATOR);
862
+          encoderPosition = 0;
863
+
864
+          const float new_zoffset = zprobe_zoffset + steps_to_mm[Z_AXIS] * babystep_increment;
865
+          if (WITHIN(new_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) {
866
+
867
+            if (planner.abl_enabled)
868
+              thermalManager.babystep_axis(Z_AXIS, babystep_increment);
869
+
870
+            zprobe_zoffset = new_zoffset;
871
+            refresh_zprobe_zoffset(true);
872
+            lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
873
+          }
874
+        }
875
+        if (lcdDrawUpdate)
876
+          lcd_implementation_drawedit(PSTR(MSG_ZPROBE_ZOFFSET), ftostr43sign(zprobe_zoffset));
877
+      }
878
+
879
+    #else // !HAS_BED_PROBE
880
+
881
+      void _lcd_babystep_z() { _lcd_babystep(Z_AXIS, PSTR(MSG_BABYSTEPPING_Z)); }
882
+      void lcd_babystep_z() { lcd_goto_screen(_lcd_babystep_z); babysteps_done = 0; defer_return_to_status = true; }
883
+
884
+    #endif // HAS_BED_PROBE
855 885
 
856 886
   #endif //BABYSTEPPING
857 887
 
@@ -1057,7 +1087,9 @@ void kill_screen(const char* lcd_msg) {
1057 1087
         MENU_ITEM(submenu, MSG_BABYSTEP_X, lcd_babystep_x);
1058 1088
         MENU_ITEM(submenu, MSG_BABYSTEP_Y, lcd_babystep_y);
1059 1089
       #endif //BABYSTEP_XY
1060
-      MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);
1090
+      #if !HAS_BED_PROBE
1091
+        MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);
1092
+      #endif
1061 1093
     #endif
1062 1094
 
1063 1095
     //
@@ -2378,7 +2410,11 @@ void kill_screen(const char* lcd_msg) {
2378 2410
     START_MENU();
2379 2411
     MENU_BACK(MSG_CONTROL);
2380 2412
     #if HAS_BED_PROBE
2381
-      MENU_ITEM_EDIT(float32, MSG_ZPROBE_ZOFFSET, &zprobe_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX);
2413
+      #if ENABLED(BABYSTEPPING)
2414
+        MENU_ITEM(submenu, MSG_ZPROBE_ZOFFSET, lcd_babystep_zoffset);
2415
+      #else
2416
+        MENU_ITEM_EDIT_CALLBACK(float32, MSG_ZPROBE_ZOFFSET, &zprobe_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX, refresh_zprobe_zoffset);
2417
+      #endif
2382 2418
     #endif
2383 2419
     // Manual bed leveling, Bed Z:
2384 2420
     #if ENABLED(MESH_BED_LEVELING) && ENABLED(LCD_BED_LEVELING)

Loading…
Cancel
Save