Additional cleanup of UBL code

This commit is contained in:
Scott Lahteine
2017-03-20 01:42:41 -05:00
parent cc3204509c
commit e244399766
35 changed files with 2201 additions and 2070 deletions

View File

@@ -37,27 +37,27 @@
// from the search location
} mesh_index_pair;
struct vector { double dx, dy, dz; };
typedef struct { double dx, dy, dz; } vector;
enum Mesh_Point_Type { INVALID, REAL, SET_IN_BITMAP };
enum MeshPointType { INVALID, REAL, SET_IN_BITMAP };
bool axis_unhomed_error(bool, bool, bool);
void dump(char *str, float f);
bool G29_lcd_clicked();
bool ubl_lcd_clicked();
void probe_entire_mesh(float, float, bool, bool);
void UBL_line_to_destination(const float&, const float&, const float&, const float&, const float&, uint8_t);
void ubl_line_to_destination(const float&, const float&, const float&, const float&, const float&, uint8_t);
void manually_probe_remaining_mesh(float, float, float, float, bool);
struct vector tilt_mesh_based_on_3pts(float, float, float);
vector tilt_mesh_based_on_3pts(float, float, float);
void new_set_bed_level_equation_3pts(float, float, float);
float measure_business_card_thickness(float);
mesh_index_pair find_closest_mesh_point_of_type(Mesh_Point_Type, float, float, bool, unsigned int[16]);
void Find_Mean_Mesh_Height();
void Shift_Mesh_Height();
bool G29_Parameter_Parsing();
void G29_What_Command();
void G29_EEPROM_Dump();
void G29_Kompare_Current_Mesh_to_Stored_Mesh();
void fine_tune_mesh(float, float, float, bool);
mesh_index_pair find_closest_mesh_point_of_type(MeshPointType, float, float, bool, unsigned int[16]);
void find_mean_mesh_height();
void shift_mesh_height();
bool g29_parameter_parsing();
void g29_what_command();
void g29_eeprom_dump();
void g29_compare_current_mesh_to_stored_mesh();
void fine_tune_mesh(float, float, bool);
void bit_clear(uint16_t bits[16], uint8_t x, uint8_t y);
void bit_set(uint16_t bits[16], uint8_t x, uint8_t y);
bool is_bit_set(uint16_t bits[16], uint8_t x, uint8_t y);
@@ -68,8 +68,8 @@
void gcode_G29();
extern char conv[9];
void save_UBL_active_state_and_disable();
void restore_UBL_active_state_and_leave();
void save_ubl_active_state_and_disable();
void restore_ubl_active_state_and_leave();
///////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -83,19 +83,19 @@
#define MESH_X_DIST ((float(UBL_MESH_MAX_X) - float(UBL_MESH_MIN_X)) / (float(UBL_MESH_NUM_X_POINTS) - 1.0))
#define MESH_Y_DIST ((float(UBL_MESH_MAX_Y) - float(UBL_MESH_MIN_Y)) / (float(UBL_MESH_NUM_Y_POINTS) - 1.0))
extern bool G26_Debug_flag;
extern bool g26_debug_flag;
extern float last_specified_z;
extern float fade_scaling_factor_for_current_height;
extern float z_values[UBL_MESH_NUM_X_POINTS][UBL_MESH_NUM_Y_POINTS];
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
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
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
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 bed_leveling {
class unified_bed_leveling {
public:
struct ubl_state {
bool active = false;
float z_offset = 0.0;
int EEPROM_storage_slot = -1,
int eeprom_storage_slot = -1,
n_x = UBL_MESH_NUM_X_POINTS,
n_y = UBL_MESH_NUM_Y_POINTS;
float mesh_x_min = UBL_MESH_MIN_X,
@@ -104,8 +104,8 @@
mesh_y_max = UBL_MESH_MAX_Y,
mesh_x_dist = MESH_X_DIST,
mesh_y_dist = MESH_Y_DIST,
G29_Correction_Fade_Height = 10.0,
G29_Fade_Height_Multiplier = 1.0 / 10.0; // It is cheaper to do a floating point multiply than a floating
g29_correction_fade_height = 10.0,
g29_fade_height_multiplier = 1.0 / 10.0; // It is cheaper to do a floating point multiply than a floating
// point divide. So, we keep this number in both forms. The first
// is for the user. The second one is the one that is actually used
// again and again and again during the correction calculations.
@@ -119,8 +119,8 @@
// the padding[] to keep the size the same!
} state, pre_initialized;
bed_leveling();
// ~bed_leveling(); // No destructor because this object never goes away!
unified_bed_leveling();
// ~unified_bed_leveling(); // No destructor because this object never goes away!
void display_map(int);
@@ -203,7 +203,7 @@
return NAN;
}
const float a0ma1diva2ma1 = (x0 - mesh_index_to_X_location[x1_i]) * (1.0 / (MESH_X_DIST)),
const float a0ma1diva2ma1 = (x0 - mesh_index_to_x_location[x1_i]) * (1.0 / (MESH_X_DIST)),
z1 = z_values[x1_i][yi],
z2 = z_values[x1_i + 1][yi],
dz = (z2 - z1);
@@ -224,7 +224,7 @@
return NAN;
}
const float a0ma1diva2ma1 = (y0 - mesh_index_to_Y_location[y1_i]) * (1.0 / (MESH_Y_DIST)),
const float a0ma1diva2ma1 = (y0 - mesh_index_to_y_location[y1_i]) * (1.0 / (MESH_Y_DIST)),
z1 = z_values[xi][y1_i],
z2 = z_values[xi][y1_i + 1],
dz = (z2 - z1);
@@ -271,20 +271,20 @@
SERIAL_ECHOPAIR(" raw get_z_correction(", x0);
SERIAL_ECHOPAIR(",", y0);
SERIAL_ECHOPGM(")=");
SERIAL_PROTOCOL_F(z0, 6);
SERIAL_ECHO_F(z0, 6);
}
#endif
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(MESH_ADJUST)) {
SERIAL_ECHOPGM(" >>>---> ");
SERIAL_PROTOCOL_F(z0, 6);
SERIAL_ECHO_F(z0, 6);
SERIAL_EOL;
}
#endif
if (isnan(z0)) { // if part of the Mesh is undefined, it will show up as NAN
z0 = 0.0; // in blm.z_values[][] and propagate through the
z0 = 0.0; // in ubl.z_values[][] and propagate through the
// calculations. If our correction is NAN, we throw it out
// because part of the Mesh is undefined and we don't have the
// information we need to complete the height correction.
@@ -311,21 +311,21 @@
* If it must do a calcuation, it will return a scaling factor of 0.0 if the UBL System is not active
* or if the current Z Height is past the specified 'Fade Height'
*/
FORCE_INLINE float fade_scaling_factor_for_Z(float current_z) {
FORCE_INLINE float fade_scaling_factor_for_z(float current_z) {
if (last_specified_z == current_z)
return fade_scaling_factor_for_current_height;
last_specified_z = current_z;
fade_scaling_factor_for_current_height =
state.active && current_z < state.G29_Correction_Fade_Height
? 1.0 - (current_z * state.G29_Fade_Height_Multiplier)
state.active && current_z < state.g29_correction_fade_height
? 1.0 - (current_z * state.g29_fade_height_multiplier)
: 0.0;
return fade_scaling_factor_for_current_height;
}
};
extern bed_leveling blm;
extern int Unified_Bed_Leveling_EEPROM_start;
extern unified_bed_leveling ubl;
extern int ubl_eeprom_start;
#endif // AUTO_BED_LEVELING_UBL
#endif // UNIFIED_BED_LEVELING_H