Permalink
Browse files

First stab at proper endstop/homing implementation

Untested as my endstops are too unreliable. I need to go pull some 18/2 shielded out of my copper pile and rewire my endstops.
  • Loading branch information...
1 parent 7d703ba commit 4129358b2c0c68b1ef274bb8492e0f839a137402 @jgilmore committed Nov 16, 2010
Showing with 66 additions and 79 deletions.
  1. +40 −24 dda.c
  2. +5 −0 dda.h
  3. +21 −55 gcode_process.c
View
64 dda.c
@@ -12,6 +12,7 @@
#include "dda_queue.h"
#include "debug.h"
#include "sersendf.h"
+#include "delay.h"
/*
X Stepper
@@ -475,14 +476,7 @@ void dda_step(DDA *dda) {
// called from interrupt context! keep it as simple as possible
uint8_t did_step = 0;
- if ((current_position.X != dda->endpoint.X)
- #ifdef X_MAX_PIN
- && ( !dda->x_direction || x_max() )
- #endif
- #ifdef X_MIN_PIN
- && ( dda->x_direction || x_min() )
- #endif
- ) {
+ if (current_position.X != dda->endpoint.X) {
dda->x_counter -= dda->x_delta;
if (dda->x_counter < 0) {
x_step();
@@ -496,14 +490,7 @@ void dda_step(DDA *dda) {
}
}
- if ((current_position.Y != dda->endpoint.Y)
- #ifdef Y_MAX_PIN
- && ( !dda->y_direction || y_max() )
- #endif
- #ifdef Y_MIN_PIN
- && ( dda->y_direction || y_min() )
- #endif
- ) {
+ if (current_position.Y != dda->endpoint.Y) {
dda->y_counter -= dda->y_delta;
if (dda->y_counter < 0) {
y_step();
@@ -517,14 +504,7 @@ void dda_step(DDA *dda) {
}
}
- if ((current_position.Z != dda->endpoint.Z)
- #ifdef Z_MAX_PIN
- && ( !dda->z_direction || z_max() )
- #endif
- #ifdef Z_MIN_PIN
- && ( dda->z_direction || z_min() )
- #endif
- ) {
+ if (current_position.Z != dda->endpoint.Z) {
dda->z_counter -= dda->z_delta;
if (dda->z_counter < 0) {
z_step();
@@ -630,3 +610,39 @@ void dda_step(DDA *dda) {
// we also hope that we don't step before the drivers register the low- limit maximum speed if you think this is a problem.
unstep();
}
+
+
+#if defined X_MIN_PIN && defined Y_MIN_PIN && defined Z_MIN_PIN
+void hit_endstops(void) {
+ /*
+ Hit the X and Y endstops first, then do Z seperately.
+ TODO: use search feedrate to actually find the endstops again after hiting them hard.
+ */
+ uint16_t xtrack=0,ytrack=0,ztrack=0;
+ x_direction(1);
+ y_direction(1);
+ z_direction(1);
+
+ while( !x_min() || !y_min()){
+ if(--xtrack<0 && !x_min()){
+ x_step();
+ xtrack = 100000/((long)STEPS_PER_MM_X*MAXIMUM_FEEDRATE_X);
+ }
+ if(--ytrack<0 && !y_min()){
+ y_step();
+ ytrack = 100000/((long)STEPS_PER_MM_Y*MAXIMUM_FEEDRATE_Y);
+ }
+ /* Delay 1/10000 sec (10µSec) */
+ delay(1);
+ unstep();
+ }
+ while( !z_min() ){
+ if(--ztrack<0){
+ z_step();
+ ztrack = 100000/((long)STEPS_PER_MM_Z*MAXIMUM_FEEDRATE_Z);
+ }
+ delay(1);
+ unstep();
+ }
+}
+#endif
View
5 dda.h
@@ -121,4 +121,9 @@ void dda_start(DDA *dda) __attribute__ ((hot));
// DDA takes one step (called from timer interrupt)
void dda_step(DDA *dda) __attribute__ ((hot));
+// hit_endstops() move towards the MAX endstops, XY first & then Z.
+// Does NOT update position or feedrate.
+void hit_endstops(void)
+ __attribute__ ((cold));
+
#endif /* _DDA_H */
View
@@ -15,6 +15,10 @@
#include "sersendf.h"
#include "debug.h"
+uint8_t SetHomeSeen;
+TARGET home;
+
+
/****************************************************************************
* *
* Command Received - process it *
@@ -90,61 +94,21 @@ void process_gcode_command() {
// G28 - go home
case 28:
- /*
- Home XY first
- */
- // hit endstops, no acceleration- we don't care about skipped steps
- startpoint.F = MAXIMUM_FEEDRATE_X;
- SpecialMoveXY(-250L * STEPS_PER_MM_X, -250L * STEPS_PER_MM_Y, MAXIMUM_FEEDRATE_X);
- startpoint.X = startpoint.Y = 0;
-
- // move forward a bit
- SpecialMoveXY(5 * STEPS_PER_MM_X, 5 * STEPS_PER_MM_Y, SEARCH_FEEDRATE_X);
-
- // move back in to endstops slowly
- SpecialMoveXY(-20 * STEPS_PER_MM_X, -20 * STEPS_PER_MM_Y, SEARCH_FEEDRATE_X);
-
- // wait for queue to complete
- for (;queue_empty() == 0;)
- wd_reset();
-
- // this is our home point
- startpoint.X = startpoint.Y = current_position.X = current_position.Y = 0;
-
- /*
- Home Z
- */
- // hit endstop, no acceleration- we don't care about skipped steps
- startpoint.F = MAXIMUM_FEEDRATE_Z;
- SpecialMoveZ(-250L * STEPS_PER_MM_Z, MAXIMUM_FEEDRATE_Z);
- startpoint.Z = 0;
-
- // move forward a bit
- SpecialMoveZ(5 * STEPS_PER_MM_Z, SEARCH_FEEDRATE_Z);
-
- // move back into endstop slowly
- SpecialMoveZ(-20L * STEPS_PER_MM_Z, SEARCH_FEEDRATE_Z);
-
- // wait for queue to complete
- for (;queue_empty() == 0;)
- wd_reset();
-
- // this is our home point
- startpoint.Z = current_position.Z = 0;
-
- /*
- Home E
- */
- // extruder only runs one way and we have no "endstop", just set this point as home
- startpoint.E = current_position.E = 0;
-
- /*
- Home F
- */
-
- // F has been left at SEARCH_FEEDRATE_Z by the last move, this is a usable "home"
- // uncomment the following or substitute if you prefer a different default feedrate
- // startpoint.F = SEARCH_FEEDRATE_Z
+ if( SetHomeSeen ) {
+ enqueue(&home);
+ }
+ else{
+ // wait for queue to complete
+ for (;queue_empty() == 0;)
+ wd_reset();
+
+ hit_endstops();
+
+ // this is our home point
+ startpoint.X = startpoint.Y = current_position.X = current_position.Y = 0;
+
+ startpoint.F = SEARCH_FEEDRATE_Z;
+ }
break;
@@ -160,6 +124,8 @@ void process_gcode_command() {
// G92 - set home
case 92:
+ home = startpoint;
+ SetHomeSeen = 1;
startpoint.X = startpoint.Y = startpoint.Z = startpoint.E =
current_position.X = current_position.Y = current_position.Z = current_position.E = 0;
startpoint.F =

0 comments on commit 4129358

Please sign in to comment.