Merge pull request #6537 from thinkyhead/rc_cleanup_sunday

Various leveling-related patches
This commit is contained in:
Scott Lahteine 2017-05-02 00:59:59 -05:00 committed by GitHub
commit 99b11db1a1
11 changed files with 92 additions and 101 deletions

View File

@ -718,15 +718,14 @@
#endif
/**
* Set ABL options based on the specific type of leveling
* Set granular options based on the specific type of leveling
*/
#define ABL_PLANAR (ENABLED(AUTO_BED_LEVELING_LINEAR) || ENABLED(AUTO_BED_LEVELING_3POINT))
#define ABL_GRID (ENABLED(AUTO_BED_LEVELING_LINEAR) || ENABLED(AUTO_BED_LEVELING_BILINEAR))
#define HAS_ABL (ABL_PLANAR || ABL_GRID || ENABLED(AUTO_BED_LEVELING_UBL))
#define PLANNER_LEVELING (HAS_ABL || ENABLED(MESH_BED_LEVELING))
#define HAS_LEVELING (HAS_ABL || ENABLED(MESH_BED_LEVELING))
#define PLANNER_LEVELING (ABL_PLANAR || ABL_GRID || ENABLED(MESH_BED_LEVELING))
#define HAS_PROBING_PROCEDURE (HAS_ABL || ENABLED(Z_MIN_PROBE_REPEATABILITY_TEST))
#if HAS_PROBING_PROCEDURE
#define PROBE_BED_WIDTH abs(RIGHT_PROBE_BED_POSITION - (LEFT_PROBE_BED_POSITION))
#define PROBE_BED_HEIGHT abs(BACK_PROBE_BED_POSITION - (FRONT_PROBE_BED_POSITION))

View File

