summaryrefslogtreecommitdiff
path: root/Sprinter
diff options
context:
space:
mode:
authorFelipe CorrĂȘa da Silva Sanches <juca@members.fsf.org>2012-06-18 11:03:06 -0300
committerFelipe CorrĂȘa da Silva Sanches <juca@members.fsf.org>2012-06-18 11:03:06 -0300
commit05e1d6083b47c014f3db51d4ac132ef482517ef8 (patch)
treec538144b7c619e916602197251f0f3fff9c8cae8 /Sprinter
parent1d4bc83291467c97e35eb0a84d1c28766c172f10 (diff)
refactoring homing routine to avoid copy&pasted code
Diffstat (limited to 'Sprinter')
-rw-r--r--Sprinter/Sprinter.pde134
1 files changed, 39 insertions, 95 deletions
diff --git a/Sprinter/Sprinter.pde b/Sprinter/Sprinter.pde
index 94aa538..b423c32 100644
--- a/Sprinter/Sprinter.pde
+++ b/Sprinter/Sprinter.pde
@@ -1150,6 +1150,42 @@ FORCE_INLINE void process_commands()
manage_heater();
}
break;
+
+#define X_HOME_BOUNCE 10
+#define Y_HOME_BOUNCE 10
+#define Z_HOME_BOUNCE 4
+
+#define HOMING_ROUTINE(coord)\
+ if ((coord##_MIN_PIN > -1 && coord##_HOME_DIR==-1) || (coord##_MAX_PIN > -1 && coord##_HOME_DIR==1))\
+ {\
+ current_position[coord##_AXIS] = -1.5 * coord##_MAX_LENGTH * coord##_HOME_DIR;\
+ plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);\
+ destination[coord##_AXIS] = 0;\
+ feedrate = homing_feedrate[coord##_AXIS];\
+ prepare_move();\
+ st_synchronize();\
+ \
+ current_position[coord##_AXIS] = coord##_HOME_BOUNCE/2 * coord##_HOME_DIR;\
+ plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);\
+ destination[coord##_AXIS] = 0;\
+ prepare_move();\
+ st_synchronize();\
+ \
+ current_position[coord##_AXIS] = -coord##_HOME_BOUNCE * coord##_HOME_DIR;\
+ plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);\
+ destination[coord##_AXIS] = 0;\
+ feedrate = homing_feedrate[coord##_AXIS]/2;\
+ prepare_move();\
+ st_synchronize();\
+ \
+ current_position[coord##_AXIS] = (coord##_HOME_DIR == -1) ? 0 : coord##_MAX_LENGTH;\
+ current_position[coord##_AXIS] += add_homing[coord##_AXIS];\
+ plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);\
+ destination[coord##_AXIS] = current_position[coord##_AXIS];\
+ feedrate = 0;\
+ /*showString(PSTR("HOME " #coord " AXIS\r\n"));*/\
+ }
+
case 28: //G28 Home all Axis one at a time
saved_feedrate = feedrate;
saved_feedmultiply = feedmultiply;
@@ -1169,105 +1205,13 @@ FORCE_INLINE void process_commands()
home_all_axis = !((code_seen(axis_codes[0])) || (code_seen(axis_codes[1])) || (code_seen(axis_codes[2])));
if((home_all_axis) || (code_seen(axis_codes[X_AXIS])))
- {
- if ((X_MIN_PIN > -1 && X_HOME_DIR==-1) || (X_MAX_PIN > -1 && X_HOME_DIR==1))
- {
- st_synchronize();
- current_position[X_AXIS] = -1.5 * X_MAX_LENGTH * X_HOME_DIR;
- plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
- destination[X_AXIS] = 0;
- feedrate = homing_feedrate[X_AXIS];
- prepare_move();
-
- st_synchronize();
- current_position[X_AXIS] = 5 * X_HOME_DIR;
- plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
- destination[X_AXIS] = 0;
- prepare_move();
-
- st_synchronize();
- current_position[X_AXIS] = -10 * X_HOME_DIR;
- plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
- destination[X_AXIS] = 0;
- feedrate = homing_feedrate[X_AXIS]/2 ;
- prepare_move();
- st_synchronize();
-
- current_position[X_AXIS] = (X_HOME_DIR == -1) ? 0 : X_MAX_LENGTH;
- current_position[X_AXIS] += add_homing[0];
- 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];
- feedrate = 0;
- }
- }
- //showString(PSTR("HOME X AXIS\r\n"));
+ HOMING_ROUTINE(X)
if((home_all_axis) || (code_seen(axis_codes[Y_AXIS])))
- {
- if ((Y_MIN_PIN > -1 && Y_HOME_DIR==-1) || (Y_MAX_PIN > -1 && Y_HOME_DIR==1))
- {
- current_position[Y_AXIS] = -1.5 * Y_MAX_LENGTH * Y_HOME_DIR;
- plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
- destination[Y_AXIS] = 0;
- feedrate = homing_feedrate[Y_AXIS];
- prepare_move();
- st_synchronize();
-
- current_position[Y_AXIS] = 5 * Y_HOME_DIR;
- plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
- destination[Y_AXIS] = 0;
- prepare_move();
- st_synchronize();
-
- current_position[Y_AXIS] = -10 * Y_HOME_DIR;
- plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
- destination[Y_AXIS] = 0;
- feedrate = homing_feedrate[Y_AXIS]/2;
- prepare_move();
- st_synchronize();
-
- current_position[Y_AXIS] = (Y_HOME_DIR == -1) ? 0 : Y_MAX_LENGTH;
- current_position[Y_AXIS] += add_homing[1];
- plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
- destination[Y_AXIS] = current_position[Y_AXIS];
- feedrate = 0;
- }
- }
- //showString(PSTR("HOME Y AXIS\r\n"));
+ HOMING_ROUTINE(Y)
if((home_all_axis) || (code_seen(axis_codes[Z_AXIS])))
- {
- if ((Z_MIN_PIN > -1 && Z_HOME_DIR==-1) || (Z_MAX_PIN > -1 && Z_HOME_DIR==1))
- {
- current_position[Z_AXIS] = -1.5 * Z_MAX_LENGTH * Z_HOME_DIR;
- plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
- destination[Z_AXIS] = 0;
- feedrate = homing_feedrate[Z_AXIS];
- prepare_move();
- st_synchronize();
-
- current_position[Z_AXIS] = 2 * Z_HOME_DIR;
- plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
- destination[Z_AXIS] = 0;
- prepare_move();
- st_synchronize();
-
- current_position[Z_AXIS] = -3 * Z_HOME_DIR;
- plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
- destination[Z_AXIS] = 0;
- feedrate = homing_feedrate[Z_AXIS]/2;
- prepare_move();
- st_synchronize();
-
- current_position[Z_AXIS] = (Z_HOME_DIR == -1) ? 0 : Z_MAX_LENGTH;
- current_position[Z_AXIS] += add_homing[2];
- plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
- destination[Z_AXIS] = current_position[Z_AXIS];
- feedrate = 0;
- }
- }
-
- //showString(PSTR("HOME Z AXIS\r\n"));
+ HOMING_ROUTINE(Z)
#ifdef ENDSTOPS_ONLY_FOR_HOMING
enable_endstops(false);