From 538189cc19182f28209912efd353081f18aa76e7 Mon Sep 17 00:00:00 2001 From: Chris Palmer Date: Sat, 2 Jun 2012 13:17:47 +0100 Subject: [PATCH] Fixed soft limits when the origin is in the middle. HOME_POS is now always where the endstop is and can be outside the limits. The limits are now defined by MIN_POS and MAX_POS rather than HOME_POS and MAX_LENGTH. The Z is axis now homed first if direction is away from the bed. Saguinololu limit pins change from MIN to MAX according to the homing direction. --- Marlin/Configuration.h | 14 +++++++++++--- Marlin/Marlin.pde | 29 +++++++++++++++++++---------- Marlin/pins.h | 27 +++++++++++++++++++++------ 3 files changed, 51 insertions(+), 19 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 2da2478d9..1248029ed 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -187,9 +187,17 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th #define min_software_endstops true //If true, axis won't move to coordinates less than HOME_POS. #define max_software_endstops true //If true, axis won't move to coordinates greater than the defined lengths below. -#define X_MAX_LENGTH 205 -#define Y_MAX_LENGTH 205 -#define Z_MAX_LENGTH 200 +// Travel limits after homing +#define X_MAX_POS 205 +#define X_MIN_POS 0 +#define Y_MAX_POS 205 +#define Y_MIN_POS 0 +#define Z_MAX_POS 200 +#define Z_MIN_POS 0 + +#define X_MAX_LENGTH (X_MAX_POS - X_MIN_POS) +#define Y_MAX_LENGTH (Y_MAX_POS - Y_MIN_POS) +#define Z_MAX_LENGTH (Z_MAX_POS - Z_MIN_POS) // The position of the homing switches. Use MAX_LENGTH * -0.5 if the center should be 0, 0, 0 #define X_HOME_POS 0 diff --git a/Marlin/Marlin.pde b/Marlin/Marlin.pde index 2bba4222d..73f1f4126 100644 --- a/Marlin/Marlin.pde +++ b/Marlin/Marlin.pde @@ -562,7 +562,7 @@ bool code_seen(char code) plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); \ st_synchronize();\ \ - current_position[LETTER##_AXIS] = (LETTER##_HOME_DIR == -1) ? LETTER##_HOME_POS : LETTER##_MAX_LENGTH;\ + current_position[LETTER##_AXIS] = LETTER##_HOME_POS;\ destination[LETTER##_AXIS] = current_position[LETTER##_AXIS];\ feedrate = 0.0;\ endstops_hit_on_purpose();\ @@ -656,6 +656,13 @@ void process_commands() } feedrate = 0.0; home_all_axis = !((code_seen(axis_codes[0])) || (code_seen(axis_codes[1])) || (code_seen(axis_codes[2]))); + + #if Z_HOME_DIR > 0 // If homing away from BED do Z first + if((home_all_axis) || (code_seen(axis_codes[Z_AXIS]))) { + HOMEAXIS(Z); + } + #endif + #ifdef QUICK_HOME if((home_all_axis)||( code_seen(axis_codes[X_AXIS]) && code_seen(axis_codes[Y_AXIS])) ) //first diagonal move { @@ -669,8 +676,8 @@ void process_commands() plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); st_synchronize(); - current_position[X_AXIS] = (X_HOME_DIR == -1) ? X_HOME_POS : X_MAX_LENGTH; - current_position[Y_AXIS] = (Y_HOME_DIR == -1) ? Y_HOME_POS : Y_MAX_LENGTH; + current_position[X_AXIS] = X_HOME_POS; + current_position[Y_AXIS] = Y_HOME_POS; plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); destination[X_AXIS] = current_position[X_AXIS]; destination[Y_AXIS] = current_position[Y_AXIS]; @@ -687,12 +694,14 @@ void process_commands() } if((home_all_axis) || (code_seen(axis_codes[Y_AXIS]))) { - HOMEAXIS(Y); + HOMEAXIS(Y); } + #if Z_HOME_DIR < 0 // If homing towards BED do Z last if((home_all_axis) || (code_seen(axis_codes[Z_AXIS]))) { HOMEAXIS(Z); } + #endif if(code_seen(axis_codes[X_AXIS])) { @@ -1533,15 +1542,15 @@ void get_arc_coordinates() void prepare_move() { if (min_software_endstops) { - if (destination[X_AXIS] < X_HOME_POS) destination[X_AXIS] = X_HOME_POS; - if (destination[Y_AXIS] < Y_HOME_POS) destination[Y_AXIS] = Y_HOME_POS; - if (destination[Z_AXIS] < Z_HOME_POS) destination[Z_AXIS] = Z_HOME_POS; + if (destination[X_AXIS] < X_MIN_POS) destination[X_AXIS] = X_MIN_POS; + if (destination[Y_AXIS] < Y_MIN_POS) destination[Y_AXIS] = Y_MIN_POS; + if (destination[Z_AXIS] < Z_MIN_POS) destination[Z_AXIS] = Z_MIN_POS; } if (max_software_endstops) { - if (destination[X_AXIS] > X_MAX_LENGTH) destination[X_AXIS] = X_MAX_LENGTH; - if (destination[Y_AXIS] > Y_MAX_LENGTH) destination[Y_AXIS] = Y_MAX_LENGTH; - if (destination[Z_AXIS] > Z_MAX_LENGTH) destination[Z_AXIS] = Z_MAX_LENGTH; + if (destination[X_AXIS] > X_MAX_POS) destination[X_AXIS] = X_MAX_POS; + if (destination[Y_AXIS] > Y_MAX_POS) destination[Y_AXIS] = Y_MAX_POS; + if (destination[Z_AXIS] > Z_MAX_POS) destination[Z_AXIS] = Z_MAX_POS; } previous_millis_cmd = millis(); plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate*feedmultiply/60/100.0, active_extruder); diff --git a/Marlin/pins.h b/Marlin/pins.h index c4d56590f..419ddb643 100644 --- a/Marlin/pins.h +++ b/Marlin/pins.h @@ -572,18 +572,33 @@ #define X_STEP_PIN 15 #define X_DIR_PIN 21 -#define X_MIN_PIN 18 -#define X_MAX_PIN -1 +#if X_HOME_DIR < 0 +# define X_MIN_PIN 18 +# define X_MAX_PIN -1 +#else +# define X_MIN_PIN -1 +# define X_MAX_PIN 18 +#endif #define Y_STEP_PIN 22 #define Y_DIR_PIN 23 -#define Y_MIN_PIN 19 -#define Y_MAX_PIN -1 +#if Y_HOME_DIR < 0 +# define Y_MIN_PIN 19 +# define Y_MAX_PIN -1 +#else +# define Y_MIN_PIN -1 +# define Y_MAX_PIN 19 +#endif #define Z_STEP_PIN 3 #define Z_DIR_PIN 2 -#define Z_MIN_PIN 20 -#define Z_MAX_PIN -1 +#if Z_HOME_DIR < 0 +# define Z_MIN_PIN 20 +# define Z_MAX_PIN -1 +#else +# define Z_MIN_PIN -1 +# define Z_MAX_PIN 20 +#endif #define E0_STEP_PIN 1 #define E0_DIR_PIN 0