@ -115,25 +115,29 @@
* Y # Y coordinate Specify the starting location of the drawing activity.
*/
// External references
extern float feedrate;
extern Planner planner;
//#if ENABLED(ULTRA_LCD)
#if ENABLED(ULTRA_LCD)
extern char lcd_status_message[];
//#endif
#endif
extern float destination[XYZE];
extern void set_destination_to_current();
extern void set_current_to_destination();
extern float code_value_float();
extern bool code_value_bool();
extern bool code_has_value();
extern void lcd_init();
extern void lcd_setstatuspgm(const char* const message, const uint8_t level);
#define PLANNER_XY_FEEDRATE() (min(planner.max_feedrate_mm_s[X_AXIS], planner.max_feedrate_mm_s[Y_AXIS])) //bob
void set_destination_to_current();
void set_current_to_destination();
float code_value_float();
bool code_value_bool();
bool code_has_value();
void lcd_init();
void lcd_setstatuspgm(const char* const message, const uint8_t level);
bool prepare_move_to_destination_cartesian();
void line_to_destination();
void line_to_destination(float);
void gcode_G28();
void sync_plan_position_e();
void chirp_at_user();
// Private functions
void un_retract_filament(float where[XYZE]);
void retract_filament(float where[XYZE]);
void look_for_lines_to_connect();
@ -142,17 +146,14 @@
void print_line_from_here_to_there(const float&, const float&, const float&, const float&, const float&, const float&);
bool turn_on_heaters();
bool prime_nozzle();
void chirp_at_user();
static uint16_t circle_flags[16], horizontal_mesh_line_flags[16], vertical_mesh_line_flags[16], continue_with_closest = 0;
float g26_e_axis_feedrate = 0.020,
random_deviation = 0.0,
layer_height = LAYER_HEIGHT;
bool g26_retracted = false; // We keep track of the state of the nozzle to know if it
// is currently retracted or not. This allows us to be
// less careful because mis-matched retractions and un-retractions
// won't leave us in a bad state.
static bool g26_retracted = false; // Track the retracted state of the nozzle so mismatched
// retracts/recovers won't result in a bad state.
float valid_trig_angle(float);
mesh_index_pair find_closest_circle_to_print(const float&, const float&);
@ -167,9 +168,9 @@
hotend_temp = HOTEND_TEMP,
ooze_amount = OOZE_AMOUNT;
int8_t prime_flag = 0;
static int8_t prime_flag = 0;
bool keep_heaters_on = false;
static bool keep_heaters_on = false;
/**
* G26: Mesh Validation Pattern generation.

View File

@ -324,7 +324,7 @@ float code_value_temp_diff();
linear_fit* lsf_linear_fit(double x[], double y[], double z[], const int);
#endif
#if PLANNER_LEVELING
#if HAS_LEVELING
void reset_bed_level();
#endif

View File

@ -490,8 +490,6 @@ static uint8_t target_extruder;
float zprobe_zoffset = Z_PROBE_OFFSET_FROM_EXTRUDER;
#endif
#define PLANNER_XY_FEEDRATE() (min(planner.max_feedrate_mm_s[X_AXIS], planner.max_feedrate_mm_s[Y_AXIS]))
#if HAS_ABL
float xy_probe_feedrate_mm_s = MMM_TO_MMS(XY_PROBE_SPEED);
#define XY_PROBE_FEEDRATE_MM_S xy_probe_feedrate_mm_s
@ -2405,7 +2403,7 @@ static void clean_up_after_endstop_or_probe_move() {
#endif // HAS_BED_PROBE
#if PLANNER_LEVELING
#if HAS_LEVELING
/**
* Turn bed leveling on or off, fixing the current
* position as-needed.
@ -2426,7 +2424,12 @@ static void clean_up_after_endstop_or_probe_move() {
if (enable && mbl.has_mesh()) planner.unapply_leveling(current_position);
}
#elif HAS_ABL && !ENABLED(AUTO_BED_LEVELING_UBL)
#elif ENABLED(AUTO_BED_LEVELING_UBL)
ubl.state.active = enable;
//set_current_from_steppers_for_axis(Z_AXIS);
#else
#if ENABLED(AUTO_BED_LEVELING_BILINEAR)
const bool can_change = (!enable || (bilinear_grid_spacing[0] && bilinear_grid_spacing[1]));
@ -2454,9 +2457,6 @@ static void clean_up_after_endstop_or_probe_move() {
else
planner.unapply_leveling(current_position);
}
#elif ENABLED(AUTO_BED_LEVELING_UBL)
ubl.state.active = enable;
//set_current_from_steppers_for_axis(Z_AXIS);
#endif
}
@ -2513,7 +2513,7 @@ static void clean_up_after_endstop_or_probe_move() {
#endif
}
#endif // PLANNER_LEVELING
#endif // HAS_LEVELING
#if ENABLED(AUTO_BED_LEVELING_BILINEAR) || ENABLED(MESH_BED_LEVELING)
@ -3749,10 +3749,7 @@ inline void gcode_G28() {
#endif
// Disable the leveling matrix before homing
#if PLANNER_LEVELING
#if ENABLED(AUTO_BED_LEVELING_UBL)
const bool bed_leveling_state_at_entry = ubl.state.active;
#endif
#if HAS_LEVELING
set_bed_leveling_enabled(false);
#endif
@ -3895,25 +3892,6 @@ inline void gcode_G28() {
do_blocking_move_to_z(delta_clip_start_height);
#endif
#if ENABLED(AUTO_BED_LEVELING_UBL)
set_bed_leveling_enabled(bed_leveling_state_at_entry);
#endif
// Enable mesh leveling again
#if ENABLED(MESH_BED_LEVELING)
if (mbl.reactivate()) {
set_bed_leveling_enabled(true);
if (home_all_axis || (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && homeZ)) {
#if ENABLED(MESH_G28_REST_ORIGIN)
current_position[Z_AXIS] = LOGICAL_Z_POSITION(Z_MIN_POS);
set_destination_to_current();
line_to_destination(homing_feedrate_mm_s[Z_AXIS]);
stepper.synchronize();
#endif
}
}
#endif
clean_up_after_endstop_or_probe_move();
// Restore the active tool after homing
@ -3928,6 +3906,8 @@ inline void gcode_G28() {
#endif
}
void home_all_axes() { gcode_G28(); }
#if HAS_PROBING_PROCEDURE
void out_of_range_error(const char* p_edge) {
@ -3980,6 +3960,18 @@ inline void gcode_G28() {
);
}
void mesh_probing_done() {
mbl.set_has_mesh(true);
home_all_axes();
set_bed_leveling_enabled(true);
#if ENABLED(MESH_G28_REST_ORIGIN)
current_position[Z_AXIS] = LOGICAL_Z_POSITION(Z_MIN_POS);
set_destination_to_current();
line_to_destination(homing_feedrate_mm_s[Z_AXIS]);
stepper.synchronize();
#endif
}
/**
* G29: Mesh-based Z probe, probes a grid and produces a
* mesh to compensate for variable bed height
@ -4070,14 +4062,12 @@ inline void gcode_G28() {
line_to_current_position();
stepper.synchronize();
// After recording the last point, activate the mbl and home
SERIAL_PROTOCOLLNPGM("Mesh probing done.");
// After recording the last point, activate home and activate
mbl_probe_index = -1;
mbl.set_has_mesh(true);
mbl.set_reactivate(true);
enqueue_and_echo_commands_P(PSTR("G28"));
SERIAL_PROTOCOLLNPGM("Mesh probing done.");
BUZZ(100, 659);
BUZZ(100, 698);
mesh_probing_done();
}
break;
@ -4368,7 +4358,7 @@ inline void gcode_G28() {
#endif
#if PLANNER_LEVELING
#if HAS_LEVELING
// Jettison bed leveling data
if (code_seen('J')) {
@ -5013,7 +5003,7 @@ inline void gcode_G28() {
SYNC_PLAN_POSITION_KINEMATIC();
}
#endif // HAS_ABL && DISABLED(AUTO_BED_LEVELING_UBL)
#endif // HAS_ABL && !AUTO_BED_LEVELING_UBL
#if HAS_BED_PROBE
@ -5034,7 +5024,7 @@ inline void gcode_G28() {
if (!position_is_reachable(pos, true)) return;
// Disable leveling so the planner won't mess with us
#if PLANNER_LEVELING
#if HAS_LEVELING
set_bed_leveling_enabled(false);
#endif
@ -5091,7 +5081,7 @@ inline void gcode_G28() {
stepper.synchronize();
#if PLANNER_LEVELING
#if HAS_LEVELING
set_bed_leveling_enabled(false);
#endif
@ -6198,10 +6188,6 @@ inline void gcode_M42() {
* regenerated.
*/
inline void gcode_M48() {
#if ENABLED(AUTO_BED_LEVELING_UBL)
bool bed_leveling_state_at_entry=0;
bed_leveling_state_at_entry = ubl.state.active;
#endif
if (axis_unhomed_error(true, true, true)) return;
@ -6267,8 +6253,17 @@ inline void gcode_M42() {
SERIAL_PROTOCOLLNPGM("Positioning the probe...");
// Disable bed level correction in M48 because we want the raw data when we probe
#if HAS_ABL
const bool abl_was_enabled = planner.abl_enabled;
#if HAS_LEVELING
const bool was_enabled =
#if ENABLED(AUTO_BED_LEVELING_UBL)
ubl.state.active
#elif ENABLED(MESH_BED_LEVELING)
mbl.active()
#else
planner.abl_enabled
#endif
;
set_bed_leveling_enabled(false);
#endif
@ -6420,14 +6415,9 @@ inline void gcode_M42() {
clean_up_after_endstop_or_probe_move();
// Re-enable bed level correction if it has been on
// Re-enable bed level correction if it had been on
#if HAS_ABL
set_bed_leveling_enabled(abl_was_enabled);
#endif
#if ENABLED(AUTO_BED_LEVELING_UBL)
set_bed_leveling_enabled(bed_leveling_state_at_entry);
ubl.state.active = bed_leveling_state_at_entry;
set_bed_leveling_enabled(was_enabled);
#endif
report_current_position();
@ -7294,7 +7284,7 @@ inline void gcode_M115() {
#endif
// MESH_REPORT (M420 V)
#if PLANNER_LEVELING
#if HAS_LEVELING
SERIAL_PROTOCOLLNPGM("Cap:LEVELING_DATA:1");
#else
SERIAL_PROTOCOLLNPGM("Cap:LEVELING_DATA:0");
@ -8336,7 +8326,7 @@ void quickstop_stepper() {
SYNC_PLAN_POSITION_KINEMATIC();
}
#if PLANNER_LEVELING
#if HAS_LEVELING
/**
* M420: Enable/Disable Bed Leveling and/or set the Z fade height.
*
@ -9857,12 +9847,12 @@ void process_next_command() {
gcode_G28();
break;
#if PLANNER_LEVELING || ENABLED(AUTO_BED_LEVELING_UBL)
#if HAS_LEVELING
case 29: // G29 Detailed Z probe, probes the bed at 3 or more points,
// or provides access to the UBL System if enabled.
gcode_G29();
break;
#endif // PLANNER_LEVELING
#endif // HAS_LEVELING
#if HAS_BED_PROBE
@ -10363,7 +10353,7 @@ void process_next_command() {
break;
#endif // FILAMENT_WIDTH_SENSOR
#if PLANNER_LEVELING
#if HAS_LEVELING
case 420: // M420: Enable/Disable Bed Leveling
gcode_M420();
break;
@ -10917,7 +10907,7 @@ void get_cartesian_from_steppers() {
*/
void set_current_from_steppers_for_axis(const AxisEnum axis) {
get_cartesian_from_steppers();
#if PLANNER_LEVELING && DISABLED(AUTO_BED_LEVELING_UBL)
#if PLANNER_LEVELING
planner.unapply_leveling(cartes);
#endif
if (axis == ALL_AXES)

View File

@ -1071,7 +1071,7 @@ void MarlinSettings::reset() {
#endif
// Applies to all MBL and ABL
#if PLANNER_LEVELING
#if HAS_LEVELING
reset_bed_level();
#endif

View File

@ -36,8 +36,7 @@
enum MBLStatus {
MBL_STATUS_NONE = 0,
MBL_STATUS_HAS_MESH_BIT = 0,
MBL_STATUS_ACTIVE_BIT = 1,
MBL_STATUS_REACTIVATE_BIT = 2
MBL_STATUS_ACTIVE_BIT = 1
};
#define MESH_X_DIST ((MESH_MAX_X - (MESH_MIN_X)) / (GRID_MAX_POINTS_X - 1))
@ -61,8 +60,6 @@
static void set_active(const bool onOff) { onOff ? SBI(status, MBL_STATUS_ACTIVE_BIT) : CBI(status, MBL_STATUS_ACTIVE_BIT); }
static bool has_mesh() { return TEST(status, MBL_STATUS_HAS_MESH_BIT); }
static void set_has_mesh(const bool onOff) { onOff ? SBI(status, MBL_STATUS_HAS_MESH_BIT) : CBI(status, MBL_STATUS_HAS_MESH_BIT); }
static bool reactivate() { bool b = TEST(status, MBL_STATUS_REACTIVATE_BIT); CBI(status, MBL_STATUS_REACTIVATE_BIT); return b; }
static void set_reactivate(const bool onOff) { onOff ? SBI(status, MBL_STATUS_REACTIVATE_BIT) : CBI(status, MBL_STATUS_REACTIVATE_BIT); }
static inline void zigzag(const int8_t index, int8_t &px, int8_t &py) {
px = index % (GRID_MAX_POINTS_X);

View File

@ -530,7 +530,7 @@ void Planner::check_axes_activity() {
#endif
}
#if PLANNER_LEVELING && DISABLED(AUTO_BED_LEVELING_UBL)
#if PLANNER_LEVELING
/**
* lx, ly, lz - logical (cartesian, not delta) positions in mm
*/
@ -634,7 +634,7 @@ void Planner::check_axes_activity() {
#endif
}
#endif // PLANNER_LEVELING && !AUTO_BED_LEVELING_UBL
#endif // PLANNER_LEVELING
/**
* Planner::_buffer_line
@ -1434,7 +1434,7 @@ void Planner::_set_position_mm(const float &a, const float &b, const float &c, c
}
void Planner::set_position_mm_kinematic(const float position[NUM_AXIS]) {
#if PLANNER_LEVELING && DISABLED(AUTO_BED_LEVELING_UBL)
#if PLANNER_LEVELING
float lpos[XYZ] = { position[X_AXIS], position[Y_AXIS], position[Z_AXIS] };
apply_leveling(lpos);
#else

View File

@ -246,7 +246,7 @@ class Planner {
static bool is_full() { return (block_buffer_tail == BLOCK_MOD(block_buffer_head + 1)); }
#if PLANNER_LEVELING && DISABLED(AUTO_BED_LEVELING_UBL)
#if PLANNER_LEVELING
#define ARG_X float lx
#define ARG_Y float ly
@ -296,7 +296,7 @@ class Planner {
* extruder - target extruder
*/
static FORCE_INLINE void buffer_line(ARG_X, ARG_Y, ARG_Z, const float &e, const float &fr_mm_s, const uint8_t extruder) {
#if PLANNER_LEVELING && DISABLED(AUTO_BED_LEVELING_UBL) && IS_CARTESIAN
#if PLANNER_LEVELING && IS_CARTESIAN
apply_leveling(lx, ly, lz);
#endif
_buffer_line(lx, ly, lz, e, fr_mm_s, extruder);
@ -312,7 +312,7 @@ class Planner {
* extruder - target extruder
*/
static FORCE_INLINE void buffer_line_kinematic(const float ltarget[XYZE], const float &fr_mm_s, const uint8_t extruder) {
#if PLANNER_LEVELING && DISABLED(AUTO_BED_LEVELING_UBL)
#if PLANNER_LEVELING
float lpos[XYZ] = { ltarget[X_AXIS], ltarget[Y_AXIS], ltarget[Z_AXIS] };
apply_leveling(lpos);
#else
@ -336,7 +336,7 @@ class Planner {
* Clears previous speed values.
*/
static FORCE_INLINE void set_position_mm(ARG_X, ARG_Y, ARG_Z, const float &e) {
#if PLANNER_LEVELING && DISABLED(AUTO_BED_LEVELING_UBL) && IS_CARTESIAN
#if PLANNER_LEVELING && IS_CARTESIAN
apply_leveling(lx, ly, lz);
#endif
_set_position_mm(lx, ly, lz, e);
@ -469,6 +469,8 @@ class Planner {
};
#define PLANNER_XY_FEEDRATE() (min(planner.max_feedrate_mm_s[X_AXIS], planner.max_feedrate_mm_s[Y_AXIS]))
extern Planner planner;
#endif // PLANNER_H

View File

@ -61,8 +61,9 @@
bool is_bit_set(uint16_t bits[16], uint8_t x, uint8_t y);
char *ftostr43sign(const float&, char);
void home_all_axes();
void gcode_G26();
void gcode_G28();
void gcode_G29();
extern int ubl_cnt;

View File

@ -324,7 +324,7 @@
}
if (!code_seen('N') && axis_unhomed_error(true, true, true)) // Don't allow auto-leveling without homing first
gcode_G28();
home_all_axes();
if (g29_parameter_parsing()) return; // abort if parsing the simple parameters causes a problem,

View File

@ -162,6 +162,7 @@ uint16_t max_display_update_time = 0;
#if ENABLED(MESH_BED_LEVELING) && ENABLED(LCD_BED_LEVELING)
#include "mesh_bed_leveling.h"
extern void mesh_probing_done();
#endif
////////////////////////////////////////////
@ -1539,9 +1540,9 @@ void kill_screen(const char* lcd_msg) {
// Enable leveling, if needed
#if ENABLED(MESH_BED_LEVELING)
lcd_synchronize();
mbl.set_has_mesh(true);
mbl.set_reactivate(true);
enqueue_and_echo_commands_P(PSTR("G28"));
mesh_probing_done();
#elif ENABLED(AUTO_BED_LEVELING_UBL)