Add G26 mesh leveling routines.

This commit is contained in:
Knutwurst
2020-06-04 19:23:05 +02:00
parent c0035b40c0
commit 943f19ecff

View File

@@ -43,8 +43,10 @@
#include "../../lcd/ultralcd.h" #include "../../lcd/ultralcd.h"
#define EXTRUSION_MULTIPLIER 1.0 #define EXTRUSION_MULTIPLIER 1.0
#define PRIME_LENGTH 10.0 #define RETRACTION_LENGTH 1
#define OOZE_AMOUNT 0.3 #define UNRETRACTION_LENGTH 1.2
#define PRIME_LENGTH 5
#define OOZE_AMOUNT 2.25
#define INTERSECTION_CIRCLE_RADIUS 5 #define INTERSECTION_CIRCLE_RADIUS 5
#define CROSSHAIRS_SIZE 3 #define CROSSHAIRS_SIZE 3
@@ -117,8 +119,9 @@
* pliers while holding the LCD Click wheel in a depressed state. If you do not have * pliers while holding the LCD Click wheel in a depressed state. If you do not have
* an LCD, you must specify a value if you use P. * an LCD, you must specify a value if you use P.
* *
* Q # Multiplier Retraction Multiplier. Normally not needed. Retraction defaults to 1.0mm and * Q # Retract Retraction length. Defaults to 1mm if not specified.
* un-retraction is at 1.2mm These numbers will be scaled by the specified amount * Z # Unretract Unretraction length. Defaults to 1.2mm if not specified.
* Note: If Q is specified but Z isn't, Z defaults to Q * 1.2.
* *
* R # Repeat Prints the number of patterns given as a parameter, starting at the current location. * R # Repeat Prints the number of patterns given as a parameter, starting at the current location.
* If a parameter isn't given, every point will be printed unless G26 is interrupted. * If a parameter isn't given, every point will be printed unless G26 is interrupted.
@@ -153,7 +156,8 @@ static bool g26_retracted = false; // Track the retracted state of the nozzle so
// retracts/recovers won't result in a bad state. // retracts/recovers won't result in a bad state.
float g26_extrusion_multiplier, float g26_extrusion_multiplier,
g26_retraction_multiplier, g26_retraction_length,
g26_unretraction_length,
g26_layer_height, g26_layer_height,
g26_prime_length; g26_prime_length;
@@ -169,8 +173,10 @@ int8_t g26_prime_flag;
/** /**
* If the LCD is clicked, cancel, wait for release, return true * If the LCD is clicked, cancel, wait for release, return true
*/ */
bool user_canceled() { bool user_canceled()
if (!ui.button_pressed()) return false; // Return if the button isn't pressed {
if (!ui.button_pressed())
return false; // Return if the button isn't pressed
ui.set_status_P(GET_TEXT(MSG_G26_CANCELED), 99); ui.set_status_P(GET_TEXT(MSG_G26_CANCELED), 99);
#if HAS_LCD_MENU #if HAS_LCD_MENU
ui.quick_feedback(); ui.quick_feedback();
@@ -181,14 +187,17 @@ int8_t g26_prime_flag;
#endif #endif
mesh_index_pair find_closest_circle_to_print(const xy_pos_t &pos) { mesh_index_pair find_closest_circle_to_print(const xy_pos_t &pos)
{
float closest = 99999.99; float closest = 99999.99;
mesh_index_pair out_point; mesh_index_pair out_point;
out_point.pos = -1; out_point.pos = -1;
GRID_LOOP(i, j) { GRID_LOOP(i, j)
if (!circle_flags.marked(i, j)) { {
if (!circle_flags.marked(i, j))
{
// We found a circle that needs to be printed // We found a circle that needs to be printed
const xy_pos_t m = {_GET_MESH_X(i), _GET_MESH_Y(j)}; const xy_pos_t m = {_GET_MESH_X(i), _GET_MESH_Y(j)};
@@ -202,9 +211,11 @@ mesh_index_pair find_closest_circle_to_print(const xy_pos_t &pos) {
f += (g26_xy_pos - m).magnitude() / 15.0f; f += (g26_xy_pos - m).magnitude() / 15.0f;
// Add the specified amount of Random Noise to our search // Add the specified amount of Random Noise to our search
if (random_deviation > 1.0) f += random(0.0, random_deviation); if (random_deviation > 1.0)
f += random(0.0, random_deviation);
if (f < closest) { if (f < closest)
{
closest = f; // Found a closer un-printed location closest = f; // Found a closer un-printed location
out_point.pos.set(i, j); // Save its data out_point.pos.set(i, j); // Save its data
out_point.distance = closest; out_point.distance = closest;
@@ -215,7 +226,8 @@ mesh_index_pair find_closest_circle_to_print(const xy_pos_t &pos) {
return out_point; return out_point;
} }
void move_to(const float &rx, const float &ry, const float &z, const float &e_delta) { void move_to(const float &rx, const float &ry, const float &z, const float &e_delta)
{
static float last_z = -999.99; static float last_z = -999.99;
const xy_pos_t dest = {rx, ry}; const xy_pos_t dest = {rx, ry};
@@ -224,7 +236,8 @@ void move_to(const float &rx, const float &ry, const float &z, const float &e_de
destination = current_position; destination = current_position;
if (z != last_z) { if (z != last_z)
{
last_z = destination.z = z; last_z = destination.z = z;
const feedRate_t feed_value = planner.settings.max_feedrate_mm_s[Z_AXIS] * 0.5f; // Use half of the Z_AXIS max feed rate const feedRate_t feed_value = planner.settings.max_feedrate_mm_s[Z_AXIS] * 0.5f; // Use half of the Z_AXIS max feed rate
prepare_internal_move_to_destination(feed_value); prepare_internal_move_to_destination(feed_value);
@@ -241,23 +254,28 @@ void move_to(const float &rx, const float &ry, const float &z, const float &e_de
FORCE_INLINE void move_to(const xyz_pos_t &where, const float &de) { move_to(where.x, where.y, where.z, de); } FORCE_INLINE void move_to(const xyz_pos_t &where, const float &de) { move_to(where.x, where.y, where.z, de); }
void retract_filament(const xyz_pos_t &where) { void retract_filament(const xyz_pos_t &where)
if (!g26_retracted) { // Only retract if we are not already retracted! {
if (!g26_retracted)
{ // Only retract if we are not already retracted!
g26_retracted = true; g26_retracted = true;
move_to(where, -1.0f * g26_retraction_multiplier); move_to(where, -1.0 * g26_retraction_length);
} }
} }
// TODO: Parameterize the Z lift with a define // TODO: Parameterize the Z lift with a define
void retract_lift_move(const xyz_pos_t &s) { void retract_lift_move(const xyz_pos_t &s)
{
retract_filament(destination); retract_filament(destination);
move_to(current_position.x, current_position.y, current_position.z + 0.5f, 0.0); // Z lift to minimize scraping move_to(current_position.x, current_position.y, current_position.z + 0.5f, 0.0); // Z lift to minimize scraping
move_to(s.x, s.y, s.z + 0.5f, 0.0); // Get to the starting point with no extrusion while lifted move_to(s.x, s.y, s.z + 0.5f, 0.0); // Get to the starting point with no extrusion while lifted
} }
void recover_filament(const xyz_pos_t &where) { void recover_filament(const xyz_pos_t &where)
if (g26_retracted) { // Only un-retract if we are retracted. {
move_to(where, 1.2f * g26_retraction_multiplier); if (g26_retracted)
{ // Only un-retract if we are retracted.
move_to(where, g26_unretraction_length);
g26_retracted = false; g26_retracted = false;
} }
} }
@@ -277,7 +295,8 @@ void recover_filament(const xyz_pos_t &where) {
* segment of a 'circle'. The time this requires is very short and is easily saved by the other * segment of a 'circle'. The time this requires is very short and is easily saved by the other
* cases where the optimization comes into play. * cases where the optimization comes into play.
*/ */
void print_line_from_here_to_there(const xyz_pos_t &s, const xyz_pos_t &e) { void print_line_from_here_to_there(const xyz_pos_t &s, const xyz_pos_t &e)
{
// Distances to the start / end of the line // Distances to the start / end of the line
xy_float_t svec = current_position - s, evec = current_position - e; xy_float_t svec = current_position - s, evec = current_position - e;
@@ -292,7 +311,8 @@ void print_line_from_here_to_there(const xyz_pos_t &s, const xyz_pos_t &e) {
return print_line_from_here_to_there(e, s); return print_line_from_here_to_there(e, s);
// Decide whether to retract & lift // Decide whether to retract & lift
if (dist_start > 2.0) retract_lift_move(s); if (dist_start > 2.0)
retract_lift_move(s);
move_to(s, 0.0); // Get to the starting point with no extrusion / un-Z lift move_to(s, 0.0); // Get to the starting point with no extrusion / un-Z lift
@@ -302,21 +322,27 @@ void print_line_from_here_to_there(const xyz_pos_t &s, const xyz_pos_t &e) {
move_to(e, e_pos_delta); // Get to the ending point with an appropriate amount of extrusion move_to(e, e_pos_delta); // Get to the ending point with an appropriate amount of extrusion
} }
inline bool look_for_lines_to_connect() { inline bool look_for_lines_to_connect()
{
xyz_pos_t s, e; xyz_pos_t s, e;
s.z = e.z = g26_layer_height; s.z = e.z = g26_layer_height;
GRID_LOOP(i, j) { GRID_LOOP(i, j)
{
#if HAS_LCD_MENU #if HAS_LCD_MENU
if (user_canceled()) return true; if (user_canceled())
return true;
#endif #endif
if (i < (GRID_MAX_POINTS_X)) { // Can't connect to anything farther to the right than GRID_MAX_POINTS_X. if (i < (GRID_MAX_POINTS_X))
{ // Can't connect to anything farther to the right than GRID_MAX_POINTS_X.
// Already a half circle at the edge of the bed. // Already a half circle at the edge of the bed.
if (circle_flags.marked(i, j) && circle_flags.marked(i + 1, j)) { // Test whether a leftward line can be done if (circle_flags.marked(i, j) && circle_flags.marked(i + 1, j))
if (!horizontal_mesh_line_flags.marked(i, j)) { { // Test whether a leftward line can be done
if (!horizontal_mesh_line_flags.marked(i, j))
{
// Two circles need a horizontal line to connect them // Two circles need a horizontal line to connect them
s.x = _GET_MESH_X(i) + (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // right edge s.x = _GET_MESH_X(i) + (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // right edge
e.x = _GET_MESH_X(i + 1) - (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // left edge e.x = _GET_MESH_X(i + 1) - (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // left edge
@@ -332,11 +358,14 @@ inline bool look_for_lines_to_connect() {
} }
} }
if (j < (GRID_MAX_POINTS_Y)) { // Can't connect to anything further back than GRID_MAX_POINTS_Y. if (j < (GRID_MAX_POINTS_Y))
{ // Can't connect to anything further back than GRID_MAX_POINTS_Y.
// Already a half circle at the edge of the bed. // Already a half circle at the edge of the bed.
if (circle_flags.marked(i, j) && circle_flags.marked(i, j + 1)) { // Test whether a downward line can be done if (circle_flags.marked(i, j) && circle_flags.marked(i, j + 1))
if (!vertical_mesh_line_flags.marked(i, j)) { { // Test whether a downward line can be done
if (!vertical_mesh_line_flags.marked(i, j))
{
// Two circles that need a vertical line to connect them // Two circles that need a vertical line to connect them
s.y = _GET_MESH_Y(j) + (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // top edge s.y = _GET_MESH_Y(j) + (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // top edge
e.y = _GET_MESH_Y(j + 1) - (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // bottom edge e.y = _GET_MESH_Y(j + 1) - (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // bottom edge
@@ -361,13 +390,15 @@ inline bool look_for_lines_to_connect() {
* Turn on the bed and nozzle heat and * Turn on the bed and nozzle heat and
* wait for them to get up to temperature. * wait for them to get up to temperature.
*/ */
inline bool turn_on_heaters() { inline bool turn_on_heaters()
{
SERIAL_ECHOLNPGM("Waiting for heatup."); SERIAL_ECHOLNPGM("Waiting for heatup.");
#if HAS_HEATED_BED #if HAS_HEATED_BED
if (g26_bed_temp > 25) { if (g26_bed_temp > 25)
{
#if HAS_SPI_LCD #if HAS_SPI_LCD
ui.set_status_P(GET_TEXT(MSG_G26_HEATING_BED), 99); ui.set_status_P(GET_TEXT(MSG_G26_HEATING_BED), 99);
ui.quick_feedback(); ui.quick_feedback();
@@ -380,10 +411,11 @@ inline bool turn_on_heaters() {
// Wait for the temperature to stabilize // Wait for the temperature to stabilize
if (!thermalManager.wait_for_bed(true if (!thermalManager.wait_for_bed(true
#if G26_CLICK_CAN_CANCEL #if G26_CLICK_CAN_CANCEL
, true ,
true
#endif #endif
) ))
) return G26_ERR; return G26_ERR;
} }
#endif // HAS_HEATED_BED #endif // HAS_HEATED_BED
@@ -398,10 +430,11 @@ inline bool turn_on_heaters() {
// Wait for the temperature to stabilize // Wait for the temperature to stabilize
if (!thermalManager.wait_for_hotend(active_extruder, true if (!thermalManager.wait_for_hotend(active_extruder, true
#if G26_CLICK_CAN_CANCEL #if G26_CLICK_CAN_CANCEL
, true ,
true
#endif #endif
) ))
) return G26_ERR; return G26_ERR;
#if HAS_SPI_LCD #if HAS_SPI_LCD
ui.reset_status(); ui.reset_status();
@@ -414,7 +447,8 @@ inline bool turn_on_heaters() {
/** /**
* Prime the nozzle if needed. Return true on error. * Prime the nozzle if needed. Return true on error.
*/ */
inline bool prime_nozzle() { inline bool prime_nozzle()
{
const feedRate_t fr_slow_e = planner.settings.max_feedrate_mm_s[E_AXIS] / 15.0f; const feedRate_t fr_slow_e = planner.settings.max_feedrate_mm_s[E_AXIS] / 15.0f;
#if HAS_LCD_MENU && DISABLED(TOUCH_BUTTONS) // ui.button_pressed issue with touchscreen #if HAS_LCD_MENU && DISABLED(TOUCH_BUTTONS) // ui.button_pressed issue with touchscreen
@@ -422,7 +456,8 @@ inline bool prime_nozzle() {
float Total_Prime = 0.0; float Total_Prime = 0.0;
#endif #endif
if (g26_prime_flag == -1) { // The user wants to control how much filament gets purged if (g26_prime_flag == -1)
{ // The user wants to control how much filament gets purged
ui.capture(); ui.capture();
ui.set_status_P(GET_TEXT(MSG_G26_MANUAL_PRIME), 99); ui.set_status_P(GET_TEXT(MSG_G26_MANUAL_PRIME), 99);
ui.chirp(); ui.chirp();
@@ -431,12 +466,14 @@ inline bool prime_nozzle() {
recover_filament(destination); // Make sure G26 doesn't think the filament is retracted(). recover_filament(destination); // Make sure G26 doesn't think the filament is retracted().
while (!ui.button_pressed()) { while (!ui.button_pressed())
{
ui.chirp(); ui.chirp();
destination.e += 0.25; destination.e += 0.25;
#if ENABLED(PREVENT_LENGTHY_EXTRUDE) #if ENABLED(PREVENT_LENGTHY_EXTRUDE)
Total_Prime += 0.25; Total_Prime += 0.25;
if (Total_Prime >= EXTRUDE_MAXLENGTH) { if (Total_Prime >= EXTRUDE_MAXLENGTH)
{
ui.release(); ui.release();
return G26_ERR; return G26_ERR;
} }
@@ -497,18 +534,22 @@ inline bool prime_nozzle() {
* X X position * X X position
* Y Y position * Y Y position
*/ */
void GcodeSuite::G26() { void GcodeSuite::G26()
{
SERIAL_ECHOLNPGM("G26 starting..."); SERIAL_ECHOLNPGM("G26 starting...");
// Don't allow Mesh Validation without homing first, // Don't allow Mesh Validation without homing first,
// or if the parameter parsing did not go OK, abort // or if the parameter parsing did not go OK, abort
if (axis_unhomed_error()) return; if (axis_unhomed_error())
return;
// Change the tool first, if specified // Change the tool first, if specified
if (parser.seenval('T')) tool_change(parser.value_int()); if (parser.seenval('T'))
tool_change(parser.value_int());
g26_extrusion_multiplier = EXTRUSION_MULTIPLIER; g26_extrusion_multiplier = EXTRUSION_MULTIPLIER;
g26_retraction_multiplier = G26_RETRACT_MULTIPLIER; g26_retraction_length = RETRACTION_LENGTH;
g26_unretraction_length = UNRETRACTION_LENGTH;
g26_layer_height = MESH_TEST_LAYER_HEIGHT; g26_layer_height = MESH_TEST_LAYER_HEIGHT;
g26_prime_length = PRIME_LENGTH; g26_prime_length = PRIME_LENGTH;
g26_bed_temp = MESH_TEST_BED_TEMP; g26_bed_temp = MESH_TEST_BED_TEMP;
@@ -523,47 +564,96 @@ void GcodeSuite::G26() {
g26_keep_heaters_on = parser.boolval('K'); g26_keep_heaters_on = parser.boolval('K');
#if HAS_HEATED_BED #if HAS_HEATED_BED
if (parser.seenval('B')) { if (parser.seenval('B'))
{
g26_bed_temp = parser.value_celsius(); g26_bed_temp = parser.value_celsius();
if (g26_bed_temp && !WITHIN(g26_bed_temp, 40, (BED_MAXTEMP - 10))) { if (g26_bed_temp && !WITHIN(g26_bed_temp, 40, (BED_MAXTEMP - 10)))
{
SERIAL_ECHOLNPAIR("?Specified bed temperature not plausible (40-", int(BED_MAXTEMP - 10), "C)."); SERIAL_ECHOLNPAIR("?Specified bed temperature not plausible (40-", int(BED_MAXTEMP - 10), "C).");
return; return;
} }
} }
#endif #endif
if (parser.seenval('L')) { if (parser.seenval('L'))
{
g26_layer_height = parser.value_linear_units(); g26_layer_height = parser.value_linear_units();
if (!WITHIN(g26_layer_height, 0.0, 2.0)) { if (!WITHIN(g26_layer_height, 0.0, 2.0))
{
SERIAL_ECHOLNPGM("?Specified layer height not plausible."); SERIAL_ECHOLNPGM("?Specified layer height not plausible.");
return; return;
} }
} }
if (parser.seen('Q')) { if (parser.seen('Q'))
if (parser.has_value()) { {
g26_retraction_multiplier = parser.value_float(); if (parser.has_value())
if (!WITHIN(g26_retraction_multiplier, 0.05, 15.0)) { {
SERIAL_ECHOLNPGM("?Specified Retraction Multiplier not plausible."); g26_retraction_length = parser.value_float();
if (!WITHIN(g26_retraction_length, 0.05, 15.0))
{
SERIAL_ECHOLNPGM("?Specified Retraction length not plausible.");
return; return;
} }
} }
else { else
SERIAL_ECHOLNPGM("?Retraction Multiplier must be specified."); {
SERIAL_ECHOLNPGM("?Retraction length must be specified.");
return; return;
} }
} }
if (parser.seenval('S')) { if (parser.seen('Z'))
{
if (parser.has_value())
{
g26_unretraction_length = parser.value_float();
if (!WITHIN(g26_unretraction_length, 0.05, 15.0))
{
SERIAL_ECHOLNPGM("?Specified Unretraction length not plausible.");
return;
}
}
else
{
SERIAL_ECHOLNPGM("?Unretraction length must be specified.");
return;
}
}
if (!parser.seen('Z') && parser.seen('Q'))
{
// retraction without unretraction specified, use 1.2 multiplier (preserve Gcode spec)
g26_unretraction_length = g26_retraction_length * 1.2;
SERIAL_ECHOPAIR(" Unretraction amount automatically set to ", g26_unretraction_length);
SERIAL_EOL();
}
if (parser.seen('Z') && parser.seen('Q'))
{
// consider typos or unreasonable retract/unretract ratios
float g26_retract_unretract_delta = g26_unretraction_length - g26_retraction_length;
if (!WITHIN(g26_retract_unretract_delta, -5, 5))
{
SERIAL_ECHOLNPGM("?Invalid Retraction/Unretraction ratio. Must be within 5mm.");
return;
}
}
if (parser.seenval('S'))
{
g26_nozzle = parser.value_float(); g26_nozzle = parser.value_float();
if (!WITHIN(g26_nozzle, 0.1, 2.0)) { if (!WITHIN(g26_nozzle, 0.1, 2.0))
{
SERIAL_ECHOLNPGM("?Specified nozzle size not plausible."); SERIAL_ECHOLNPGM("?Specified nozzle size not plausible.");
return; return;
} }
} }
if (parser.seen('P')) { if (parser.seen('P'))
if (!parser.has_value()) { {
if (!parser.has_value())
{
#if HAS_LCD_MENU #if HAS_LCD_MENU
g26_prime_flag = -1; g26_prime_flag = -1;
#else #else
@@ -571,19 +661,23 @@ void GcodeSuite::G26() {
return; return;
#endif #endif
} }
else { else
{
g26_prime_flag++; g26_prime_flag++;
g26_prime_length = parser.value_linear_units(); g26_prime_length = parser.value_linear_units();
if (!WITHIN(g26_prime_length, 0.0, 25.0)) { if (!WITHIN(g26_prime_length, 0.0, 25.0))
{
SERIAL_ECHOLNPGM("?Specified prime length not plausible."); SERIAL_ECHOLNPGM("?Specified prime length not plausible.");
return; return;
} }
} }
} }
if (parser.seenval('F')) { if (parser.seenval('F'))
{
g26_filament_diameter = parser.value_linear_units(); g26_filament_diameter = parser.value_linear_units();
if (!WITHIN(g26_filament_diameter, 1.0, 4.0)) { if (!WITHIN(g26_filament_diameter, 1.0, 4.0))
{
SERIAL_ECHOLNPGM("?Specified filament size not plausible."); SERIAL_ECHOLNPGM("?Specified filament size not plausible.");
return; return;
} }
@@ -594,15 +688,18 @@ void GcodeSuite::G26() {
g26_extrusion_multiplier *= g26_filament_diameter * sq(g26_nozzle) / sq(0.3); // Scale up by nozzle size g26_extrusion_multiplier *= g26_filament_diameter * sq(g26_nozzle) / sq(0.3); // Scale up by nozzle size
if (parser.seenval('H')) { if (parser.seenval('H'))
{
g26_hotend_temp = parser.value_celsius(); g26_hotend_temp = parser.value_celsius();
if (!WITHIN(g26_hotend_temp, 165, (HEATER_0_MAXTEMP - 15))) { if (!WITHIN(g26_hotend_temp, 165, (HEATER_0_MAXTEMP - 15)))
{
SERIAL_ECHOLNPGM("?Specified nozzle temperature not plausible."); SERIAL_ECHOLNPGM("?Specified nozzle temperature not plausible.");
return; return;
} }
} }
if (parser.seen('U')) { if (parser.seen('U'))
{
randomSeed(millis()); randomSeed(millis());
// This setting will persist for the next G26 // This setting will persist for the next G26
random_deviation = parser.has_value() ? parser.value_float() : 50.0; random_deviation = parser.has_value() ? parser.value_float() : 50.0;
@@ -612,21 +709,24 @@ void GcodeSuite::G26() {
#if HAS_LCD_MENU #if HAS_LCD_MENU
g26_repeats = parser.intval('R', GRID_MAX_POINTS + 1); g26_repeats = parser.intval('R', GRID_MAX_POINTS + 1);
#else #else
if (!parser.seen('R')) { if (!parser.seen('R'))
{
SERIAL_ECHOLNPGM("?(R)epeat must be specified when not using an LCD."); SERIAL_ECHOLNPGM("?(R)epeat must be specified when not using an LCD.");
return; return;
} }
else else
g26_repeats = parser.has_value() ? parser.value_int() : GRID_MAX_POINTS + 1; g26_repeats = parser.has_value() ? parser.value_int() : GRID_MAX_POINTS + 1;
#endif #endif
if (g26_repeats < 1) { if (g26_repeats < 1)
{
SERIAL_ECHOLNPGM("?(R)epeat value not plausible; must be at least 1."); SERIAL_ECHOLNPGM("?(R)epeat value not plausible; must be at least 1.");
return; return;
} }
g26_xy_pos.set(parser.seenval('X') ? RAW_X_POSITION(parser.value_linear_units()) : current_position.x, g26_xy_pos.set(parser.seenval('X') ? RAW_X_POSITION(parser.value_linear_units()) : current_position.x,
parser.seenval('Y') ? RAW_Y_POSITION(parser.value_linear_units()) : current_position.y); parser.seenval('Y') ? RAW_Y_POSITION(parser.value_linear_units()) : current_position.y);
if (!position_is_reachable(g26_xy_pos)) { if (!position_is_reachable(g26_xy_pos))
{
SERIAL_ECHOLNPGM("?Specified X,Y coordinate out of bounds."); SERIAL_ECHOLNPGM("?Specified X,Y coordinate out of bounds.");
return; return;
} }
@@ -645,12 +745,14 @@ void GcodeSuite::G26() {
planner.calculate_volumetric_multipliers(); planner.calculate_volumetric_multipliers();
#endif #endif
if (turn_on_heaters() != G26_OK) goto LEAVE; if (turn_on_heaters() != G26_OK)
goto LEAVE;
current_position.e = 0.0; current_position.e = 0.0;
sync_plan_position_e(); sync_plan_position_e();
if (g26_prime_flag && prime_nozzle() != G26_OK) goto LEAVE; if (g26_prime_flag && prime_nozzle() != G26_OK)
goto LEAVE;
/** /**
* Bed is preheated * Bed is preheated
@@ -697,15 +799,18 @@ void GcodeSuite::G26() {
#endif // !ARC_SUPPORT #endif // !ARC_SUPPORT
mesh_index_pair location; mesh_index_pair location;
do { do
{
// Find the nearest confluence // Find the nearest confluence
location = find_closest_circle_to_print(g26_continue_with_closest ? xy_pos_t(current_position) : g26_xy_pos); location = find_closest_circle_to_print(g26_continue_with_closest ? xy_pos_t(current_position) : g26_xy_pos);
if (location.valid()) { if (location.valid())
{
const xy_pos_t circle = _GET_MESH_POS(location.pos); const xy_pos_t circle = _GET_MESH_POS(location.pos);
// If this mesh location is outside the printable radius, skip it. // If this mesh location is outside the printable radius, skip it.
if (!position_is_reachable(circle)) continue; if (!position_is_reachable(circle))
continue;
// Determine where to start and end the circle, // Determine where to start and end the circle,
// which is always drawn counter-clockwise. // which is always drawn counter-clockwise.
@@ -724,23 +829,39 @@ void GcodeSuite::G26() {
// Figure out where to start and end the arc - we always print counterclockwise // Figure out where to start and end the arc - we always print counterclockwise
float arc_length = ARC_LENGTH(4); float arc_length = ARC_LENGTH(4);
if (st.x == 0) { // left edge if (st.x == 0)
if (!f) { s.x = circle.x; s.y -= INTERSECTION_CIRCLE_RADIUS; } { // left edge
if (!b) { e.x = circle.x; e.y += INTERSECTION_CIRCLE_RADIUS; } if (!f)
{
s.x = circle.x;
s.y -= INTERSECTION_CIRCLE_RADIUS;
}
if (!b)
{
e.x = circle.x;
e.y += INTERSECTION_CIRCLE_RADIUS;
}
arc_length = (f || b) ? ARC_LENGTH(1) : ARC_LENGTH(2); arc_length = (f || b) ? ARC_LENGTH(1) : ARC_LENGTH(2);
} }
else if (r) { // right edge else if (r)
if (b) s.set(circle.x - (INTERSECTION_CIRCLE_RADIUS), circle.y); { // right edge
else s.set(circle.x, circle.y + INTERSECTION_CIRCLE_RADIUS); if (b)
if (f) e.set(circle.x - (INTERSECTION_CIRCLE_RADIUS), circle.y); s.set(circle.x - (INTERSECTION_CIRCLE_RADIUS), circle.y);
else e.set(circle.x, circle.y - (INTERSECTION_CIRCLE_RADIUS)); else
s.set(circle.x, circle.y + INTERSECTION_CIRCLE_RADIUS);
if (f)
e.set(circle.x - (INTERSECTION_CIRCLE_RADIUS), circle.y);
else
e.set(circle.x, circle.y - (INTERSECTION_CIRCLE_RADIUS));
arc_length = (f || b) ? ARC_LENGTH(1) : ARC_LENGTH(2); arc_length = (f || b) ? ARC_LENGTH(1) : ARC_LENGTH(2);
} }
else if (f) { else if (f)
{
e.x -= INTERSECTION_CIRCLE_DIAM; e.x -= INTERSECTION_CIRCLE_DIAM;
arc_length = ARC_LENGTH(2); arc_length = ARC_LENGTH(2);
} }
else if (b) { else if (b)
{
s.x -= INTERSECTION_CIRCLE_DIAM; s.x -= INTERSECTION_CIRCLE_DIAM;
arc_length = ARC_LENGTH(2); arc_length = ARC_LENGTH(2);
} }
@@ -750,10 +871,10 @@ void GcodeSuite::G26() {
const float dist_start = HYPOT2(dist.x, dist.y); const float dist_start = HYPOT2(dist.x, dist.y);
const xyze_pos_t endpoint = { const xyze_pos_t endpoint = {
e.x, e.y, g26_layer_height, e.x, e.y, g26_layer_height,
current_position.e + (arc_length * g26_e_axis_feedrate * g26_extrusion_multiplier) current_position.e + (arc_length * g26_e_axis_feedrate * g26_extrusion_multiplier)};
};
if (dist_start > 2.0) { if (dist_start > 2.0)
{
s.z = g26_layer_height + 0.5f; s.z = g26_layer_height + 0.5f;
retract_lift_move(s); retract_lift_move(s);
} }
@@ -770,33 +891,40 @@ void GcodeSuite::G26() {
destination = current_position; destination = current_position;
#if HAS_LCD_MENU #if HAS_LCD_MENU
if (user_canceled()) goto LEAVE; // Check if the user wants to stop the Mesh Validation if (user_canceled())
goto LEAVE; // Check if the user wants to stop the Mesh Validation
#endif #endif
#else // !ARC_SUPPORT #else // !ARC_SUPPORT
int8_t start_ind = -2, end_ind = 9; // Assume a full circle (from 5:00 to 5:00) int8_t start_ind = -2, end_ind = 9; // Assume a full circle (from 5:00 to 5:00)
if (st.x == 0) { // Left edge? Just right half. if (st.x == 0)
{ // Left edge? Just right half.
start_ind = f ? 0 : -3; // 03:00 to 12:00 for front-left start_ind = f ? 0 : -3; // 03:00 to 12:00 for front-left
end_ind = b ? 0 : 2; // 06:00 to 03:00 for back-left end_ind = b ? 0 : 2; // 06:00 to 03:00 for back-left
} }
else if (r) { // Right edge? Just left half. else if (r)
{ // Right edge? Just left half.
start_ind = b ? 6 : 3; // 12:00 to 09:00 for front-right start_ind = b ? 6 : 3; // 12:00 to 09:00 for front-right
end_ind = f ? 5 : 8; // 09:00 to 06:00 for back-right end_ind = f ? 5 : 8; // 09:00 to 06:00 for back-right
} }
else if (f) { // Front edge? Just back half. else if (f)
{ // Front edge? Just back half.
start_ind = 0; // 03:00 start_ind = 0; // 03:00
end_ind = 5; // 09:00 end_ind = 5; // 09:00
} }
else if (b) { // Back edge? Just front half. else if (b)
{ // Back edge? Just front half.
start_ind = 6; // 09:00 start_ind = 6; // 09:00
end_ind = 11; // 03:00 end_ind = 11; // 03:00
} }
for (int8_t ind = start_ind; ind <= end_ind; ind++) { for (int8_t ind = start_ind; ind <= end_ind; ind++)
{
#if HAS_LCD_MENU #if HAS_LCD_MENU
if (user_canceled()) goto LEAVE; // Check if the user wants to stop the Mesh Validation if (user_canceled())
goto LEAVE; // Check if the user wants to stop the Mesh Validation
#endif #endif
xyz_float_t p = {circle.x + _COS(ind), circle.y + _SIN(ind), g26_layer_height}, xyz_float_t p = {circle.x + _COS(ind), circle.y + _SIN(ind), g26_layer_height},
@@ -804,7 +932,8 @@ void GcodeSuite::G26() {
#if IS_KINEMATIC #if IS_KINEMATIC
// Check to make sure this segment is entirely on the bed, skip if not. // Check to make sure this segment is entirely on the bed, skip if not.
if (!position_is_reachable(p) || !position_is_reachable(q)) continue; if (!position_is_reachable(p) || !position_is_reachable(q))
continue;
#else #else
LIMIT(p.x, X_MIN_POS + 1, X_MAX_POS - 1); // Prevent hitting the endstops LIMIT(p.x, X_MIN_POS + 1, X_MAX_POS - 1); // Prevent hitting the endstops
LIMIT(p.y, Y_MIN_POS + 1, Y_MAX_POS - 1); LIMIT(p.y, Y_MIN_POS + 1, Y_MAX_POS - 1);
@@ -818,7 +947,8 @@ void GcodeSuite::G26() {
#endif // !ARC_SUPPORT #endif // !ARC_SUPPORT
if (look_for_lines_to_connect()) goto LEAVE; if (look_for_lines_to_connect())
goto LEAVE;
} }
SERIAL_FLUSH(); // Prevent host M105 buffer overrun. SERIAL_FLUSH(); // Prevent host M105 buffer overrun.
@@ -844,7 +974,8 @@ void GcodeSuite::G26() {
ui.release(); // Give back control of the LCD ui.release(); // Give back control of the LCD
#endif #endif
if (!g26_keep_heaters_on) { if (!g26_keep_heaters_on)
{
#if HAS_HEATED_BED #if HAS_HEATED_BED
thermalManager.setTargetBed(0); thermalManager.setTargetBed(0);
#endif #endif