More data in UBL class, make it a static class
- Make all `unified_bed_leveling` data/methods static - Move some UBL-related variables into the class - Replace `map_[xy]_index_to_bed_location` with `mesh_index_to_[xy]pos`
This commit is contained in:
		@@ -265,8 +265,8 @@
 | 
				
			|||||||
        location = find_closest_circle_to_print(x_pos, y_pos); // Find the closest Mesh Intersection to where we are now.
 | 
					        location = find_closest_circle_to_print(x_pos, y_pos); // Find the closest Mesh Intersection to where we are now.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if (location.x_index >= 0 && location.y_index >= 0) {
 | 
					      if (location.x_index >= 0 && location.y_index >= 0) {
 | 
				
			||||||
        circle_x = ubl.map_x_index_to_bed_location(location.x_index);
 | 
					        circle_x = ubl.mesh_index_to_xpos[location.x_index];
 | 
				
			||||||
        circle_y = ubl.map_y_index_to_bed_location(location.y_index);
 | 
					        circle_y = ubl.mesh_index_to_ypos[location.y_index];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Let's do a couple of quick sanity checks.  We can pull this code out later if we never see it catch a problem
 | 
					        // Let's do a couple of quick sanity checks.  We can pull this code out later if we never see it catch a problem
 | 
				
			||||||
        #ifdef DELTA
 | 
					        #ifdef DELTA
 | 
				
			||||||
@@ -415,8 +415,8 @@
 | 
				
			|||||||
    for (uint8_t i = 0; i < UBL_MESH_NUM_X_POINTS; i++) {
 | 
					    for (uint8_t i = 0; i < UBL_MESH_NUM_X_POINTS; i++) {
 | 
				
			||||||
      for (uint8_t j = 0; j < UBL_MESH_NUM_Y_POINTS; j++) {
 | 
					      for (uint8_t j = 0; j < UBL_MESH_NUM_Y_POINTS; j++) {
 | 
				
			||||||
        if (!is_bit_set(circle_flags, i, j)) {
 | 
					        if (!is_bit_set(circle_flags, i, j)) {
 | 
				
			||||||
          mx = ubl.map_x_index_to_bed_location(i);  // We found a circle that needs to be printed
 | 
					          mx = ubl.mesh_index_to_xpos[i];  // We found a circle that needs to be printed
 | 
				
			||||||
          my = ubl.map_y_index_to_bed_location(j);
 | 
					          my = ubl.mesh_index_to_ypos[j];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          dx = X - mx;        // Get the distance to this intersection
 | 
					          dx = X - mx;        // Get the distance to this intersection
 | 
				
			||||||
          dy = Y - my;
 | 
					          dy = Y - my;
 | 
				
			||||||
@@ -461,11 +461,11 @@
 | 
				
			|||||||
              // We found two circles that need a horizontal line to connect them
 | 
					              // We found two circles that need a horizontal line to connect them
 | 
				
			||||||
              // Print it!
 | 
					              // Print it!
 | 
				
			||||||
              //
 | 
					              //
 | 
				
			||||||
              sx = ubl.map_x_index_to_bed_location(i);
 | 
					              sx = ubl.mesh_index_to_xpos[i];
 | 
				
			||||||
              sx = sx + SIZE_OF_INTERSECTION_CIRCLES - SIZE_OF_CROSS_HAIRS; // get the right edge of the circle
 | 
					              sx = sx + SIZE_OF_INTERSECTION_CIRCLES - SIZE_OF_CROSS_HAIRS; // get the right edge of the circle
 | 
				
			||||||
              sy = ubl.map_y_index_to_bed_location(j);
 | 
					              sy = ubl.mesh_index_to_ypos[j];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
              ex = ubl.map_x_index_to_bed_location(i + 1);
 | 
					              ex = ubl.mesh_index_to_xpos[i + 1];
 | 
				
			||||||
              ex = ex - SIZE_OF_INTERSECTION_CIRCLES + SIZE_OF_CROSS_HAIRS; // get the left edge of the circle
 | 
					              ex = ex - SIZE_OF_INTERSECTION_CIRCLES + SIZE_OF_CROSS_HAIRS; // get the left edge of the circle
 | 
				
			||||||
              ey = sy;
 | 
					              ey = sy;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -498,12 +498,12 @@
 | 
				
			|||||||
                // We found two circles that need a vertical line to connect them
 | 
					                // We found two circles that need a vertical line to connect them
 | 
				
			||||||
                // Print it!
 | 
					                // Print it!
 | 
				
			||||||
                //
 | 
					                //
 | 
				
			||||||
                sx = ubl.map_x_index_to_bed_location(i);
 | 
					                sx = ubl.mesh_index_to_xpos[i];
 | 
				
			||||||
                sy = ubl.map_y_index_to_bed_location(j);
 | 
					                sy = ubl.mesh_index_to_ypos[j];
 | 
				
			||||||
                sy = sy + SIZE_OF_INTERSECTION_CIRCLES - SIZE_OF_CROSS_HAIRS; // get the top edge of the circle
 | 
					                sy = sy + SIZE_OF_INTERSECTION_CIRCLES - SIZE_OF_CROSS_HAIRS; // get the top edge of the circle
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                ex = sx;
 | 
					                ex = sx;
 | 
				
			||||||
                ey = ubl.map_y_index_to_bed_location(j + 1);
 | 
					                ey = ubl.mesh_index_to_ypos[j + 1];
 | 
				
			||||||
                ey = ey - SIZE_OF_INTERSECTION_CIRCLES + SIZE_OF_CROSS_HAIRS; // get the bottom edge of the circle
 | 
					                ey = ey - SIZE_OF_INTERSECTION_CIRCLES + SIZE_OF_CROSS_HAIRS; // get the bottom edge of the circle
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                sx = constrain(sx, X_MIN_POS + 1, X_MAX_POS - 1);             // This keeps us from bumping the endstops
 | 
					                sx = constrain(sx, X_MIN_POS + 1, X_MAX_POS - 1);             // This keeps us from bumping the endstops
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -430,4 +430,8 @@ void do_blocking_move_to_x(const float &x, const float &fr_mm_s=0.0);
 | 
				
			|||||||
void do_blocking_move_to_z(const float &z, const float &fr_mm_s=0.0);
 | 
					void do_blocking_move_to_z(const float &z, const float &fr_mm_s=0.0);
 | 
				
			||||||
void do_blocking_move_to_xy(const float &x, const float &y, const float &fr_mm_s=0.0);
 | 
					void do_blocking_move_to_xy(const float &x, const float &y, const float &fr_mm_s=0.0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if ENABLED(Z_PROBE_ALLEN_KEY) || ENABLED(Z_PROBE_SLED) || HAS_PROBING_PROCEDURE || HOTENDS > 1 || ENABLED(NOZZLE_CLEAN_FEATURE) || ENABLED(NOZZLE_PARK_FEATURE)
 | 
				
			||||||
 | 
					  bool axis_unhomed_error(const bool x, const bool y, const bool z);
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif //MARLIN_H
 | 
					#endif //MARLIN_H
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3221,7 +3221,7 @@ inline void gcode_G4() {
 | 
				
			|||||||
   */
 | 
					   */
 | 
				
			||||||
  inline void gcode_G12() {
 | 
					  inline void gcode_G12() {
 | 
				
			||||||
    // Don't allow nozzle cleaning without homing first
 | 
					    // Don't allow nozzle cleaning without homing first
 | 
				
			||||||
    if (axis_unhomed_error(true, true, true)) { return; }
 | 
					    if (axis_unhomed_error(true, true, true)) return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const uint8_t pattern = code_seen('P') ? code_value_ushort() : 0,
 | 
					    const uint8_t pattern = code_seen('P') ? code_value_ushort() : 0,
 | 
				
			||||||
                  strokes = code_seen('S') ? code_value_ushort() : NOZZLE_CLEAN_STROKES,
 | 
					                  strokes = code_seen('S') ? code_value_ushort() : NOZZLE_CLEAN_STROKES,
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										96
									
								
								Marlin/UBL.h
									
									
									
									
									
								
							
							
						
						
									
										96
									
								
								Marlin/UBL.h
									
									
									
									
									
								
							@@ -39,7 +39,6 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    enum MeshPointType { INVALID, REAL, SET_IN_BITMAP };
 | 
					    enum MeshPointType { INVALID, REAL, SET_IN_BITMAP };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    bool axis_unhomed_error(bool, bool, bool);
 | 
					 | 
				
			||||||
    void dump(char * const str, const float &f);
 | 
					    void dump(char * const str, const float &f);
 | 
				
			||||||
    bool ubl_lcd_clicked();
 | 
					    bool ubl_lcd_clicked();
 | 
				
			||||||
    void probe_entire_mesh(const float&, const float&, const bool, const bool, const bool);
 | 
					    void probe_entire_mesh(const float&, const float&, const bool, const bool, const bool);
 | 
				
			||||||
@@ -78,30 +77,10 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    enum MBLStatus { MBL_STATUS_NONE = 0, MBL_STATUS_HAS_MESH_BIT = 0, MBL_STATUS_ACTIVE_BIT = 1 };
 | 
					    enum MBLStatus { MBL_STATUS_NONE = 0, MBL_STATUS_HAS_MESH_BIT = 0, MBL_STATUS_ACTIVE_BIT = 1 };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #define MESH_X_DIST ((float(UBL_MESH_MAX_X) - float(UBL_MESH_MIN_X)) / (float(UBL_MESH_NUM_X_POINTS) - 1.0))
 | 
					    #define MESH_X_DIST (float(UBL_MESH_MAX_X - (UBL_MESH_MIN_X)) / float(UBL_MESH_NUM_X_POINTS - 1))
 | 
				
			||||||
    #define MESH_Y_DIST ((float(UBL_MESH_MAX_Y) - float(UBL_MESH_MIN_Y)) / (float(UBL_MESH_NUM_Y_POINTS) - 1.0))
 | 
					    #define MESH_Y_DIST (float(UBL_MESH_MAX_Y - (UBL_MESH_MIN_Y)) / float(UBL_MESH_NUM_Y_POINTS - 1))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    extern float mesh_index_to_x_location[UBL_MESH_NUM_X_POINTS + 1]; // +1 just because of paranoia that we might end up on the
 | 
					    typedef struct {
 | 
				
			||||||
    extern float mesh_index_to_y_location[UBL_MESH_NUM_Y_POINTS + 1]; // the last Mesh Line and that is the start of a whole new cell
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    class unified_bed_leveling {
 | 
					 | 
				
			||||||
      private:
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      float last_specified_z,
 | 
					 | 
				
			||||||
            fade_scaling_factor_for_current_height;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      public:
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      float z_values[UBL_MESH_NUM_X_POINTS][UBL_MESH_NUM_Y_POINTS];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      bool g26_debug_flag = false,
 | 
					 | 
				
			||||||
           has_control_of_lcd_panel = false;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      int8_t eeprom_start = -1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      volatile int encoder_diff; // Volatile because it's changed at interrupt time.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      struct ubl_state {
 | 
					 | 
				
			||||||
      bool active = false;
 | 
					      bool active = false;
 | 
				
			||||||
      float z_offset = 0.0;
 | 
					      float z_offset = 0.0;
 | 
				
			||||||
      int8_t eeprom_storage_slot = -1,
 | 
					      int8_t eeprom_storage_slot = -1,
 | 
				
			||||||
@@ -126,7 +105,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
      // If you change this struct, adjust TOTAL_STRUCT_SIZE
 | 
					      // If you change this struct, adjust TOTAL_STRUCT_SIZE
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        #define TOTAL_STRUCT_SIZE 43 // Total size of the above fields
 | 
					      #define TOTAL_STRUCT_SIZE 40 // Total size of the above fields
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // padding provides space to add state variables without
 | 
					      // padding provides space to add state variables without
 | 
				
			||||||
      // changing the location of data structures in the EEPROM.
 | 
					      // changing the location of data structures in the EEPROM.
 | 
				
			||||||
@@ -134,26 +113,44 @@
 | 
				
			|||||||
      // users from having to regenerate their mesh data.
 | 
					      // users from having to regenerate their mesh data.
 | 
				
			||||||
      unsigned char padding[64 - TOTAL_STRUCT_SIZE];
 | 
					      unsigned char padding[64 - TOTAL_STRUCT_SIZE];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      } state, pre_initialized;
 | 
					    } ubl_state;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    class unified_bed_leveling {
 | 
				
			||||||
 | 
					      private:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        static float last_specified_z,
 | 
				
			||||||
 | 
					                     fade_scaling_factor_for_current_height;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        static ubl_state state, pre_initialized;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        static float z_values[UBL_MESH_NUM_X_POINTS][UBL_MESH_NUM_Y_POINTS],
 | 
				
			||||||
 | 
					                     mesh_index_to_xpos[UBL_MESH_NUM_X_POINTS + 1], // +1 safety margin for now, until determinism prevails
 | 
				
			||||||
 | 
					                     mesh_index_to_ypos[UBL_MESH_NUM_Y_POINTS + 1];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        static bool g26_debug_flag,
 | 
				
			||||||
 | 
					                    has_control_of_lcd_panel;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        static int8_t eeprom_start;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        static volatile int encoder_diff; // Volatile because it's changed at interrupt time.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        unified_bed_leveling();
 | 
					        unified_bed_leveling();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      void display_map(const int);
 | 
					        static void display_map(const int);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      void reset();
 | 
					        static void reset();
 | 
				
			||||||
      void invalidate();
 | 
					        static void invalidate();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      void store_state();
 | 
					        static void store_state();
 | 
				
			||||||
      void load_state();
 | 
					        static void load_state();
 | 
				
			||||||
      void store_mesh(const int16_t);
 | 
					        static void store_mesh(const int16_t);
 | 
				
			||||||
      void load_mesh(const int16_t);
 | 
					        static void load_mesh(const int16_t);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      bool sanity_check();
 | 
					        static bool sanity_check();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      FORCE_INLINE static float map_x_index_to_bed_location(const int8_t i) { return ((float) UBL_MESH_MIN_X) + (((float) MESH_X_DIST) * (float) i); };
 | 
					        static FORCE_INLINE void set_z(const int8_t px, const int8_t py, const float &z) { z_values[px][py] = z; }
 | 
				
			||||||
      FORCE_INLINE static float map_y_index_to_bed_location(const int8_t i) { return ((float) UBL_MESH_MIN_Y) + (((float) MESH_Y_DIST) * (float) i); };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      FORCE_INLINE void set_z(const int8_t px, const int8_t py, const float &z) { z_values[px][py] = z; }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        static int8_t get_cell_index_x(const float &x) {
 | 
					        static int8_t get_cell_index_x(const float &x) {
 | 
				
			||||||
          const int8_t cx = (x - (UBL_MESH_MIN_X)) * (1.0 / (MESH_X_DIST));
 | 
					          const int8_t cx = (x - (UBL_MESH_MIN_X)) * (1.0 / (MESH_X_DIST));
 | 
				
			||||||
@@ -209,7 +206,7 @@
 | 
				
			|||||||
         * the X index of the x0 intersection available and we don't want to perform any extra floating
 | 
					         * the X index of the x0 intersection available and we don't want to perform any extra floating
 | 
				
			||||||
         * point operations.
 | 
					         * point operations.
 | 
				
			||||||
         */
 | 
					         */
 | 
				
			||||||
      inline float get_z_correction_along_horizontal_mesh_line_at_specific_X(const float &x0, const int x1_i, const int yi) {
 | 
					        static inline float get_z_correction_along_horizontal_mesh_line_at_specific_X(const float &x0, const int x1_i, const int yi) {
 | 
				
			||||||
          if (x1_i < 0 || yi < 0 || x1_i >= UBL_MESH_NUM_X_POINTS || yi >= UBL_MESH_NUM_Y_POINTS) {
 | 
					          if (x1_i < 0 || yi < 0 || x1_i >= UBL_MESH_NUM_X_POINTS || yi >= UBL_MESH_NUM_Y_POINTS) {
 | 
				
			||||||
            SERIAL_ECHOPAIR("? in get_z_correction_along_horizontal_mesh_line_at_specific_X(x0=", x0);
 | 
					            SERIAL_ECHOPAIR("? in get_z_correction_along_horizontal_mesh_line_at_specific_X(x0=", x0);
 | 
				
			||||||
            SERIAL_ECHOPAIR(",x1_i=", x1_i);
 | 
					            SERIAL_ECHOPAIR(",x1_i=", x1_i);
 | 
				
			||||||
@@ -219,7 +216,7 @@
 | 
				
			|||||||
            return NAN;
 | 
					            return NAN;
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const float xratio = (RAW_X_POSITION(x0) - mesh_index_to_x_location[x1_i]) * (1.0 / (MESH_X_DIST)),
 | 
					          const float xratio = (RAW_X_POSITION(x0) - mesh_index_to_xpos[x1_i]) * (1.0 / (MESH_X_DIST)),
 | 
				
			||||||
                      z1 = z_values[x1_i][yi],
 | 
					                      z1 = z_values[x1_i][yi],
 | 
				
			||||||
                      z2 = z_values[x1_i + 1][yi],
 | 
					                      z2 = z_values[x1_i + 1][yi],
 | 
				
			||||||
                      dz = (z2 - z1);
 | 
					                      dz = (z2 - z1);
 | 
				
			||||||
@@ -230,7 +227,7 @@
 | 
				
			|||||||
        //
 | 
					        //
 | 
				
			||||||
        // See comments above for get_z_correction_along_horizontal_mesh_line_at_specific_X
 | 
					        // See comments above for get_z_correction_along_horizontal_mesh_line_at_specific_X
 | 
				
			||||||
        //
 | 
					        //
 | 
				
			||||||
      inline float get_z_correction_along_vertical_mesh_line_at_specific_Y(const float &y0, const int xi, const int y1_i) {
 | 
					        static inline float get_z_correction_along_vertical_mesh_line_at_specific_Y(const float &y0, const int xi, const int y1_i) {
 | 
				
			||||||
          if (xi < 0 || y1_i < 0 || xi >= UBL_MESH_NUM_X_POINTS || y1_i >= UBL_MESH_NUM_Y_POINTS) {
 | 
					          if (xi < 0 || y1_i < 0 || xi >= UBL_MESH_NUM_X_POINTS || y1_i >= UBL_MESH_NUM_Y_POINTS) {
 | 
				
			||||||
            SERIAL_ECHOPAIR("? in get_z_correction_along_vertical_mesh_line_at_specific_X(y0=", y0);
 | 
					            SERIAL_ECHOPAIR("? in get_z_correction_along_vertical_mesh_line_at_specific_X(y0=", y0);
 | 
				
			||||||
            SERIAL_ECHOPAIR(", x1_i=", xi);
 | 
					            SERIAL_ECHOPAIR(", x1_i=", xi);
 | 
				
			||||||
@@ -240,7 +237,7 @@
 | 
				
			|||||||
            return NAN;
 | 
					            return NAN;
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const float yratio = (RAW_Y_POSITION(y0) - mesh_index_to_y_location[y1_i]) * (1.0 / (MESH_Y_DIST)),
 | 
					          const float yratio = (RAW_Y_POSITION(y0) - mesh_index_to_ypos[y1_i]) * (1.0 / (MESH_Y_DIST)),
 | 
				
			||||||
                      z1 = z_values[xi][y1_i],
 | 
					                      z1 = z_values[xi][y1_i],
 | 
				
			||||||
                      z2 = z_values[xi][y1_i + 1],
 | 
					                      z2 = z_values[xi][y1_i + 1],
 | 
				
			||||||
                      dz = (z2 - z1);
 | 
					                      dz = (z2 - z1);
 | 
				
			||||||
@@ -254,7 +251,7 @@
 | 
				
			|||||||
         * Z-Height at both ends. Then it does a linear interpolation of these heights based
 | 
					         * Z-Height at both ends. Then it does a linear interpolation of these heights based
 | 
				
			||||||
         * on the Y position within the cell.
 | 
					         * on the Y position within the cell.
 | 
				
			||||||
         */
 | 
					         */
 | 
				
			||||||
      float get_z_correction(const float &x0, const float &y0) const {
 | 
					        static float get_z_correction(const float &x0, const float &y0) {
 | 
				
			||||||
          const int8_t cx = get_cell_index_x(RAW_X_POSITION(x0)),
 | 
					          const int8_t cx = get_cell_index_x(RAW_X_POSITION(x0)),
 | 
				
			||||||
                       cy = get_cell_index_y(RAW_Y_POSITION(y0));
 | 
					                       cy = get_cell_index_y(RAW_Y_POSITION(y0));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -273,14 +270,14 @@
 | 
				
			|||||||
          }
 | 
					          }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          const float z1 = calc_z0(RAW_X_POSITION(x0),
 | 
					          const float z1 = calc_z0(RAW_X_POSITION(x0),
 | 
				
			||||||
                      map_x_index_to_bed_location(cx), z_values[cx][cy],
 | 
					                        mesh_index_to_xpos[cx], z_values[cx][cy],
 | 
				
			||||||
                      map_x_index_to_bed_location(cx + 1), z_values[cx + 1][cy]),
 | 
					                        mesh_index_to_xpos[cx + 1], z_values[cx + 1][cy]),
 | 
				
			||||||
                      z2 = calc_z0(RAW_X_POSITION(x0),
 | 
					                      z2 = calc_z0(RAW_X_POSITION(x0),
 | 
				
			||||||
                      map_x_index_to_bed_location(cx), z_values[cx][cy + 1],
 | 
					                        mesh_index_to_xpos[cx], z_values[cx][cy + 1],
 | 
				
			||||||
                      map_x_index_to_bed_location(cx + 1), z_values[cx + 1][cy + 1]);
 | 
					                        mesh_index_to_xpos[cx + 1], z_values[cx + 1][cy + 1]);
 | 
				
			||||||
                float z0 = calc_z0(RAW_Y_POSITION(y0),
 | 
					                float z0 = calc_z0(RAW_Y_POSITION(y0),
 | 
				
			||||||
                  map_y_index_to_bed_location(cy), z1,
 | 
					                    mesh_index_to_ypos[cy], z1,
 | 
				
			||||||
                  map_y_index_to_bed_location(cy + 1), z2);
 | 
					                    mesh_index_to_ypos[cy + 1], z2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          #if ENABLED(DEBUG_LEVELING_FEATURE)
 | 
					          #if ENABLED(DEBUG_LEVELING_FEATURE)
 | 
				
			||||||
            if (DEBUGGING(MESH_ADJUST)) {
 | 
					            if (DEBUGGING(MESH_ADJUST)) {
 | 
				
			||||||
@@ -355,5 +352,4 @@
 | 
				
			|||||||
    #define UBL_LAST_EEPROM_INDEX (E2END - sizeof(unified_bed_leveling::state))
 | 
					    #define UBL_LAST_EEPROM_INDEX (E2END - sizeof(unified_bed_leveling::state))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  #endif // AUTO_BED_LEVELING_UBL
 | 
					  #endif // AUTO_BED_LEVELING_UBL
 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif // UNIFIED_BED_LEVELING_H
 | 
					#endif // UNIFIED_BED_LEVELING_H
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -57,23 +57,26 @@
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  ubl_state unified_bed_leveling::state, unified_bed_leveling::pre_initialized;
 | 
				
			||||||
   * These variables used to be declared inside the unified_bed_leveling class. We are going to
 | 
					
 | 
				
			||||||
   * still declare them within the .cpp file for bed leveling. But there is only one instance of
 | 
					  float unified_bed_leveling::z_values[UBL_MESH_NUM_X_POINTS][UBL_MESH_NUM_Y_POINTS],
 | 
				
			||||||
   * the bed leveling object and we can get rid of a level of inderection by not making them
 | 
					        unified_bed_leveling::last_specified_z,
 | 
				
			||||||
   * 'member data'. So, in the interest of speed, we do it this way. On a 32-bit CPU they can be
 | 
					        unified_bed_leveling::fade_scaling_factor_for_current_height,
 | 
				
			||||||
   * moved back inside the bed leveling class.
 | 
					        unified_bed_leveling::mesh_index_to_xpos[UBL_MESH_NUM_X_POINTS + 1], // +1 safety margin for now, until determinism prevails
 | 
				
			||||||
   */
 | 
					        unified_bed_leveling::mesh_index_to_ypos[UBL_MESH_NUM_Y_POINTS + 1];
 | 
				
			||||||
  float mesh_index_to_x_location[UBL_MESH_NUM_X_POINTS + 1], // +1 just because of paranoia that we might end up on the
 | 
					
 | 
				
			||||||
        mesh_index_to_y_location[UBL_MESH_NUM_Y_POINTS + 1]; // the last Mesh Line and that is the start of a whole new cell
 | 
					  bool unified_bed_leveling::g26_debug_flag = false,
 | 
				
			||||||
 | 
					       unified_bed_leveling::has_control_of_lcd_panel = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  int8_t unified_bed_leveling::eeprom_start = -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  volatile int unified_bed_leveling::encoder_diff;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  unified_bed_leveling::unified_bed_leveling() {
 | 
					  unified_bed_leveling::unified_bed_leveling() {
 | 
				
			||||||
    for (uint8_t i = 0; i <= UBL_MESH_NUM_X_POINTS; i++)  // We go one past what we expect to ever need for safety
 | 
					    for (uint8_t i = 0; i < COUNT(mesh_index_to_xpos); i++)
 | 
				
			||||||
      mesh_index_to_x_location[i] = double(UBL_MESH_MIN_X) + double(MESH_X_DIST) * double(i);
 | 
					      mesh_index_to_xpos[i] = UBL_MESH_MIN_X + i * (MESH_X_DIST);
 | 
				
			||||||
 | 
					    for (uint8_t i = 0; i < COUNT(mesh_index_to_ypos); i++)
 | 
				
			||||||
    for (uint8_t i = 0; i <= UBL_MESH_NUM_Y_POINTS; i++)  // We go one past what we expect to ever need for safety
 | 
					      mesh_index_to_ypos[i] = UBL_MESH_MIN_Y + i * (MESH_Y_DIST);
 | 
				
			||||||
      mesh_index_to_y_location[i] = double(UBL_MESH_MIN_Y) + double(MESH_Y_DIST) * double(i);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    reset();
 | 
					    reset();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -161,9 +164,6 @@
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void unified_bed_leveling::invalidate() {
 | 
					  void unified_bed_leveling::invalidate() {
 | 
				
			||||||
    print_hex_word((uint16_t)this);
 | 
					 | 
				
			||||||
    SERIAL_EOL;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    state.active = false;
 | 
					    state.active = false;
 | 
				
			||||||
    state.z_offset = 0;
 | 
					    state.z_offset = 0;
 | 
				
			||||||
    for (int x = 0; x < UBL_MESH_NUM_X_POINTS; x++)
 | 
					    for (int x = 0; x < UBL_MESH_NUM_X_POINTS; x++)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -750,8 +750,8 @@
 | 
				
			|||||||
      location = find_closest_mesh_point_of_type(INVALID, lx, ly, 1, NULL, do_furthest );  // the '1' says we want the location to be relative to the probe
 | 
					      location = find_closest_mesh_point_of_type(INVALID, lx, ly, 1, NULL, do_furthest );  // the '1' says we want the location to be relative to the probe
 | 
				
			||||||
      if (location.x_index >= 0 && location.y_index >= 0) {
 | 
					      if (location.x_index >= 0 && location.y_index >= 0) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const float rawx = ubl.map_x_index_to_bed_location(location.x_index),
 | 
					        const float rawx = ubl.mesh_index_to_xpos[location.x_index],
 | 
				
			||||||
                    rawy = ubl.map_y_index_to_bed_location(location.y_index);
 | 
					                    rawy = ubl.mesh_index_to_ypos[location.y_index];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // TODO: Change to use `position_is_reachable` (for SCARA-compatibility)
 | 
					        // TODO: Change to use `position_is_reachable` (for SCARA-compatibility)
 | 
				
			||||||
        if (rawx < (MIN_PROBE_X) || rawx > (MAX_PROBE_X) || rawy < (MIN_PROBE_Y) || rawy > (MAX_PROBE_Y)) {
 | 
					        if (rawx < (MIN_PROBE_X) || rawx > (MAX_PROBE_X) || rawy < (MIN_PROBE_Y) || rawy > (MAX_PROBE_Y)) {
 | 
				
			||||||
@@ -900,8 +900,8 @@
 | 
				
			|||||||
      // It doesn't matter if the probe can't reach the NAN location. This is a manual probe.
 | 
					      // It doesn't matter if the probe can't reach the NAN location. This is a manual probe.
 | 
				
			||||||
      if (location.x_index < 0 && location.y_index < 0) continue;
 | 
					      if (location.x_index < 0 && location.y_index < 0) continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      const float rawx = ubl.map_x_index_to_bed_location(location.x_index),
 | 
					      const float rawx = ubl.mesh_index_to_xpos[location.x_index],
 | 
				
			||||||
                  rawy = ubl.map_y_index_to_bed_location(location.y_index);
 | 
					                  rawy = ubl.mesh_index_to_ypos[location.y_index];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // TODO: Change to use `position_is_reachable` (for SCARA-compatibility)
 | 
					      // TODO: Change to use `position_is_reachable` (for SCARA-compatibility)
 | 
				
			||||||
      if (rawx < (X_MIN_POS) || rawx > (X_MAX_POS) || rawy < (Y_MIN_POS) || rawy > (Y_MAX_POS)) {
 | 
					      if (rawx < (X_MIN_POS) || rawx > (X_MAX_POS) || rawy < (Y_MIN_POS) || rawy > (Y_MAX_POS)) {
 | 
				
			||||||
@@ -1137,7 +1137,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    SERIAL_PROTOCOLPGM("X-Axis Mesh Points at: ");
 | 
					    SERIAL_PROTOCOLPGM("X-Axis Mesh Points at: ");
 | 
				
			||||||
    for (uint8_t i = 0; i < UBL_MESH_NUM_X_POINTS; i++) {
 | 
					    for (uint8_t i = 0; i < UBL_MESH_NUM_X_POINTS; i++) {
 | 
				
			||||||
      SERIAL_PROTOCOL_F(LOGICAL_X_POSITION(ubl.map_x_index_to_bed_location(i)), 1);
 | 
					      SERIAL_PROTOCOL_F(LOGICAL_X_POSITION(ubl.mesh_index_to_xpos[i]), 1);
 | 
				
			||||||
      SERIAL_PROTOCOLPGM("  ");
 | 
					      SERIAL_PROTOCOLPGM("  ");
 | 
				
			||||||
      safe_delay(50);
 | 
					      safe_delay(50);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -1145,7 +1145,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    SERIAL_PROTOCOLPGM("Y-Axis Mesh Points at: ");
 | 
					    SERIAL_PROTOCOLPGM("Y-Axis Mesh Points at: ");
 | 
				
			||||||
    for (uint8_t i = 0; i < UBL_MESH_NUM_Y_POINTS; i++) {
 | 
					    for (uint8_t i = 0; i < UBL_MESH_NUM_Y_POINTS; i++) {
 | 
				
			||||||
      SERIAL_PROTOCOL_F(LOGICAL_Y_POSITION(ubl.map_y_index_to_bed_location(i)), 1);
 | 
					      SERIAL_PROTOCOL_F(LOGICAL_Y_POSITION(ubl.mesh_index_to_ypos[i]), 1);
 | 
				
			||||||
      SERIAL_PROTOCOLPGM("  ");
 | 
					      SERIAL_PROTOCOLPGM("  ");
 | 
				
			||||||
      safe_delay(50);
 | 
					      safe_delay(50);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -1283,8 +1283,8 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
          // We only get here if we found a Mesh Point of the specified type
 | 
					          // We only get here if we found a Mesh Point of the specified type
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          const float rawx = ubl.map_x_index_to_bed_location(i), // Check if we can probe this mesh location
 | 
					          const float rawx = ubl.mesh_index_to_xpos[i], // Check if we can probe this mesh location
 | 
				
			||||||
                      rawy = ubl.map_y_index_to_bed_location(j);
 | 
					                      rawy = ubl.mesh_index_to_ypos[j];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          // If using the probe as the reference there are some unreachable locations.
 | 
					          // If using the probe as the reference there are some unreachable locations.
 | 
				
			||||||
          // Prune them from the list and ignore them till the next Phase (manual nozzle probing).
 | 
					          // Prune them from the list and ignore them till the next Phase (manual nozzle probing).
 | 
				
			||||||
@@ -1350,8 +1350,8 @@
 | 
				
			|||||||
      bit_clear(not_done, location.x_index, location.y_index);  // Mark this location as 'adjusted' so we will find a
 | 
					      bit_clear(not_done, location.x_index, location.y_index);  // Mark this location as 'adjusted' so we will find a
 | 
				
			||||||
                                                                // different location the next time through the loop
 | 
					                                                                // different location the next time through the loop
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      const float rawx = ubl.map_x_index_to_bed_location(location.x_index),
 | 
					      const float rawx = ubl.mesh_index_to_xpos[location.x_index],
 | 
				
			||||||
                  rawy = ubl.map_y_index_to_bed_location(location.y_index);
 | 
					                  rawy = ubl.mesh_index_to_ypos[location.y_index];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // TODO: Change to use `position_is_reachable` (for SCARA-compatibility)
 | 
					      // TODO: Change to use `position_is_reachable` (for SCARA-compatibility)
 | 
				
			||||||
      if (rawx < (X_MIN_POS) || rawx > (X_MAX_POS) || rawy < (Y_MIN_POS) || rawy > (Y_MAX_POS)) { // In theory, we don't need this check.
 | 
					      if (rawx < (X_MIN_POS) || rawx > (X_MAX_POS) || rawy < (Y_MIN_POS) || rawy > (Y_MAX_POS)) { // In theory, we don't need this check.
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -167,16 +167,16 @@
 | 
				
			|||||||
       * to create a 1-over number for us. That will allow us to do a floating point multiply instead of a floating point divide.
 | 
					       * to create a 1-over number for us. That will allow us to do a floating point multiply instead of a floating point divide.
 | 
				
			||||||
       */
 | 
					       */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      const float xratio = (RAW_X_POSITION(x_end) - mesh_index_to_x_location[cell_dest_xi]) * (1.0 / (MESH_X_DIST)),
 | 
					      const float xratio = (RAW_X_POSITION(x_end) - ubl.mesh_index_to_xpos[cell_dest_xi]) * (1.0 / (MESH_X_DIST)),
 | 
				
			||||||
                  z1 = z_values[cell_dest_xi    ][cell_dest_yi    ] + xratio *
 | 
					                  z1 = ubl.z_values[cell_dest_xi    ][cell_dest_yi    ] + xratio *
 | 
				
			||||||
                      (z_values[cell_dest_xi + 1][cell_dest_yi    ] - z_values[cell_dest_xi][cell_dest_yi    ]),
 | 
					                      (ubl.z_values[cell_dest_xi + 1][cell_dest_yi    ] - ubl.z_values[cell_dest_xi][cell_dest_yi    ]),
 | 
				
			||||||
                  z2 = z_values[cell_dest_xi    ][cell_dest_yi + 1] + xratio *
 | 
					                  z2 = ubl.z_values[cell_dest_xi    ][cell_dest_yi + 1] + xratio *
 | 
				
			||||||
                      (z_values[cell_dest_xi + 1][cell_dest_yi + 1] - z_values[cell_dest_xi][cell_dest_yi + 1]);
 | 
					                      (ubl.z_values[cell_dest_xi + 1][cell_dest_yi + 1] - ubl.z_values[cell_dest_xi][cell_dest_yi + 1]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // we are done with the fractional X distance into the cell. Now with the two Z-Heights we have calculated, we
 | 
					      // we are done with the fractional X distance into the cell. Now with the two Z-Heights we have calculated, we
 | 
				
			||||||
      // are going to apply the Y-Distance into the cell to interpolate the final Z correction.
 | 
					      // are going to apply the Y-Distance into the cell to interpolate the final Z correction.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      const float yratio = (RAW_Y_POSITION(y_end) - mesh_index_to_y_location[cell_dest_yi]) * (1.0 / (MESH_Y_DIST));
 | 
					      const float yratio = (RAW_Y_POSITION(y_end) - ubl.mesh_index_to_ypos[cell_dest_yi]) * (1.0 / (MESH_Y_DIST));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      float z0 = z1 + (z2 - z1) * yratio;
 | 
					      float z0 = z1 + (z2 - z1) * yratio;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -274,7 +274,7 @@
 | 
				
			|||||||
      current_yi += down_flag;  // Line is heading down, we just want to go to the bottom
 | 
					      current_yi += down_flag;  // Line is heading down, we just want to go to the bottom
 | 
				
			||||||
      while (current_yi != cell_dest_yi + down_flag) {
 | 
					      while (current_yi != cell_dest_yi + down_flag) {
 | 
				
			||||||
        current_yi += dyi;
 | 
					        current_yi += dyi;
 | 
				
			||||||
        const float next_mesh_line_y = LOGICAL_Y_POSITION(mesh_index_to_y_location[current_yi]);
 | 
					        const float next_mesh_line_y = LOGICAL_Y_POSITION(ubl.mesh_index_to_ypos[current_yi]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /**
 | 
					        /**
 | 
				
			||||||
         * inf_m_flag? the slope of the line is infinite, we won't do the calculations
 | 
					         * inf_m_flag? the slope of the line is infinite, we won't do the calculations
 | 
				
			||||||
@@ -316,7 +316,7 @@
 | 
				
			|||||||
         */
 | 
					         */
 | 
				
			||||||
        if (isnan(z0)) z0 = 0.0;
 | 
					        if (isnan(z0)) z0 = 0.0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const float y = LOGICAL_Y_POSITION(mesh_index_to_y_location[current_yi]);
 | 
					        const float y = LOGICAL_Y_POSITION(ubl.mesh_index_to_ypos[current_yi]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /**
 | 
					        /**
 | 
				
			||||||
         * Without this check, it is possible for the algorithm to generate a zero length move in the case
 | 
					         * Without this check, it is possible for the algorithm to generate a zero length move in the case
 | 
				
			||||||
@@ -365,7 +365,7 @@
 | 
				
			|||||||
                                // edge of this cell for the first move.
 | 
					                                // edge of this cell for the first move.
 | 
				
			||||||
      while (current_xi != cell_dest_xi + left_flag) {
 | 
					      while (current_xi != cell_dest_xi + left_flag) {
 | 
				
			||||||
        current_xi += dxi;
 | 
					        current_xi += dxi;
 | 
				
			||||||
        const float next_mesh_line_x = LOGICAL_X_POSITION(mesh_index_to_x_location[current_xi]),
 | 
					        const float next_mesh_line_x = LOGICAL_X_POSITION(ubl.mesh_index_to_xpos[current_xi]),
 | 
				
			||||||
                    y = m * next_mesh_line_x + c;   // Calculate X at the next Y mesh line
 | 
					                    y = m * next_mesh_line_x + c;   // Calculate X at the next Y mesh line
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        float z0 = ubl.get_z_correction_along_vertical_mesh_line_at_specific_Y(y, current_xi, current_yi);
 | 
					        float z0 = ubl.get_z_correction_along_vertical_mesh_line_at_specific_Y(y, current_xi, current_yi);
 | 
				
			||||||
@@ -401,7 +401,7 @@
 | 
				
			|||||||
         */
 | 
					         */
 | 
				
			||||||
        if (isnan(z0)) z0 = 0.0;
 | 
					        if (isnan(z0)) z0 = 0.0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const float x = LOGICAL_X_POSITION(mesh_index_to_x_location[current_xi]);
 | 
					        const float x = LOGICAL_X_POSITION(ubl.mesh_index_to_xpos[current_xi]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /**
 | 
					        /**
 | 
				
			||||||
         * Without this check, it is possible for the algorithm to generate a zero length move in the case
 | 
					         * Without this check, it is possible for the algorithm to generate a zero length move in the case
 | 
				
			||||||
@@ -451,8 +451,8 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    while (xi_cnt > 0 || yi_cnt > 0) {
 | 
					    while (xi_cnt > 0 || yi_cnt > 0) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      const float next_mesh_line_x = LOGICAL_X_POSITION(mesh_index_to_x_location[current_xi + dxi]),
 | 
					      const float next_mesh_line_x = LOGICAL_X_POSITION(ubl.mesh_index_to_xpos[current_xi + dxi]),
 | 
				
			||||||
                  next_mesh_line_y = LOGICAL_Y_POSITION(mesh_index_to_y_location[current_yi + dyi]),
 | 
					                  next_mesh_line_y = LOGICAL_Y_POSITION(ubl.mesh_index_to_ypos[current_yi + dyi]),
 | 
				
			||||||
                  y = m * next_mesh_line_x + c,   // Calculate Y at the next X mesh line
 | 
					                  y = m * next_mesh_line_x + c,   // Calculate Y at the next X mesh line
 | 
				
			||||||
                  x = (next_mesh_line_y - c) / m; // Calculate X at the next Y mesh line    (we don't have to worry
 | 
					                  x = (next_mesh_line_y - c) / m; // Calculate X at the next Y mesh line    (we don't have to worry
 | 
				
			||||||
                                                  // about m being equal to 0.0  If this was the case, we would have
 | 
					                                                  // about m being equal to 0.0  If this was the case, we would have
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user