From c6122eda74a02f46cb331336e65f1e8fe1fef05b Mon Sep 17 00:00:00 2001 From: Michael Moon Date: Sun, 20 Feb 2011 14:10:53 +1100 Subject: [PATCH] add G161/G162 commands, upgrade home.c to provide negative/positive homing calls for G161/G162 --- gcode_process.c | 19 ++++ home.c | 273 +++++++++++++++++++++++++++++------------------- home.h | 9 +- 3 files changed, 192 insertions(+), 109 deletions(-) diff --git a/gcode_process.c b/gcode_process.c index 70b47ac..694b716 100644 --- a/gcode_process.c +++ b/gcode_process.c @@ -233,6 +233,25 @@ void process_gcode_command() { startpoint.E = current_position.E = 0; } break; + + // G161 - Home negative + case 161: + if (next_target.seen_X) + home_x_negative(); + if (next_target.seen_Y) + home_y_negative(); + if (next_target.seen_Z) + home_z_negative(); + break; + // G162 - Home positive + case 162: + if (next_target.seen_X) + home_x_positive(); + if (next_target.seen_Y) + home_y_positive(); + if (next_target.seen_Z) + home_z_positive(); + break; // unknown gcode: spit an error default: diff --git a/home.c b/home.c index c778ad9..c72e100 100644 --- a/home.c +++ b/home.c @@ -5,48 +5,38 @@ #include "delay.h" #include "pinio.h" - -// F is mm/min -// DELAY is clocks per step -// 1 clock = 1 second/F_CPU -// intermediaries are steps/mm and F_CPU per min -// F mm/min * steps_per_mm = steps/min -// clocks per min = 60 * F_CPU -// clocks/min / (steps/min) = clocks per step -// so delay = 60 * F_CPU / steps_per_mm / F -// #define FEEDRATE_TO_DELAY(F) 60.0 * ((float) F_CPU) / STEPS_PER_MM_X / F - void home() { - #if (! defined X_MIN_PIN) || (! defined Y_MIN_PIN) || (! defined Z_MIN_PIN) -// TARGET t = {0, 0, 0, 0, 0}; - #endif queue_wait(); -// uint8_t denoise_count = 0; - - home_x(); - home_y(); - home_z(); + #if defined X_MIN_PIN + home_x_negative(); + #elif defined X_MAX_PIN + home_x_positive(); + #endif + + #if defined Y_MIN_PIN + home_y_negative(); + #elif defined Y_MAX_PIN + home_y_positive(); + #endif + + #if defined Z_MIN_PIN + home_z_negative(); + #elif defined Z_MAX_PIN + home_z_positive(); + #endif } -void home_x() { - uint8_t denoise_count = 0; +void home_x_negative() { + #if defined X_MIN_PIN + uint8_t denoise_count = 0; - // home X - #if defined X_MIN_PIN || defined X_MAX_PIN + // home X // hit home hard - #ifdef X_MIN_PIN x_direction(0); - #else - x_direction(1); - #endif while (denoise_count < 8) { // denoise - #ifdef X_MIN_PIN if (x_min()) - #else - if (x_max()) - #endif denoise_count++; else denoise_count = 0; @@ -60,13 +50,8 @@ void home_x() { denoise_count = 0; // back off slowly - #ifdef X_MIN_PIN x_direction(1); while (x_min() != 0) { - #else - x_direction(0); - while (x_max() != 0) { - #endif // step x_step(); delay(5); @@ -76,37 +61,63 @@ void home_x() { } // set X home - #ifdef X_MIN_PIN - startpoint.X = current_position.X = 0; - #else - TARGET t = {0, 0, 0, 0, 0}; - // set position to MAX - startpoint.X = current_position.X = (int32_t) (X_MAX * STEPS_PER_MM_X); - // go to zero - t.F = MAXIMUM_FEEDRATE_X; - enqueue(&t); - #endif + startpoint.X = current_position.X = 0; #endif } - -void home_y() { - uint8_t denoise_count = 0; - // home Y - #if defined Y_MIN_PIN || defined Y_MAX_PIN +void home_x_positive() { + #if defined X_MAX_PIN + uint8_t denoise_count = 0; + + // home X // hit home hard - #ifdef Y_MIN_PIN - y_direction(0); - #else - y_direction(1); - #endif + x_direction(1); + while (denoise_count < 8) { + // denoise + if (x_max()) + denoise_count++; + else + denoise_count = 0; + // step + x_step(); + delay(5); + unstep(); + // wait until next step time + delay((uint32_t) (60.0 * ((float) F_CPU) / STEPS_PER_MM_X / ((float) MAXIMUM_FEEDRATE_X))); + } + denoise_count = 0; + + // back off slowly + x_direction(0); + while (x_max() != 0) { + // step + x_step(); + delay(5); + unstep(); + // wait until next step time + delay((uint32_t) (60.0 * ((float) F_CPU) / STEPS_PER_MM_X / ((float) SEARCH_FEEDRATE_X))); + } + + // set X home + TARGET t = {0, 0, 0, 0, 0}; + // set position to MAX + startpoint.X = current_position.X = (int32_t) (X_MAX * STEPS_PER_MM_X); + // go to zero + t.F = MAXIMUM_FEEDRATE_X; + enqueue(&t); + #endif +} + +void home_y_negative() { + #if defined Y_MIN_PIN + uint8_t denoise_count = 0; + + // home Y + // hit home hard + y_direction(0); while (denoise_count < 8) { // denoise - #ifdef Y_MIN_PIN if (y_min()) - #else - if (y_max()) - #endif denoise_count++; else denoise_count = 0; @@ -120,13 +131,8 @@ void home_y() { denoise_count = 0; // back off slowly - #ifdef Y_MIN_PIN - y_direction(1); - while (y_min() != 0) { - #else - y_direction(0); - while (y_max() != 0) { - #endif + y_direction(1); + while (y_min() != 0) { // step y_step(); delay(5); @@ -136,37 +142,63 @@ void home_y() { } // set Y home - #ifdef Y_MIN_PIN - startpoint.Y = current_position.Y = 0; - #else - TARGET t = {0, 0, 0, 0, 0}; - // set position to MAX - startpoint.Y = current_position.Y = (int32_t) (Y_MAX * STEPS_PER_MM_Y); - // go to zero - t.F = MAXIMUM_FEEDRATE_Y; - enqueue(&t); - #endif + startpoint.Y = current_position.Y = 0; #endif } -void home_z() { - uint8_t denoise_count = 0; - - // home Z - #if defined Z_MIN_PIN || defined Z_MAX_PIN +void home_y_positive() { + #if defined Y_MAX_PIN + uint8_t denoise_count = 0; + + // home Y // hit home hard - #ifdef Z_MIN_PIN - z_direction(0); - #else - z_direction(1); - #endif + y_direction(1); + while (denoise_count < 8) { + // denoise + if (y_max()) + denoise_count++; + else + denoise_count = 0; + // step + y_step(); + delay(5); + unstep(); + // wait until neyt step time + delay((uint32_t) (60.0 * ((float) F_CPU) / STEPS_PER_MM_Y / ((float) MAXIMUM_FEEDRATE_Y))); + } + denoise_count = 0; + + // back off slowly + y_direction(0); + while (y_max() != 0) { + // step + y_step(); + delay(5); + unstep(); + // wait until next step time + delay((uint32_t) (60.0 * ((float) F_CPU) / STEPS_PER_MM_Y / ((float) SEARCH_FEEDRATE_Y))); + } + + // set Y home + TARGET t = {0, 0, 0, 0, 0}; + // set position to MAX + startpoint.Y = current_position.Y = (int32_t) (Y_MAX * STEPS_PER_MM_Y); + // go to zero + t.F = MAXIMUM_FEEDRATE_Y; + enqueue(&t); + #endif +} + +void home_z_negative() { + #if defined Z_MIN_PIN + uint8_t denoise_count = 0; + + // home Z + // hit home hard + z_direction(0); while (denoise_count < 8) { // denoise - #ifdef Z_MIN_PIN if (z_min()) - #else - if (z_max()) - #endif denoise_count++; else denoise_count = 0; @@ -180,13 +212,8 @@ void home_z() { denoise_count = 0; // back off slowly - #ifdef Z_MIN_PIN z_direction(1); while (z_min() != 0) { - #else - z_direction(0); - while (z_max() != 0) { - #endif // step z_step(); delay(5); @@ -196,15 +223,49 @@ void home_z() { } // set Z home - #ifdef Z_MIN_PIN - startpoint.Z = current_position.Z = 0; - #else - TARGET t = {0, 0, 0, 0, 0}; - // set position to MAX - startpoint.Z = current_position.Z = (int32_t) (Z_MAX * STEPS_PER_MM_Z); - // go to zero - t.F = MAXIMUM_FEEDRATE_Z; - enqueue(&t); - #endif + startpoint.Z = current_position.Z = 0; + #endif +} + +void home_z_positive() { + #if defined Z_MAX_PIN + uint8_t denoise_count = 0; + + // home Z + // hit home hard + z_direction(1); + while (denoise_count < 8) { + // denoise + if (z_max()) + denoise_count++; + else + denoise_count = 0; + // step + z_step(); + delay(5); + unstep(); + // wait until next step time + delay((uint32_t) (60.0 * ((float) F_CPU) / STEPS_PER_MM_Z / ((float) MAXIMUM_FEEDRATE_Z))); + } + denoise_count = 0; + + // back off slowly + z_direction(0); + while (z_max() != 0) { + // step + z_step(); + delay(5); + unstep(); + // wait until next step time + delay((uint32_t) (60.0 * ((float) F_CPU) / STEPS_PER_MM_Z / ((float) SEARCH_FEEDRATE_Z))); + } + + // set Z home + TARGET t = {0, 0, 0, 0, 0}; + // set position to MAX + startpoint.Z = current_position.Z = (int32_t) (Z_MAX * STEPS_PER_MM_Z); + // go to zero + t.F = MAXIMUM_FEEDRATE_Z; + enqueue(&t); #endif } diff --git a/home.h b/home.h index 693af60..69a12cf 100644 --- a/home.h +++ b/home.h @@ -2,8 +2,11 @@ void home(void); -void home_x(void); -void home_y(void); -void home_z(void); +void home_x_negative(void); +void home_x_positive(void); +void home_y_negative(void); +void home_y_positive(void); +void home_z_negative(void); +void home_z_positive(void); #endif /* _HOME_H */