Various UBL cleanups and bug fixes

This commit is contained in:
Scott Lahteine
2017-03-28 19:45:54 -05:00
parent f49aec057f
commit 9217e4b8ec
11 changed files with 458 additions and 548 deletions

View File

@@ -35,7 +35,6 @@
#include "temperature.h"
#include "UBL.h"
#include "ultralcd.h"
//#include <avr/pgmspace.h>
#define EXTRUSION_MULTIPLIER 1.0 // This is too much clutter for the main Configuration.h file But
#define RETRACTION_MULTIPLIER 1.0 // some user have expressed an interest in being able to customize
@@ -177,7 +176,7 @@
/**
* G26: Mesh Validation Pattern generation.
*
*
* Used to interactively edit UBL's Mesh by placing the
* nozzle in a problem area and doing a G29 P4 R command.
*/
@@ -234,7 +233,7 @@
move_to(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], ooze_amount);
ubl_has_control_of_lcd_panel = true; // Take control of the LCD Panel!
// debug_current_and_destination((char*)"Starting G26 Mesh Validation Pattern.");
//debug_current_and_destination((char*)"Starting G26 Mesh Validation Pattern.");
/**
* Declare and generate a sin() & cos() table to be used during the circle drawing. This will lighten
@@ -250,16 +249,17 @@
if (ubl_lcd_clicked()) { // Check if the user wants to stop the Mesh Validation
#if ENABLED(ULTRA_LCD)
lcd_setstatuspgm(PSTR("Mesh Validation Stopped."), (uint8_t) 99);
lcd_setstatuspgm(PSTR("Mesh Validation Stopped."), 99);
lcd_quick_feedback();
#endif
while (!ubl_lcd_clicked()) { // Wait until the user is done pressing the
idle(); // Encoder Wheel if that is why we are leaving
lcd_setstatuspgm(PSTR(" "), (uint8_t) 99);
lcd_reset_alert_level();
lcd_setstatuspgm(PSTR(""));
}
while ( ubl_lcd_clicked()) { // Wait until the user is done pressing the
while (ubl_lcd_clicked()) { // Wait until the user is done pressing the
idle(); // Encoder Wheel if that is why we are leaving
lcd_setstatuspgm(PSTR("Unpress Wheel "), (uint8_t) 99);
lcd_setstatuspgm(PSTR("Unpress Wheel"), 99);
}
goto LEAVE;
}
@@ -276,13 +276,16 @@
// 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
if (HYPOT2(circle_x, circle_y) > sq(DELTA_PRINTABLE_RADIUS)) {
SERIAL_PROTOCOLLNPGM("?Error: Attempt to print outside of DELTA_PRINTABLE_RADIUS.");
SERIAL_ERROR_START;
SERIAL_ERRORLNPGM("Attempt to print outside of DELTA_PRINTABLE_RADIUS.");
goto LEAVE;
}
#endif
if (circle_x < X_MIN_POS || circle_x > X_MAX_POS || circle_y < Y_MIN_POS || circle_y > Y_MAX_POS) {
SERIAL_PROTOCOLLNPGM("?Error: Attempt to print off the bed.");
// TODO: Change this to use `position_is_reachable`
if (circle_x < (X_MIN_POS) || circle_x > (X_MAX_POS) || circle_y < (Y_MIN_POS) || circle_y > (Y_MAX_POS)) {
SERIAL_ERROR_START;
SERIAL_ERRORLNPGM("Attempt to print off the bed.");
goto LEAVE;
}
@@ -290,11 +293,10 @@
yi = location.y_index;
if (g26_debug_flag) {
SERIAL_ECHOPGM(" Doing circle at: (xi=");
SERIAL_ECHO(xi);
SERIAL_ECHOPGM(", yi=");
SERIAL_ECHO(yi);
SERIAL_ECHOLNPGM(")");
SERIAL_ECHOPAIR(" Doing circle at: (xi=", xi);
SERIAL_ECHOPAIR(", yi=", yi);
SERIAL_CHAR(')');
SERIAL_EOL;
}
start_angle = 0.0; // assume it is going to be a full circle
@@ -344,56 +346,53 @@
ye = constrain(ye, Y_MIN_POS + 1, Y_MAX_POS - 1);
#endif
// if (g26_debug_flag) {
// char ccc, *cptr, seg_msg[50], seg_num[10];
// strcpy(seg_msg, " segment: ");
// strcpy(seg_num, " \n");
// cptr = (char*) "01234567890ABCDEF????????";
// ccc = cptr[tmp_div_30];
// seg_num[1] = ccc;
// strcat(seg_msg, seg_num);
// debug_current_and_destination(seg_msg);
// }
//if (g26_debug_flag) {
// char ccc, *cptr, seg_msg[50], seg_num[10];
// strcpy(seg_msg, " segment: ");
// strcpy(seg_num, " \n");
// cptr = (char*) "01234567890ABCDEF????????";
// ccc = cptr[tmp_div_30];
// seg_num[1] = ccc;
// strcat(seg_msg, seg_num);
// debug_current_and_destination(seg_msg);
//}
print_line_from_here_to_there(x, y, layer_height, xe, ye, layer_height);
}
// lcd_init_counter++;
// if (lcd_init_counter > 10) {
// lcd_init_counter = 0;
// lcd_init(); // Some people's LCD Displays are locking up. This might help them
// ubl_has_control_of_lcd_panel = true; // Make sure UBL still is controlling the LCD Panel
// }
//lcd_init_counter++;
//if (lcd_init_counter > 10) {
// lcd_init_counter = 0;
// lcd_init(); // Some people's LCD Displays are locking up. This might help them
// ubl_has_control_of_lcd_panel = true; // Make sure UBL still is controlling the LCD Panel
//}
// If the end point of the line is closer to the nozzle, we are going to
// debug_current_and_destination((char*)"Looking for lines to connect.");
//debug_current_and_destination((char*)"Looking for lines to connect.");
look_for_lines_to_connect();
// debug_current_and_destination((char*)"Done with line connect.");
//debug_current_and_destination((char*)"Done with line connect.");
}
// debug_current_and_destination((char*)"Done with current circle.");
// If the end point of the line is closer to the nozzle, we are going to
//debug_current_and_destination((char*)"Done with current circle.");
}
while (location.x_index >= 0 && location.y_index >= 0);
LEAVE:
lcd_setstatuspgm(PSTR("Leaving G26 "), (uint8_t) 99);
lcd_reset_alert_level();
lcd_setstatuspgm(PSTR("Leaving G26"));
retract_filament();
destination[Z_AXIS] = Z_CLEARANCE_BETWEEN_PROBES; // Raise the nozzle
destination[Z_AXIS] = Z_CLEARANCE_BETWEEN_PROBES;
// debug_current_and_destination((char*)"ready to do Z-Raise.");
move_to( destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], 0); // Raise the nozzle
// debug_current_and_destination((char*)"done doing Z-Raise.");
//debug_current_and_destination((char*)"ready to do Z-Raise.");
move_to(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], 0); // Raise the nozzle
//debug_current_and_destination((char*)"done doing Z-Raise.");
destination[X_AXIS] = x_pos; // Move back to the starting position
destination[X_AXIS] = x_pos; // Move back to the starting position
destination[Y_AXIS] = y_pos;
destination[Z_AXIS] = Z_CLEARANCE_BETWEEN_PROBES; // Keep the nozzle where it is
//destination[Z_AXIS] = Z_CLEARANCE_BETWEEN_PROBES; // Keep the nozzle where it is
move_to(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], 0); // Move back to the starting position
// debug_current_and_destination((char*)"done doing X/Y move.");
//debug_current_and_destination((char*)"done doing X/Y move.");
ubl_has_control_of_lcd_panel = false; // Give back control of the LCD Panel!
@@ -481,16 +480,13 @@
ey = constrain(ey, Y_MIN_POS + 1, Y_MAX_POS - 1);
if (g26_debug_flag) {
SERIAL_ECHOPGM(" Connecting with horizontal line (sx=");
SERIAL_ECHO(sx);
SERIAL_ECHOPGM(", sy=");
SERIAL_ECHO(sy);
SERIAL_ECHOPGM(") -> (ex=");
SERIAL_ECHO(ex);
SERIAL_ECHOPGM(", ey=");
SERIAL_ECHO(ey);
SERIAL_ECHOLNPGM(")");
// debug_current_and_destination((char*)"Connecting horizontal line.");
SERIAL_ECHOPAIR(" Connecting with horizontal line (sx=", sx);
SERIAL_ECHOPAIR(", sy=", sy);
SERIAL_ECHOPAIR(") -> (ex=", ex);
SERIAL_ECHOPAIR(", ey=", ey);
SERIAL_CHAR(')');
SERIAL_EOL;
//debug_current_and_destination((char*)"Connecting horizontal line.");
}
print_line_from_here_to_there(sx, sy, layer_height, ex, ey, layer_height);
@@ -521,15 +517,12 @@
ey = constrain(ey, Y_MIN_POS + 1, Y_MAX_POS - 1);
if (g26_debug_flag) {
SERIAL_ECHOPGM(" Connecting with vertical line (sx=");
SERIAL_ECHO(sx);
SERIAL_ECHOPGM(", sy=");
SERIAL_ECHO(sy);
SERIAL_ECHOPGM(") -> (ex=");
SERIAL_ECHO(ex);
SERIAL_ECHOPGM(", ey=");
SERIAL_ECHO(ey);
SERIAL_ECHOLNPGM(")");
SERIAL_ECHOPAIR(" Connecting with vertical line (sx=", sx);
SERIAL_ECHOPAIR(", sy=", sy);
SERIAL_ECHOPAIR(") -> (ex=", ex);
SERIAL_ECHOPAIR(", ey=", ey);
SERIAL_CHAR(')');
SERIAL_EOL;
debug_current_and_destination((char*)"Connecting vertical line.");
}
print_line_from_here_to_there(sx, sy, layer_height, ex, ey, layer_height);
@@ -548,16 +541,10 @@
bool has_xy_component = (x != current_position[X_AXIS] || y != current_position[Y_AXIS]); // Check if X or Y is involved in the movement.
// if (g26_debug_flag) {
// SERIAL_ECHOPAIR("in move_to() has_xy_component:", (int)has_xy_component);
// SERIAL_EOL;
// }
//if (g26_debug_flag) SERIAL_ECHOLNPAIR("in move_to() has_xy_component:", (int)has_xy_component);
if (z != last_z) {
// if (g26_debug_flag) {
// SERIAL_ECHOPAIR("in move_to() changing Z to ", (int)z);
// SERIAL_EOL;
// }
//if (g26_debug_flag) SERIAL_ECHOLNPAIR("in move_to() changing Z to ", (int)z);
last_z = z;
feed_value = planner.max_feedrate_mm_s[Z_AXIS]/(3.0); // Base the feed rate off of the configured Z_AXIS feed rate
@@ -572,30 +559,24 @@
stepper.synchronize();
set_destination_to_current();
// if (g26_debug_flag)
// debug_current_and_destination((char*)" in move_to() done with Z move");
//if (g26_debug_flag) debug_current_and_destination((char*)" in move_to() done with Z move");
}
// Check if X or Y is involved in the movement.
// Yes: a 'normal' movement. No: a retract() or un_retract()
feed_value = has_xy_component ? PLANNER_XY_FEEDRATE() / 10.0 : planner.max_feedrate_mm_s[E_AXIS] / 1.5;
if (g26_debug_flag) {
SERIAL_ECHOPAIR("in move_to() feed_value for XY:", feed_value);
SERIAL_EOL;
}
if (g26_debug_flag) SERIAL_ECHOLNPAIR("in move_to() feed_value for XY:", feed_value);
destination[X_AXIS] = x;
destination[Y_AXIS] = y;
destination[E_AXIS] += e_delta;
// if (g26_debug_flag)
// debug_current_and_destination((char*)" in move_to() doing last move");
//if (g26_debug_flag) debug_current_and_destination((char*)" in move_to() doing last move");
ubl_line_to_destination(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feed_value, 0);
// if (g26_debug_flag)
// debug_current_and_destination((char*)" in move_to() after last move");
//if (g26_debug_flag) debug_current_and_destination((char*)" in move_to() after last move");
stepper.synchronize();
set_destination_to_current();
@@ -605,9 +586,9 @@
void retract_filament() {
if (!g26_retracted) { // Only retract if we are not already retracted!
g26_retracted = true;
// if (g26_debug_flag) SERIAL_ECHOLNPGM(" Decided to do retract.");
//if (g26_debug_flag) SERIAL_ECHOLNPGM(" Decided to do retract.");
move_to(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], -1.0 * retraction_multiplier);
// if (g26_debug_flag) SERIAL_ECHOLNPGM(" Retraction done.");
//if (g26_debug_flag) SERIAL_ECHOLNPGM(" Retraction done.");
}
}
@@ -615,7 +596,7 @@
if (g26_retracted) { // Only un-retract if we are retracted.
move_to(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], 1.2 * retraction_multiplier);
g26_retracted = false;
// if (g26_debug_flag) SERIAL_ECHOLNPGM(" unretract done.");
//if (g26_debug_flag) SERIAL_ECHOLNPGM(" unretract done.");
}
}
@@ -635,27 +616,24 @@
* cases where the optimization comes into play.
*/
void print_line_from_here_to_there( float sx, float sy, float sz, float ex, float ey, float ez) {
float dx, dy, dx_s, dy_s, dx_e, dy_e, dist_start, dist_end, Line_Length;
const float dx_s = current_position[X_AXIS] - sx, // find our distance from the start of the actual line segment
dy_s = current_position[Y_AXIS] - sy,
dist_start = HYPOT2(dx_s, dy_s), // We don't need to do a sqrt(), we can compare the distance^2
// to save computation time
dx_e = current_position[X_AXIS] - ex, // find our distance from the end of the actual line segment
dy_e = current_position[Y_AXIS] - ey,
dist_end = HYPOT2(dx_e, dy_e),
dx_s = current_position[X_AXIS] - sx; // find our distance from the start of the actual line segment
dy_s = current_position[Y_AXIS] - sy;
dist_start = HYPOT2(dx_s, dy_s); // We don't need to do a sqrt(), we can compare the distance^2
// to save computation time
dx_e = current_position[X_AXIS] - ex; // find our distance from the end of the actual line segment
dy_e = current_position[Y_AXIS] - ey;
dist_end = HYPOT2(dx_e, dy_e);
dx = ex - sx;
dy = ey - sy;
Line_Length = HYPOT(dx, dy);
dx = ex - sx,
dy = ey - sy,
line_length = HYPOT(dx, dy);
// If the end point of the line is closer to the nozzle, we are going to
// flip the direction of this line. We will print it from the end to the start.
// On very small lines we don't do the optimization because it just isn't worth it.
//
if (dist_end < dist_start && (SIZE_OF_INTERSECTION_CIRCLES) < abs(Line_Length)) {
// if (g26_debug_flag)
// SERIAL_ECHOLNPGM(" Reversing start and end of print_line_from_here_to_there()");
if (dist_end < dist_start && (SIZE_OF_INTERSECTION_CIRCLES) < abs(line_length)) {
//if (g26_debug_flag) SERIAL_ECHOLNPGM(" Reversing start and end of print_line_from_here_to_there()");
print_line_from_here_to_there(ex, ey, ez, sx, sy, sz);
return;
}
@@ -664,26 +642,19 @@
if (dist_start > 2.0) {
retract_filament();
// if (g26_debug_flag)
// SERIAL_ECHOLNPGM(" filament retracted.");
//if (g26_debug_flag) SERIAL_ECHOLNPGM(" filament retracted.");
}
// If the end point of the line is closer to the nozzle, we are going to
move_to(sx, sy, sz, 0.0); // Get to the starting point with no extrusion
// If the end point of the line is closer to the nozzle, we are going to
float e_pos_delta = Line_Length * g26_e_axis_feedrate * extrusion_multiplier;
const float e_pos_delta = line_length * g26_e_axis_feedrate * extrusion_multiplier;
un_retract_filament();
// If the end point of the line is closer to the nozzle, we are going to
// if (g26_debug_flag) {
// SERIAL_ECHOLNPGM(" doing printing move.");
// debug_current_and_destination((char*)"doing final move_to() inside print_line_from_here_to_there()");
// }
//if (g26_debug_flag) {
// SERIAL_ECHOLNPGM(" doing printing move.");
// debug_current_and_destination((char*)"doing final move_to() inside print_line_from_here_to_there()");
//}
move_to(ex, ey, ez, e_pos_delta); // Get to the ending point with an appropriate amount of extrusion
// If the end point of the line is closer to the nozzle, we are going to
}
/**
@@ -820,6 +791,14 @@
return UBL_OK;
}
bool exit_from_g26() {
//strcpy(lcd_status_message, "Leaving G26"); // We can't do lcd_setstatus() without having it continue;
lcd_reset_alert_level();
lcd_setstatuspgm(PSTR("Leaving G26"));
while (ubl_lcd_clicked()) idle();
return UBL_ERR;
}
/**
* Turn on the bed and nozzle heat and
* wait for them to get up to temperature.
@@ -828,24 +807,18 @@
#if HAS_TEMP_BED
#if ENABLED(ULTRA_LCD)
if (bed_temp > 25) {
lcd_setstatuspgm(PSTR("G26 Heating Bed."), (uint8_t) 99);
lcd_setstatuspgm(PSTR("G26 Heating Bed."), 99);
lcd_quick_feedback();
#endif
ubl_has_control_of_lcd_panel = true;
thermalManager.setTargetBed(bed_temp);
while (abs(thermalManager.degBed() - bed_temp) > 3) {
if (ubl_lcd_clicked()) {
strcpy(lcd_status_message, "Leaving G26"); // We can't do lcd_setstatus() without having it continue;
lcd_setstatuspgm(PSTR("Leaving G26"), (uint8_t) 99); // Now we do it right.
while (ubl_lcd_clicked()) // Debounce Encoder Wheel
idle();
return UBL_ERR;
}
if (ubl_lcd_clicked()) return exit_from_g26();
idle();
}
#if ENABLED(ULTRA_LCD)
}
lcd_setstatuspgm(PSTR("G26 Heating Nozzle."), (uint8_t) 99);
lcd_setstatuspgm(PSTR("G26 Heating Nozzle."), 99);
lcd_quick_feedback();
#endif
#endif
@@ -853,18 +826,13 @@
// Start heating the nozzle and wait for it to reach temperature.
thermalManager.setTargetHotend(hotend_temp, 0);
while (abs(thermalManager.degHotend(0) - hotend_temp) > 3) {
if (ubl_lcd_clicked()) {
strcpy(lcd_status_message, "Leaving G26"); // We can't do lcd_setstatuspgm() without having it continue;
lcd_setstatuspgm(PSTR("Leaving G26"), (uint8_t) 99); // Now we do it right.
while (ubl_lcd_clicked()) // Debounce Encoder Wheel
idle();
return UBL_ERR;
}
if (ubl_lcd_clicked()) return exit_from_g26();
idle();
}
#if ENABLED(ULTRA_LCD)
lcd_setstatuspgm(PSTR(""), (uint8_t) 99);
lcd_reset_alert_level();
lcd_setstatuspgm(PSTR(""));
lcd_quick_feedback();
#endif
return UBL_OK;
@@ -877,7 +845,7 @@
float Total_Prime = 0.0;
if (prime_flag == -1) { // The user wants to control how much filament gets purged
lcd_setstatuspgm(PSTR("User-Controlled Prime"), (uint8_t) 99);
lcd_setstatuspgm(PSTR("User-Controlled Prime"), 99);
chirp_at_user();
set_destination_to_current();
@@ -894,7 +862,6 @@
#endif
ubl_line_to_destination(
destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS],
//planner.max_feedrate_mm_s[E_AXIS] / 15.0, 0, 0xFFFF, 0xFFFF);
planner.max_feedrate_mm_s[E_AXIS] / 15.0, 0
);
@@ -906,26 +873,24 @@
idle();
}
strcpy(lcd_status_message, "Done Priming"); // We can't do lcd_setstatuspgm() without having it continue;
// So... We cheat to get a message up.
while (ubl_lcd_clicked()) // Debounce Encoder Wheel
idle();
while (ubl_lcd_clicked()) idle(); // Debounce Encoder Wheel
#if ENABLED(ULTRA_LCD)
lcd_setstatuspgm(PSTR("Done Priming"), (uint8_t) 99);
strcpy_P(lcd_status_message, PSTR("Done Priming")); // We can't do lcd_setstatuspgm() without having it continue;
// So... We cheat to get a message up.
lcd_setstatuspgm(PSTR("Done Priming"), 99);
lcd_quick_feedback();
#endif
}
else {
#if ENABLED(ULTRA_LCD)
lcd_setstatuspgm(PSTR("Fixed Length Prime."), (uint8_t) 99);
lcd_setstatuspgm(PSTR("Fixed Length Prime."), 99);
lcd_quick_feedback();
#endif
set_destination_to_current();
destination[E_AXIS] += prime_length;
ubl_line_to_destination(
destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS],
//planner.max_feedrate_mm_s[E_AXIS] / 15.0, 0, 0xFFFF, 0xFFFF);
planner.max_feedrate_mm_s[E_AXIS] / 15.0, 0
);
stepper.synchronize();