Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix raise by MIN_Z_HEIGHT_FOR_HOMING (first attempt) #4217

Merged
merged 3 commits into from
Jul 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions Marlin/Conditionals.h
Original file line number Diff line number Diff line change
Expand Up @@ -783,14 +783,11 @@
#define XY_PROBE_SPEED 4000
#endif
#endif
#ifndef Z_RAISE_PROBE_DEPLOY_STOW
#if defined(Z_RAISE_BEFORE_PROBING) && defined(Z_RAISE_AFTER_PROBING)
#define Z_RAISE_PROBE_DEPLOY_STOW (max(Z_RAISE_BEFORE_PROBING, Z_RAISE_AFTER_PROBING))
#else
#error "You must set Z_RAISE_PROBE_DEPLOY_STOW in your configuration."
#endif
#if Z_RAISE_BETWEEN_PROBINGS > Z_RAISE_PROBE_DEPLOY_STOW
#define _Z_RAISE_PROBE_DEPLOY_STOW Z_RAISE_BETWEEN_PROBINGS
#else
#define _Z_RAISE_PROBE_DEPLOY_STOW Z_RAISE_PROBE_DEPLOY_STOW
#endif
#define _Z_RAISE_PROBE_DEPLOY_STOW (max(Z_RAISE_PROBE_DEPLOY_STOW, Z_RAISE_BETWEEN_PROBINGS))
#endif

/**
Expand Down
160 changes: 79 additions & 81 deletions Marlin/Marlin_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1728,9 +1728,8 @@ static void clean_up_after_endstop_or_probe_move() {
if ((Z_HOME_DIR) < 0 && zprobe_zoffset < 0)
z_dest -= zprobe_zoffset;

if (z_dest > current_position[Z_AXIS]) {
if (z_dest > current_position[Z_AXIS])
do_blocking_move_to_z(z_dest);
}
}

#endif //HAS_BED_PROBE
Expand Down Expand Up @@ -2764,6 +2763,57 @@ inline void gcode_G4() {
}
#endif

#if ENABLED(QUICK_HOME)

static void quick_home_xy() {

current_position[X_AXIS] = current_position[Y_AXIS] = 0;

#if ENABLED(DUAL_X_CARRIAGE)
int x_axis_home_dir = x_home_dir(active_extruder);
extruder_duplication_enabled = false;
#else
int x_axis_home_dir = home_dir(X_AXIS);
#endif

SYNC_PLAN_POSITION_KINEMATIC();

float mlx = max_length(X_AXIS), mly = max_length(Y_AXIS),
mlratio = mlx > mly ? mly / mlx : mlx / mly;

destination[X_AXIS] = 1.5 * mlx * x_axis_home_dir;
destination[Y_AXIS] = 1.5 * mly * home_dir(Y_AXIS);
feedrate = min(homing_feedrate[X_AXIS], homing_feedrate[Y_AXIS]) * sqrt(mlratio * mlratio + 1);
line_to_destination();
stepper.synchronize();

set_axis_is_at_home(X_AXIS);
set_axis_is_at_home(Y_AXIS);
SYNC_PLAN_POSITION_KINEMATIC();

#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("> QUICK_HOME 1", current_position);
#endif

destination[X_AXIS] = current_position[X_AXIS];
destination[Y_AXIS] = current_position[Y_AXIS];
line_to_destination();
stepper.synchronize();
endstops.hit_on_purpose(); // clear endstop hit flags

current_position[X_AXIS] = destination[X_AXIS];
current_position[Y_AXIS] = destination[Y_AXIS];
#if DISABLED(SCARA)
current_position[Z_AXIS] = destination[Z_AXIS];
#endif

#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("> QUICK_HOME 2", current_position);
#endif
}

#endif // QUICK_HOME

/**
* G28: Home all axes according to settings
*
Expand Down Expand Up @@ -2815,16 +2865,9 @@ inline void gcode_G28() {

setup_for_endstop_move();

/**
* Directly after a reset this is all 0. Later we get a hint if we have
* to raise z or not.
*/
set_destination_to_current();

#if ENABLED(DELTA)
/**
* A delta can only safely home all axis at the same time
* all axis have to home at the same time
* A delta can only safely home all axes at the same time
*/

