Merge pull request #6533 from thinkyhead/rc_autocal_patches

General cleanup of G33
This commit is contained in:
Scott Lahteine 2017-05-02 16:01:02 -05:00 committed by GitHub
commit 0803c9d997
6 changed files with 118 additions and 108 deletions

View File

@ -61,7 +61,7 @@
* G30 - Single Z probe, probes bed at X Y location (defaults to current XY location) * G30 - Single Z probe, probes bed at X Y location (defaults to current XY location)
* G31 - Dock sled (Z_PROBE_SLED only) * G31 - Dock sled (Z_PROBE_SLED only)
* G32 - Undock sled (Z_PROBE_SLED only) * G32 - Undock sled (Z_PROBE_SLED only)
* G33 - Delta '1-4-7-point' auto calibration : "G33 V<verbose> P<points> <A> <O> <T>" (Requires DELTA) * G33 - Delta Auto-Calibration (Requires DELTA_AUTO_CALIBRATION)
* G38 - Probe target - similar to G28 except it uses the Z_MIN_PROBE for all three axes * G38 - Probe target - similar to G28 except it uses the Z_MIN_PROBE for all three axes
* G90 - Use Absolute Coordinates * G90 - Use Absolute Coordinates
* G91 - Use Relative Coordinates * G91 - Use Relative Coordinates
@ -3904,7 +3904,7 @@ inline void gcode_G28() {
#if ENABLED(DEBUG_LEVELING_FEATURE) #if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("<<< gcode_G28"); if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("<<< gcode_G28");
#endif #endif
} } // G28
void home_all_axes() { gcode_G28(); } void home_all_axes() { gcode_G28(); }
@ -5057,46 +5057,64 @@ void home_all_axes() { gcode_G28(); }
#if ENABLED(DELTA_AUTO_CALIBRATION) #if ENABLED(DELTA_AUTO_CALIBRATION)
/** /**
* G33 - Delta '1-4-7-point' auto calibration (Requires DELTA) * G33 - Delta '1-4-7-point' Auto-Calibration
* Calibrate height, endstops, delta radius, and tower angles.
* *
* Usage: * Parameters:
* G33 <Vn> <Pn> <A> <O> <T>
* *
* Vn = verbose level (n=0-2 default 1) * P Number of probe points:
* n=0 dry-run mode: setting + probe results / no calibration *
* n=1 settings * P1 Probe center and set height only.
* n=2 setting + probe results * P2 Probe center and towers. Set height, endstops, and delta radius.
* Pn = n=-7 -> +7 : n*n probe points * P3 Probe all positions: center, towers and opposite towers. Set all.
* calibrates height ('1 point'), endstops, and delta radius ('4 points') * P4-P7 Probe all positions at different locations and average them.
* and tower angles with n > 2 ('7+ points') *
* n=1 probes center / sets height only * A Abort delta height calibration after 1 probe (only P1)
* n=2 probes center and towers / sets height, endstops and delta radius *
* n=3 probes all points: center, towers and opposite towers / sets all * O Use opposite tower points instead of tower points (only P2)
* n>3 probes all points multiple times and averages *
* A = abort 1 point delta height calibration after 1 probe * T Don't calibrate tower angle corrections (P3-P7)
* O = use oposite tower points instead of tower points with 4 point calibration *
* T = do not calibrate tower angles with 7+ point calibration * V Verbose level:
*
* V0 Dry-run mode. Report settings and probe results. No calibration.
* V1 Report settings
* V2 Report settings and probe results
*/ */
inline void gcode_G33() { inline void gcode_G33() {
stepper.synchronize(); const int8_t probe_points = code_seen('P') ? code_value_int() : DELTA_CALIBRATION_DEFAULT_POINTS;
if (!WITHIN(probe_points, 1, 7)) {
SERIAL_PROTOCOLLNPGM("?(P)oints is implausible (1 to 7).");
return;
}
const int8_t verbose_level = code_seen('V') ? code_value_byte() : 1;
if (!WITHIN(verbose_level, 0, 2)) {
SERIAL_PROTOCOLLNPGM("?(V)erbose Level is implausible (0-2).");
return;
}
const bool do_height_only = probe_points == 1,
do_center_and_towers = probe_points == 2,
do_all_positions = probe_points == 3,
do_circle_x2 = probe_points == 5,
do_circle_x3 = probe_points == 6,
do_circle_x4 = probe_points == 7,
probe_center_plus_3 = probe_points >= 3,
point_averaging = probe_points >= 4,
probe_center_plus_6 = probe_points >= 5;
const char negating_parameter = do_height_only ? 'A' : do_center_and_towers ? 'O' : 'T';
int8_t probe_mode = code_seen(negating_parameter) && code_value_bool() ? -probe_points : probe_points;
SERIAL_PROTOCOLLNPGM("G33 Auto Calibrate");
#if HAS_LEVELING #if HAS_LEVELING
set_bed_leveling_enabled(false); set_bed_leveling_enabled(false);
#endif #endif
int8_t pp = (code_seen('P') ? code_value_int() : DELTA_CALIBRATION_DEFAULT_POINTS), home_all_axes();
probe_mode = (WITHIN(pp, 1, 7) ? pp : DELTA_CALIBRATION_DEFAULT_POINTS);
probe_mode = (code_seen('A') && probe_mode == 1 ? -probe_mode : probe_mode);
probe_mode = (code_seen('O') && probe_mode == 2 ? -probe_mode : probe_mode);
probe_mode = (code_seen('T') && probe_mode > 2 ? -probe_mode : probe_mode);
int8_t verbose_level = (code_seen('V') ? code_value_byte() : 1);
if (!WITHIN(verbose_level, 0, 2)) verbose_level = 1;
gcode_G28();
const static char save_message[] PROGMEM = "Save with M500 and/or copy to Configuration.h"; const static char save_message[] PROGMEM = "Save with M500 and/or copy to Configuration.h";
float test_precision, float test_precision,
@ -5110,30 +5128,16 @@ void home_all_axes() { gcode_G28(); }
zh_old = home_offset[Z_AXIS], zh_old = home_offset[Z_AXIS],
alpha_old = delta_tower_angle_trim[A_AXIS], alpha_old = delta_tower_angle_trim[A_AXIS],
beta_old = delta_tower_angle_trim[B_AXIS]; beta_old = delta_tower_angle_trim[B_AXIS];
int8_t iterations = 0,
probe_points = abs(probe_mode);
const bool pp_equals_1 = (probe_points == 1),
pp_equals_2 = (probe_points == 2),
pp_equals_3 = (probe_points == 3),
pp_equals_4 = (probe_points == 4),
pp_equals_5 = (probe_points == 5),
pp_equals_6 = (probe_points == 6),
pp_equals_7 = (probe_points == 7),
pp_greather_2 = (probe_points > 2),
pp_greather_3 = (probe_points > 3),
pp_greather_4 = (probe_points > 4),
pp_greather_5 = (probe_points > 5);
// print settings // print settings
SERIAL_PROTOCOLLNPGM("G33 Auto Calibrate");
SERIAL_PROTOCOLPGM("Checking... AC"); SERIAL_PROTOCOLPGM("Checking... AC");
if (verbose_level == 0) SERIAL_PROTOCOLPGM(" (DRY-RUN)"); if (verbose_level == 0) SERIAL_PROTOCOLPGM(" (DRY-RUN)");
SERIAL_EOL; SERIAL_EOL;
LCD_MESSAGEPGM("Checking... AC"); LCD_MESSAGEPGM("Checking... AC");
SERIAL_PROTOCOLPAIR(".Height:", DELTA_HEIGHT + home_offset[Z_AXIS]); SERIAL_PROTOCOLPAIR(".Height:", DELTA_HEIGHT + home_offset[Z_AXIS]);
if (!pp_equals_1) { if (!do_height_only) {
SERIAL_PROTOCOLPGM(" Ex:"); SERIAL_PROTOCOLPGM(" Ex:");
if (endstop_adj[A_AXIS] >= 0) SERIAL_CHAR('+'); if (endstop_adj[A_AXIS] >= 0) SERIAL_CHAR('+');
SERIAL_PROTOCOL_F(endstop_adj[A_AXIS], 2); SERIAL_PROTOCOL_F(endstop_adj[A_AXIS], 2);
@ -5161,6 +5165,8 @@ void home_all_axes() { gcode_G28(); }
DEPLOY_PROBE(); DEPLOY_PROBE();
#endif #endif
int8_t iterations = 0;
do { do {
float z_at_pt[13] = { 0 }, float z_at_pt[13] = { 0 },
@ -5171,54 +5177,52 @@ void home_all_axes() { gcode_G28(); }
test_precision = zero_std_dev; test_precision = zero_std_dev;
iterations++; iterations++;
// probe the points // Probe the points
if (!pp_equals_3 && !pp_equals_6) { // probe the centre if (!do_all_positions && !do_circle_x3) { // probe the center
setup_for_endstop_or_probe_move(); setup_for_endstop_or_probe_move();
z_at_pt[0] += probe_pt(0.0, 0.0 , true, 1); z_at_pt[0] += probe_pt(0.0, 0.0 , true, 1);
clean_up_after_endstop_or_probe_move(); clean_up_after_endstop_or_probe_move();
} }
if (pp_greather_2) { // probe extra centre points if (probe_center_plus_3) { // probe extra center points
for (int8_t axis = (pp_greather_4 ? 11 : 9); axis > 0; axis -= (pp_greather_4 ? 2 : 4)) { for (int8_t axis = probe_center_plus_6 ? 11 : 9; axis > 0; axis -= probe_center_plus_6 ? 2 : 4) {
setup_for_endstop_or_probe_move(); setup_for_endstop_or_probe_move();
z_at_pt[0] += probe_pt( z_at_pt[0] += probe_pt(
cos(RADIANS(180 + 30 * axis)) * (0.1 * delta_calibration_radius), cos(RADIANS(180 + 30 * axis)) * (0.1 * delta_calibration_radius),
sin(RADIANS(180 + 30 * axis)) * (0.1 * delta_calibration_radius), true, 1); sin(RADIANS(180 + 30 * axis)) * (0.1 * delta_calibration_radius), true, 1);
clean_up_after_endstop_or_probe_move(); clean_up_after_endstop_or_probe_move();
} }
z_at_pt[0] /= (pp_equals_5 ? 7 : probe_points); z_at_pt[0] /= float(do_circle_x2 ? 7 : probe_points);
} }
if (!pp_equals_1) { // probe the radius if (!do_height_only) { // probe the radius
float start_circles = (pp_equals_7 ? -1.5 : pp_equals_6 || pp_equals_5 ? -1 : 0),
end_circles = -start_circles;
bool zig_zag = true; bool zig_zag = true;
for (uint8_t axis = (probe_mode == -2 ? 3 : 1); axis < 13; for (uint8_t axis = (probe_mode == -2 ? 3 : 1); axis < 13;
axis += (pp_equals_2 ? 4 : pp_equals_3 || pp_equals_5 ? 2 : 1)) { axis += (do_center_and_towers ? 4 : do_all_positions ? 2 : 1)) {
for (float circles = start_circles ; circles <= end_circles; circles++) { float offset_circles = (do_circle_x4 ? (zig_zag ? 1.5 : 1.0) :
do_circle_x3 ? (zig_zag ? 1.0 : 0.5) :
do_circle_x2 ? (zig_zag ? 0.5 : 0.0) : 0);
for (float circles = -offset_circles ; circles <= offset_circles; circles++) {
setup_for_endstop_or_probe_move(); setup_for_endstop_or_probe_move();
z_at_pt[axis] += probe_pt( z_at_pt[axis] += probe_pt(
cos(RADIANS(180 + 30 * axis)) * cos(RADIANS(180 + 30 * axis)) * delta_calibration_radius *
(1 + circles * 0.1 * (zig_zag ? 1 : -1)) * delta_calibration_radius, (1 + circles * 0.1 * (zig_zag ? 1 : -1)),
sin(RADIANS(180 + 30 * axis)) * sin(RADIANS(180 + 30 * axis)) * delta_calibration_radius *
(1 + circles * 0.1 * (zig_zag ? 1 : -1)) * delta_calibration_radius, true, 1); (1 + circles * 0.1 * (zig_zag ? 1 : -1)), true, 1);
clean_up_after_endstop_or_probe_move(); clean_up_after_endstop_or_probe_move();
} }
start_circles += (pp_greather_5 ? (zig_zag ? 0.5 : -0.5) : 0);
end_circles = -start_circles;
zig_zag = !zig_zag; zig_zag = !zig_zag;
z_at_pt[axis] /= (pp_equals_7 ? (zig_zag ? 4.0 : 3.0) : z_at_pt[axis] /= (2 * offset_circles + 1);
pp_equals_6 ? (zig_zag ? 3.0 : 2.0) : pp_equals_5 ? 3 : 1);
} }
} }
if (pp_greather_3 && !pp_equals_5) // average intermediates to tower and opposites if (point_averaging) // average intermediates to tower and opposites
for (uint8_t axis = 1; axis < 13; axis += 2) for (uint8_t axis = 1; axis <= 11; axis += 2)
z_at_pt[axis] = (z_at_pt[axis] + (z_at_pt[axis + 1] + z_at_pt[(axis + 10) % 12 + 1]) / 2.0) / 2.0; z_at_pt[axis] = (z_at_pt[axis] + (z_at_pt[axis + 1] + z_at_pt[(axis + 10) % 12 + 1]) / 2.0) / 2.0;
S1 += z_at_pt[0]; S1 += z_at_pt[0];
S2 += sq(z_at_pt[0]); S2 += sq(z_at_pt[0]);
N++; N++;
if (!pp_equals_1) // std dev from zero plane if (!do_height_only) // std dev from zero plane
for (uint8_t axis = (probe_mode == -2 ? 3 : 1); axis < 13; axis += (pp_equals_2 ? 4 : 2)) { for (uint8_t axis = (probe_mode == -2 ? 3 : 1); axis < 13; axis += (do_center_and_towers ? 4 : 2)) {
S1 += z_at_pt[axis]; S1 += z_at_pt[axis];
S2 += sq(z_at_pt[axis]); S2 += sq(z_at_pt[axis]);
N++; N++;
@ -5315,7 +5319,7 @@ void home_all_axes() { gcode_G28(); }
SERIAL_PROTOCOLPGM(". c:"); SERIAL_PROTOCOLPGM(". c:");
if (z_at_pt[0] > 0) SERIAL_CHAR('+'); if (z_at_pt[0] > 0) SERIAL_CHAR('+');
SERIAL_PROTOCOL_F(z_at_pt[0], 2); SERIAL_PROTOCOL_F(z_at_pt[0], 2);
if (probe_mode == 2 || pp_greather_2) { if (probe_mode == 2 || probe_center_plus_3) {
SERIAL_PROTOCOLPGM(" x:"); SERIAL_PROTOCOLPGM(" x:");
if (z_at_pt[1] >= 0) SERIAL_CHAR('+'); if (z_at_pt[1] >= 0) SERIAL_CHAR('+');
SERIAL_PROTOCOL_F(z_at_pt[1], 2); SERIAL_PROTOCOL_F(z_at_pt[1], 2);
@ -5327,8 +5331,8 @@ void home_all_axes() { gcode_G28(); }
SERIAL_PROTOCOL_F(z_at_pt[9], 2); SERIAL_PROTOCOL_F(z_at_pt[9], 2);
} }
if (probe_mode != -2) SERIAL_EOL; if (probe_mode != -2) SERIAL_EOL;
if (probe_mode == -2 || pp_greather_2) { if (probe_mode == -2 || probe_center_plus_3) {
if (pp_greather_2) { if (probe_center_plus_3) {
SERIAL_CHAR('.'); SERIAL_CHAR('.');
SERIAL_PROTOCOL_SP(13); SERIAL_PROTOCOL_SP(13);
} }
@ -5364,7 +5368,7 @@ void home_all_axes() { gcode_G28(); }
lcd_setstatus(mess); lcd_setstatus(mess);
} }
SERIAL_PROTOCOLPAIR(".Height:", DELTA_HEIGHT + home_offset[Z_AXIS]); SERIAL_PROTOCOLPAIR(".Height:", DELTA_HEIGHT + home_offset[Z_AXIS]);
if (!pp_equals_1) { if (!do_height_only) {
SERIAL_PROTOCOLPGM(" Ex:"); SERIAL_PROTOCOLPGM(" Ex:");
if (endstop_adj[A_AXIS] >= 0) SERIAL_CHAR('+'); if (endstop_adj[A_AXIS] >= 0) SERIAL_CHAR('+');
SERIAL_PROTOCOL_F(endstop_adj[A_AXIS], 2); SERIAL_PROTOCOL_F(endstop_adj[A_AXIS], 2);
@ -5411,7 +5415,7 @@ void home_all_axes() { gcode_G28(); }
stepper.synchronize(); stepper.synchronize();
gcode_G28(); home_all_axes();
} while (zero_std_dev < test_precision && iterations < 31); } while (zero_std_dev < test_precision && iterations < 31);
@ -6416,7 +6420,7 @@ inline void gcode_M42() {
clean_up_after_endstop_or_probe_move(); clean_up_after_endstop_or_probe_move();
// Re-enable bed level correction if it had been on // Re-enable bed level correction if it had been on
#if HAS_ABL #if HAS_LEVELING
set_bed_leveling_enabled(was_enabled); set_bed_leveling_enabled(was_enabled);
#endif #endif
@ -9874,7 +9878,7 @@ void process_next_command() {
#if ENABLED(DELTA_AUTO_CALIBRATION) #if ENABLED(DELTA_AUTO_CALIBRATION)
case 33: // G33: Delta Auto Calibrate case 33: // G33: Delta Auto-Calibration
gcode_G33(); gcode_G33();
break; break;

View File

@ -36,13 +36,13 @@
* *
*/ */
#define EEPROM_VERSION "V36" #define EEPROM_VERSION "V37"
// Change EEPROM version if these are changed: // Change EEPROM version if these are changed:
#define EEPROM_OFFSET 100 #define EEPROM_OFFSET 100
/** /**
* V35 EEPROM Layout: * V37 EEPROM Layout:
* *
* 100 Version (char x4) * 100 Version (char x4)
* 104 EEPROM Checksum (uint16_t) * 104 EEPROM Checksum (uint16_t)

View File

@ -39,7 +39,7 @@
void bit_set(uint16_t bits[16], uint8_t x, uint8_t y) { SBI(bits[y], x); } void bit_set(uint16_t bits[16], uint8_t x, uint8_t y) { SBI(bits[y], x); }
bool is_bit_set(uint16_t bits[16], uint8_t x, uint8_t y) { return TEST(bits[y], x); } bool is_bit_set(uint16_t bits[16], uint8_t x, uint8_t y) { return TEST(bits[y], x); }
int ubl_cnt=0; uint8_t ubl_cnt = 0;
static void serial_echo_xy(const uint16_t x, const uint16_t y) { static void serial_echo_xy(const uint16_t x, const uint16_t y) {
SERIAL_CHAR('('); SERIAL_CHAR('(');

View File

@ -40,33 +40,42 @@
float distance; // When populated, the distance from the search location float distance; // When populated, the distance from the search location
} mesh_index_pair; } mesh_index_pair;
// ubl.cpp
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);
// ubl_motion.cpp
void debug_current_and_destination(const char * const title);
void ubl_line_to_destination(const float&, uint8_t);
// ubl_G29.cpp
enum MeshPointType { INVALID, REAL, SET_IN_BITMAP }; enum MeshPointType { INVALID, REAL, SET_IN_BITMAP };
void dump(char * const str, const float &f); void dump(char * const str, const float &f);
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);
void debug_current_and_destination(const char * const title);
void ubl_line_to_destination(const float&, uint8_t);
void manually_probe_remaining_mesh(const float&, const float&, const float&, const float&, const bool); void manually_probe_remaining_mesh(const float&, const float&, const float&, const float&, const bool);
float measure_business_card_thickness(const float&); float measure_business_card_thickness(const float&);
mesh_index_pair find_closest_mesh_point_of_type(const MeshPointType, const float&, const float&, const bool, unsigned int[16], bool); mesh_index_pair find_closest_mesh_point_of_type(const MeshPointType, const float&, const float&, const bool, unsigned int[16], bool);
void shift_mesh_height(); void shift_mesh_height();
void fine_tune_mesh(const float&, const float&, const bool);
bool g29_parameter_parsing(); bool g29_parameter_parsing();
void g29_what_command(); void g29_what_command();
void g29_eeprom_dump(); void g29_eeprom_dump();
void g29_compare_current_mesh_to_stored_mesh(); void g29_compare_current_mesh_to_stored_mesh();
void fine_tune_mesh(const float&, const float&, const bool);
void bit_clear(uint16_t bits[16], uint8_t x, uint8_t y); // External references
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);
char *ftostr43sign(const float&, char); char *ftostr43sign(const float&, char);
bool ubl_lcd_clicked();
void home_all_axes(); void home_all_axes();
void gcode_G26(); void gcode_G26();
void gcode_G29(); void gcode_G29();
extern int ubl_cnt; extern uint8_t ubl_cnt;
/////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////
@ -75,7 +84,6 @@
void lcd_quick_feedback(); void lcd_quick_feedback();
#endif #endif
#define MESH_X_DIST (float(UBL_MESH_MAX_X - (UBL_MESH_MIN_X)) / float(GRID_MAX_POINTS_X - 1)) #define MESH_X_DIST (float(UBL_MESH_MAX_X - (UBL_MESH_MIN_X)) / float(GRID_MAX_POINTS_X - 1))
#define MESH_Y_DIST (float(UBL_MESH_MAX_Y - (UBL_MESH_MIN_Y)) / float(GRID_MAX_POINTS_Y - 1)) #define MESH_Y_DIST (float(UBL_MESH_MAX_Y - (UBL_MESH_MIN_Y)) / float(GRID_MAX_POINTS_Y - 1))

View File

@ -1195,7 +1195,7 @@
SERIAL_EOL; SERIAL_EOL;
safe_delay(50); safe_delay(50);
SERIAL_PROTOCOLLNPAIR("UBL object count: ", ubl_cnt); SERIAL_PROTOCOLLNPAIR("UBL object count: ", (int)ubl_cnt);
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
SERIAL_PROTOCOLLNPAIR("planner.z_fade_height : ", planner.z_fade_height); SERIAL_PROTOCOLLNPAIR("planner.z_fade_height : ", planner.z_fade_height);

View File

@ -1,4 +1,3 @@
/** /**
* Marlin 3D Printer Firmware * Marlin 3D Printer Firmware
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
@ -284,7 +283,6 @@
//on_axis_distance = use_x_dist ? next_mesh_line_x - start[X_AXIS] : y - start[Y_AXIS]; //on_axis_distance = use_x_dist ? next_mesh_line_x - start[X_AXIS] : y - start[Y_AXIS];
//on_axis_distance = use_x_dist ? x - start[X_AXIS] : next_mesh_line_y - start[Y_AXIS]; //on_axis_distance = use_x_dist ? x - start[X_AXIS] : next_mesh_line_y - start[Y_AXIS];
e_position = start[E_AXIS] + on_axis_distance * e_normalized_dist; e_position = start[E_AXIS] + on_axis_distance * e_normalized_dist;
z_position = start[Z_AXIS] + on_axis_distance * z_normalized_dist; z_position = start[Z_AXIS] + on_axis_distance * z_normalized_dist;
} }