Browse Source

Added G29 command

Edward Patel 9 years ago
parent
commit
3d0a060a7a
1 changed files with 89 additions and 0 deletions
  1. 89
    0
      Marlin/Marlin_main.cpp

+ 89
- 0
Marlin/Marlin_main.cpp View File

@@ -1983,6 +1983,89 @@ inline void gcode_G28() {
1983 1983
   endstops_hit_on_purpose();
1984 1984
 }
1985 1985
 
1986
+#if defined(MESH_BED_LEVELING)
1987
+
1988
+  inline void gcode_G29() {
1989
+    static int probe_point = -1;
1990
+    int state = 0;
1991
+    if (code_seen('S') || code_seen('s')) {
1992
+      state = code_value_long();
1993
+      if (state < 0 || state > 2) {
1994
+        SERIAL_PROTOCOLPGM("S out of range (0-2).\n");
1995
+        return;
1996
+      }
1997
+    }
1998
+
1999
+    if (state == 0) { // Dump mesh_bed_leveling
2000
+      if (mbl.active) {
2001
+        SERIAL_PROTOCOLPGM("Num X,Y: ");
2002
+        SERIAL_PROTOCOL(MESH_NUM_X_POINTS);
2003
+        SERIAL_PROTOCOLPGM(",");
2004
+        SERIAL_PROTOCOL(MESH_NUM_Y_POINTS);
2005
+        SERIAL_PROTOCOLPGM("\nZ search height: ");
2006
+        SERIAL_PROTOCOL(MESH_HOME_SEARCH_Z);
2007
+        SERIAL_PROTOCOLPGM("\nMeasured points:\n");              
2008
+        for (int y=0; y<MESH_NUM_Y_POINTS; y++) {
2009
+          for (int x=0; x<MESH_NUM_X_POINTS; x++) {
2010
+            SERIAL_PROTOCOLPGM("  ");              
2011
+            SERIAL_PROTOCOL_F(mbl.z_values[y][x], 5);
2012
+          }
2013
+          SERIAL_EOL;
2014
+        }
2015
+      } else {
2016
+        SERIAL_PROTOCOLPGM("Mesh bed leveling not active.\n");
2017
+      }
2018
+
2019
+    } else if (state == 1) { // Begin probing mesh points
2020
+
2021
+      mbl.reset();
2022
+      probe_point = 0;
2023
+      enquecommands_P(PSTR("G28"));
2024
+      enquecommands_P(PSTR("G29 S2"));
2025
+
2026
+    } else if (state == 2) { // Goto next point
2027
+
2028
+      if (probe_point < 0) {
2029
+        SERIAL_PROTOCOLPGM("Mesh probing not started.\n");
2030
+        return;
2031
+      }
2032
+      int ix, iy;
2033
+      if (probe_point == 0) {
2034
+        current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
2035
+        plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
2036
+      } else {
2037
+        ix = (probe_point-1) % MESH_NUM_X_POINTS;
2038
+        iy = (probe_point-1) / MESH_NUM_X_POINTS;
2039
+        if (iy&1) { // Zig zag
2040
+          ix = (MESH_NUM_X_POINTS - 1) - ix;
2041
+        }
2042
+        mbl.set_z(ix, iy, current_position[Z_AXIS]);
2043
+        current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
2044
+        plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], homing_feedrate[X_AXIS]/60, active_extruder);
2045
+        st_synchronize();
2046
+      }
2047
+      if (probe_point == MESH_NUM_X_POINTS*MESH_NUM_Y_POINTS) {
2048
+        SERIAL_PROTOCOLPGM("Mesh done.\n");
2049
+        probe_point = -1;
2050
+        mbl.active = 1;
2051
+        enquecommands_P(PSTR("G28"));
2052
+        return;
2053
+      }
2054
+      ix = probe_point % MESH_NUM_X_POINTS;
2055
+      iy = probe_point / MESH_NUM_X_POINTS;
2056
+      if (iy&1) { // Zig zag
2057
+        ix = (MESH_NUM_X_POINTS - 1) - ix;
2058
+      }
2059
+      current_position[X_AXIS] = mbl.get_x(ix);
2060
+      current_position[Y_AXIS] = mbl.get_y(iy);
2061
+      plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], homing_feedrate[X_AXIS]/60, active_extruder);
2062
+      st_synchronize();
2063
+      probe_point++;
2064
+    }
2065
+  }
2066
+
2067
+#endif
2068
+
1986 2069
 #ifdef ENABLE_AUTO_BED_LEVELING
1987 2070
 
1988 2071
   // Define the possible boundaries for probing based on set limits
@@ -4687,6 +4770,12 @@ void process_commands() {
4687 4770
       gcode_G28();
4688 4771
       break;
4689 4772
 
4773
+    #if defined(MESH_BED_LEVELING)
4774
+      case 29: // G29 Handle mesh based leveling
4775
+        gcode_G29();
4776
+        break;
4777
+    #endif
4778
+
4690 4779
     #ifdef ENABLE_AUTO_BED_LEVELING
4691 4780
 
4692 4781
       case 29: // G29 Detailed Z-Probe, probes the bed at 3 or more points.

Loading…
Cancel
Save