// Pretend the current position is 0,0,0
Expand Down Expand Up @@ -2860,6 +2903,8 @@ inline void gcode_G28() {

home_all_axis = (!homeX && !homeY && !homeZ) || (homeX && homeY && homeZ);

set_destination_to_current();

#if Z_HOME_DIR > 0 // If homing away from BED do Z first

if (home_all_axis || homeZ) {
Expand All @@ -2871,98 +2916,51 @@ inline void gcode_G28() {

#elif defined(MIN_Z_HEIGHT_FOR_HOMING) && MIN_Z_HEIGHT_FOR_HOMING > 0

#if HAS_BED_PROBE
do_probe_raise(MIN_Z_HEIGHT_FOR_HOMING);
destination[Z_AXIS] = current_position[Z_AXIS];
#else
// Raise Z before homing any other axes and z is not already high enough (never lower z)
if (current_position[Z_AXIS] <= MIN_Z_HEIGHT_FOR_HOMING) {
destination[Z_AXIS] = MIN_Z_HEIGHT_FOR_HOMING;
feedrate = planner.max_feedrate[Z_AXIS] * 60; // feedrate (mm/m) = max_feedrate (mm/s)
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) {
SERIAL_ECHOPAIR("Raise Z (before homing) to ", (MIN_Z_HEIGHT_FOR_HOMING));
SERIAL_EOL;
DEBUG_POS("> (home_all_axis || homeZ)", current_position);
DEBUG_POS("> (home_all_axis || homeZ)", destination);
}
#endif
line_to_destination();
stepper.synchronize();

/**
* Update the current Z position even if it currently not real from
* Z-home otherwise each call to line_to_destination() will want to
* move Z-axis by MIN_Z_HEIGHT_FOR_HOMING.
*/
current_position[Z_AXIS] = destination[Z_AXIS];
// Raise Z before homing any other axes and z is not already high enough (never lower z)
float z_dest = (current_position[Z_AXIS] += MIN_Z_HEIGHT_FOR_HOMING);
#if ENABLED(DEBUG_LEVELING_FEATURE)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you'll stay with this crap - at least change the comment above.

if (DEBUGGING(LEVELING)) {
SERIAL_ECHOPAIR("Raise Z (before homing) to ", z_dest);
SERIAL_EOL;
}
#endif
#endif

#if ENABLED(QUICK_HOME)

if (home_all_axis || (homeX && homeY)) { // First diagonal move

current_position[X_AXIS] = current_position[Y_AXIS] = 0;

#if ENABLED(DUAL_X_CARRIAGE)
int x_axis_home_dir = x_home_dir(active_extruder);
extruder_duplication_enabled = false;
#else
int x_axis_home_dir = home_dir(X_AXIS);
#endif

SYNC_PLAN_POSITION_KINEMATIC();

float mlx = max_length(X_AXIS), mly = max_length(Y_AXIS),
mlratio = mlx > mly ? mly / mlx : mlx / mly;
feedrate = homing_feedrate[Z_AXIS];

destination[X_AXIS] = 1.5 * mlx * x_axis_home_dir;
destination[Y_AXIS] = 1.5 * mly * home_dir(Y_AXIS);
feedrate = min(homing_feedrate[X_AXIS], homing_feedrate[Y_AXIS]) * sqrt(mlratio * mlratio + 1);
line_to_destination();
#if HAS_BED_PROBE
do_blocking_move_to_z(z_dest);
#else
line_to_z(z_dest);
stepper.synchronize();
#endif

set_axis_is_at_home(X_AXIS);
set_axis_is_at_home(Y_AXIS);
SYNC_PLAN_POSITION_KINEMATIC();
#endif // MIN_Z_HEIGHT_FOR_HOMING

#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("> QUICK_HOME 1", current_position);
#endif
#if ENABLED(QUICK_HOME)

destination[X_AXIS] = current_position[X_AXIS];
destination[Y_AXIS] = current_position[Y_AXIS];
line_to_destination();
stepper.synchronize();
endstops.hit_on_purpose(); // clear endstop hit flags
bool quick_homed = home_all_axis || (homeX && homeY);
if (quick_homed) quick_home_xy();

current_position[X_AXIS] = destination[X_AXIS];
current_position[Y_AXIS] = destination[Y_AXIS];
#if DISABLED(SCARA)
current_position[Z_AXIS] = destination[Z_AXIS];
#endif
#else

#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("> QUICK_HOME 2", current_position);
#endif
}
const bool quick_homed = false;

#endif // QUICK_HOME
#endif

#if ENABLED(HOME_Y_BEFORE_X)

// Home Y
if (home_all_axis || homeY) {
if (!quick_homed && (home_all_axis || homeY)) {
HOMEAXIS(Y);
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("> homeY", current_position);
#endif
}

#endif

// Home X
if (home_all_axis || homeX) {
if (!quick_homed && (home_all_axis || homeX)) {
#if ENABLED(DUAL_X_CARRIAGE)
int tmp_extruder = active_extruder;
extruder_duplication_enabled = false;
Expand All @@ -2985,7 +2983,7 @@ inline void gcode_G28() {

#if DISABLED(HOME_Y_BEFORE_X)
// Home Y
if (home_all_axis || homeY) {
if (!quick_homed && (home_all_axis || homeY)) {
HOMEAXIS(Y);
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("> homeY", current_position);
Expand Down
15 changes: 15 additions & 0 deletions Marlin/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,21 @@
//#endif
#endif

/**
* Make sure Z raise values are set
*/
#if defined(Z_RAISE_BEFORE_PROBING) || defined(Z_RAISE_AFTER_PROBING)
#error "Z_RAISE_(BEFORE|AFTER)_PROBING are deprecated. Use Z_RAISE_PROBE_DEPLOY_STOW instead."
#elif !defined(Z_RAISE_PROBE_DEPLOY_STOW)
#error "You must set Z_RAISE_PROBE_DEPLOY_STOW in your configuration."
#elif !defined(Z_RAISE_BETWEEN_PROBINGS)
#error "You must set Z_RAISE_BETWEEN_PROBINGS in your configuration."
#elif Z_RAISE_PROBE_DEPLOY_STOW < 1
#error "Probes need Z_RAISE_PROBE_DEPLOY_STOW >= 1."
#elif Z_RAISE_BETWEEN_PROBINGS < 1
#error "Probes need Z_RAISE_BETWEEN_PROBINGS >= 1."
#endif

#else

/**
Expand Down