From afd8a023ce9ff79973846bde4318fb44467a5468 Mon Sep 17 00:00:00 2001 From: Chris Marzano Date: Fri, 25 Jul 2014 09:17:06 -0700 Subject: [PATCH 01/71] Initial test commit. --- Marlin/Configuration.h | 20 ++++++++++---------- Marlin/pins.h | 1 + foo.txt | 1 + 3 files changed, 12 insertions(+), 10 deletions(-) create mode 100644 foo.txt diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index fc864a1a95c1..4d4ded68296c 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -274,7 +274,7 @@ #define ENDSTOPPULLUP_ZMAX #define ENDSTOPPULLUP_XMIN #define ENDSTOPPULLUP_YMIN - #define ENDSTOPPULLUP_ZMIN + //#define ENDSTOPPULLUP_ZMIN #endif // The pullups are needed if you directly connect a mechanical endswitch between the signal and ground pins. @@ -349,7 +349,7 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o // Probe 3 arbitrary points on the bed (that aren't colinear) // You must specify the X & Y coordinates of all 3 points - //#define AUTO_BED_LEVELING_GRID + #define AUTO_BED_LEVELING_GRID // with AUTO_BED_LEVELING_GRID, the bed is sampled in a // AUTO_BED_LEVELING_GRID_POINTSxAUTO_BED_LEVELING_GRID_POINTS grid // and least squares solution is calculated @@ -357,16 +357,16 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o #ifdef AUTO_BED_LEVELING_GRID // set the rectangle in which to probe - #define LEFT_PROBE_BED_POSITION 15 - #define RIGHT_PROBE_BED_POSITION 170 - #define BACK_PROBE_BED_POSITION 180 + #define LEFT_PROBE_BED_POSITION 20 + #define RIGHT_PROBE_BED_POSITION 135 + #define BACK_PROBE_BED_POSITION 103 #define FRONT_PROBE_BED_POSITION 20 // set the number of grid points per dimension // I wouldn't see a reason to go above 3 (=9 probing points on the bed) - #define AUTO_BED_LEVELING_GRID_POINTS 2 - + #define AUTO_BED_LEVELING_GRID_POINTS 3 +//154x106 #else // not AUTO_BED_LEVELING_GRID // with no grid, just probe 3 arbitrary points. A simple cross-product // is used to esimate the plane of the print bed @@ -382,8 +382,8 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o // these are the offsets to the probe relative to the extruder tip (Hotend - Probe) - #define X_PROBE_OFFSET_FROM_EXTRUDER -13.6 - #define Y_PROBE_OFFSET_FROM_EXTRUDER 27 + #define X_PROBE_OFFSET_FROM_EXTRUDER 0 + #define Y_PROBE_OFFSET_FROM_EXTRUDER 0 #define Z_PROBE_OFFSET_FROM_EXTRUDER 0 #define ABL_Z_DIRECTION -1 // set to 1 or -1 to control ABL correction direction. relates to *_HOME_DIR @@ -455,7 +455,7 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o // default settings -#define DEFAULT_AXIS_STEPS_PER_UNIT {80,80,2535,162} // default steps per unit for Ultimaker +#define DEFAULT_AXIS_STEPS_PER_UNIT {40,40,2535,162} // default steps per unit for Ultimaker #define DEFAULT_MAX_FEEDRATE {400, 400, 3, 12} // (mm/sec) #define DEFAULT_MAX_ACCELERATION {2500,2500,100,5000} // X, Y, Z, E maximum start speed for accelerated moves. E default values are good for Skeinforge 40+, for older versions raise them a lot. diff --git a/Marlin/pins.h b/Marlin/pins.h index ed5c86b63124..ebf2b949d9f2 100644 --- a/Marlin/pins.h +++ b/Marlin/pins.h @@ -1594,6 +1594,7 @@ #define Z_STOP_PIN 36 #define TEMP_0_PIN 1 // Extruder / Analog pin numbering #define TEMP_BED_PIN 0 // Bed / Analog pin numbering + #define FSR_ABL_PIN 2 // MSM FSR ABL @pin 40 (Bottom left of EXP1) #endif #define TEMP_1_PIN -1 diff --git a/foo.txt b/foo.txt new file mode 100644 index 000000000000..3462721fd4da --- /dev/null +++ b/foo.txt @@ -0,0 +1 @@ +hello! \ No newline at end of file From eef93926d6d21336bebb186b18b69eca21c4ff32 Mon Sep 17 00:00:00 2001 From: Chris Marzano Date: Fri, 25 Jul 2014 09:21:09 -0700 Subject: [PATCH 02/71] Removed foo.txt reference. --- foo.txt | 1 - 1 file changed, 1 deletion(-) delete mode 100644 foo.txt diff --git a/foo.txt b/foo.txt deleted file mode 100644 index 3462721fd4da..000000000000 --- a/foo.txt +++ /dev/null @@ -1 +0,0 @@ -hello! \ No newline at end of file From a04bc6fd40a457a29de7e26b8cc18854ac578c96 Mon Sep 17 00:00:00 2001 From: Chris Marzano Date: Fri, 25 Jul 2014 10:34:32 -0700 Subject: [PATCH 03/71] Temp commit for saving --- Marlin/Configuration.h | 1 + Marlin/forceabl.cpp | 5 +++++ Marlin/forceabl.h | 13 +++++++++++++ 3 files changed, 19 insertions(+) create mode 100644 Marlin/forceabl.cpp create mode 100644 Marlin/forceabl.h diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 4d4ded68296c..cb0d2732ea4c 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -481,6 +481,7 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o #ifdef MSM_Printeer #define CUSTOM_M_CODES #define CUSTOM_G_CODES +#define FSR_Z #endif // Custom M code points diff --git a/Marlin/forceabl.cpp b/Marlin/forceabl.cpp new file mode 100644 index 000000000000..6260cab487a7 --- /dev/null +++ b/Marlin/forceabl.cpp @@ -0,0 +1,5 @@ +/* + forceabl.cpp + +*/ + diff --git a/Marlin/forceabl.h b/Marlin/forceabl.h new file mode 100644 index 000000000000..5dd04b38309a --- /dev/null +++ b/Marlin/forceabl.h @@ -0,0 +1,13 @@ +/* + forceabl.h + +*/ + +#ifndef forceabl_h +#define forceabl_h + +#include "Marlin.h" +#include "planner.h" +#endif + +// Public functions \ No newline at end of file From 161d04df7365acd32e0aa51ee46a6914e28dcba2 Mon Sep 17 00:00:00 2001 From: Chris Marzano Date: Fri, 25 Jul 2014 11:00:37 -0700 Subject: [PATCH 04/71] Enabled temp1 pin and made temp accessible --- Marlin/pins.h | 3 +-- Marlin/temperature.cpp | 3 ++- Marlin/temperature.h | 5 +++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Marlin/pins.h b/Marlin/pins.h index ebf2b949d9f2..b11b4302fb85 100644 --- a/Marlin/pins.h +++ b/Marlin/pins.h @@ -1594,10 +1594,9 @@ #define Z_STOP_PIN 36 #define TEMP_0_PIN 1 // Extruder / Analog pin numbering #define TEMP_BED_PIN 0 // Bed / Analog pin numbering - #define FSR_ABL_PIN 2 // MSM FSR ABL @pin 40 (Bottom left of EXP1) #endif -#define TEMP_1_PIN -1 +#define TEMP_1_PIN 2 // Pin for FSR ABL (#40, bottom left of EXP1) #define TEMP_2_PIN -1 #define SDPOWER -1 diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index 6be3177a18de..c62443b0321b 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -1158,7 +1158,8 @@ ISR(TIMER0_COMPB_vect) break; case 5: // Measure TEMP_1 #if defined(TEMP_1_PIN) && (TEMP_1_PIN > -1) - raw_temp_1_value += ADC; + raw_temp_1_sample = ADC; + raw_temp_1_value += raw_temp_1_sample; #endif temp_state = 6; break; diff --git a/Marlin/temperature.h b/Marlin/temperature.h index a8580def56e5..6e6f01a44085 100644 --- a/Marlin/temperature.h +++ b/Marlin/temperature.h @@ -39,6 +39,7 @@ extern float current_temperature[EXTRUDERS]; extern int current_temperature_raw[EXTRUDERS]; extern int current_temperature_bed_raw; #endif +extern int raw_temp_1_sample; extern int target_temperature_bed; extern float current_temperature_bed; #ifdef TEMP_SENSOR_1_AS_REDUNDANT @@ -84,6 +85,10 @@ FORCE_INLINE float degHotend(uint8_t extruder) { }; #endif +FORCE_INLINE int rawTemp1Sample(){ + return raw_temp_1_sample; +} + FORCE_INLINE float degBed() { return current_temperature_bed; }; From 4cdf67f259886cd417495808fca439925bb5e36e Mon Sep 17 00:00:00 2001 From: Chris Marzano Date: Fri, 25 Jul 2014 11:07:39 -0700 Subject: [PATCH 05/71] Moved FSR ABL define to ABL section --- Marlin/Configuration.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index cb0d2732ea4c..29ff8a7f9ea5 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -336,7 +336,7 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o #define ENABLE_AUTO_BED_LEVELING // Delete the comment to enable (remove // at the start of the line) #ifdef ENABLE_AUTO_BED_LEVELING - +#define FSR_BED_LEVELING // Use force sensing resistors to perform ABL // There are 2 different ways to pick the X and Y locations to probe: // - "grid" mode @@ -481,7 +481,6 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o #ifdef MSM_Printeer #define CUSTOM_M_CODES #define CUSTOM_G_CODES -#define FSR_Z #endif // Custom M code points From 65aeb6f2548701ad1e652238195f78ba5b72101a Mon Sep 17 00:00:00 2001 From: Chris Marzano Date: Fri, 25 Jul 2014 11:35:41 -0700 Subject: [PATCH 06/71] Added M505 command for testing porpoises. --- Marlin/Marlin_main.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index e79deb16da85..fd679821210b 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -913,10 +913,14 @@ static void set_bed_level_equation_3pts(float z_at_pt_1, float z_at_pt_2, float #endif // AUTO_BED_LEVELING_GRID +bool touching_print_surface(int threshold) { + return rawTemp1Sample() < threshold; +} + static void run_z_probe() { plan_bed_level_matrix.set_to_identity(); feedrate = homing_feedrate[Z_AXIS]; - + #ifdef FSR_BED_LEVELING // move down until you find the bed float zPosition = -10; plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], zPosition, current_position[E_AXIS], feedrate/60, active_extruder); @@ -2789,6 +2793,12 @@ void process_commands() { Config_PrintSettings(); } + case 505: // M505 Test function for FSR ABL + { + SERIAL_ECHO_START; + SERIAL_ECHOLNPGM("M505 run"); + SERIAL_PROTOCOLLN(""); + } break; #ifdef ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED case 540: From e2e7e8409692d17bd1949740978b5da92f1e9bbb Mon Sep 17 00:00:00 2001 From: Chris Marzano Date: Fri, 25 Jul 2014 16:31:26 -0700 Subject: [PATCH 07/71] Fixed open definition to compile. --- Marlin/Marlin_main.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index fd679821210b..5356d744926a 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -920,7 +920,6 @@ bool touching_print_surface(int threshold) { static void run_z_probe() { plan_bed_level_matrix.set_to_identity(); feedrate = homing_feedrate[Z_AXIS]; - #ifdef FSR_BED_LEVELING // move down until you find the bed float zPosition = -10; plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], zPosition, current_position[E_AXIS], feedrate/60, active_extruder); @@ -2795,8 +2794,13 @@ void process_commands() } case 505: // M505 Test function for FSR ABL { + for (int i=10; i>0; i--){ + int fsr_starting_level += rawTemp1Sample() + } + fsr_starting_level /= 10; + SERIAL_ECHO_START; - SERIAL_ECHOLNPGM("M505 run"); + SERIAL_ECHOLNPGM(fsr_starting_level); SERIAL_PROTOCOLLN(""); } break; From 0a85eef4864a3315ca4f47a7d62ecf23449cf254 Mon Sep 17 00:00:00 2001 From: Chris Marzano Date: Fri, 25 Jul 2014 16:48:42 -0700 Subject: [PATCH 08/71] Fixed syntax errors (;'s, inits) to compile code. --- Marlin/Marlin_main.cpp | 6 ++++-- Marlin/temperature.cpp | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 5356d744926a..6777e4201116 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -2794,13 +2794,15 @@ void process_commands() } case 505: // M505 Test function for FSR ABL { + int fsr_starting_level; for (int i=10; i>0; i--){ - int fsr_starting_level += rawTemp1Sample() + fsr_starting_level += rawTemp1Sample(); } fsr_starting_level /= 10; SERIAL_ECHO_START; - SERIAL_ECHOLNPGM(fsr_starting_level); + SERIAL_ECHOLNPGM("ADC Reading: "); + SERIAL_ECHO(fsr_starting_level); SERIAL_PROTOCOLLN(""); } break; diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index c62443b0321b..f14f208a0bdb 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -43,6 +43,7 @@ int current_temperature_raw[EXTRUDERS] = { 0 }; float current_temperature[EXTRUDERS] = { 0.0 }; int current_temperature_bed_raw = 0; float current_temperature_bed = 0.0; +int raw_temp_1_sample = 0; #ifdef TEMP_SENSOR_1_AS_REDUNDANT int redundant_temperature_raw = 0; float redundant_temperature = 0.0; From 9da53f14e5e31dd6b9252f3361de62a0b27001fb Mon Sep 17 00:00:00 2001 From: Chris Marzano Date: Fri, 25 Jul 2014 17:37:45 -0700 Subject: [PATCH 09/71] Corrected bed touching logic, added comment. --- Marlin/Marlin_main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 6777e4201116..7c8415df05ee 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -913,9 +913,11 @@ static void set_bed_level_equation_3pts(float z_at_pt_1, float z_at_pt_2, float #endif // AUTO_BED_LEVELING_GRID +#ifdef FSR_BED_LEVELING bool touching_print_surface(int threshold) { - return rawTemp1Sample() < threshold; + return rawTemp1Sample() > threshold; // With pull-down resistor, increases when pressed } +#endif static void run_z_probe() { plan_bed_level_matrix.set_to_identity(); From 1a6104188ffc80da44fc4766269d67186eccc73b Mon Sep 17 00:00:00 2001 From: Chris Marzano Date: Mon, 28 Jul 2014 09:36:05 -0700 Subject: [PATCH 10/71] FSR ABL feature implemented in stepper.cpp. Needs testing and tidying. --- Marlin/Marlin_main.cpp | 6 ------ Marlin/stepper.cpp | 26 ++++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 7c8415df05ee..d4b62b8bc3bf 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -913,12 +913,6 @@ static void set_bed_level_equation_3pts(float z_at_pt_1, float z_at_pt_2, float #endif // AUTO_BED_LEVELING_GRID -#ifdef FSR_BED_LEVELING -bool touching_print_surface(int threshold) { - return rawTemp1Sample() > threshold; // With pull-down resistor, increases when pressed -} -#endif - static void run_z_probe() { plan_bed_level_matrix.set_to_identity(); feedrate = homing_feedrate[Z_AXIS]; diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index 98efc9d57c54..16a2a38a18d6 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -514,8 +514,30 @@ ISR(TIMER1_COMPA_vect) count_direction[Z_AXIS]=-1; CHECK_ENDSTOPS { - #if defined(Z_MIN_PIN) && Z_MIN_PIN > -1 - bool z_min_endstop=(READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING); + #if defined (FSR_BED_LEVELING) && defined(TEMP_1_PIN) && TEMP_1_PIN > -1 + int fsr_average; + int threshold = 125; + bool fsr_trigger = false; + for (int i=10; i>0; i--){ + fsr_average += rawTemp1Sample(); + } + fsr_average /= 10; + // Check if ADC average is above switching threshold + if (fsr_average > threshold){ + fsr_trigger = true; + } + else{ + fsr_trigger = false; + } + // Run endstop triggered logic + if(fsr_trigger && old_z_min_endstop && (current_block->steps_z > 0)) { + endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS]; + endstop_z_hit=true; + step_events_completed = current_block->step_event_count; + } + old_z_min_endstop = fsr_trigger; + #elif defined(Z_MIN_PIN) && Z_MIN_PIN > -1 + if bool z_min_endstop=(READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING); if(z_min_endstop && old_z_min_endstop && (current_block->steps_z > 0)) { endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS]; endstop_z_hit=true; From 2e0c4a091479c99a79be6d49b174f1f60e547256 Mon Sep 17 00:00:00 2001 From: Chris Marzano Date: Mon, 28 Jul 2014 09:55:01 -0700 Subject: [PATCH 11/71] Configured probe region for more reliable probing. Z_MIN always shows triggered in m119. --- Marlin/Configuration.h | 4 ++-- Marlin/stepper.cpp | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 29ff8a7f9ea5..deed056cc944 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -357,8 +357,8 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o #ifdef AUTO_BED_LEVELING_GRID // set the rectangle in which to probe - #define LEFT_PROBE_BED_POSITION 20 - #define RIGHT_PROBE_BED_POSITION 135 + #define LEFT_PROBE_BED_POSITION 10 + #define RIGHT_PROBE_BED_POSITION 95 #define BACK_PROBE_BED_POSITION 103 #define FRONT_PROBE_BED_POSITION 20 diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index 16a2a38a18d6..cd151a6f4b1b 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -536,6 +536,7 @@ ISR(TIMER1_COMPA_vect) step_events_completed = current_block->step_event_count; } old_z_min_endstop = fsr_trigger; + // End of FSR ABL #elif defined(Z_MIN_PIN) && Z_MIN_PIN > -1 if bool z_min_endstop=(READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING); if(z_min_endstop && old_z_min_endstop && (current_block->steps_z > 0)) { From f35d0f701da84781eee6c01d08a7164a070f2eb7 Mon Sep 17 00:00:00 2001 From: Chris Marzano Date: Mon, 28 Jul 2014 10:24:46 -0700 Subject: [PATCH 12/71] Settings adjusted to improve reliability. M119 not registering changes correctly. --- Marlin/Configuration.h | 4 ++-- Marlin/stepper.cpp | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index deed056cc944..fcf759cf770e 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -357,10 +357,10 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o #ifdef AUTO_BED_LEVELING_GRID // set the rectangle in which to probe - #define LEFT_PROBE_BED_POSITION 10 + #define LEFT_PROBE_BED_POSITION 0 #define RIGHT_PROBE_BED_POSITION 95 #define BACK_PROBE_BED_POSITION 103 - #define FRONT_PROBE_BED_POSITION 20 + #define FRONT_PROBE_BED_POSITION 25 // set the number of grid points per dimension // I wouldn't see a reason to go above 3 (=9 probing points on the bed) diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index cd151a6f4b1b..77e6df8c437f 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -516,12 +516,14 @@ ISR(TIMER1_COMPA_vect) { #if defined (FSR_BED_LEVELING) && defined(TEMP_1_PIN) && TEMP_1_PIN > -1 int fsr_average; - int threshold = 125; + // Number of readings to average + int fsr_checks = 5; + int threshold = 120; bool fsr_trigger = false; - for (int i=10; i>0; i--){ + for (int i=fsr_checks; i>0; i--){ fsr_average += rawTemp1Sample(); } - fsr_average /= 10; + fsr_average /= fsr_checks; // Check if ADC average is above switching threshold if (fsr_average > threshold){ fsr_trigger = true; From 3b1456243726550c8109dcebce288e217f2c6af7 Mon Sep 17 00:00:00 2001 From: Chris Marzano Date: Mon, 28 Jul 2014 10:57:04 -0700 Subject: [PATCH 13/71] Changed from FSR threshold switching to rolling weighted average switching. --- Marlin/stepper.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index 77e6df8c437f..5a42f76d0a57 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -516,16 +516,19 @@ ISR(TIMER1_COMPA_vect) { #if defined (FSR_BED_LEVELING) && defined(TEMP_1_PIN) && TEMP_1_PIN > -1 int fsr_average; + // Additional weighting slows the movement of the rolling average + int fsr_weighting = 3; + int fsr_rolling_avg; // Number of readings to average int fsr_checks = 5; - int threshold = 120; bool fsr_trigger = false; + for (int i=fsr_checks; i>0; i--){ fsr_average += rawTemp1Sample(); } fsr_average /= fsr_checks; // Check if ADC average is above switching threshold - if (fsr_average > threshold){ + if ((fsr_average > 1.1*fsr_rolling_avg) || (fsr_average < .9*fsr_rolling_avg) && (fsr_average > 20)){ fsr_trigger = true; } else{ @@ -537,7 +540,11 @@ ISR(TIMER1_COMPA_vect) endstop_z_hit=true; step_events_completed = current_block->step_event_count; } - old_z_min_endstop = fsr_trigger; + old_z_min_endstop = fsr_trigger; + // Rolling weighted average adjustment + fsr_rolling_avg *= fsr_weighting; + fsr_rolling_avg += fsr_average; + fsr_rolling_avg /= (fsr_weighting+1) // End of FSR ABL #elif defined(Z_MIN_PIN) && Z_MIN_PIN > -1 if bool z_min_endstop=(READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING); From b8764ae0d52958e5efc9429f336a504b14272b6e Mon Sep 17 00:00:00 2001 From: Chris Marzano Date: Mon, 28 Jul 2014 10:58:57 -0700 Subject: [PATCH 14/71] Fixed ; for compiling. --- Marlin/stepper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index 5a42f76d0a57..0962ffed1dc4 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -544,7 +544,7 @@ ISR(TIMER1_COMPA_vect) // Rolling weighted average adjustment fsr_rolling_avg *= fsr_weighting; fsr_rolling_avg += fsr_average; - fsr_rolling_avg /= (fsr_weighting+1) + fsr_rolling_avg /= (fsr_weighting+1); // End of FSR ABL #elif defined(Z_MIN_PIN) && Z_MIN_PIN > -1 if bool z_min_endstop=(READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING); From f97ed8fded0f0ebfc633f6d47bf785d348a46d85 Mon Sep 17 00:00:00 2001 From: Chris Marzano Date: Mon, 28 Jul 2014 11:50:43 -0700 Subject: [PATCH 15/71] Changes to FSR ABL calibration and m119. --- Marlin/Marlin_main.cpp | 14 ++++++++++---- Marlin/stepper.cpp | 17 +++++++++++------ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index d4b62b8bc3bf..b78a2be511a9 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -184,7 +184,8 @@ //=========================================================================== //=============================imported variables============================ //=========================================================================== - +extern bool fsr_z_endstop; +extern int fsr_rolling_avg; //=========================================================================== //=============================public variables============================= @@ -2317,7 +2318,10 @@ void process_commands() SERIAL_PROTOCOLPGM(MSG_Y_MAX); SERIAL_PROTOCOLLN(((READ(Y_MAX_PIN)^Y_MAX_ENDSTOP_INVERTING)?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN)); #endif - #if defined(Z_MIN_PIN) && Z_MIN_PIN > -1 + #if defined FSR_BED_LEVELING + SERIAL_PROTOCOLPGM(MSG_Z_MIN); + SERIAL_PROTOCOLLN((fsr_z_endstop?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN)); + #elif defined(Z_MIN_PIN) && Z_MIN_PIN > -1 SERIAL_PROTOCOLPGM(MSG_Z_MIN); SERIAL_PROTOCOLLN(((READ(Z_MIN_PIN)^Z_MIN_ENDSTOP_INVERTING)?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN)); #endif @@ -2797,8 +2801,10 @@ void process_commands() fsr_starting_level /= 10; SERIAL_ECHO_START; - SERIAL_ECHOLNPGM("ADC Reading: "); - SERIAL_ECHO(fsr_starting_level); + SERIAL_ECHOPGM("ADC Reading: "); + SERIAL_ECHOLN(fsr_starting_level); + SERIAL_ECHOPGM(" Rolling Avg: "); + SERIAL_ECHOLN(fsr_rolling_avg); SERIAL_PROTOCOLLN(""); } break; diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index 0962ffed1dc4..d6e7c89da2fa 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -38,6 +38,10 @@ //=============================public variables ============================ //=========================================================================== block_t *current_block; // A pointer to the block currently being traced +#ifdef FSR_BED_LEVELING +bool fsr_z_endstop; // Public variable to fix m119 code +int fsr_rolling_avg = 50; // Public variable declaration for m505 +#endif //=========================================================================== @@ -517,12 +521,11 @@ ISR(TIMER1_COMPA_vect) #if defined (FSR_BED_LEVELING) && defined(TEMP_1_PIN) && TEMP_1_PIN > -1 int fsr_average; // Additional weighting slows the movement of the rolling average - int fsr_weighting = 3; - int fsr_rolling_avg; + int fsr_weighting = 1; // Number of readings to average int fsr_checks = 5; bool fsr_trigger = false; - + // Sample and average for fsr_checks for (int i=fsr_checks; i>0; i--){ fsr_average += rawTemp1Sample(); } @@ -530,9 +533,11 @@ ISR(TIMER1_COMPA_vect) // Check if ADC average is above switching threshold if ((fsr_average > 1.1*fsr_rolling_avg) || (fsr_average < .9*fsr_rolling_avg) && (fsr_average > 20)){ fsr_trigger = true; + fsr_z_endstop = true; } else{ fsr_trigger = false; + fsr_z_endstop = false; } // Run endstop triggered logic if(fsr_trigger && old_z_min_endstop && (current_block->steps_z > 0)) { @@ -542,9 +547,9 @@ ISR(TIMER1_COMPA_vect) } old_z_min_endstop = fsr_trigger; // Rolling weighted average adjustment - fsr_rolling_avg *= fsr_weighting; - fsr_rolling_avg += fsr_average; - fsr_rolling_avg /= (fsr_weighting+1); + fsr_rolling_avg = fsr_rolling_avg*fsr_weighting; + fsr_rolling_avg = fsr_rolling_avg+fsr_average; + fsr_rolling_avg = fsr_rolling_avg/(fsr_weighting+1); // End of FSR ABL #elif defined(Z_MIN_PIN) && Z_MIN_PIN > -1 if bool z_min_endstop=(READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING); From 2f06f269e3f3dee87c0d07c631c2d732f4cf6aaa Mon Sep 17 00:00:00 2001 From: Chris Marzano Date: Mon, 28 Jul 2014 12:19:04 -0700 Subject: [PATCH 16/71] Rolling average now functional. --- Marlin/stepper.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index d6e7c89da2fa..60be4fbf63f3 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -40,7 +40,6 @@ block_t *current_block; // A pointer to the block currently being traced #ifdef FSR_BED_LEVELING bool fsr_z_endstop; // Public variable to fix m119 code -int fsr_rolling_avg = 50; // Public variable declaration for m505 #endif @@ -76,6 +75,9 @@ static volatile bool endstop_z_hit=false; #ifdef MSM_Printeer static volatile bool endstop_z_max_hit=false; #endif +#ifdef FSR_BED_LEVELING +int fsr_rolling_avg; +#endif #ifdef ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED bool abort_on_endstop_hit = false; #endif @@ -523,15 +525,19 @@ ISR(TIMER1_COMPA_vect) // Additional weighting slows the movement of the rolling average int fsr_weighting = 1; // Number of readings to average - int fsr_checks = 5; + int fsr_checks = 20; bool fsr_trigger = false; // Sample and average for fsr_checks for (int i=fsr_checks; i>0; i--){ fsr_average += rawTemp1Sample(); } fsr_average /= fsr_checks; + if (bool fsr_first_run = false){ + fsr_rolling_avg = fsr_average; + fsr_first_run = true; + } // Check if ADC average is above switching threshold - if ((fsr_average > 1.1*fsr_rolling_avg) || (fsr_average < .9*fsr_rolling_avg) && (fsr_average > 20)){ + if ((fsr_average > 1.5*fsr_rolling_avg) || (fsr_average < .8*fsr_rolling_avg) && (fsr_average > 20)){ fsr_trigger = true; fsr_z_endstop = true; } From d4cd9a9f88efe78b9679656a2dbd04ac4a99a88d Mon Sep 17 00:00:00 2001 From: Chris Marzano Date: Mon, 28 Jul 2014 18:06:44 -0700 Subject: [PATCH 17/71] Need to fix for compilation. --- Marlin/Marlin_main.cpp | 3 +-- Marlin/stepper.cpp | 10 ++-------- Marlin/temperature.cpp | 11 +++++++++++ Marlin/temperature.h | 9 +++++++++ 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index b78a2be511a9..aedb85ee04f8 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -185,7 +185,6 @@ //=============================imported variables============================ //=========================================================================== extern bool fsr_z_endstop; -extern int fsr_rolling_avg; //=========================================================================== //=============================public variables============================= @@ -2804,7 +2803,7 @@ void process_commands() SERIAL_ECHOPGM("ADC Reading: "); SERIAL_ECHOLN(fsr_starting_level); SERIAL_ECHOPGM(" Rolling Avg: "); - SERIAL_ECHOLN(fsr_rolling_avg); + SERIAL_ECHOLN(fsr_rolling_avg()); SERIAL_PROTOCOLLN(""); } break; diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index 60be4fbf63f3..f200b9fc20c6 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -75,9 +75,6 @@ static volatile bool endstop_z_hit=false; #ifdef MSM_Printeer static volatile bool endstop_z_max_hit=false; #endif -#ifdef FSR_BED_LEVELING -int fsr_rolling_avg; -#endif #ifdef ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED bool abort_on_endstop_hit = false; #endif @@ -532,12 +529,9 @@ ISR(TIMER1_COMPA_vect) fsr_average += rawTemp1Sample(); } fsr_average /= fsr_checks; - if (bool fsr_first_run = false){ - fsr_rolling_avg = fsr_average; - fsr_first_run = true; - } + // Check if ADC average is above switching threshold - if ((fsr_average > 1.5*fsr_rolling_avg) || (fsr_average < .8*fsr_rolling_avg) && (fsr_average > 20)){ + if ((fsr_average > 1.5*fsr_rolling_avg()) || (fsr_average < .8*fsr_rolling_avg) && (fsr_average > 20)){ fsr_trigger = true; fsr_z_endstop = true; } diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index f14f208a0bdb..a18984e950ce 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -44,6 +44,7 @@ float current_temperature[EXTRUDERS] = { 0.0 }; int current_temperature_bed_raw = 0; float current_temperature_bed = 0.0; int raw_temp_1_sample = 0; +int fsr_rolling_avg = 0; #ifdef TEMP_SENSOR_1_AS_REDUNDANT int redundant_temperature_raw = 0; float redundant_temperature = 0.0; @@ -1161,6 +1162,16 @@ ISR(TIMER0_COMPB_vect) #if defined(TEMP_1_PIN) && (TEMP_1_PIN > -1) raw_temp_1_sample = ADC; raw_temp_1_value += raw_temp_1_sample; + #if defined FSR_BED_LEVELING + int fsr_weighting = 1; + for (int i=10; i>0; i--){ + fsr_average += ADC; + } + fsr_average /= 10; + fsr_rolling = fsr_rolling*fsr_weighting; + fsr_rolling = fsr_rolling+fsr_average; + fsr_rolling = fsr_rolling/(fsr_weighting+1); + #endif #endif temp_state = 6; break; diff --git a/Marlin/temperature.h b/Marlin/temperature.h index 6e6f01a44085..e207f693c952 100644 --- a/Marlin/temperature.h +++ b/Marlin/temperature.h @@ -42,6 +42,9 @@ extern float current_temperature[EXTRUDERS]; extern int raw_temp_1_sample; extern int target_temperature_bed; extern float current_temperature_bed; +#if defined FSR_BED_LEVELING +extern int fsr_rolling; +#endif #ifdef TEMP_SENSOR_1_AS_REDUNDANT extern float redundant_temperature; #endif @@ -89,6 +92,12 @@ FORCE_INLINE int rawTemp1Sample(){ return raw_temp_1_sample; } +#if defined FSR_BED_LEVELING +FORCE_INLINE int fsr_rolling_avg(){ + return fsr_rolling; +} +#endif + FORCE_INLINE float degBed() { return current_temperature_bed; }; From d7df3ec51fbfeb1191256c864b37fe393dae3f2d Mon Sep 17 00:00:00 2001 From: Chris Marzano Date: Tue, 29 Jul 2014 09:17:44 -0700 Subject: [PATCH 18/71] Rolling average successfully moved to temperature.cpp. Code compiles. --- Marlin/stepper.cpp | 6 +----- Marlin/temperature.cpp | 9 +++++++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index f200b9fc20c6..76b78d65397c 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -531,7 +531,7 @@ ISR(TIMER1_COMPA_vect) fsr_average /= fsr_checks; // Check if ADC average is above switching threshold - if ((fsr_average > 1.5*fsr_rolling_avg()) || (fsr_average < .8*fsr_rolling_avg) && (fsr_average > 20)){ + if ((fsr_average > 1.2*fsr_rolling_avg()) || (fsr_average < .8*fsr_rolling_avg()) && (fsr_average > 20)){ fsr_trigger = true; fsr_z_endstop = true; } @@ -546,10 +546,6 @@ ISR(TIMER1_COMPA_vect) step_events_completed = current_block->step_event_count; } old_z_min_endstop = fsr_trigger; - // Rolling weighted average adjustment - fsr_rolling_avg = fsr_rolling_avg*fsr_weighting; - fsr_rolling_avg = fsr_rolling_avg+fsr_average; - fsr_rolling_avg = fsr_rolling_avg/(fsr_weighting+1); // End of FSR ABL #elif defined(Z_MIN_PIN) && Z_MIN_PIN > -1 if bool z_min_endstop=(READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING); diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index a18984e950ce..19bce106f3e6 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -44,7 +44,7 @@ float current_temperature[EXTRUDERS] = { 0.0 }; int current_temperature_bed_raw = 0; float current_temperature_bed = 0.0; int raw_temp_1_sample = 0; -int fsr_rolling_avg = 0; +int fsr_rolling = 0; #ifdef TEMP_SENSOR_1_AS_REDUNDANT int redundant_temperature_raw = 0; float redundant_temperature = 0.0; @@ -109,6 +109,11 @@ static volatile bool temp_meas_ready = false; static unsigned long previous_millis_bed_heater; #endif //PIDTEMPBED static unsigned char soft_pwm[EXTRUDERS]; + + #if defined FSR_BED_LEVELING + int fsr_weighting = 3; + int fsr_average = 0; + #endif #ifdef FAN_SOFT_PWM static unsigned char soft_pwm_fan; @@ -1163,7 +1168,7 @@ ISR(TIMER0_COMPB_vect) raw_temp_1_sample = ADC; raw_temp_1_value += raw_temp_1_sample; #if defined FSR_BED_LEVELING - int fsr_weighting = 1; + for (int i=10; i>0; i--){ fsr_average += ADC; } From 1ebfdb20205ea5c1b9312d28fa3bf4d30184be9f Mon Sep 17 00:00:00 2001 From: Chris Marzano Date: Tue, 29 Jul 2014 11:20:10 -0700 Subject: [PATCH 19/71] Several changes to probing region size and FSR filtering. --- Marlin/Configuration.h | 4 ++-- Marlin/stepper.cpp | 2 +- Marlin/temperature.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index fcf759cf770e..c9e298b9e9a3 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -358,8 +358,8 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o // set the rectangle in which to probe #define LEFT_PROBE_BED_POSITION 0 - #define RIGHT_PROBE_BED_POSITION 95 - #define BACK_PROBE_BED_POSITION 103 + #define RIGHT_PROBE_BED_POSITION 75 + #define BACK_PROBE_BED_POSITION 90 #define FRONT_PROBE_BED_POSITION 25 // set the number of grid points per dimension diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index 76b78d65397c..c19890fc5ce0 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -531,7 +531,7 @@ ISR(TIMER1_COMPA_vect) fsr_average /= fsr_checks; // Check if ADC average is above switching threshold - if ((fsr_average > 1.2*fsr_rolling_avg()) || (fsr_average < .8*fsr_rolling_avg()) && (fsr_average > 20)){ + if (((fsr_average > 1.15*fsr_rolling_avg()) || (fsr_average < .9*fsr_rolling_avg()) || (fsr_average > 200)) && (fsr_average > 100)){ fsr_trigger = true; fsr_z_endstop = true; } diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index 19bce106f3e6..9bd294b47375 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -111,7 +111,7 @@ static volatile bool temp_meas_ready = false; static unsigned char soft_pwm[EXTRUDERS]; #if defined FSR_BED_LEVELING - int fsr_weighting = 3; + int fsr_weighting = 8; int fsr_average = 0; #endif From be396ffbfdb7b29535fed199224cb9b379a4dd84 Mon Sep 17 00:00:00 2001 From: Chris Marzano Date: Tue, 29 Jul 2014 13:35:18 -0700 Subject: [PATCH 20/71] Changed filter settings --- Marlin/stepper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index c19890fc5ce0..b8080216ab68 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -531,7 +531,7 @@ ISR(TIMER1_COMPA_vect) fsr_average /= fsr_checks; // Check if ADC average is above switching threshold - if (((fsr_average > 1.15*fsr_rolling_avg()) || (fsr_average < .9*fsr_rolling_avg()) || (fsr_average > 200)) && (fsr_average > 100)){ + if (((fsr_average > 1.15*fsr_rolling_avg()) || (fsr_average < .9*fsr_rolling_avg()) || (fsr_average > 200)) && (fsr_average > 110)){ fsr_trigger = true; fsr_z_endstop = true; } From e04c9d556f6ee53da33c8d4ce4f559ee2110fff0 Mon Sep 17 00:00:00 2001 From: Chris Marzano Date: Tue, 29 Jul 2014 14:34:30 -0700 Subject: [PATCH 21/71] Removed unused files. --- Marlin/forceabl.cpp | 5 ----- Marlin/forceabl.h | 13 ------------- 2 files changed, 18 deletions(-) delete mode 100644 Marlin/forceabl.cpp delete mode 100644 Marlin/forceabl.h diff --git a/Marlin/forceabl.cpp b/Marlin/forceabl.cpp deleted file mode 100644 index 6260cab487a7..000000000000 --- a/Marlin/forceabl.cpp +++ /dev/null @@ -1,5 +0,0 @@ -/* - forceabl.cpp - -*/ - diff --git a/Marlin/forceabl.h b/Marlin/forceabl.h deleted file mode 100644 index 5dd04b38309a..000000000000 --- a/Marlin/forceabl.h +++ /dev/null @@ -1,13 +0,0 @@ -/* - forceabl.h - -*/ - -#ifndef forceabl_h -#define forceabl_h - -#include "Marlin.h" -#include "planner.h" -#endif - -// Public functions \ No newline at end of file From d6a2989c76a681b2d36ff65df3720bc46aaebe02 Mon Sep 17 00:00:00 2001 From: Chris Marzano Date: Tue, 29 Jul 2014 15:51:29 -0700 Subject: [PATCH 22/71] Changed lower trigger point to fix false positive problems. --- Marlin/stepper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index b8080216ab68..e25e889ff15c 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -531,7 +531,7 @@ ISR(TIMER1_COMPA_vect) fsr_average /= fsr_checks; // Check if ADC average is above switching threshold - if (((fsr_average > 1.15*fsr_rolling_avg()) || (fsr_average < .9*fsr_rolling_avg()) || (fsr_average > 200)) && (fsr_average > 110)){ + if (((fsr_average > 1.15*fsr_rolling_avg()) || (fsr_average < .9*fsr_rolling_avg()) || (fsr_average > 200)) && (fsr_average > 125)){ fsr_trigger = true; fsr_z_endstop = true; } From b03d99df1bd026a3f76135e06e35c0c9c7ed1fed Mon Sep 17 00:00:00 2001 From: Chris Marzano Date: Wed, 30 Jul 2014 11:15:07 -0700 Subject: [PATCH 23/71] Added serial output to stepper for debugging. --- Marlin/Configuration.h | 4 ++-- Marlin/stepper.cpp | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index c9e298b9e9a3..b6f09c1e3e4d 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -407,7 +407,7 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o //If you have enabled the Bed Auto Leveling and are using the same Z Probe for Z Homing, //it is highly recommended you let this Z_SAFE_HOMING enabled!!! - #define Z_SAFE_HOMING // This feature is meant to avoid Z homing with probe outside the bed area. + //#define Z_SAFE_HOMING // This feature is meant to avoid Z homing with probe outside the bed area. // When defined, it will: // - Allow Z homing only after X and Y homing AND stepper drivers still enabled // - If stepper drivers timeout, it will need X and Y homing again before Z homing @@ -430,7 +430,7 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o // Without this option set, "G28 Z0" will do a straight Z-home from // anywhere in the bed area. That will cause mayhem on our printer. // - G30 command is disabled, for the same reason. - #define Z_SAFE_HOMING_FIXED_POINT + //#define Z_SAFE_HOMING_FIXED_POINT #endif diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index e25e889ff15c..a3b83f4661f4 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -531,9 +531,15 @@ ISR(TIMER1_COMPA_vect) fsr_average /= fsr_checks; // Check if ADC average is above switching threshold - if (((fsr_average > 1.15*fsr_rolling_avg()) || (fsr_average < .9*fsr_rolling_avg()) || (fsr_average > 200)) && (fsr_average > 125)){ + if (((fsr_average > 2*fsr_rolling_avg()) || (fsr_average < .8*fsr_rolling_avg()) || (fsr_average > 400)) && (fsr_average > 50)){ fsr_trigger = true; fsr_z_endstop = true; + SERIAL_ECHO_START; + SERIAL_ECHOPGM("ADC Avg: "); + SERIAL_ECHOLN(fsr_average); + SERIAL_ECHOPGM(" Rolling Avg: "); + SERIAL_ECHOLN(fsr_rolling_avg()); + SERIAL_PROTOCOLLN(""); } else{ fsr_trigger = false; From 7922e5c15941f99c45acbb94c0cde274c29b092a Mon Sep 17 00:00:00 2001 From: Chris Marzano Date: Wed, 30 Jul 2014 13:28:26 -0700 Subject: [PATCH 24/71] Filter adjustments. --- Marlin/Configuration_adv.h | 2 +- Marlin/stepper.cpp | 2 +- Marlin/temperature.cpp | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index e06ca2ce8164..a8770e2c0603 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -215,7 +215,7 @@ //homing hits the endstop, then retracts by this distance, before it tries to slowly bump again: #define X_HOME_RETRACT_MM 5 #define Y_HOME_RETRACT_MM 5 -#define Z_HOME_RETRACT_MM 1 +#define Z_HOME_RETRACT_MM 3 //#define QUICK_HOME //if this is defined, if both x and y are to be homed, a diagonal move will be performed initially. #define AXIS_RELATIVE_MODES {false, false, false, false} diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index a3b83f4661f4..ffc7bce92d61 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -531,7 +531,7 @@ ISR(TIMER1_COMPA_vect) fsr_average /= fsr_checks; // Check if ADC average is above switching threshold - if (((fsr_average > 2*fsr_rolling_avg()) || (fsr_average < .8*fsr_rolling_avg()) || (fsr_average > 400)) && (fsr_average > 50)){ + if (((fsr_average > 1.3*fsr_rolling_avg()) || (fsr_average < .5*fsr_rolling_avg()) || (fsr_average > 600)) && (fsr_average > 50)){ fsr_trigger = true; fsr_z_endstop = true; SERIAL_ECHO_START; diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index 9bd294b47375..f9d0c570f0fa 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -111,7 +111,7 @@ static volatile bool temp_meas_ready = false; static unsigned char soft_pwm[EXTRUDERS]; #if defined FSR_BED_LEVELING - int fsr_weighting = 8; + int fsr_weighting = 5; int fsr_average = 0; #endif @@ -1169,10 +1169,10 @@ ISR(TIMER0_COMPB_vect) raw_temp_1_value += raw_temp_1_sample; #if defined FSR_BED_LEVELING - for (int i=10; i>0; i--){ + for (int i=5; i>0; i--){ fsr_average += ADC; } - fsr_average /= 10; + fsr_average /= 5; fsr_rolling = fsr_rolling*fsr_weighting; fsr_rolling = fsr_rolling+fsr_average; fsr_rolling = fsr_rolling/(fsr_weighting+1); From 0ebc84858cfdbaa6bc2e8d08d755a04411cc94aa Mon Sep 17 00:00:00 2001 From: Chris Marzano Date: Wed, 30 Jul 2014 14:23:47 -0700 Subject: [PATCH 25/71] Attempt at moving all code into stepper.cpp since values from temperature.cpp are not updated while in the endstop ISR. --- Marlin/Marlin_main.cpp | 12 +++----- Marlin/pins.h | 3 +- Marlin/stepper.cpp | 62 ++++++++++++++++++++++++++++-------------- Marlin/temperature.cpp | 15 ---------- Marlin/temperature.h | 9 ------ 5 files changed, 48 insertions(+), 53 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index aedb85ee04f8..09cd44b74df3 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -185,6 +185,8 @@ //=============================imported variables============================ //=========================================================================== extern bool fsr_z_endstop; +extern int fsr_rolling_avg; +extern int fsr_average; //=========================================================================== //=============================public variables============================= @@ -2793,17 +2795,11 @@ void process_commands() } case 505: // M505 Test function for FSR ABL { - int fsr_starting_level; - for (int i=10; i>0; i--){ - fsr_starting_level += rawTemp1Sample(); - } - fsr_starting_level /= 10; - SERIAL_ECHO_START; SERIAL_ECHOPGM("ADC Reading: "); - SERIAL_ECHOLN(fsr_starting_level); + SERIAL_ECHOLN(fsr_average); SERIAL_ECHOPGM(" Rolling Avg: "); - SERIAL_ECHOLN(fsr_rolling_avg()); + SERIAL_ECHOLN(fsr_rolling_avg); SERIAL_PROTOCOLLN(""); } break; diff --git a/Marlin/pins.h b/Marlin/pins.h index b11b4302fb85..1bea0018cc96 100644 --- a/Marlin/pins.h +++ b/Marlin/pins.h @@ -1556,6 +1556,7 @@ #define LED_RED_PIN 11 #define LED_BUTTON_PIN 12 #define Z_STOP_MAX_PIN 37 // 25 +#define FSR_PIN 2 // ADC PIN #endif #define X_STEP_PIN 0 @@ -1596,7 +1597,7 @@ #define TEMP_BED_PIN 0 // Bed / Analog pin numbering #endif -#define TEMP_1_PIN 2 // Pin for FSR ABL (#40, bottom left of EXP1) +#define TEMP_1_PIN -1 // Pin for FSR ABL (#40, bottom left of EXP1) #define TEMP_2_PIN -1 #define SDPOWER -1 diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index ffc7bce92d61..c190b4382f70 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -40,6 +40,8 @@ block_t *current_block; // A pointer to the block currently being traced #ifdef FSR_BED_LEVELING bool fsr_z_endstop; // Public variable to fix m119 code +int fsr_rolling_avg; // The rolling average as calculated per loop +int fsr_average; // Calculated average of fsr adc readings #endif @@ -517,35 +519,54 @@ ISR(TIMER1_COMPA_vect) count_direction[Z_AXIS]=-1; CHECK_ENDSTOPS { - #if defined (FSR_BED_LEVELING) && defined(TEMP_1_PIN) && TEMP_1_PIN > -1 - int fsr_average; - // Additional weighting slows the movement of the rolling average - int fsr_weighting = 1; - // Number of readings to average - int fsr_checks = 20; - bool fsr_trigger = false; - // Sample and average for fsr_checks - for (int i=fsr_checks; i>0; i--){ - fsr_average += rawTemp1Sample(); - } - fsr_average /= fsr_checks; - - // Check if ADC average is above switching threshold - if (((fsr_average > 1.3*fsr_rolling_avg()) || (fsr_average < .5*fsr_rolling_avg()) || (fsr_average > 600)) && (fsr_average > 50)){ + #if defined (FSR_BED_LEVELING) && defined(FSR_PIN) && FSR_PIN > -1 + // Setup FSR ADC pin + #if FSR_PIN > 7 + ADCSRB = 1<0; i--){ + fsr_rolling_avg += ADC; + } + fsr_rolling_avg /= fsr_checks; + + + while (fsr_trigger = false){ + // Test adc for fsr_checks and average + for (int i=fsr_checks; i>0; i--){ + fsr_average += ADC; + } + fsr_average /= fsr_checks; + + // Escape when endstop trigger conditions are met + if (((fsr_average > 1.3*fsr_rolling_avg) || (fsr_average < .5*fsr_rolling_avg) || (fsr_average > 600)) && (fsr_average > 50)){ fsr_trigger = true; fsr_z_endstop = true; SERIAL_ECHO_START; SERIAL_ECHOPGM("ADC Avg: "); SERIAL_ECHOLN(fsr_average); SERIAL_ECHOPGM(" Rolling Avg: "); - SERIAL_ECHOLN(fsr_rolling_avg()); + SERIAL_ECHOLN(fsr_rolling_avg); SERIAL_PROTOCOLLN(""); } - else{ - fsr_trigger = false; - fsr_z_endstop = false; + // Update rolling average + else{ + fsr_rolling_avg = fsr_rolling_avg*fsr_weighting; + fsr_rolling_avg = fsr_rolling_avg+fsr_average; + fsr_rolling_avg = fsr_rolling_avg/(fsr_weighting+1); } - // Run endstop triggered logic + } + // Run endstop triggered logic, fsr_trigger signals endstop status if(fsr_trigger && old_z_min_endstop && (current_block->steps_z > 0)) { endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS]; endstop_z_hit=true; @@ -553,6 +574,7 @@ ISR(TIMER1_COMPA_vect) } old_z_min_endstop = fsr_trigger; // End of FSR ABL + #elif defined(Z_MIN_PIN) && Z_MIN_PIN > -1 if bool z_min_endstop=(READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING); if(z_min_endstop && old_z_min_endstop && (current_block->steps_z > 0)) { diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index f9d0c570f0fa..13dc63cb85b1 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -110,11 +110,6 @@ static volatile bool temp_meas_ready = false; #endif //PIDTEMPBED static unsigned char soft_pwm[EXTRUDERS]; - #if defined FSR_BED_LEVELING - int fsr_weighting = 5; - int fsr_average = 0; - #endif - #ifdef FAN_SOFT_PWM static unsigned char soft_pwm_fan; #endif @@ -1167,16 +1162,6 @@ ISR(TIMER0_COMPB_vect) #if defined(TEMP_1_PIN) && (TEMP_1_PIN > -1) raw_temp_1_sample = ADC; raw_temp_1_value += raw_temp_1_sample; - #if defined FSR_BED_LEVELING - - for (int i=5; i>0; i--){ - fsr_average += ADC; - } - fsr_average /= 5; - fsr_rolling = fsr_rolling*fsr_weighting; - fsr_rolling = fsr_rolling+fsr_average; - fsr_rolling = fsr_rolling/(fsr_weighting+1); - #endif #endif temp_state = 6; break; diff --git a/Marlin/temperature.h b/Marlin/temperature.h index e207f693c952..6e6f01a44085 100644 --- a/Marlin/temperature.h +++ b/Marlin/temperature.h @@ -42,9 +42,6 @@ extern float current_temperature[EXTRUDERS]; extern int raw_temp_1_sample; extern int target_temperature_bed; extern float current_temperature_bed; -#if defined FSR_BED_LEVELING -extern int fsr_rolling; -#endif #ifdef TEMP_SENSOR_1_AS_REDUNDANT extern float redundant_temperature; #endif @@ -92,12 +89,6 @@ FORCE_INLINE int rawTemp1Sample(){ return raw_temp_1_sample; } -#if defined FSR_BED_LEVELING -FORCE_INLINE int fsr_rolling_avg(){ - return fsr_rolling; -} -#endif - FORCE_INLINE float degBed() { return current_temperature_bed; }; From 3e42832068d19502f9f92250a7874010fee78ce9 Mon Sep 17 00:00:00 2001 From: Chris Marzano Date: Wed, 30 Jul 2014 16:03:10 -0700 Subject: [PATCH 26/71] Created fsr_abl.cpp and .h. Files contain functions needed for FSR ABL. Not compiling due to undefined references. --- Marlin/Marlin_main.cpp | 14 ++++---- Marlin/fsr_abl.cpp | 72 ++++++++++++++++++++++++++++++++++++++++++ Marlin/fsr_abl.h | 13 ++++++++ Marlin/stepper.cpp | 61 ++++------------------------------- Marlin/temperature.cpp | 4 +++ 5 files changed, 103 insertions(+), 61 deletions(-) create mode 100644 Marlin/fsr_abl.cpp create mode 100644 Marlin/fsr_abl.h diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 09cd44b74df3..6ed35807bd52 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -61,6 +61,10 @@ #include #endif +#if defined FSR_BED_LEVELING +#include "fsr_abl.h" +#endif + #define VERSION_STRING "1.0.0" // look here for descriptions of G-codes: http://linuxcnc.org/handbook/gcode/g-code.html @@ -184,9 +188,7 @@ //=========================================================================== //=============================imported variables============================ //=========================================================================== -extern bool fsr_z_endstop; -extern int fsr_rolling_avg; -extern int fsr_average; +//extern bool fsr_z_endstop; //=========================================================================== //=============================public variables============================= @@ -2321,7 +2323,7 @@ void process_commands() #endif #if defined FSR_BED_LEVELING SERIAL_PROTOCOLPGM(MSG_Z_MIN); - SERIAL_PROTOCOLLN((fsr_z_endstop?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN)); + //SERIAL_PROTOCOLLN((fsr_z_endstop?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN)); #elif defined(Z_MIN_PIN) && Z_MIN_PIN > -1 SERIAL_PROTOCOLPGM(MSG_Z_MIN); SERIAL_PROTOCOLLN(((READ(Z_MIN_PIN)^Z_MIN_ENDSTOP_INVERTING)?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN)); @@ -2797,9 +2799,9 @@ void process_commands() { SERIAL_ECHO_START; SERIAL_ECHOPGM("ADC Reading: "); - SERIAL_ECHOLN(fsr_average); + SERIAL_ECHOLN(FSR_ABL_Reading()); SERIAL_ECHOPGM(" Rolling Avg: "); - SERIAL_ECHOLN(fsr_rolling_avg); + SERIAL_ECHOLN(FSR_ABL_Get_Avg()); SERIAL_PROTOCOLLN(""); } break; diff --git a/Marlin/fsr_abl.cpp b/Marlin/fsr_abl.cpp new file mode 100644 index 000000000000..f28cc0884575 --- /dev/null +++ b/Marlin/fsr_abl.cpp @@ -0,0 +1,72 @@ +/* + fsr_abl.cpp contains the functions needed to operate automatic bed leveling with force sensing resistors. + +*/ +#if defined (FSR_BED_LEVELING) && defined (FSR_PIN) && (FSR_PIN > -1) +// Public Variables + +// Private Variables (static preserves between function calls and prevents calling by extern) +static int fsr_rolling_avg; +static int fsr_weighting = 1; +static int fsr_checks = 5; // Number of times to run ADC + +int FSR_ABL_Reading() +{ + int fsr_reading = 0; + #if defined FSR_PIN && FSR_PIN > -1 + // Averages fsr_checks readings + for (int i=fsr_checks; i>0; i--){ + #if FSR_PIN > 7 + ADCSRB = 1< 7 + ADCSRB = 1< 1.3*fsr_rolling_avg) || (fsr_reading < .5*fsr_rolling_avg) || (fsr_reading > 600)) && (fsr_reading > 50)){ + SERIAL_ECHO_START; + SERIAL_ECHOPGM("Read: "); + SERIAL_ECHOLN(fsr_reading); + SERIAL_ECHOPGM(" Roll: "); + SERIAL_ECHOLN(fsr_rolling_avg); + SERIAL_PROTOCOLLN(""); + return(true); + } + // Update rolling average + else{ + //fsr_rolling_avg = fsr_rolling_avg*fsr_weighting; + //fsr_rolling_avg = fsr_rolling_avg+fsr_reading; + //fsr_rolling_avg = fsr_rolling_avg/(fsr_weighting+1); + return(false); + } +} + +#endif diff --git a/Marlin/fsr_abl.h b/Marlin/fsr_abl.h new file mode 100644 index 000000000000..cb0d0c01ea69 --- /dev/null +++ b/Marlin/fsr_abl.h @@ -0,0 +1,13 @@ +/* + fsr_abl.h contains the functions needed to operate automatic bed leveling with force sensing resistors. + +*/ +#ifndef fsr_abl_h +#define fsr_abl_h +#endif + +#ifdef FSR_BED_LEVELING +int FSR_ABL_Reading(); +int FSR_ABL_Get_Avg(); +bool FSR_ABL_Trigger(); +#endif \ No newline at end of file diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index c190b4382f70..a8561ca3c0db 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -29,6 +29,9 @@ #include "language.h" #include "cardreader.h" #include "speed_lookuptable.h" +#if defined FSR_BED_LEVELING +#include "fsr_abl.h" +#endif #if defined(DIGIPOTSS_PIN) && DIGIPOTSS_PIN > -1 #include #endif @@ -38,12 +41,6 @@ //=============================public variables ============================ //=========================================================================== block_t *current_block; // A pointer to the block currently being traced -#ifdef FSR_BED_LEVELING -bool fsr_z_endstop; // Public variable to fix m119 code -int fsr_rolling_avg; // The rolling average as calculated per loop -int fsr_average; // Calculated average of fsr adc readings -#endif - //=========================================================================== //=============================private variables ============================ @@ -519,60 +516,14 @@ ISR(TIMER1_COMPA_vect) count_direction[Z_AXIS]=-1; CHECK_ENDSTOPS { - #if defined (FSR_BED_LEVELING) && defined(FSR_PIN) && FSR_PIN > -1 - // Setup FSR ADC pin - #if FSR_PIN > 7 - ADCSRB = 1<0; i--){ - fsr_rolling_avg += ADC; - } - fsr_rolling_avg /= fsr_checks; - - - while (fsr_trigger = false){ - // Test adc for fsr_checks and average - for (int i=fsr_checks; i>0; i--){ - fsr_average += ADC; - } - fsr_average /= fsr_checks; - - // Escape when endstop trigger conditions are met - if (((fsr_average > 1.3*fsr_rolling_avg) || (fsr_average < .5*fsr_rolling_avg) || (fsr_average > 600)) && (fsr_average > 50)){ - fsr_trigger = true; - fsr_z_endstop = true; - SERIAL_ECHO_START; - SERIAL_ECHOPGM("ADC Avg: "); - SERIAL_ECHOLN(fsr_average); - SERIAL_ECHOPGM(" Rolling Avg: "); - SERIAL_ECHOLN(fsr_rolling_avg); - SERIAL_PROTOCOLLN(""); - } - // Update rolling average - else{ - fsr_rolling_avg = fsr_rolling_avg*fsr_weighting; - fsr_rolling_avg = fsr_rolling_avg+fsr_average; - fsr_rolling_avg = fsr_rolling_avg/(fsr_weighting+1); - } - } + #if defined (FSR_BED_LEVELING) && defined(FSR_PIN) && FSR_PIN > -1 // Run endstop triggered logic, fsr_trigger signals endstop status - if(fsr_trigger && old_z_min_endstop && (current_block->steps_z > 0)) { + if(FSR_ABL_Trigger() && old_z_min_endstop && (current_block->steps_z > 0)) { endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS]; endstop_z_hit=true; step_events_completed = current_block->step_event_count; } - old_z_min_endstop = fsr_trigger; + old_z_min_endstop = FSR_ABL_Trigger(); // End of FSR ABL #elif defined(Z_MIN_PIN) && Z_MIN_PIN > -1 diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index 13dc63cb85b1..063064ff078a 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -33,6 +33,9 @@ #include "ultralcd.h" #include "temperature.h" #include "watchdog.h" +#if defined FSR_BED_LEVELING +#include "fsr_abl.h" +#endif //=========================================================================== //=============================public variables============================ @@ -1187,6 +1190,7 @@ ISR(TIMER0_COMPB_vect) break; case 8: //Startup, delay initial temp reading a tiny bit so the hardware can settle. temp_state = 0; + FSR_ABL_Reading(); break; // default: // SERIAL_ERROR_START; From c78876bd7a7a93a2d9af6017da6573187395cdc7 Mon Sep 17 00:00:00 2001 From: Chris Marzano Date: Wed, 30 Jul 2014 16:12:59 -0700 Subject: [PATCH 27/71] Removed old lines of code from temperature.cpp. --- Marlin/temperature.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index 063064ff078a..2d137a189699 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -46,8 +46,6 @@ int current_temperature_raw[EXTRUDERS] = { 0 }; float current_temperature[EXTRUDERS] = { 0.0 }; int current_temperature_bed_raw = 0; float current_temperature_bed = 0.0; -int raw_temp_1_sample = 0; -int fsr_rolling = 0; #ifdef TEMP_SENSOR_1_AS_REDUNDANT int redundant_temperature_raw = 0; float redundant_temperature = 0.0; From 9016256b7695f4a66b6329e30580ad553c51d296 Mon Sep 17 00:00:00 2001 From: Chris Marzano Date: Wed, 30 Jul 2014 16:47:45 -0700 Subject: [PATCH 28/71] Code now compiles with fsr_abl.cpp. --- Marlin/fsr_abl.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Marlin/fsr_abl.cpp b/Marlin/fsr_abl.cpp index f28cc0884575..d6b275e196f3 100644 --- a/Marlin/fsr_abl.cpp +++ b/Marlin/fsr_abl.cpp @@ -2,7 +2,10 @@ fsr_abl.cpp contains the functions needed to operate automatic bed leveling with force sensing resistors. */ -#if defined (FSR_BED_LEVELING) && defined (FSR_PIN) && (FSR_PIN > -1) +//#ifdef FSR_BED_LEVELING //&& defined FSR_PIN && FSR_PIN > -1 +#include "fsr_abl.h" +#include "Marlin.h" + // Public Variables // Private Variables (static preserves between function calls and prevents calling by extern) @@ -30,7 +33,7 @@ int FSR_ABL_Reading() fsr_rolling_avg = fsr_rolling_avg+fsr_reading; fsr_rolling_avg = fsr_rolling_avg/(fsr_weighting+1); #endif - return(fsr_reading) + return(fsr_reading); } int FSR_ABL_Get_Avg() @@ -68,5 +71,4 @@ if (((fsr_reading > 1.3*fsr_rolling_avg) || (fsr_reading < .5*fsr_rolling_avg) | return(false); } } - -#endif +//#endif From 66d47755f16c83b1a7cbe0cd320070a2f1a56759 Mon Sep 17 00:00:00 2001 From: Chris Marzano Date: Wed, 30 Jul 2014 19:00:47 -0700 Subject: [PATCH 29/71] Fixed FSR reading and averaging. --- Marlin/Marlin_main.cpp | 4 ++-- Marlin/fsr_abl.cpp | 47 ++++++++++++----------------------------- Marlin/fsr_abl.h | 1 + Marlin/stepper.cpp | 2 +- Marlin/temperature.cpp | 48 +++++++++++++++++++++++++++++++++++++----- Marlin/temperature.h | 10 +++++++++ 6 files changed, 70 insertions(+), 42 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 6ed35807bd52..07c2cc64d53f 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -188,7 +188,7 @@ //=========================================================================== //=============================imported variables============================ //=========================================================================== -//extern bool fsr_z_endstop; + //=========================================================================== //=============================public variables============================= @@ -2799,7 +2799,7 @@ void process_commands() { SERIAL_ECHO_START; SERIAL_ECHOPGM("ADC Reading: "); - SERIAL_ECHOLN(FSR_ABL_Reading()); + SERIAL_ECHOLN(FSR_ABL_Get_Read()); SERIAL_ECHOPGM(" Rolling Avg: "); SERIAL_ECHOLN(FSR_ABL_Get_Avg()); SERIAL_PROTOCOLLN(""); diff --git a/Marlin/fsr_abl.cpp b/Marlin/fsr_abl.cpp index d6b275e196f3..899ab904bf0b 100644 --- a/Marlin/fsr_abl.cpp +++ b/Marlin/fsr_abl.cpp @@ -5,35 +5,25 @@ //#ifdef FSR_BED_LEVELING //&& defined FSR_PIN && FSR_PIN > -1 #include "fsr_abl.h" #include "Marlin.h" +#include "temperature.h" // Public Variables // Private Variables (static preserves between function calls and prevents calling by extern) static int fsr_rolling_avg; static int fsr_weighting = 1; -static int fsr_checks = 5; // Number of times to run ADC +static int fsr_checks = 1; // Number of times to run ADC -int FSR_ABL_Reading() +void FSR_ABL_Reading() { - int fsr_reading = 0; - #if defined FSR_PIN && FSR_PIN > -1 - // Averages fsr_checks readings - for (int i=fsr_checks; i>0; i--){ - #if FSR_PIN > 7 - ADCSRB = 1< 7 - ADCSRB = 1< 1.3*fsr_rolling_avg) || (fsr_reading < .5*fsr_rolling_avg) || (fsr_reading > 600)) && (fsr_reading > 50)){ +if (((current_fsr_sample() > 1.3*fsr_rolling_avg) || (current_fsr_sample() < .5*fsr_rolling_avg) || (current_fsr_sample() > 600)) && (current_fsr_sample() > 50)){ SERIAL_ECHO_START; SERIAL_ECHOPGM("Read: "); - SERIAL_ECHOLN(fsr_reading); + SERIAL_ECHOLN(current_fsr_sample()); SERIAL_ECHOPGM(" Roll: "); SERIAL_ECHOLN(fsr_rolling_avg); SERIAL_PROTOCOLLN(""); @@ -65,9 +46,7 @@ if (((fsr_reading > 1.3*fsr_rolling_avg) || (fsr_reading < .5*fsr_rolling_avg) | } // Update rolling average else{ - //fsr_rolling_avg = fsr_rolling_avg*fsr_weighting; - //fsr_rolling_avg = fsr_rolling_avg+fsr_reading; - //fsr_rolling_avg = fsr_rolling_avg/(fsr_weighting+1); + // Do nothing but return false return(false); } } diff --git a/Marlin/fsr_abl.h b/Marlin/fsr_abl.h index cb0d0c01ea69..543edfc6ddcb 100644 --- a/Marlin/fsr_abl.h +++ b/Marlin/fsr_abl.h @@ -8,6 +8,7 @@ #ifdef FSR_BED_LEVELING int FSR_ABL_Reading(); +int FSR_ABL_Get_Read(); int FSR_ABL_Get_Avg(); bool FSR_ABL_Trigger(); #endif \ No newline at end of file diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index a8561ca3c0db..eb5f4e74e1df 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -516,7 +516,7 @@ ISR(TIMER1_COMPA_vect) count_direction[Z_AXIS]=-1; CHECK_ENDSTOPS { - #if defined (FSR_BED_LEVELING) && defined(FSR_PIN) && FSR_PIN > -1 + #if defined FSR_BED_LEVELING && defined FSR_PIN && FSR_PIN > -1 // Run endstop triggered logic, fsr_trigger signals endstop status if(FSR_ABL_Trigger() && old_z_min_endstop && (current_block->steps_z > 0)) { endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS]; diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index 2d137a189699..e117f7e03021 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -46,6 +46,10 @@ int current_temperature_raw[EXTRUDERS] = { 0 }; float current_temperature[EXTRUDERS] = { 0.0 }; int current_temperature_bed_raw = 0; float current_temperature_bed = 0.0; +#if defined FSR_BED_LEVELING +int current_fsr_value = 0; +#endif + #ifdef TEMP_SENSOR_1_AS_REDUNDANT int redundant_temperature_raw = 0; float redundant_temperature = 0.0; @@ -213,7 +217,6 @@ void PID_autotune(float temp, int extruder, int ncycles) if(temp_meas_ready == true) { // temp sample ready updateTemperaturesFromRawValues(); - input = (extruder<0)?current_temperature_bed:current_temperature[extruder]; max=max(max,input); @@ -282,7 +285,7 @@ void PID_autotune(float temp, int extruder, int ncycles) cycles++; min=temp; } - } + } } if(input > (temp + 20)) { SERIAL_PROTOCOLLNPGM("PID Autotune failed! Temperature too high"); @@ -688,6 +691,10 @@ static void updateTemperaturesFromRawValues() #ifdef TEMP_SENSOR_1_AS_REDUNDANT redundant_temperature = analog2temp(redundant_temperature_raw, 1); #endif + #if defined FSR_BED_LEVELING + FSR_ABL_Reading(); + #endif + //Reset the watchdog after we know we have a temperature measurement. watchdog_reset(); @@ -1043,7 +1050,7 @@ ISR(TIMER0_COMPB_vect) static unsigned long raw_temp_1_value = 0; static unsigned long raw_temp_2_value = 0; static unsigned long raw_temp_bed_value = 0; - static unsigned char temp_state = 8; + static unsigned char temp_state = 9; static unsigned char pwm_count = (1 << SOFT_PWM_SCALE); static unsigned char soft_pwm_0; #if (EXTRUDERS > 1) || defined(HEATERS_PARALLEL) @@ -1056,6 +1063,10 @@ ISR(TIMER0_COMPB_vect) static unsigned char soft_pwm_b; #endif + #if defined FSR_BED_LEVELING + static unsigned long raw_fsr_value = 0; + #endif + if(pwm_count == 0){ soft_pwm_0 = soft_pwm[0]; if(soft_pwm_0 > 0) { @@ -1183,12 +1194,32 @@ ISR(TIMER0_COMPB_vect) #if defined(TEMP_2_PIN) && (TEMP_2_PIN > -1) raw_temp_2_value += ADC; #endif + temp_state = 8; + #ifndef FSR_BED_LEVELING temp_state = 0; temp_count++; + #endif break; - case 8: //Startup, delay initial temp reading a tiny bit so the hardware can settle. + case 8: // Prepare for FSR_ABL measurement + #if defined FSR_BED_LEVELING && FSR_PIN && FSR_PIN > -1 + #if FSR_PIN > 7 + ADCSRB = 1< -1 + raw_fsr_value = ADC; + #endif + temp_state = 0; + temp_count++; + case 10: //Startup, delay initial temp reading a tiny bit so the hardware can settle. temp_state = 0; - FSR_ABL_Reading(); break; // default: // SERIAL_ERROR_START; @@ -1211,6 +1242,10 @@ ISR(TIMER0_COMPB_vect) current_temperature_raw[2] = raw_temp_2_value; #endif current_temperature_bed_raw = raw_temp_bed_value; + + #if defined FSR_BED_LEVELING + current_fsr_value = raw_fsr_value; + #endif } temp_meas_ready = true; @@ -1219,6 +1254,9 @@ ISR(TIMER0_COMPB_vect) raw_temp_1_value = 0; raw_temp_2_value = 0; raw_temp_bed_value = 0; + #if defined FSR_BED_LEVELING + raw_fsr_value = 0; + #endif #if HEATER_0_RAW_LO_TEMP > HEATER_0_RAW_HI_TEMP if(current_temperature_raw[0] <= maxttemp_raw[0]) { diff --git a/Marlin/temperature.h b/Marlin/temperature.h index 6e6f01a44085..ad245986fa38 100644 --- a/Marlin/temperature.h +++ b/Marlin/temperature.h @@ -42,6 +42,10 @@ extern float current_temperature[EXTRUDERS]; extern int raw_temp_1_sample; extern int target_temperature_bed; extern float current_temperature_bed; +#if defined FSR_BED_LEVELING +extern int current_fsr_value; +#endif + #ifdef TEMP_SENSOR_1_AS_REDUNDANT extern float redundant_temperature; #endif @@ -85,6 +89,12 @@ FORCE_INLINE float degHotend(uint8_t extruder) { }; #endif +#ifdef FSR_BED_LEVELING + FORCE_INLINE int current_fsr_sample(){ + return current_fsr_value; +} +#endif + FORCE_INLINE int rawTemp1Sample(){ return raw_temp_1_sample; } From 37e78bd06e08e00214d6702a94102398b6bddcc5 Mon Sep 17 00:00:00 2001 From: Chris Marzano Date: Wed, 30 Jul 2014 19:05:25 -0700 Subject: [PATCH 30/71] Still having problems with hotend not re-approaching endstop after first contact. --- Marlin/fsr_abl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/fsr_abl.cpp b/Marlin/fsr_abl.cpp index 899ab904bf0b..10c06e2fc539 100644 --- a/Marlin/fsr_abl.cpp +++ b/Marlin/fsr_abl.cpp @@ -11,7 +11,7 @@ // Private Variables (static preserves between function calls and prevents calling by extern) static int fsr_rolling_avg; -static int fsr_weighting = 1; +static float fsr_weighting = .25; static int fsr_checks = 1; // Number of times to run ADC void FSR_ABL_Reading() From ab8a470f96111f9ac0f2dcf5d33d20aeda7ebb70 Mon Sep 17 00:00:00 2001 From: Chris Marzano Date: Thu, 31 Jul 2014 13:47:19 -0700 Subject: [PATCH 31/71] Updated comments. --- Marlin/fsr_abl.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Marlin/fsr_abl.cpp b/Marlin/fsr_abl.cpp index 10c06e2fc539..c273ddccf69d 100644 --- a/Marlin/fsr_abl.cpp +++ b/Marlin/fsr_abl.cpp @@ -14,6 +14,7 @@ static int fsr_rolling_avg; static float fsr_weighting = .25; static int fsr_checks = 1; // Number of times to run ADC +// Updates rolling average with most recent value from ADC void FSR_ABL_Reading() { fsr_rolling_avg = fsr_rolling_avg*fsr_weighting; @@ -21,11 +22,13 @@ void FSR_ABL_Reading() fsr_rolling_avg = fsr_rolling_avg/(fsr_weighting+1); } +// Returns most recent sampled value from ADC int FSR_ABL_Get_Read() { return(current_fsr_sample()); } +// Returns the current rolling average int FSR_ABL_Get_Avg() { return(fsr_rolling_avg); @@ -44,8 +47,7 @@ if (((current_fsr_sample() > 1.3*fsr_rolling_avg) || (current_fsr_sample() < .5* SERIAL_PROTOCOLLN(""); return(true); } - // Update rolling average - else{ +else{ // Do nothing but return false return(false); } From 234ac9922ec841be6b6a365d5b897322ee73a4f3 Mon Sep 17 00:00:00 2001 From: Chris Marzano Date: Thu, 31 Jul 2014 14:15:33 -0700 Subject: [PATCH 32/71] Removed serial output from FSR_ABL_Trigger function. --- Marlin/fsr_abl.cpp | 4 ++-- Marlin/stepper.cpp | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Marlin/fsr_abl.cpp b/Marlin/fsr_abl.cpp index c273ddccf69d..e4ae92badddf 100644 --- a/Marlin/fsr_abl.cpp +++ b/Marlin/fsr_abl.cpp @@ -39,12 +39,12 @@ bool FSR_ABL_Trigger() { // Check filter for trigger conditions if (((current_fsr_sample() > 1.3*fsr_rolling_avg) || (current_fsr_sample() < .5*fsr_rolling_avg) || (current_fsr_sample() > 600)) && (current_fsr_sample() > 50)){ - SERIAL_ECHO_START; + /* SERIAL_ECHO_START; SERIAL_ECHOPGM("Read: "); SERIAL_ECHOLN(current_fsr_sample()); SERIAL_ECHOPGM(" Roll: "); SERIAL_ECHOLN(fsr_rolling_avg); - SERIAL_PROTOCOLLN(""); + SERIAL_PROTOCOLLN(""); */ return(true); } else{ diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index eb5f4e74e1df..b9c4550236fd 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -518,12 +518,13 @@ ISR(TIMER1_COMPA_vect) { #if defined FSR_BED_LEVELING && defined FSR_PIN && FSR_PIN > -1 // Run endstop triggered logic, fsr_trigger signals endstop status - if(FSR_ABL_Trigger() && old_z_min_endstop && (current_block->steps_z > 0)) { + bool fsr_trigger = FSR_ABL_Trigger(); + if(fsr_trigger && old_z_min_endstop && (current_block->steps_z > 0)) { endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS]; endstop_z_hit=true; step_events_completed = current_block->step_event_count; } - old_z_min_endstop = FSR_ABL_Trigger(); + old_z_min_endstop = fsr_trigger; // End of FSR ABL #elif defined(Z_MIN_PIN) && Z_MIN_PIN > -1 From 05c575eeeee33ad0de2dbcd9960010337644fd41 Mon Sep 17 00:00:00 2001 From: Joe Marino Date: Thu, 31 Jul 2014 15:00:28 -0700 Subject: [PATCH 33/71] Force retract in Z homing Forcing the Z axis to retract by 5 during Z homing --- Marlin/Marlin_main.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 07c2cc64d53f..7077c3c0cdac 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -1076,6 +1076,13 @@ static void homeaxis(int axis) { current_position[axis] = 0; plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); + + if (axis == Z_AXIS) { + destination[axis] = 5; + plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); + st_synchronize(); + } + destination[axis] = -home_retract_mm(axis) * axis_home_dir; plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); st_synchronize(); From e740191b61e255930e334ecba4a95b52354be17e Mon Sep 17 00:00:00 2001 From: Chris Marzano Date: Thu, 31 Jul 2014 16:43:08 -0700 Subject: [PATCH 34/71] Changed ABL filter weighting. --- Marlin/fsr_abl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/fsr_abl.cpp b/Marlin/fsr_abl.cpp index e4ae92badddf..88cc2bda0188 100644 --- a/Marlin/fsr_abl.cpp +++ b/Marlin/fsr_abl.cpp @@ -11,7 +11,7 @@ // Private Variables (static preserves between function calls and prevents calling by extern) static int fsr_rolling_avg; -static float fsr_weighting = .25; +static float fsr_weighting = 8; static int fsr_checks = 1; // Number of times to run ADC // Updates rolling average with most recent value from ADC From 49807d1eabbdddfba3579f3f7f419362505d6bc6 Mon Sep 17 00:00:00 2001 From: Chris Marzano Date: Thu, 31 Jul 2014 17:38:56 -0700 Subject: [PATCH 35/71] Additional filter adjustments. --- Marlin/fsr_abl.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Marlin/fsr_abl.cpp b/Marlin/fsr_abl.cpp index 88cc2bda0188..e3a9e5ca910f 100644 --- a/Marlin/fsr_abl.cpp +++ b/Marlin/fsr_abl.cpp @@ -11,7 +11,7 @@ // Private Variables (static preserves between function calls and prevents calling by extern) static int fsr_rolling_avg; -static float fsr_weighting = 8; +static float fsr_weighting = 4; static int fsr_checks = 1; // Number of times to run ADC // Updates rolling average with most recent value from ADC @@ -39,12 +39,12 @@ bool FSR_ABL_Trigger() { // Check filter for trigger conditions if (((current_fsr_sample() > 1.3*fsr_rolling_avg) || (current_fsr_sample() < .5*fsr_rolling_avg) || (current_fsr_sample() > 600)) && (current_fsr_sample() > 50)){ - /* SERIAL_ECHO_START; + SERIAL_ECHO_START; SERIAL_ECHOPGM("Read: "); SERIAL_ECHOLN(current_fsr_sample()); SERIAL_ECHOPGM(" Roll: "); SERIAL_ECHOLN(fsr_rolling_avg); - SERIAL_PROTOCOLLN(""); */ + SERIAL_PROTOCOLLN(""); return(true); } else{ From fe40975d6995b9645275a9c90b2b356a81dcfed9 Mon Sep 17 00:00:00 2001 From: Joe Marino Date: Fri, 1 Aug 2014 11:16:52 -0700 Subject: [PATCH 36/71] Remove the retract during homing and ABL --- Marlin/Marlin_main.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 7077c3c0cdac..d47f50f6a9b1 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -929,17 +929,18 @@ static void run_z_probe() { zPosition = st_get_position_mm(Z_AXIS); plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], zPosition, current_position[E_AXIS]); + // move up the retract distance zPosition += home_retract_mm(Z_AXIS); plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], zPosition, current_position[E_AXIS], feedrate/60, active_extruder); st_synchronize(); - // move back down slowly to find bed +/* // move back down slowly to find bed feedrate = homing_feedrate[Z_AXIS]/4; zPosition -= home_retract_mm(Z_AXIS) * 2; plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], zPosition, current_position[E_AXIS], feedrate/60, active_extruder); st_synchronize(); - +*/ current_position[Z_AXIS] = st_get_position_mm(Z_AXIS); // make sure the planner knows where we are as it may be a bit different than we last said to move to plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); @@ -1076,7 +1077,7 @@ static void homeaxis(int axis) { current_position[axis] = 0; plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); - +/* if (axis == Z_AXIS) { destination[axis] = 5; plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); @@ -1103,7 +1104,7 @@ static void homeaxis(int axis) { plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); st_synchronize(); } -#endif +#endif*/ axis_is_at_home(axis); destination[axis] = current_position[axis]; feedrate = 0.0; From f22ea0ea43531af3b8c0e7564afd8f9d5d2116d8 Mon Sep 17 00:00:00 2001 From: Joe Marino Date: Mon, 4 Aug 2014 14:39:16 -0700 Subject: [PATCH 37/71] G405 at startup and fix endstop enable System will now Z-Max when Marlin starts Also, the endstops were not disabled at the end of G405 for ENDSTOPS_FOR_HOMING_ONLY, this has been corrected --- Marlin/Marlin_main.cpp | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index d47f50f6a9b1..b42a35cf9db9 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -535,6 +535,28 @@ void setup() pinMode(LED_BUTTON_PIN, OUTPUT); digitalWrite(LED_BUTTON_PIN,HIGH); + + enable_endstops(true); + + // clear any existing bed level matix + plan_bed_level_matrix.set_to_identity(); + + feedrate = homing_feedrate[Z_AXIS]; + + // bed until it hits the z_max_endstop + float zPosition = Z_MAX_POS * 1.2; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], zPosition, current_position[E_AXIS], feedrate/60, active_extruder); + st_synchronize(); + + // set the current position to Z_MAX position + current_position[Z_AXIS] = Z_MAX_POS; + plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); + + endstops_hit_on_purpose(); + + #ifdef ENDSTOPS_ONLY_FOR_HOMING + enable_endstops(false); + #endif #endif @@ -1668,7 +1690,7 @@ void process_commands() feedrate = homing_feedrate[Z_AXIS]; // bed until it hits the z_max_endstop - float zPosition = Z_MAX_POS * 3; + float zPosition = Z_MAX_POS * 1.2; plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], zPosition, current_position[E_AXIS], feedrate/60, active_extruder); st_synchronize(); @@ -1677,6 +1699,12 @@ void process_commands() plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); endstops_hit_on_purpose(); + + #ifdef ENDSTOPS_ONLY_FOR_HOMING + enable_endstops(false); + #endif + + } break; From 4d0cf36ac77b00214a9efa84636670f96a99b3ad Mon Sep 17 00:00:00 2001 From: Chris Marzano Date: Tue, 5 Aug 2014 11:31:05 -0700 Subject: [PATCH 38/71] Inverse logic for red board. --- Marlin/Configuration.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index b6f09c1e3e4d..2880b86e60a5 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -304,10 +304,10 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o #define DISABLE_Z false #define DISABLE_E false // For all extruders -#define INVERT_X_DIR false // for Mendel set to false, for Orca set to true -#define INVERT_Y_DIR true // for Mendel set to true, for Orca set to false -#define INVERT_Z_DIR false // for Mendel set to false, for Orca set to true -#define INVERT_E0_DIR false // for direct drive extruder v9 set to true, for geared extruder set to false +#define INVERT_X_DIR true // for Mendel set to false, for Orca set to true +#define INVERT_Y_DIR false // for Mendel set to true, for Orca set to false +#define INVERT_Z_DIR true // for Mendel set to false, for Orca set to true +#define INVERT_E0_DIR true // for direct drive extruder v9 set to true, for geared extruder set to false #define INVERT_E1_DIR false // for direct drive extruder v9 set to true, for geared extruder set to false #define INVERT_E2_DIR false // for direct drive extruder v9 set to true, for geared extruder set to false From a70f065c5f4c691bcbc3ad0049f8aa3de371bcc3 Mon Sep 17 00:00:00 2001 From: Joe Marino Date: Mon, 4 Aug 2014 15:04:33 -0700 Subject: [PATCH 39/71] Increased the bounds for M851 +/- 3 mm was insuffcient, changed to +/- 10 for the Z Probe Offset --- Marlin/Configuration.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 2880b86e60a5..34b8f173906b 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -487,8 +487,8 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o #ifdef CUSTOM_M_CODES #define CUSTOM_M_CODE_REPORT_BUILD_INFO 850 #define CUSTOM_M_CODE_SET_Z_PROBE_OFFSET 851 - #define Z_PROBE_OFFSET_RANGE_MIN -3 - #define Z_PROBE_OFFSET_RANGE_MAX 3 + #define Z_PROBE_OFFSET_RANGE_MIN -10 + #define Z_PROBE_OFFSET_RANGE_MAX 10 #endif // Custom G code points From 8d1a4f90d80ede13f79837b7bf682e09bff37b87 Mon Sep 17 00:00:00 2001 From: Joe Marino Date: Mon, 4 Aug 2014 20:25:03 -0700 Subject: [PATCH 40/71] Force Z Retract after before ABL probe points --- Marlin/Marlin_main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index b42a35cf9db9..3050aba1328d 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -1099,13 +1099,13 @@ static void homeaxis(int axis) { current_position[axis] = 0; plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); -/* + if (axis == Z_AXIS) { - destination[axis] = 5; + destination[axis] = 3; plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); st_synchronize(); } - +/* destination[axis] = -home_retract_mm(axis) * axis_home_dir; plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); st_synchronize(); From 8708346dea718d6d601ee0eb2b0866a016eb7827 Mon Sep 17 00:00:00 2001 From: Joe Marino Date: Wed, 6 Aug 2014 12:04:05 -0700 Subject: [PATCH 41/71] Changed motor directions for Black Printrboard --- Marlin/Configuration.h | 10 +++++----- Marlin/Makefile | 2 +- Marlin/Marlin_main.cpp | 19 ++++++++++++------- Marlin/fsr_abl.cpp | 9 +++++++-- Marlin/fsr_abl.h | 8 ++++++-- Marlin/stepper.cpp | 2 +- Marlin/temperature.cpp | 2 +- run_tests.sh | 22 +++++++++++----------- 8 files changed, 44 insertions(+), 30 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 34b8f173906b..8cf719f99509 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -304,10 +304,10 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o #define DISABLE_Z false #define DISABLE_E false // For all extruders -#define INVERT_X_DIR true // for Mendel set to false, for Orca set to true -#define INVERT_Y_DIR false // for Mendel set to true, for Orca set to false -#define INVERT_Z_DIR true // for Mendel set to false, for Orca set to true -#define INVERT_E0_DIR true // for direct drive extruder v9 set to true, for geared extruder set to false +#define INVERT_X_DIR false // for Mendel set to false, for Orca set to true +#define INVERT_Y_DIR true // for Mendel set to true, for Orca set to false +#define INVERT_Z_DIR false // for Mendel set to false, for Orca set to true +#define INVERT_E0_DIR false // for direct drive extruder v9 set to true, for geared extruder set to false #define INVERT_E1_DIR false // for direct drive extruder v9 set to true, for geared extruder set to false #define INVERT_E2_DIR false // for direct drive extruder v9 set to true, for geared extruder set to false @@ -336,7 +336,7 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o #define ENABLE_AUTO_BED_LEVELING // Delete the comment to enable (remove // at the start of the line) #ifdef ENABLE_AUTO_BED_LEVELING -#define FSR_BED_LEVELING // Use force sensing resistors to perform ABL +// #define FSR_BED_LEVELING // Use force sensing resistors to perform ABL // There are 2 different ways to pick the X and Y locations to probe: // - "grid" mode diff --git a/Marlin/Makefile b/Marlin/Makefile index 41e101fdd9db..f58235111a17 100644 --- a/Marlin/Makefile +++ b/Marlin/Makefile @@ -261,7 +261,7 @@ CXXSRC = WMath.cpp WString.cpp Print.cpp Marlin_main.cpp \ SdFile.cpp SdVolume.cpp motion_control.cpp planner.cpp \ stepper.cpp temperature.cpp cardreader.cpp ConfigurationStore.cpp \ watchdog.cpp SPI.cpp Servo.cpp Tone.cpp ultralcd.cpp digipot_mcp4451.cpp \ - vector_3.cpp qr_solve.cpp + vector_3.cpp qr_solve.cpp fsr_abl.cpp ifeq ($(LIQUID_TWI2), 0) CXXSRC += LiquidCrystal.cpp else diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 3050aba1328d..715c12e05b45 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -61,7 +61,7 @@ #include #endif -#if defined FSR_BED_LEVELING +#ifdef FSR_BED_LEVELING #include "fsr_abl.h" #endif @@ -2833,12 +2833,17 @@ void process_commands() } case 505: // M505 Test function for FSR ABL { - SERIAL_ECHO_START; - SERIAL_ECHOPGM("ADC Reading: "); - SERIAL_ECHOLN(FSR_ABL_Get_Read()); - SERIAL_ECHOPGM(" Rolling Avg: "); - SERIAL_ECHOLN(FSR_ABL_Get_Avg()); - SERIAL_PROTOCOLLN(""); + #ifdef FSR_BED_LEVELING + SERIAL_ECHO_START; + SERIAL_ECHOPGM("ADC Reading: "); + SERIAL_ECHOLN(FSR_ABL_Get_Read()); + SERIAL_ECHOPGM(" Rolling Avg: "); + SERIAL_ECHOLN(FSR_ABL_Get_Avg()); + SERIAL_PROTOCOLLN(""); + #else + SERIAL_ECHO_START; + SERIAL_ECHOPGM("NO FSR ABL"); + #endif } break; #ifdef ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED diff --git a/Marlin/fsr_abl.cpp b/Marlin/fsr_abl.cpp index e3a9e5ca910f..0b1cfec7db50 100644 --- a/Marlin/fsr_abl.cpp +++ b/Marlin/fsr_abl.cpp @@ -2,11 +2,14 @@ fsr_abl.cpp contains the functions needed to operate automatic bed leveling with force sensing resistors. */ -//#ifdef FSR_BED_LEVELING //&& defined FSR_PIN && FSR_PIN > -1 + + #include "fsr_abl.h" #include "Marlin.h" #include "temperature.h" +#ifdef FSR_BED_LEVELING //&& defined FSR_PIN && FSR_PIN > -1 + // Public Variables // Private Variables (static preserves between function calls and prevents calling by extern) @@ -52,4 +55,6 @@ else{ return(false); } } -//#endif + + +#endif diff --git a/Marlin/fsr_abl.h b/Marlin/fsr_abl.h index 543edfc6ddcb..d21fa9e9525b 100644 --- a/Marlin/fsr_abl.h +++ b/Marlin/fsr_abl.h @@ -4,11 +4,15 @@ */ #ifndef fsr_abl_h #define fsr_abl_h -#endif + +#include "Marlin.h" + #ifdef FSR_BED_LEVELING -int FSR_ABL_Reading(); +void FSR_ABL_Reading(); int FSR_ABL_Get_Read(); int FSR_ABL_Get_Avg(); bool FSR_ABL_Trigger(); +#endif + #endif \ No newline at end of file diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index b9c4550236fd..d9372e7bad4c 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -528,7 +528,7 @@ ISR(TIMER1_COMPA_vect) // End of FSR ABL #elif defined(Z_MIN_PIN) && Z_MIN_PIN > -1 - if bool z_min_endstop=(READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING); + bool z_min_endstop=(READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING); if(z_min_endstop && old_z_min_endstop && (current_block->steps_z > 0)) { endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS]; endstop_z_hit=true; diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index e117f7e03021..bd9dd2be2153 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -691,7 +691,7 @@ static void updateTemperaturesFromRawValues() #ifdef TEMP_SENSOR_1_AS_REDUNDANT redundant_temperature = analog2temp(redundant_temperature_raw, 1); #endif - #if defined FSR_BED_LEVELING + #ifdef FSR_BED_LEVELING FSR_ABL_Reading(); #endif diff --git a/run_tests.sh b/run_tests.sh index 91feaa134fd9..0badf11a1f07 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -14,10 +14,11 @@ function print_vars echo " " DELTA=$DELTA echo " " MOTHERBOARD=$MOTHERBOARD echo " " ENABLE_AUTO_BED_LEVELING=$ENABLE_AUTO_BED_LEVELING - echo " " AUTO_BED_LEVELING_ANY_POINTS=$AUTO_BED_LEVELING_ANY_POINTS echo " " Z_SAFE_HOMING_FIXED_POINT=$Z_SAFE_HOMING_FIXED_POINT echo " " CUSTOM_M_CODES=$CUSTOM_M_CODES + echo " " CUSTOM_G_CODES=$CUSTOM_G_CODES echo " " MSM_Printeer=$MSM_Printeer + echo " " FSR_BED_LEVELING=$FSR_BED_LEVELING } function reset_vars @@ -25,10 +26,11 @@ function reset_vars export DELTA= export MOTHERBOARD= export ENABLE_AUTO_BED_LEVELING= - export AUTO_BED_LEVELING_ANY_POINTS= export Z_SAFE_HOMING_FIXED_POINT= export CUSTOM_M_CODES= + export CUSTOM_G_CODES= export MSM_Printeer= + export FSR_BED_LEVELING= } function reset_configs @@ -47,9 +49,9 @@ function run CFG=Marlin/Configuration.h cp $CFG $CFG.orig - cat $CFG.orig | ./set-defines.sh MOTHERBOARD ENABLE_AUTO_BED_LEVELING AUTO_BED_LEVELING_ANY_POINTS Z_SAFE_HOMING_FIXED_POINT CUSTOM_M_CODES MSM_Printeer > $CFG + cat $CFG.orig | ./set-defines.sh MOTHERBOARD ENABLE_AUTO_BED_LEVELING Z_SAFE_HOMING_FIXED_POINT CUSTOM_M_CODES MSM_Printeer FSR_BED_LEVELING > $CFG echo "Current defines:" - grep -e MOTHERBOARD -e ENABLE_AUTO_BED_LEVELING -e AUTO_BED_LEVELING_ANY_POINTS -e Z_SAFE_HOMING_FIXED_POINT -e DELTA -e CUSTOM_M_CODES -e MSM_Printeer $CFG + grep -e MOTHERBOARD -e ENABLE_AUTO_BED_LEVELING -e AZ_SAFE_HOMING_FIXED_POINT -e DELTA -e CUSTOM_M_CODES -e MSM_Printeer -e FSR_BED_LEVELING $CFG sleep 2 (cd Marlin && make clean && make HARDWARE_MOTHERBOARD=$MOTHERBOARD AVR_TOOLS_PATH=$AVR_TOOLS_PATH ARDUINO_INSTALL_DIR=$ARDUINO_INSTALL_DIR) @@ -61,24 +63,22 @@ function run reset_vars reset_configs -MOTHERBOARD=81 ENABLE_AUTO_BED_LEVELING=1 AUTO_BED_LEVELING_ANY_POINTS=1 Z_SAFE_HOMING_FIXED_POINT=1 CUSTOM_M_CODES=1 MSM_Printeer=1 +MOTHERBOARD=81 ENABLE_AUTO_BED_LEVELING=1 CUSTOM_M_CODES=1 CUSTOM_G_CODES=1 MSM_Printeer=1 FSR_BED_LEVELING=1 run -MOTHERBOARD=81 ENABLE_AUTO_BED_LEVELING=1 AUTO_BED_LEVELING_ANY_POINTS=1 Z_SAFE_HOMING_FIXED_POINT=1 CUSTOM_M_CODES=1 +MOTHERBOARD=81 ENABLE_AUTO_BED_LEVELING=1 Z_SAFE_HOMING_FIXED_POINT=1 CUSTOM_M_CODES=1 MSM_Printeer=1 run -MOTHERBOARD=81 ENABLE_AUTO_BED_LEVELING=1 AUTO_BED_LEVELING_ANY_POINTS=1 Z_SAFE_HOMING_FIXED_POINT=1 -run - -MOTHERBOARD=81 ENABLE_AUTO_BED_LEVELING=1 AUTO_BED_LEVELING_ANY_POINTS=1 +MOTHERBOARD=81 ENABLE_AUTO_BED_LEVELING=1 Z_SAFE_HOMING_FIXED_POINT=1 CUSTOM_M_CODES=1 run MOTHERBOARD=81 ENABLE_AUTO_BED_LEVELING=1 Z_SAFE_HOMING_FIXED_POINT=1 run -MOTHERBOARD=81 ENABLE_AUTO_BED_LEVELING=1 +MOTHERBOARD=81 ENABLE_AUTO_BED_LEVELING=1 run + MOTHERBOARD=81 run From adfefcc1f67c6ebd7e28d7a5bc7967b1755b413c Mon Sep 17 00:00:00 2001 From: Joe Marino Date: Tue, 12 Aug 2014 09:28:38 -0700 Subject: [PATCH 42/71] Uncommented FSR_BED_LEVELING --- Marlin/Configuration.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 8cf719f99509..9b92f3933dd1 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -336,7 +336,7 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o #define ENABLE_AUTO_BED_LEVELING // Delete the comment to enable (remove // at the start of the line) #ifdef ENABLE_AUTO_BED_LEVELING -// #define FSR_BED_LEVELING // Use force sensing resistors to perform ABL +#define FSR_BED_LEVELING // Use force sensing resistors to perform ABL // There are 2 different ways to pick the X and Y locations to probe: // - "grid" mode From dc8a48b8b964bc0db3bdf66e838e70b79b460d7d Mon Sep 17 00:00:00 2001 From: Chris Marzano Date: Tue, 19 Aug 2014 11:26:12 -0700 Subject: [PATCH 43/71] Tuned filter parameters to improve FSR ABL. Z offset will need to be re-tested for existing printers. --- Marlin/fsr_abl.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Marlin/fsr_abl.cpp b/Marlin/fsr_abl.cpp index 0b1cfec7db50..b63aa0f0489d 100644 --- a/Marlin/fsr_abl.cpp +++ b/Marlin/fsr_abl.cpp @@ -14,8 +14,8 @@ // Private Variables (static preserves between function calls and prevents calling by extern) static int fsr_rolling_avg; -static float fsr_weighting = 4; -static int fsr_checks = 1; // Number of times to run ADC +static float fsr_weighting = 5; // Higher weighting means ave changes slower +//static int fsr_checks = 1; // Number of times to run ADC NO LONGER USED // Updates rolling average with most recent value from ADC void FSR_ABL_Reading() @@ -41,13 +41,13 @@ int FSR_ABL_Get_Avg() bool FSR_ABL_Trigger() { // Check filter for trigger conditions -if (((current_fsr_sample() > 1.3*fsr_rolling_avg) || (current_fsr_sample() < .5*fsr_rolling_avg) || (current_fsr_sample() > 600)) && (current_fsr_sample() > 50)){ - SERIAL_ECHO_START; - SERIAL_ECHOPGM("Read: "); - SERIAL_ECHOLN(current_fsr_sample()); - SERIAL_ECHOPGM(" Roll: "); - SERIAL_ECHOLN(fsr_rolling_avg); - SERIAL_PROTOCOLLN(""); +if (((current_fsr_sample() > 1.2*fsr_rolling_avg) || (current_fsr_sample() < .85*fsr_rolling_avg) || (current_fsr_sample() > 400)) && (current_fsr_sample() > 50)){ + // SERIAL_ECHO_START; + // SERIAL_ECHOPGM("Read: "); + // SERIAL_ECHOLN(current_fsr_sample()); + // SERIAL_ECHOPGM(" Roll: "); + // SERIAL_ECHOLN(fsr_rolling_avg); + // SERIAL_PROTOCOLLN(""); return(true); } else{ From 4f407ee7c2d55fe65600675f1ad0d48fbaa1764b Mon Sep 17 00:00:00 2001 From: Joe Marino Date: Tue, 19 Aug 2014 13:30:54 -0700 Subject: [PATCH 44/71] Update FSR rolling average sample size --- Marlin/fsr_abl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/fsr_abl.cpp b/Marlin/fsr_abl.cpp index b63aa0f0489d..5286c583e86b 100644 --- a/Marlin/fsr_abl.cpp +++ b/Marlin/fsr_abl.cpp @@ -41,7 +41,7 @@ int FSR_ABL_Get_Avg() bool FSR_ABL_Trigger() { // Check filter for trigger conditions -if (((current_fsr_sample() > 1.2*fsr_rolling_avg) || (current_fsr_sample() < .85*fsr_rolling_avg) || (current_fsr_sample() > 400)) && (current_fsr_sample() > 50)){ +if (((current_fsr_sample() > 1.2*fsr_rolling_avg) || (current_fsr_sample() < .85*fsr_rolling_avg) || (current_fsr_sample() > 500)) && (current_fsr_sample() > 50)){ // SERIAL_ECHO_START; // SERIAL_ECHOPGM("Read: "); // SERIAL_ECHOLN(current_fsr_sample()); From 3bf4fbd0233b3d622f94de9fdd04d146f43ee177 Mon Sep 17 00:00:00 2001 From: Chris Marzano Date: Tue, 19 Aug 2014 15:34:03 -0700 Subject: [PATCH 45/71] Tuned filter and reduced grid to 4 points. The grid is much smaller which reduces error in the FSR probe. --- Marlin/Configuration.h | 10 +++++----- Marlin/fsr_abl.cpp | 8 -------- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 9b92f3933dd1..20511b70304a 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -357,14 +357,14 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o #ifdef AUTO_BED_LEVELING_GRID // set the rectangle in which to probe - #define LEFT_PROBE_BED_POSITION 0 - #define RIGHT_PROBE_BED_POSITION 75 - #define BACK_PROBE_BED_POSITION 90 - #define FRONT_PROBE_BED_POSITION 25 + #define LEFT_PROBE_BED_POSITION 15 + #define RIGHT_PROBE_BED_POSITION 50 + #define BACK_PROBE_BED_POSITION 80 + #define FRONT_PROBE_BED_POSITION 50 // set the number of grid points per dimension // I wouldn't see a reason to go above 3 (=9 probing points on the bed) - #define AUTO_BED_LEVELING_GRID_POINTS 3 + #define AUTO_BED_LEVELING_GRID_POINTS 2 //154x106 #else // not AUTO_BED_LEVELING_GRID diff --git a/Marlin/fsr_abl.cpp b/Marlin/fsr_abl.cpp index 5286c583e86b..b6183a87ba29 100644 --- a/Marlin/fsr_abl.cpp +++ b/Marlin/fsr_abl.cpp @@ -1,6 +1,5 @@ /* fsr_abl.cpp contains the functions needed to operate automatic bed leveling with force sensing resistors. - */ @@ -15,7 +14,6 @@ // Private Variables (static preserves between function calls and prevents calling by extern) static int fsr_rolling_avg; static float fsr_weighting = 5; // Higher weighting means ave changes slower -//static int fsr_checks = 1; // Number of times to run ADC NO LONGER USED // Updates rolling average with most recent value from ADC void FSR_ABL_Reading() @@ -42,12 +40,6 @@ bool FSR_ABL_Trigger() { // Check filter for trigger conditions if (((current_fsr_sample() > 1.2*fsr_rolling_avg) || (current_fsr_sample() < .85*fsr_rolling_avg) || (current_fsr_sample() > 500)) && (current_fsr_sample() > 50)){ - // SERIAL_ECHO_START; - // SERIAL_ECHOPGM("Read: "); - // SERIAL_ECHOLN(current_fsr_sample()); - // SERIAL_ECHOPGM(" Roll: "); - // SERIAL_ECHOLN(fsr_rolling_avg); - // SERIAL_PROTOCOLLN(""); return(true); } else{ From 83baca70ee2c31d623c794eccc3763b7e6fec667 Mon Sep 17 00:00:00 2001 From: Chris Marzano Date: Thu, 21 Aug 2014 12:42:20 -0700 Subject: [PATCH 46/71] Added new feature allowing 3-point ABL points to be fudged individually. M506 is the new command, with arguments to pick which point as A,B, or C. i.e. M506 A1.5 will set the offset of the first point to 1.5. Also tuned filter settings. --- Marlin/Configuration.h | 33 +++++++------- Marlin/ConfigurationStore.cpp | 6 +++ Marlin/Marlin.h | 3 ++ Marlin/Marlin_main.cpp | 81 ++++++++++++++++++++++++++++++++++- Marlin/fsr_abl.cpp | 4 +- 5 files changed, 109 insertions(+), 18 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 20511b70304a..06a282807f28 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -304,10 +304,10 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o #define DISABLE_Z false #define DISABLE_E false // For all extruders -#define INVERT_X_DIR false // for Mendel set to false, for Orca set to true -#define INVERT_Y_DIR true // for Mendel set to true, for Orca set to false -#define INVERT_Z_DIR false // for Mendel set to false, for Orca set to true -#define INVERT_E0_DIR false // for direct drive extruder v9 set to true, for geared extruder set to false +#define INVERT_X_DIR true // for Mendel set to false, for Orca set to true +#define INVERT_Y_DIR false // for Mendel set to true, for Orca set to false +#define INVERT_Z_DIR true // for Mendel set to false, for Orca set to true +#define INVERT_E0_DIR true // for direct drive extruder v9 set to true, for geared extruder set to false #define INVERT_E1_DIR false // for direct drive extruder v9 set to true, for geared extruder set to false #define INVERT_E2_DIR false // for direct drive extruder v9 set to true, for geared extruder set to false @@ -349,7 +349,7 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o // Probe 3 arbitrary points on the bed (that aren't colinear) // You must specify the X & Y coordinates of all 3 points - #define AUTO_BED_LEVELING_GRID + //#define AUTO_BED_LEVELING_GRID // with AUTO_BED_LEVELING_GRID, the bed is sampled in a // AUTO_BED_LEVELING_GRID_POINTSxAUTO_BED_LEVELING_GRID_POINTS grid // and least squares solution is calculated @@ -357,10 +357,10 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o #ifdef AUTO_BED_LEVELING_GRID // set the rectangle in which to probe - #define LEFT_PROBE_BED_POSITION 15 - #define RIGHT_PROBE_BED_POSITION 50 - #define BACK_PROBE_BED_POSITION 80 - #define FRONT_PROBE_BED_POSITION 50 + #define LEFT_PROBE_BED_POSITION 10 + #define RIGHT_PROBE_BED_POSITION 80 + #define BACK_PROBE_BED_POSITION 90 + #define FRONT_PROBE_BED_POSITION 20 // set the number of grid points per dimension // I wouldn't see a reason to go above 3 (=9 probing points on the bed) @@ -371,12 +371,12 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o // with no grid, just probe 3 arbitrary points. A simple cross-product // is used to esimate the plane of the print bed - #define ABL_PROBE_PT_1_X -10 - #define ABL_PROBE_PT_1_Y 121 - #define ABL_PROBE_PT_2_X -10 - #define ABL_PROBE_PT_2_Y 32 - #define ABL_PROBE_PT_3_X 114 - #define ABL_PROBE_PT_3_Y 122 + #define ABL_PROBE_PT_1_X 0 + #define ABL_PROBE_PT_1_Y 60 + #define ABL_PROBE_PT_2_X 80 + #define ABL_PROBE_PT_2_Y 100 + #define ABL_PROBE_PT_3_X 80 + #define ABL_PROBE_PT_3_Y 30 #endif // AUTO_BED_LEVELING_GRID @@ -489,6 +489,9 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o #define CUSTOM_M_CODE_SET_Z_PROBE_OFFSET 851 #define Z_PROBE_OFFSET_RANGE_MIN -10 #define Z_PROBE_OFFSET_RANGE_MAX 10 + #define ABL_ADJUSTMENT 506 + #define ABL_ADJUSTMENT_MIN -5 + #define ABL_ADJUSTMENT_MAX 5 #endif // Custom G code points diff --git a/Marlin/ConfigurationStore.cpp b/Marlin/ConfigurationStore.cpp index 074ef6ae3798..7665a90122cc 100644 --- a/Marlin/ConfigurationStore.cpp +++ b/Marlin/ConfigurationStore.cpp @@ -78,6 +78,9 @@ void Config_StoreSettings() EEPROM_WRITE_VAR(i,absPreheatHPBTemp); EEPROM_WRITE_VAR(i,absPreheatFanSpeed); EEPROM_WRITE_VAR(i,zprobe_zoffset); + EEPROM_WRITE_VAR(i,abl_A_offset); + EEPROM_WRITE_VAR(i,abl_B_offset); + EEPROM_WRITE_VAR(i,abl_C_offset); #ifdef PIDTEMP EEPROM_WRITE_VAR(i,Kp); EEPROM_WRITE_VAR(i,Ki); @@ -229,6 +232,9 @@ void Config_RetrieveSettings() EEPROM_READ_VAR(i,absPreheatHPBTemp); EEPROM_READ_VAR(i,absPreheatFanSpeed); EEPROM_READ_VAR(i,zprobe_zoffset); + EEPROM_READ_VAR(i,abl_A_offset); + EEPROM_READ_VAR(i,abl_B_offset); + EEPROM_READ_VAR(i,abl_C_offset); #ifndef PIDTEMP float Kp,Ki,Kd; #endif diff --git a/Marlin/Marlin.h b/Marlin/Marlin.h index 97866c816536..9e6464bc9f5a 100644 --- a/Marlin/Marlin.h +++ b/Marlin/Marlin.h @@ -218,6 +218,9 @@ extern float min_pos[3]; extern float max_pos[3]; extern bool axis_known_position[3]; extern float zprobe_zoffset; +extern float abl_A_offset; +extern float abl_B_offset; +extern float abl_C_offset; extern int fanSpeed; #ifdef BARICUDA extern int ValvePressure; diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 715c12e05b45..9436eb9a7632 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -218,6 +218,9 @@ float min_pos[3] = { X_MIN_POS, Y_MIN_POS, Z_MIN_POS }; float max_pos[3] = { X_MAX_POS, Y_MAX_POS, Z_MAX_POS }; bool axis_known_position[3] = {false, false, false}; float zprobe_zoffset; +float abl_A_offset; +float abl_B_offset; +float abl_C_offset; // Extruder offset #if EXTRUDERS > 1 @@ -1599,7 +1602,7 @@ void process_commands() clean_up_after_endstop_move(); - set_bed_level_equation_3pts(z_at_pt_1, z_at_pt_2, z_at_pt_3); + set_bed_level_equation_3pts(z_at_pt_1-abl_A_offset, z_at_pt_2-abl_B_offset, z_at_pt_3-abl_C_offset); // Higher values lower nozzle-bed distance #endif // AUTO_BED_LEVELING_GRID @@ -2909,6 +2912,82 @@ void process_commands() SERIAL_PROTOCOLLN(""); } break; + } + case ABL_ADJUSTMENT: // Allows fudging of ABL values if necessary + { + float value; + if (code_seen('A')) // First point + { + value = code_value(); + if ((ABL_ADJUSTMENT_MIN <= value) && (value <= ABL_ADJUSTMENT_MAX)) + { + abl_A_offset = value; // lower input values bring nozzle closer to bed + SERIAL_ECHO_START; + SERIAL_ECHOLNPGM("ABL A offset has been set"); + SERIAL_PROTOCOLLN(""); + } + else + { + SERIAL_ECHO_START; + SERIAL_ECHOPGM("Invalid value. Must be between "); + SERIAL_ECHO(ABL_ADJUSTMENT_MIN); + SERIAL_ECHOPGM(" and "); + SERIAL_ECHO(ABL_ADJUSTMENT_MAX); + SERIAL_PROTOCOLLN(""); + } + } + else if (code_seen('B')) // Second point + { + value = code_value(); + if ((ABL_ADJUSTMENT_MIN <= value) && (value <= ABL_ADJUSTMENT_MAX)) + { + abl_B_offset = value; // compare w/ line 278 of ConfigurationStore.cpp + SERIAL_ECHO_START; + SERIAL_ECHOLNPGM("ABL B offset has been set"); + SERIAL_PROTOCOLLN(""); + } + else + { + SERIAL_ECHO_START; + SERIAL_ECHOPGM("Invalid value. Must be between "); + SERIAL_ECHO(ABL_ADJUSTMENT_MIN); + SERIAL_ECHOPGM(" and "); + SERIAL_ECHO(ABL_ADJUSTMENT_MAX); + SERIAL_PROTOCOLLN(""); + } + } + else if (code_seen('C')) // Third point + { + value = code_value(); + if ((ABL_ADJUSTMENT_MIN <= value) && (value <= ABL_ADJUSTMENT_MAX)) + { + abl_C_offset = value; + SERIAL_ECHO_START; + SERIAL_ECHOLNPGM("ABL C offset has been set"); + SERIAL_PROTOCOLLN(""); + } + else + { + SERIAL_ECHO_START; + SERIAL_ECHOPGM("Invalid value. Must be between "); + SERIAL_ECHO(ABL_ADJUSTMENT_MIN); + SERIAL_ECHOPGM(" and "); + SERIAL_ECHO(ABL_ADJUSTMENT_MAX); + SERIAL_PROTOCOLLN(""); + } + } + else + { + SERIAL_ECHO_START; + SERIAL_ECHOLNPGM("ABL offsets are currently A: "); + SERIAL_ECHO(abl_A_offset); + SERIAL_ECHOPGM(", B: "); + SERIAL_ECHO(abl_B_offset); + SERIAL_ECHOPGM(", C: "); + SERIAL_ECHO(abl_C_offset); + SERIAL_PROTOCOLLN(""); + } + break; } #endif // CUSTOM_M_CODES diff --git a/Marlin/fsr_abl.cpp b/Marlin/fsr_abl.cpp index b6183a87ba29..12fd8ad7c103 100644 --- a/Marlin/fsr_abl.cpp +++ b/Marlin/fsr_abl.cpp @@ -13,7 +13,7 @@ // Private Variables (static preserves between function calls and prevents calling by extern) static int fsr_rolling_avg; -static float fsr_weighting = 5; // Higher weighting means ave changes slower +static float fsr_weighting = 4.5; // Higher weighting means ave changes slower // Updates rolling average with most recent value from ADC void FSR_ABL_Reading() @@ -39,7 +39,7 @@ int FSR_ABL_Get_Avg() bool FSR_ABL_Trigger() { // Check filter for trigger conditions -if (((current_fsr_sample() > 1.2*fsr_rolling_avg) || (current_fsr_sample() < .85*fsr_rolling_avg) || (current_fsr_sample() > 500)) && (current_fsr_sample() > 50)){ +if (((current_fsr_sample() > 1.25*fsr_rolling_avg) || (current_fsr_sample() < .65*fsr_rolling_avg) || (current_fsr_sample() > 520)) && (current_fsr_sample() > 50)){ return(true); } else{ From 62d34dd56fc8e3842b1553136198aadae140f6ca Mon Sep 17 00:00:00 2001 From: Chris Marzano Date: Thu, 21 Aug 2014 15:54:23 -0700 Subject: [PATCH 47/71] Added fudge adjustment feature to grid mode. M506 now includes arguments A, B, C, and D, which correspond to the corners of the probing grid in the order they are reached. Small adjustments (~.1) are recommended between tests. Note! Axis directions are configured for a red board per this and previous commit. --- Marlin/Configuration.h | 6 ++-- Marlin/ConfigurationStore.cpp | 2 ++ Marlin/Marlin.h | 1 + Marlin/Marlin_main.cpp | 64 +++++++++++++++++++++++++++++++---- 4 files changed, 64 insertions(+), 9 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 06a282807f28..746679798f01 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -349,7 +349,7 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o // Probe 3 arbitrary points on the bed (that aren't colinear) // You must specify the X & Y coordinates of all 3 points - //#define AUTO_BED_LEVELING_GRID + #define AUTO_BED_LEVELING_GRID // with AUTO_BED_LEVELING_GRID, the bed is sampled in a // AUTO_BED_LEVELING_GRID_POINTSxAUTO_BED_LEVELING_GRID_POINTS grid // and least squares solution is calculated @@ -357,10 +357,10 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o #ifdef AUTO_BED_LEVELING_GRID // set the rectangle in which to probe - #define LEFT_PROBE_BED_POSITION 10 + #define LEFT_PROBE_BED_POSITION 30 #define RIGHT_PROBE_BED_POSITION 80 #define BACK_PROBE_BED_POSITION 90 - #define FRONT_PROBE_BED_POSITION 20 + #define FRONT_PROBE_BED_POSITION 40 // set the number of grid points per dimension // I wouldn't see a reason to go above 3 (=9 probing points on the bed) diff --git a/Marlin/ConfigurationStore.cpp b/Marlin/ConfigurationStore.cpp index 7665a90122cc..914d62bab00e 100644 --- a/Marlin/ConfigurationStore.cpp +++ b/Marlin/ConfigurationStore.cpp @@ -81,6 +81,7 @@ void Config_StoreSettings() EEPROM_WRITE_VAR(i,abl_A_offset); EEPROM_WRITE_VAR(i,abl_B_offset); EEPROM_WRITE_VAR(i,abl_C_offset); + EEPROM_WRITE_VAR(i,abl_D_offset); #ifdef PIDTEMP EEPROM_WRITE_VAR(i,Kp); EEPROM_WRITE_VAR(i,Ki); @@ -235,6 +236,7 @@ void Config_RetrieveSettings() EEPROM_READ_VAR(i,abl_A_offset); EEPROM_READ_VAR(i,abl_B_offset); EEPROM_READ_VAR(i,abl_C_offset); + EEPROM_READ_VAR(i,abl_D_offset); #ifndef PIDTEMP float Kp,Ki,Kd; #endif diff --git a/Marlin/Marlin.h b/Marlin/Marlin.h index 9e6464bc9f5a..d1c0bc36886a 100644 --- a/Marlin/Marlin.h +++ b/Marlin/Marlin.h @@ -221,6 +221,7 @@ extern float zprobe_zoffset; extern float abl_A_offset; extern float abl_B_offset; extern float abl_C_offset; +extern float abl_D_offset; extern int fanSpeed; #ifdef BARICUDA extern int ValvePressure; diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 9436eb9a7632..7fc5dd437b37 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -221,6 +221,7 @@ float zprobe_zoffset; float abl_A_offset; float abl_B_offset; float abl_C_offset; +float abl_D_offset; // Extruder offset #if EXTRUDERS > 1 @@ -1561,7 +1562,43 @@ void process_commands() } float measured_z = probe_pt(xProbe, yProbe, z_before); - + + // Fudges the value at the fourth point in a 4-pt measurement + // A negative input value increases distance between bed and nozzle + // A positive input value decreases distance between bed and nozzle + // M851 adjustment is applied after ABL transformation is applied + if ((AUTO_BED_LEVELING_GRID_POINTS == 2) && (probePointCounter == 0) || ((AUTO_BED_LEVELING_GRID_POINTS == 3) && (probePointCounter == 0))) + { + measured_z -= abl_A_offset; + } + + // Fudges the value at the fourth point in a 4-pt measurement + // A negative input value increases distance between bed and nozzle + // A positive input value decreases distance between bed and nozzle + // M851 adjustment is applied after ABL transformation is applied + if ((AUTO_BED_LEVELING_GRID_POINTS == 2) && (probePointCounter == 1) || ((AUTO_BED_LEVELING_GRID_POINTS == 3) && (probePointCounter == 2))) + { + measured_z -= abl_B_offset; + } + + // Fudges the value at the fourth point in a 4-pt measurement + // A negative input value increases distance between bed and nozzle + // A positive input value decreases distance between bed and nozzle + // M851 adjustment is applied after ABL transformation is applied + if ((AUTO_BED_LEVELING_GRID_POINTS == 2) && (probePointCounter == 2) || ((AUTO_BED_LEVELING_GRID_POINTS == 3) && (probePointCounter == 5))) + { + measured_z -= abl_C_offset; + } + + // Fudges the value at the fourth point in a 4-pt measurement + // A negative input value increases distance between bed and nozzle + // A positive input value decreases distance between bed and nozzle + // M851 adjustment is applied after ABL transformation is applied + if ((AUTO_BED_LEVELING_GRID_POINTS == 2) && (probePointCounter == 3) || ((AUTO_BED_LEVELING_GRID_POINTS == 3) && (probePointCounter == 8))) + { + measured_z -= abl_D_offset; + } + eqnBVector[probePointCounter] = measured_z; eqnAMatrix[probePointCounter + 0*AUTO_BED_LEVELING_GRID_POINTS*AUTO_BED_LEVELING_GRID_POINTS] = xProbe; @@ -2917,7 +2954,7 @@ void process_commands() { float value; if (code_seen('A')) // First point - { + { value = code_value(); if ((ABL_ADJUSTMENT_MIN <= value) && (value <= ABL_ADJUSTMENT_MAX)) { @@ -2956,7 +2993,7 @@ void process_commands() SERIAL_PROTOCOLLN(""); } } - else if (code_seen('C')) // Third point + else if (code_seen('C')) // Third point { value = code_value(); if ((ABL_ADJUSTMENT_MIN <= value) && (value <= ABL_ADJUSTMENT_MAX)) @@ -2966,25 +3003,40 @@ void process_commands() SERIAL_ECHOLNPGM("ABL C offset has been set"); SERIAL_PROTOCOLLN(""); } - else + } + else if (code_seen('D')) // Fourth point (grid only) + { + value = code_value(); + if ((ABL_ADJUSTMENT_MIN <= value) && (value <= ABL_ADJUSTMENT_MAX)) { + abl_D_offset = value; + SERIAL_ECHO_START; + SERIAL_ECHOLNPGM("ABL D offset has been set"); + SERIAL_PROTOCOLLN(""); + } + else + { SERIAL_ECHO_START; SERIAL_ECHOPGM("Invalid value. Must be between "); SERIAL_ECHO(ABL_ADJUSTMENT_MIN); SERIAL_ECHOPGM(" and "); SERIAL_ECHO(ABL_ADJUSTMENT_MAX); SERIAL_PROTOCOLLN(""); - } + } } + else { SERIAL_ECHO_START; - SERIAL_ECHOLNPGM("ABL offsets are currently A: "); + SERIAL_ECHOLNPGM("ABL offsets are currently"); + SERIAL_ECHOPGM("A: "); SERIAL_ECHO(abl_A_offset); SERIAL_ECHOPGM(", B: "); SERIAL_ECHO(abl_B_offset); SERIAL_ECHOPGM(", C: "); SERIAL_ECHO(abl_C_offset); + SERIAL_ECHOPGM(", D: "); + SERIAL_ECHO(abl_D_offset); SERIAL_PROTOCOLLN(""); } break; From 7a5d4e9a478e66d1b79256c20e07d4bf6033c850 Mon Sep 17 00:00:00 2001 From: Chris Marzano Date: Thu, 21 Aug 2014 17:05:30 -0700 Subject: [PATCH 48/71] Set ABL to 9 points with previous probing area. ABL results varied too much with 4 points and/or smaller region. --- Marlin/Configuration.h | 8 ++++---- Marlin/Marlin_main.cpp | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 746679798f01..c4243e6d81a5 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -357,14 +357,14 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o #ifdef AUTO_BED_LEVELING_GRID // set the rectangle in which to probe - #define LEFT_PROBE_BED_POSITION 30 - #define RIGHT_PROBE_BED_POSITION 80 + #define LEFT_PROBE_BED_POSITION 0 + #define RIGHT_PROBE_BED_POSITION 75 #define BACK_PROBE_BED_POSITION 90 - #define FRONT_PROBE_BED_POSITION 40 + #define FRONT_PROBE_BED_POSITION 25 // set the number of grid points per dimension // I wouldn't see a reason to go above 3 (=9 probing points on the bed) - #define AUTO_BED_LEVELING_GRID_POINTS 2 + #define AUTO_BED_LEVELING_GRID_POINTS 3 //154x106 #else // not AUTO_BED_LEVELING_GRID diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 7fc5dd437b37..791d7e776607 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -1570,6 +1570,7 @@ void process_commands() if ((AUTO_BED_LEVELING_GRID_POINTS == 2) && (probePointCounter == 0) || ((AUTO_BED_LEVELING_GRID_POINTS == 3) && (probePointCounter == 0))) { measured_z -= abl_A_offset; + SERIAL_PROTOCOLLN("A"); } // Fudges the value at the fourth point in a 4-pt measurement @@ -1579,6 +1580,7 @@ void process_commands() if ((AUTO_BED_LEVELING_GRID_POINTS == 2) && (probePointCounter == 1) || ((AUTO_BED_LEVELING_GRID_POINTS == 3) && (probePointCounter == 2))) { measured_z -= abl_B_offset; + SERIAL_PROTOCOLLN("B"); } // Fudges the value at the fourth point in a 4-pt measurement @@ -1588,6 +1590,7 @@ void process_commands() if ((AUTO_BED_LEVELING_GRID_POINTS == 2) && (probePointCounter == 2) || ((AUTO_BED_LEVELING_GRID_POINTS == 3) && (probePointCounter == 5))) { measured_z -= abl_C_offset; + SERIAL_PROTOCOLLN("C"); } // Fudges the value at the fourth point in a 4-pt measurement @@ -1597,6 +1600,7 @@ void process_commands() if ((AUTO_BED_LEVELING_GRID_POINTS == 2) && (probePointCounter == 3) || ((AUTO_BED_LEVELING_GRID_POINTS == 3) && (probePointCounter == 8))) { measured_z -= abl_D_offset; + SERIAL_PROTOCOLLN("D"); } eqnBVector[probePointCounter] = measured_z; From c72ed0455b6d3d63f345e2cc779de1ac008fe1b8 Mon Sep 17 00:00:00 2001 From: Chris Marzano Date: Thu, 21 Aug 2014 17:16:16 -0700 Subject: [PATCH 49/71] Axis logic inverted for BLACK printrboards. --- Marlin/Configuration.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index c4243e6d81a5..fd3108a7a914 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -304,10 +304,10 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o #define DISABLE_Z false #define DISABLE_E false // For all extruders -#define INVERT_X_DIR true // for Mendel set to false, for Orca set to true -#define INVERT_Y_DIR false // for Mendel set to true, for Orca set to false -#define INVERT_Z_DIR true // for Mendel set to false, for Orca set to true -#define INVERT_E0_DIR true // for direct drive extruder v9 set to true, for geared extruder set to false +#define INVERT_X_DIR false // for Mendel set to false, for Orca set to true +#define INVERT_Y_DIR true // for Mendel set to true, for Orca set to false +#define INVERT_Z_DIR false // for Mendel set to false, for Orca set to true +#define INVERT_E0_DIR false // for direct drive extruder v9 set to true, for geared extruder set to false #define INVERT_E1_DIR false // for direct drive extruder v9 set to true, for geared extruder set to false #define INVERT_E2_DIR false // for direct drive extruder v9 set to true, for geared extruder set to false From f4a55216f232a8a0e021dfe0b903988b68440d2e Mon Sep 17 00:00:00 2001 From: Chris Marzano Date: Thu, 28 Aug 2014 10:18:37 -0700 Subject: [PATCH 50/71] Updated Button LED On serial output to correctly state the button is on, not off. --- Marlin/Marlin_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 791d7e776607..be3a7eacfa99 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -1783,7 +1783,7 @@ void process_commands() case BUTTON_LED_ON: { digitalWrite(LED_BUTTON_PIN,HIGH); - SERIAL_PROTOCOLPGM("RED LED OFF \n"); + SERIAL_PROTOCOLPGM("BUTTON LED ON \n"); } break; From 6a6b1da7e1274cc672f80d7b3d6aa2290432f78f Mon Sep 17 00:00:00 2001 From: Joe Marino Date: Wed, 10 Sep 2014 09:33:17 -0700 Subject: [PATCH 51/71] Update to run_tests --- run_tests.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/run_tests.sh b/run_tests.sh index 0badf11a1f07..a8b38ca4d95c 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -51,7 +51,7 @@ function run cp $CFG $CFG.orig cat $CFG.orig | ./set-defines.sh MOTHERBOARD ENABLE_AUTO_BED_LEVELING Z_SAFE_HOMING_FIXED_POINT CUSTOM_M_CODES MSM_Printeer FSR_BED_LEVELING > $CFG echo "Current defines:" - grep -e MOTHERBOARD -e ENABLE_AUTO_BED_LEVELING -e AZ_SAFE_HOMING_FIXED_POINT -e DELTA -e CUSTOM_M_CODES -e MSM_Printeer -e FSR_BED_LEVELING $CFG + grep -e MOTHERBOARD -e ENABLE_AUTO_BED_LEVELING -e Z_SAFE_HOMING_FIXED_POINT -e DELTA -e CUSTOM_M_CODES -e MSM_Printeer -e FSR_BED_LEVELING $CFG sleep 2 (cd Marlin && make clean && make HARDWARE_MOTHERBOARD=$MOTHERBOARD AVR_TOOLS_PATH=$AVR_TOOLS_PATH ARDUINO_INSTALL_DIR=$ARDUINO_INSTALL_DIR) @@ -66,6 +66,9 @@ reset_configs MOTHERBOARD=81 ENABLE_AUTO_BED_LEVELING=1 CUSTOM_M_CODES=1 CUSTOM_G_CODES=1 MSM_Printeer=1 FSR_BED_LEVELING=1 run +MOTHERBOARD=81 ENABLE_AUTO_BED_LEVELING=1 CUSTOM_M_CODES=1 CUSTOM_G_CODES=1 MSM_Printeer=1 +run + MOTHERBOARD=81 ENABLE_AUTO_BED_LEVELING=1 Z_SAFE_HOMING_FIXED_POINT=1 CUSTOM_M_CODES=1 MSM_Printeer=1 run From 1e56dd296b352a1078025e7c2f05e22ffb95ec06 Mon Sep 17 00:00:00 2001 From: Joe Marino Date: Wed, 10 Sep 2014 16:56:03 -0700 Subject: [PATCH 52/71] Improve separation of FSR ABL for default Marlin --- Marlin/Configuration.h | 15 ++- Marlin/Marlin_main.cpp | 217 +++++++++++++++++++++-------------------- 2 files changed, 121 insertions(+), 111 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index fd3108a7a914..8d9516fc67e1 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -483,18 +483,23 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o #define CUSTOM_G_CODES #endif -// Custom M code points +// Custom M codes and parameters for FSR BED LEVELING +#ifdef FSR_BED_LEVELING + #define ABL_TEST_FUNCTION 505 + #define ABL_ADJUSTMENT 506 + #define ABL_ADJUSTMENT_MIN -5 + #define ABL_ADJUSTMENT_MAX 5 +#endif + +// Custom M code for MSM Printeer #ifdef CUSTOM_M_CODES #define CUSTOM_M_CODE_REPORT_BUILD_INFO 850 #define CUSTOM_M_CODE_SET_Z_PROBE_OFFSET 851 #define Z_PROBE_OFFSET_RANGE_MIN -10 #define Z_PROBE_OFFSET_RANGE_MAX 10 - #define ABL_ADJUSTMENT 506 - #define ABL_ADJUSTMENT_MIN -5 - #define ABL_ADJUSTMENT_MAX 5 #endif -// Custom G code points +// Custom G code for MSM Printeer #ifdef CUSTOM_G_CODES #define Move_Z_Max 405 #define GREEN_LED_ON 411 diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index be3a7eacfa99..590a3187f183 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -2875,21 +2875,7 @@ void process_commands() { Config_PrintSettings(); } - case 505: // M505 Test function for FSR ABL - { - #ifdef FSR_BED_LEVELING - SERIAL_ECHO_START; - SERIAL_ECHOPGM("ADC Reading: "); - SERIAL_ECHOLN(FSR_ABL_Get_Read()); - SERIAL_ECHOPGM(" Rolling Avg: "); - SERIAL_ECHOLN(FSR_ABL_Get_Avg()); - SERIAL_PROTOCOLLN(""); - #else - SERIAL_ECHO_START; - SERIAL_ECHOPGM("NO FSR ABL"); - #endif - } - break; + #ifdef ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED case 540: { @@ -2898,6 +2884,115 @@ void process_commands() break; #endif + + #ifdef FSR_BED_LEVELING + case ABL_TEST_FUNCTION: // M505 Test function for FSR ABL + { + #ifdef FSR_BED_LEVELING + SERIAL_ECHO_START; + SERIAL_ECHOPGM("ADC Reading: "); + SERIAL_ECHOLN(FSR_ABL_Get_Read()); + SERIAL_ECHOPGM(" Rolling Avg: "); + SERIAL_ECHOLN(FSR_ABL_Get_Avg()); + SERIAL_PROTOCOLLN(""); + #else + SERIAL_ECHO_START; + SERIAL_ECHOPGM("NO FSR ABL"); + #endif + } + break; + case ABL_ADJUSTMENT: // Allows fudging of ABL values if necessary + { + float value; + if (code_seen('A')) // First point + { + value = code_value(); + if ((ABL_ADJUSTMENT_MIN <= value) && (value <= ABL_ADJUSTMENT_MAX)) + { + abl_A_offset = value; // lower input values bring nozzle closer to bed + SERIAL_ECHO_START; + SERIAL_ECHOLNPGM("ABL A offset has been set"); + SERIAL_PROTOCOLLN(""); + } + else + { + SERIAL_ECHO_START; + SERIAL_ECHOPGM("Invalid value. Must be between "); + SERIAL_ECHO(ABL_ADJUSTMENT_MIN); + SERIAL_ECHOPGM(" and "); + SERIAL_ECHO(ABL_ADJUSTMENT_MAX); + SERIAL_PROTOCOLLN(""); + } + } + else if (code_seen('B')) // Second point + { + value = code_value(); + if ((ABL_ADJUSTMENT_MIN <= value) && (value <= ABL_ADJUSTMENT_MAX)) + { + abl_B_offset = value; // compare w/ line 278 of ConfigurationStore.cpp + SERIAL_ECHO_START; + SERIAL_ECHOLNPGM("ABL B offset has been set"); + SERIAL_PROTOCOLLN(""); + } + else + { + SERIAL_ECHO_START; + SERIAL_ECHOPGM("Invalid value. Must be between "); + SERIAL_ECHO(ABL_ADJUSTMENT_MIN); + SERIAL_ECHOPGM(" and "); + SERIAL_ECHO(ABL_ADJUSTMENT_MAX); + SERIAL_PROTOCOLLN(""); + } + } + else if (code_seen('C')) // Third point + { + value = code_value(); + if ((ABL_ADJUSTMENT_MIN <= value) && (value <= ABL_ADJUSTMENT_MAX)) + { + abl_C_offset = value; + SERIAL_ECHO_START; + SERIAL_ECHOLNPGM("ABL C offset has been set"); + SERIAL_PROTOCOLLN(""); + } + } + else if (code_seen('D')) // Fourth point (grid only) + { + value = code_value(); + if ((ABL_ADJUSTMENT_MIN <= value) && (value <= ABL_ADJUSTMENT_MAX)) + { + abl_D_offset = value; + SERIAL_ECHO_START; + SERIAL_ECHOLNPGM("ABL D offset has been set"); + SERIAL_PROTOCOLLN(""); + } + else + { + SERIAL_ECHO_START; + SERIAL_ECHOPGM("Invalid value. Must be between "); + SERIAL_ECHO(ABL_ADJUSTMENT_MIN); + SERIAL_ECHOPGM(" and "); + SERIAL_ECHO(ABL_ADJUSTMENT_MAX); + SERIAL_PROTOCOLLN(""); + } + } + else + { + SERIAL_ECHO_START; + SERIAL_ECHOLNPGM("ABL offsets are currently"); + SERIAL_ECHOPGM("A: "); + SERIAL_ECHO(abl_A_offset); + SERIAL_ECHOPGM(", B: "); + SERIAL_ECHO(abl_B_offset); + SERIAL_ECHOPGM(", C: "); + SERIAL_ECHO(abl_C_offset); + SERIAL_ECHOPGM(", D: "); + SERIAL_ECHO(abl_D_offset); + SERIAL_PROTOCOLLN(""); + } + break; + } + #endif + #ifdef CUSTOM_M_CODES case CUSTOM_M_CODE_REPORT_BUILD_INFO: { @@ -2954,97 +3049,7 @@ void process_commands() } break; } - case ABL_ADJUSTMENT: // Allows fudging of ABL values if necessary - { - float value; - if (code_seen('A')) // First point - { - value = code_value(); - if ((ABL_ADJUSTMENT_MIN <= value) && (value <= ABL_ADJUSTMENT_MAX)) - { - abl_A_offset = value; // lower input values bring nozzle closer to bed - SERIAL_ECHO_START; - SERIAL_ECHOLNPGM("ABL A offset has been set"); - SERIAL_PROTOCOLLN(""); - } - else - { - SERIAL_ECHO_START; - SERIAL_ECHOPGM("Invalid value. Must be between "); - SERIAL_ECHO(ABL_ADJUSTMENT_MIN); - SERIAL_ECHOPGM(" and "); - SERIAL_ECHO(ABL_ADJUSTMENT_MAX); - SERIAL_PROTOCOLLN(""); - } - } - else if (code_seen('B')) // Second point - { - value = code_value(); - if ((ABL_ADJUSTMENT_MIN <= value) && (value <= ABL_ADJUSTMENT_MAX)) - { - abl_B_offset = value; // compare w/ line 278 of ConfigurationStore.cpp - SERIAL_ECHO_START; - SERIAL_ECHOLNPGM("ABL B offset has been set"); - SERIAL_PROTOCOLLN(""); - } - else - { - SERIAL_ECHO_START; - SERIAL_ECHOPGM("Invalid value. Must be between "); - SERIAL_ECHO(ABL_ADJUSTMENT_MIN); - SERIAL_ECHOPGM(" and "); - SERIAL_ECHO(ABL_ADJUSTMENT_MAX); - SERIAL_PROTOCOLLN(""); - } - } - else if (code_seen('C')) // Third point - { - value = code_value(); - if ((ABL_ADJUSTMENT_MIN <= value) && (value <= ABL_ADJUSTMENT_MAX)) - { - abl_C_offset = value; - SERIAL_ECHO_START; - SERIAL_ECHOLNPGM("ABL C offset has been set"); - SERIAL_PROTOCOLLN(""); - } - } - else if (code_seen('D')) // Fourth point (grid only) - { - value = code_value(); - if ((ABL_ADJUSTMENT_MIN <= value) && (value <= ABL_ADJUSTMENT_MAX)) - { - abl_D_offset = value; - SERIAL_ECHO_START; - SERIAL_ECHOLNPGM("ABL D offset has been set"); - SERIAL_PROTOCOLLN(""); - } - else - { - SERIAL_ECHO_START; - SERIAL_ECHOPGM("Invalid value. Must be between "); - SERIAL_ECHO(ABL_ADJUSTMENT_MIN); - SERIAL_ECHOPGM(" and "); - SERIAL_ECHO(ABL_ADJUSTMENT_MAX); - SERIAL_PROTOCOLLN(""); - } - } - - else - { - SERIAL_ECHO_START; - SERIAL_ECHOLNPGM("ABL offsets are currently"); - SERIAL_ECHOPGM("A: "); - SERIAL_ECHO(abl_A_offset); - SERIAL_ECHOPGM(", B: "); - SERIAL_ECHO(abl_B_offset); - SERIAL_ECHOPGM(", C: "); - SERIAL_ECHO(abl_C_offset); - SERIAL_ECHOPGM(", D: "); - SERIAL_ECHO(abl_D_offset); - SERIAL_PROTOCOLLN(""); - } - break; - } + #endif // CUSTOM_M_CODES #ifdef FILAMENTCHANGEENABLE From 54bbff035608b139b71dd3f315b6e99d61456eed Mon Sep 17 00:00:00 2001 From: Joe Marino Date: Wed, 10 Sep 2014 17:29:17 -0700 Subject: [PATCH 53/71] Convert Z-Max and LED Init to a routine --- Marlin/ConfigurationStore.cpp | 28 +++++--- Marlin/Marlin.h | 18 +++-- Marlin/Marlin_main.cpp | 128 ++++++++++++++-------------------- 3 files changed, 84 insertions(+), 90 deletions(-) diff --git a/Marlin/ConfigurationStore.cpp b/Marlin/ConfigurationStore.cpp index 914d62bab00e..41b27ce1e7de 100644 --- a/Marlin/ConfigurationStore.cpp +++ b/Marlin/ConfigurationStore.cpp @@ -77,11 +77,15 @@ void Config_StoreSettings() EEPROM_WRITE_VAR(i,absPreheatHotendTemp); EEPROM_WRITE_VAR(i,absPreheatHPBTemp); EEPROM_WRITE_VAR(i,absPreheatFanSpeed); - EEPROM_WRITE_VAR(i,zprobe_zoffset); - EEPROM_WRITE_VAR(i,abl_A_offset); - EEPROM_WRITE_VAR(i,abl_B_offset); - EEPROM_WRITE_VAR(i,abl_C_offset); - EEPROM_WRITE_VAR(i,abl_D_offset); + #ifdef MSM_Printeer + EEPROM_WRITE_VAR(i,zprobe_zoffset); + #endif + #ifdef FSR_BED_LEVELING + EEPROM_WRITE_VAR(i,abl_A_offset); + EEPROM_WRITE_VAR(i,abl_B_offset); + EEPROM_WRITE_VAR(i,abl_C_offset); + EEPROM_WRITE_VAR(i,abl_D_offset); + #endif #ifdef PIDTEMP EEPROM_WRITE_VAR(i,Kp); EEPROM_WRITE_VAR(i,Ki); @@ -232,11 +236,15 @@ void Config_RetrieveSettings() EEPROM_READ_VAR(i,absPreheatHotendTemp); EEPROM_READ_VAR(i,absPreheatHPBTemp); EEPROM_READ_VAR(i,absPreheatFanSpeed); - EEPROM_READ_VAR(i,zprobe_zoffset); - EEPROM_READ_VAR(i,abl_A_offset); - EEPROM_READ_VAR(i,abl_B_offset); - EEPROM_READ_VAR(i,abl_C_offset); - EEPROM_READ_VAR(i,abl_D_offset); + #ifdef MSM_Printeer + EEPROM_READ_VAR(i,zprobe_zoffset); + #endif + #ifdef FSR_BED_LEVELING + EEPROM_READ_VAR(i,abl_A_offset); + EEPROM_READ_VAR(i,abl_B_offset); + EEPROM_READ_VAR(i,abl_C_offset); + EEPROM_READ_VAR(i,abl_D_offset); + #endif #ifndef PIDTEMP float Kp,Ki,Kd; #endif diff --git a/Marlin/Marlin.h b/Marlin/Marlin.h index d1c0bc36886a..f1cfcdd02d2e 100644 --- a/Marlin/Marlin.h +++ b/Marlin/Marlin.h @@ -217,11 +217,7 @@ void recalc_delta_settings(float radius, float diagonal_rod); extern float min_pos[3]; extern float max_pos[3]; extern bool axis_known_position[3]; -extern float zprobe_zoffset; -extern float abl_A_offset; -extern float abl_B_offset; -extern float abl_C_offset; -extern float abl_D_offset; + extern int fanSpeed; #ifdef BARICUDA extern int ValvePressure; @@ -250,4 +246,16 @@ extern void digipot_i2c_set_current( int channel, float current ); extern void digipot_i2c_init(); #endif +#ifdef MSM_Printeer + void run_z_max(); + void led_init(); + extern float zprobe_zoffset; +#endif +#ifdef FSR_BED_LEVELING + extern float abl_A_offset; + extern float abl_B_offset; + extern float abl_C_offset; + extern float abl_D_offset; +#endif + #endif diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 590a3187f183..0d47ae7cf805 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -217,11 +217,15 @@ float endstop_adj[3]={0,0,0}; float min_pos[3] = { X_MIN_POS, Y_MIN_POS, Z_MIN_POS }; float max_pos[3] = { X_MAX_POS, Y_MAX_POS, Z_MAX_POS }; bool axis_known_position[3] = {false, false, false}; -float zprobe_zoffset; -float abl_A_offset; -float abl_B_offset; -float abl_C_offset; -float abl_D_offset; +#ifdef MSM_Printeer + float zprobe_zoffset; +#endif +#ifdef FSR_BED_LEVELING + float abl_A_offset; + float abl_B_offset; + float abl_C_offset; + float abl_D_offset; +#endif // Extruder offset #if EXTRUDERS > 1 @@ -529,45 +533,12 @@ void setup() digipot_i2c_init(); #endif - // Turn all LEDs on at Startup #ifdef MSM_Printeer - pinMode(LED_GREEN_PIN,OUTPUT); - digitalWrite(LED_GREEN_PIN,HIGH); - - pinMode(LED_RED_PIN,OUTPUT); - digitalWrite(LED_RED_PIN,HIGH); - - pinMode(LED_BUTTON_PIN, OUTPUT); - digitalWrite(LED_BUTTON_PIN,HIGH); - - enable_endstops(true); - - // clear any existing bed level matix - plan_bed_level_matrix.set_to_identity(); - - feedrate = homing_feedrate[Z_AXIS]; - - // bed until it hits the z_max_endstop - float zPosition = Z_MAX_POS * 1.2; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], zPosition, current_position[E_AXIS], feedrate/60, active_extruder); - st_synchronize(); - - // set the current position to Z_MAX position - current_position[Z_AXIS] = Z_MAX_POS; - plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); - - endstops_hit_on_purpose(); - - #ifdef ENDSTOPS_ONLY_FOR_HOMING - enable_endstops(false); - #endif + run_z_max(); + led_init(); #endif - - - } - void loop() { if(buflen < (BUFSIZE-1)) @@ -1191,6 +1162,45 @@ void refresh_cmd_timeout(void) } //retract #endif //FWRETRACT +#ifdef MSM_Printeer + void run_z_max() + { + enable_endstops(true); + + // clear any existing bed level matix + plan_bed_level_matrix.set_to_identity(); + + feedrate = homing_feedrate[Z_AXIS]; + + // bed until it hits the z_max_endstop + float zPosition = Z_MAX_POS * 1.05; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], zPosition, current_position[E_AXIS], feedrate/60, active_extruder); + st_synchronize(); + + // set the current position to Z_MAX position + current_position[Z_AXIS] = Z_MAX_POS; + plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); + + endstops_hit_on_purpose(); + + #ifdef ENDSTOPS_ONLY_FOR_HOMING + enable_endstops(false); + #endif + } + + void led_init() + { + pinMode(LED_GREEN_PIN,OUTPUT); + digitalWrite(LED_GREEN_PIN,HIGH); + + pinMode(LED_RED_PIN,OUTPUT); + digitalWrite(LED_RED_PIN,HIGH); + + pinMode(LED_BUTTON_PIN, OUTPUT); + digitalWrite(LED_BUTTON_PIN,HIGH); + } +#endif + void process_commands() { unsigned long codenum; //throw away variable @@ -1721,72 +1731,43 @@ void process_commands() } break; - // Custom G-Codes for MSM + // Custom G-Codes for MSM Printeer #ifdef CUSTOM_G_CODES - case Move_Z_Max: { - enable_endstops(true); - - // clear any existing bed level matix - plan_bed_level_matrix.set_to_identity(); - - feedrate = homing_feedrate[Z_AXIS]; - - // bed until it hits the z_max_endstop - float zPosition = Z_MAX_POS * 1.2; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], zPosition, current_position[E_AXIS], feedrate/60, active_extruder); - st_synchronize(); - - // set the current position to Z_MAX position - current_position[Z_AXIS] = Z_MAX_POS; - plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); - - endstops_hit_on_purpose(); - - #ifdef ENDSTOPS_ONLY_FOR_HOMING - enable_endstops(false); - #endif - - + run_z_max(); } break; - case GREEN_LED_ON: { digitalWrite(LED_GREEN_PIN,HIGH); SERIAL_PROTOCOLPGM("GREEN LED ON \n"); } break; - case GREEN_LED_OFF: { digitalWrite(LED_GREEN_PIN,LOW); SERIAL_PROTOCOLPGM("GREEN LED OFF \n"); } break; - case RED_LED_ON: { digitalWrite(LED_RED_PIN,HIGH); SERIAL_PROTOCOLPGM("RED LED ON \n"); } break; - case RED_LED_OFF: { digitalWrite(LED_RED_PIN,LOW); SERIAL_PROTOCOLPGM("RED LED OFF \n"); } break; - case BUTTON_LED_ON: { digitalWrite(LED_BUTTON_PIN,HIGH); SERIAL_PROTOCOLPGM("BUTTON LED ON \n"); } break; - case BUTTON_LED_OFF: { digitalWrite(LED_BUTTON_PIN,LOW); @@ -1794,7 +1775,6 @@ void process_commands() } break; #endif - } } @@ -2884,9 +2864,8 @@ void process_commands() break; #endif - #ifdef FSR_BED_LEVELING - case ABL_TEST_FUNCTION: // M505 Test function for FSR ABL + case ABL_TEST_FUNCTION: // Test function for FSR ABL { #ifdef FSR_BED_LEVELING SERIAL_ECHO_START; @@ -3049,7 +3028,6 @@ void process_commands() } break; } - #endif // CUSTOM_M_CODES #ifdef FILAMENTCHANGEENABLE From f46c38e701c73571293af569557516bedafdbc73 Mon Sep 17 00:00:00 2001 From: Joe Marino Date: Wed, 10 Sep 2014 17:57:26 -0700 Subject: [PATCH 54/71] Separation of FSR_ABL from the rest of Marlin --- Marlin/Marlin.h | 3 +- Marlin/Marlin_main.cpp | 78 +++++++++++++++++++++++------------------- Marlin/fsr_abl.cpp | 3 +- Marlin/pins.h | 9 +++-- 4 files changed, 50 insertions(+), 43 deletions(-) diff --git a/Marlin/Marlin.h b/Marlin/Marlin.h index f1cfcdd02d2e..b32020a0653d 100644 --- a/Marlin/Marlin.h +++ b/Marlin/Marlin.h @@ -217,7 +217,7 @@ void recalc_delta_settings(float radius, float diagonal_rod); extern float min_pos[3]; extern float max_pos[3]; extern bool axis_known_position[3]; - +extern float zprobe_zoffset; extern int fanSpeed; #ifdef BARICUDA extern int ValvePressure; @@ -249,7 +249,6 @@ extern void digipot_i2c_init(); #ifdef MSM_Printeer void run_z_max(); void led_init(); - extern float zprobe_zoffset; #endif #ifdef FSR_BED_LEVELING extern float abl_A_offset; diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 0d47ae7cf805..b5bc26679331 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -217,15 +217,7 @@ float endstop_adj[3]={0,0,0}; float min_pos[3] = { X_MIN_POS, Y_MIN_POS, Z_MIN_POS }; float max_pos[3] = { X_MAX_POS, Y_MAX_POS, Z_MAX_POS }; bool axis_known_position[3] = {false, false, false}; -#ifdef MSM_Printeer - float zprobe_zoffset; -#endif -#ifdef FSR_BED_LEVELING - float abl_A_offset; - float abl_B_offset; - float abl_C_offset; - float abl_D_offset; -#endif +float zprobe_zoffset; // Extruder offset #if EXTRUDERS > 1 @@ -284,7 +276,14 @@ int EtoPPressure=0; float delta_diagonal_rod= DELTA_DIAGONAL_ROD; float delta_diagonal_rod_2= sq(delta_diagonal_rod); float delta_segments_per_second= DELTA_SEGMENTS_PER_SECOND; -#endif +#endif + +#ifdef FSR_BED_LEVELING + float abl_A_offset; + float abl_B_offset; + float abl_C_offset; + float abl_D_offset; +#endif //=========================================================================== //=============================Private Variables============================= @@ -931,13 +930,13 @@ static void run_z_probe() { zPosition += home_retract_mm(Z_AXIS); plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], zPosition, current_position[E_AXIS], feedrate/60, active_extruder); st_synchronize(); - -/* // move back down slowly to find bed - feedrate = homing_feedrate[Z_AXIS]/4; - zPosition -= home_retract_mm(Z_AXIS) * 2; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], zPosition, current_position[E_AXIS], feedrate/60, active_extruder); - st_synchronize(); -*/ + #ifndef FSR_BED_LEVELING // no second tap if FSR_BED_LEVELING + // move back down slowly to find bed + feedrate = homing_feedrate[Z_AXIS]/4; + zPosition -= home_retract_mm(Z_AXIS) * 2; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], zPosition, current_position[E_AXIS], feedrate/60, active_extruder); + st_synchronize(); + #endif current_position[Z_AXIS] = st_get_position_mm(Z_AXIS); // make sure the planner knows where we are as it may be a bit different than we last said to move to plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); @@ -1075,24 +1074,27 @@ static void homeaxis(int axis) { current_position[axis] = 0; plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); + #ifdef FSR_BED_LEVELING // ensure Z-retract after FSR_BED_LEVELING homing if (axis == Z_AXIS) { destination[axis] = 3; plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); st_synchronize(); } -/* - destination[axis] = -home_retract_mm(axis) * axis_home_dir; - plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); - st_synchronize(); + #endif + #ifndef FSR_BED_LEVELING // no second tap for FSR_BED_LEVELING homing + destination[axis] = -home_retract_mm(axis) * axis_home_dir; + plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); + st_synchronize(); - destination[axis] = 2*home_retract_mm(axis) * axis_home_dir; -#ifdef DELTA - feedrate = homing_feedrate[axis]/10; -#else - feedrate = homing_feedrate[axis]/2 ; -#endif - plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); - st_synchronize(); + destination[axis] = 2*home_retract_mm(axis) * axis_home_dir; + #ifdef DELTA + feedrate = homing_feedrate[axis]/10; + #else + feedrate = homing_feedrate[axis]/2 ; + #endif + plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); + st_synchronize(); + #endif #ifdef DELTA // retrace by the amount specified in endstop_adj if (endstop_adj[axis] * axis_home_dir < 0) { @@ -1101,7 +1103,7 @@ static void homeaxis(int axis) { plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); st_synchronize(); } -#endif*/ +#endif axis_is_at_home(axis); destination[axis] = current_position[axis]; feedrate = 0.0; @@ -1572,7 +1574,7 @@ void process_commands() } float measured_z = probe_pt(xProbe, yProbe, z_before); - + #ifdef FSR_BED_LEVELING // Fudges the value at the fourth point in a 4-pt measurement // A negative input value increases distance between bed and nozzle // A positive input value decreases distance between bed and nozzle @@ -1612,6 +1614,7 @@ void process_commands() measured_z -= abl_D_offset; SERIAL_PROTOCOLLN("D"); } + #endif eqnBVector[probePointCounter] = measured_z; @@ -1653,8 +1656,11 @@ void process_commands() clean_up_after_endstop_move(); - set_bed_level_equation_3pts(z_at_pt_1-abl_A_offset, z_at_pt_2-abl_B_offset, z_at_pt_3-abl_C_offset); // Higher values lower nozzle-bed distance - + #ifdef FSR_BED_LEVELING + set_bed_level_equation_3pts(z_at_pt_1-abl_A_offset, z_at_pt_2-abl_B_offset, z_at_pt_3-abl_C_offset); // Higher values lower nozzle-bed distance + #else + set_bed_level_equation_3pts(z_at_pt_1, z_at_pt_2, z_at_pt_3); + #endif #endif // AUTO_BED_LEVELING_GRID st_synchronize(); @@ -2381,9 +2387,9 @@ void process_commands() SERIAL_PROTOCOLPGM(MSG_Y_MAX); SERIAL_PROTOCOLLN(((READ(Y_MAX_PIN)^Y_MAX_ENDSTOP_INVERTING)?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN)); #endif - #if defined FSR_BED_LEVELING - SERIAL_PROTOCOLPGM(MSG_Z_MIN); - //SERIAL_PROTOCOLLN((fsr_z_endstop?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN)); + #ifdef FSR_BED_LEVELING + SERIAL_PROTOCOLPGM(MSG_Z_MIN); + //SERIAL_PROTOCOLLN((fsr_z_endstop?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN)); #elif defined(Z_MIN_PIN) && Z_MIN_PIN > -1 SERIAL_PROTOCOLPGM(MSG_Z_MIN); SERIAL_PROTOCOLLN(((READ(Z_MIN_PIN)^Z_MIN_ENDSTOP_INVERTING)?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN)); diff --git a/Marlin/fsr_abl.cpp b/Marlin/fsr_abl.cpp index 12fd8ad7c103..9d0389bcf9c4 100644 --- a/Marlin/fsr_abl.cpp +++ b/Marlin/fsr_abl.cpp @@ -2,12 +2,11 @@ fsr_abl.cpp contains the functions needed to operate automatic bed leveling with force sensing resistors. */ - #include "fsr_abl.h" #include "Marlin.h" #include "temperature.h" -#ifdef FSR_BED_LEVELING //&& defined FSR_PIN && FSR_PIN > -1 +#ifdef FSR_BED_LEVELING && defined FSR_PIN && FSR_PIN > -1 // Public Variables diff --git a/Marlin/pins.h b/Marlin/pins.h index 1bea0018cc96..176f77bbe0b9 100644 --- a/Marlin/pins.h +++ b/Marlin/pins.h @@ -1550,13 +1550,16 @@ #define LARGE_FLASH true -// Extra LED Pins used by MSM Bot for LEDs +// Extra LED Pins used by MSM Printeer for LEDs #ifdef MSM_Printeer #define LED_GREEN_PIN 10 #define LED_RED_PIN 11 #define LED_BUTTON_PIN 12 -#define Z_STOP_MAX_PIN 37 // 25 -#define FSR_PIN 2 // ADC PIN +#define Z_STOP_MAX_PIN 37 +#endif + +#ifdef FSR_BED_LEVELING +#define FSR_PIN 2 // ADC PIN #endif #define X_STEP_PIN 0 From 351ba7b6e5b044795d6a34a7f0109dd67bdd6450 Mon Sep 17 00:00:00 2001 From: Joe Marino Date: Wed, 10 Sep 2014 18:11:14 -0700 Subject: [PATCH 55/71] Update motor speeds --- Marlin/Configuration.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 8d9516fc67e1..1ca2890d5475 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -455,7 +455,7 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o // default settings -#define DEFAULT_AXIS_STEPS_PER_UNIT {40,40,2535,162} // default steps per unit for Ultimaker +#define DEFAULT_AXIS_STEPS_PER_UNIT {40,40,1268,81} // default steps per unit for Ultimaker #define DEFAULT_MAX_FEEDRATE {400, 400, 3, 12} // (mm/sec) #define DEFAULT_MAX_ACCELERATION {2500,2500,100,5000} // X, Y, Z, E maximum start speed for accelerated moves. E default values are good for Skeinforge 40+, for older versions raise them a lot. From 6d7e2a3be4aa3bf7f563d0c471f7df5f8e584460 Mon Sep 17 00:00:00 2001 From: Joe Marino Date: Wed, 10 Sep 2014 18:13:12 -0700 Subject: [PATCH 56/71] zprobe_zoffset is not custom to Printeer --- Marlin/ConfigurationStore.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Marlin/ConfigurationStore.cpp b/Marlin/ConfigurationStore.cpp index 41b27ce1e7de..6e980b05c3cb 100644 --- a/Marlin/ConfigurationStore.cpp +++ b/Marlin/ConfigurationStore.cpp @@ -77,9 +77,7 @@ void Config_StoreSettings() EEPROM_WRITE_VAR(i,absPreheatHotendTemp); EEPROM_WRITE_VAR(i,absPreheatHPBTemp); EEPROM_WRITE_VAR(i,absPreheatFanSpeed); - #ifdef MSM_Printeer - EEPROM_WRITE_VAR(i,zprobe_zoffset); - #endif + EEPROM_WRITE_VAR(i,zprobe_zoffset); #ifdef FSR_BED_LEVELING EEPROM_WRITE_VAR(i,abl_A_offset); EEPROM_WRITE_VAR(i,abl_B_offset); @@ -236,9 +234,7 @@ void Config_RetrieveSettings() EEPROM_READ_VAR(i,absPreheatHotendTemp); EEPROM_READ_VAR(i,absPreheatHPBTemp); EEPROM_READ_VAR(i,absPreheatFanSpeed); - #ifdef MSM_Printeer - EEPROM_READ_VAR(i,zprobe_zoffset); - #endif + EEPROM_READ_VAR(i,zprobe_zoffset); #ifdef FSR_BED_LEVELING EEPROM_READ_VAR(i,abl_A_offset); EEPROM_READ_VAR(i,abl_B_offset); From a30422f21326811e0516f8876828c12831bcea03 Mon Sep 17 00:00:00 2001 From: Joe Marino Date: Wed, 10 Sep 2014 23:25:44 -0700 Subject: [PATCH 57/71] remove unnecessary spaces --- Marlin/Configuration.h | 6 +++--- Marlin/ConfigurationStore.cpp | 10 +++++----- Marlin/Marlin_main.cpp | 34 +++++++++++++++++----------------- Marlin/fsr_abl.h | 10 +++++----- Marlin/stepper.cpp | 16 ++++++++-------- Marlin/temperature.cpp | 35 ++++++++++++++++++++--------------- Marlin/temperature.h | 14 +++++++------- run_tests.sh | 2 +- 8 files changed, 66 insertions(+), 61 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 1ca2890d5475..480960feb130 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -373,16 +373,16 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o #define ABL_PROBE_PT_1_X 0 #define ABL_PROBE_PT_1_Y 60 - #define ABL_PROBE_PT_2_X 80 + #define ABL_PROBE_PT_2_X 80 #define ABL_PROBE_PT_2_Y 100 - #define ABL_PROBE_PT_3_X 80 + #define ABL_PROBE_PT_3_X 80 #define ABL_PROBE_PT_3_Y 30 #endif // AUTO_BED_LEVELING_GRID // these are the offsets to the probe relative to the extruder tip (Hotend - Probe) - #define X_PROBE_OFFSET_FROM_EXTRUDER 0 + #define X_PROBE_OFFSET_FROM_EXTRUDER 0 #define Y_PROBE_OFFSET_FROM_EXTRUDER 0 #define Z_PROBE_OFFSET_FROM_EXTRUDER 0 diff --git a/Marlin/ConfigurationStore.cpp b/Marlin/ConfigurationStore.cpp index 6e980b05c3cb..c4b69018ce7a 100644 --- a/Marlin/ConfigurationStore.cpp +++ b/Marlin/ConfigurationStore.cpp @@ -78,7 +78,7 @@ void Config_StoreSettings() EEPROM_WRITE_VAR(i,absPreheatHPBTemp); EEPROM_WRITE_VAR(i,absPreheatFanSpeed); EEPROM_WRITE_VAR(i,zprobe_zoffset); - #ifdef FSR_BED_LEVELING + #ifdef FSR_BED_LEVELING EEPROM_WRITE_VAR(i,abl_A_offset); EEPROM_WRITE_VAR(i,abl_B_offset); EEPROM_WRITE_VAR(i,abl_C_offset); @@ -235,11 +235,11 @@ void Config_RetrieveSettings() EEPROM_READ_VAR(i,absPreheatHPBTemp); EEPROM_READ_VAR(i,absPreheatFanSpeed); EEPROM_READ_VAR(i,zprobe_zoffset); - #ifdef FSR_BED_LEVELING + #ifdef FSR_BED_LEVELING EEPROM_READ_VAR(i,abl_A_offset); - EEPROM_READ_VAR(i,abl_B_offset); - EEPROM_READ_VAR(i,abl_C_offset); - EEPROM_READ_VAR(i,abl_D_offset); + EEPROM_READ_VAR(i,abl_B_offset); + EEPROM_READ_VAR(i,abl_C_offset); + EEPROM_READ_VAR(i,abl_D_offset); #endif #ifndef PIDTEMP float Kp,Ki,Kd; diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index b5bc26679331..1bfd5028eeb4 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -276,14 +276,14 @@ int EtoPPressure=0; float delta_diagonal_rod= DELTA_DIAGONAL_ROD; float delta_diagonal_rod_2= sq(delta_diagonal_rod); float delta_segments_per_second= DELTA_SEGMENTS_PER_SECOND; -#endif +#endif -#ifdef FSR_BED_LEVELING +#ifdef FSR_BED_LEVELING float abl_A_offset; float abl_B_offset; float abl_C_offset; float abl_D_offset; -#endif +#endif //=========================================================================== //=============================Private Variables============================= @@ -534,7 +534,7 @@ void setup() #ifdef MSM_Printeer run_z_max(); - led_init(); + led_init(); #endif } @@ -1173,7 +1173,7 @@ void refresh_cmd_timeout(void) plan_bed_level_matrix.set_to_identity(); feedrate = homing_feedrate[Z_AXIS]; - + // bed until it hits the z_max_endstop float zPosition = Z_MAX_POS * 1.05; plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], zPosition, current_position[E_AXIS], feedrate/60, active_extruder); @@ -1182,7 +1182,7 @@ void refresh_cmd_timeout(void) // set the current position to Z_MAX position current_position[Z_AXIS] = Z_MAX_POS; plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); - + endstops_hit_on_purpose(); #ifdef ENDSTOPS_ONLY_FOR_HOMING @@ -1584,7 +1584,7 @@ void process_commands() measured_z -= abl_A_offset; SERIAL_PROTOCOLLN("A"); } - + // Fudges the value at the fourth point in a 4-pt measurement // A negative input value increases distance between bed and nozzle // A positive input value decreases distance between bed and nozzle @@ -1594,7 +1594,7 @@ void process_commands() measured_z -= abl_B_offset; SERIAL_PROTOCOLLN("B"); } - + // Fudges the value at the fourth point in a 4-pt measurement // A negative input value increases distance between bed and nozzle // A positive input value decreases distance between bed and nozzle @@ -1604,7 +1604,7 @@ void process_commands() measured_z -= abl_C_offset; SERIAL_PROTOCOLLN("C"); } - + // Fudges the value at the fourth point in a 4-pt measurement // A negative input value increases distance between bed and nozzle // A positive input value decreases distance between bed and nozzle @@ -1615,7 +1615,7 @@ void process_commands() SERIAL_PROTOCOLLN("D"); } #endif - + eqnBVector[probePointCounter] = measured_z; eqnAMatrix[probePointCounter + 0*AUTO_BED_LEVELING_GRID_POINTS*AUTO_BED_LEVELING_GRID_POINTS] = xProbe; @@ -2388,8 +2388,8 @@ void process_commands() SERIAL_PROTOCOLLN(((READ(Y_MAX_PIN)^Y_MAX_ENDSTOP_INVERTING)?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN)); #endif #ifdef FSR_BED_LEVELING - SERIAL_PROTOCOLPGM(MSG_Z_MIN); - //SERIAL_PROTOCOLLN((fsr_z_endstop?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN)); + //SERIAL_PROTOCOLPGM(MSG_Z_MIN); + //SERIAL_PROTOCOLLN((fsr_z_endstop?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN)); #elif defined(Z_MIN_PIN) && Z_MIN_PIN > -1 SERIAL_PROTOCOLPGM(MSG_Z_MIN); SERIAL_PROTOCOLLN(((READ(Z_MIN_PIN)^Z_MIN_ENDSTOP_INVERTING)?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN)); @@ -2861,7 +2861,7 @@ void process_commands() { Config_PrintSettings(); } - + #ifdef ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED case 540: { @@ -2934,7 +2934,7 @@ void process_commands() value = code_value(); if ((ABL_ADJUSTMENT_MIN <= value) && (value <= ABL_ADJUSTMENT_MAX)) { - abl_C_offset = value; + abl_C_offset = value; SERIAL_ECHO_START; SERIAL_ECHOLNPGM("ABL C offset has been set"); SERIAL_PROTOCOLLN(""); @@ -2945,7 +2945,7 @@ void process_commands() value = code_value(); if ((ABL_ADJUSTMENT_MIN <= value) && (value <= ABL_ADJUSTMENT_MAX)) { - abl_D_offset = value; + abl_D_offset = value; SERIAL_ECHO_START; SERIAL_ECHOLNPGM("ABL D offset has been set"); SERIAL_PROTOCOLLN(""); @@ -2959,7 +2959,7 @@ void process_commands() SERIAL_ECHO(ABL_ADJUSTMENT_MAX); SERIAL_PROTOCOLLN(""); } - } + } else { SERIAL_ECHO_START; @@ -2975,7 +2975,7 @@ void process_commands() SERIAL_PROTOCOLLN(""); } break; - } + } #endif #ifdef CUSTOM_M_CODES diff --git a/Marlin/fsr_abl.h b/Marlin/fsr_abl.h index d21fa9e9525b..e6f114bc2d55 100644 --- a/Marlin/fsr_abl.h +++ b/Marlin/fsr_abl.h @@ -9,10 +9,10 @@ #ifdef FSR_BED_LEVELING -void FSR_ABL_Reading(); -int FSR_ABL_Get_Read(); -int FSR_ABL_Get_Avg(); -bool FSR_ABL_Trigger(); + void FSR_ABL_Reading(); + int FSR_ABL_Get_Read(); + int FSR_ABL_Get_Avg(); + bool FSR_ABL_Trigger(); #endif -#endif \ No newline at end of file +#endif diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index d9372e7bad4c..9a0de2aee186 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -516,20 +516,20 @@ ISR(TIMER1_COMPA_vect) count_direction[Z_AXIS]=-1; CHECK_ENDSTOPS { - #if defined FSR_BED_LEVELING && defined FSR_PIN && FSR_PIN > -1 - // Run endstop triggered logic, fsr_trigger signals endstop status - bool fsr_trigger = FSR_ABL_Trigger(); + #if defined FSR_BED_LEVELING && defined FSR_PIN && FSR_PIN > -1 + // Run endstop triggered logic, fsr_trigger signals endstop status + bool fsr_trigger = FSR_ABL_Trigger(); if(fsr_trigger && old_z_min_endstop && (current_block->steps_z > 0)) { endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS]; endstop_z_hit=true; step_events_completed = current_block->step_event_count; } old_z_min_endstop = fsr_trigger; - // End of FSR ABL - - #elif defined(Z_MIN_PIN) && Z_MIN_PIN > -1 - bool z_min_endstop=(READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING); - if(z_min_endstop && old_z_min_endstop && (current_block->steps_z > 0)) { + // End of FSR ABL +i + #elif defined(Z_MIN_PIN) && Z_MIN_PIN > -1 + bool z_min_endstop=(READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING); + if(z_min_endstop && old_z_min_endstop && (current_block->steps_z > 0)) { endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS]; endstop_z_hit=true; step_events_completed = current_block->step_event_count; diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index bd9dd2be2153..539085c2b5d3 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -114,7 +114,7 @@ static volatile bool temp_meas_ready = false; static unsigned long previous_millis_bed_heater; #endif //PIDTEMPBED static unsigned char soft_pwm[EXTRUDERS]; - + #ifdef FAN_SOFT_PWM static unsigned char soft_pwm_fan; #endif @@ -217,6 +217,7 @@ void PID_autotune(float temp, int extruder, int ncycles) if(temp_meas_ready == true) { // temp sample ready updateTemperaturesFromRawValues(); + input = (extruder<0)?current_temperature_bed:current_temperature[extruder]; max=max(max,input); @@ -692,10 +693,10 @@ static void updateTemperaturesFromRawValues() redundant_temperature = analog2temp(redundant_temperature_raw, 1); #endif #ifdef FSR_BED_LEVELING - FSR_ABL_Reading(); + FSR_ABL_Reading(); #endif - - //Reset the watchdog after we know we have a temperature measurement. + + //Reset the watchdog after we know we have a temperature measurement. watchdog_reset(); CRITICAL_SECTION_START; @@ -1064,9 +1065,9 @@ ISR(TIMER0_COMPB_vect) #endif #if defined FSR_BED_LEVELING - static unsigned long raw_fsr_value = 0; + static unsigned long raw_fsr_value = 0; #endif - + if(pwm_count == 0){ soft_pwm_0 = soft_pwm[0]; if(soft_pwm_0 > 0) { @@ -1172,8 +1173,12 @@ ISR(TIMER0_COMPB_vect) break; case 5: // Measure TEMP_1 #if defined(TEMP_1_PIN) && (TEMP_1_PIN > -1) - raw_temp_1_sample = ADC; - raw_temp_1_value += raw_temp_1_sample; + #ifdef FSR_BED_LEVELING + raw_temp_1_sample = ADC; + raw_temp_1_value += raw_temp_1_sample; + #else + raw_temp_1_value += ADC + #endif #endif temp_state = 6; break; @@ -1242,10 +1247,10 @@ ISR(TIMER0_COMPB_vect) current_temperature_raw[2] = raw_temp_2_value; #endif current_temperature_bed_raw = raw_temp_bed_value; - - #if defined FSR_BED_LEVELING - current_fsr_value = raw_fsr_value; - #endif + + #ifdef FSR_BED_LEVELING + current_fsr_value = raw_fsr_value; + #endif } temp_meas_ready = true; @@ -1254,9 +1259,9 @@ ISR(TIMER0_COMPB_vect) raw_temp_1_value = 0; raw_temp_2_value = 0; raw_temp_bed_value = 0; - #if defined FSR_BED_LEVELING - raw_fsr_value = 0; - #endif + #ifdef FSR_BED_LEVELING + raw_fsr_value = 0; + #endif #if HEATER_0_RAW_LO_TEMP > HEATER_0_RAW_HI_TEMP if(current_temperature_raw[0] <= maxttemp_raw[0]) { diff --git a/Marlin/temperature.h b/Marlin/temperature.h index ad245986fa38..69c9a479f1c1 100644 --- a/Marlin/temperature.h +++ b/Marlin/temperature.h @@ -43,7 +43,7 @@ extern int raw_temp_1_sample; extern int target_temperature_bed; extern float current_temperature_bed; #if defined FSR_BED_LEVELING -extern int current_fsr_value; + extern int current_fsr_value; #endif #ifdef TEMP_SENSOR_1_AS_REDUNDANT @@ -91,13 +91,13 @@ FORCE_INLINE float degHotend(uint8_t extruder) { #ifdef FSR_BED_LEVELING FORCE_INLINE int current_fsr_sample(){ - return current_fsr_value; -} -#endif + return current_fsr_value; + } -FORCE_INLINE int rawTemp1Sample(){ - return raw_temp_1_sample; -} + FORCE_INLINE int rawTemp1Sample(){ + return raw_temp_1_sample; + } +#endif FORCE_INLINE float degBed() { return current_temperature_bed; diff --git a/run_tests.sh b/run_tests.sh index a8b38ca4d95c..8e866a78d9b4 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -78,7 +78,7 @@ run MOTHERBOARD=81 ENABLE_AUTO_BED_LEVELING=1 Z_SAFE_HOMING_FIXED_POINT=1 run -MOTHERBOARD=81 ENABLE_AUTO_BED_LEVELING=1 +MOTHERBOARD=81 ENABLE_AUTO_BED_LEVELING=1 run From 3cacf24aab3c3fcf619a3ff8c911b45d099161f3 Mon Sep 17 00:00:00 2001 From: Joe Marino Date: Wed, 10 Sep 2014 23:58:38 -0700 Subject: [PATCH 58/71] remove typo --- Marlin/stepper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index 9a0de2aee186..382e80ea119a 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -526,7 +526,7 @@ ISR(TIMER1_COMPA_vect) } old_z_min_endstop = fsr_trigger; // End of FSR ABL -i + #elif defined(Z_MIN_PIN) && Z_MIN_PIN > -1 bool z_min_endstop=(READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING); if(z_min_endstop && old_z_min_endstop && (current_block->steps_z > 0)) { From 8db5a9cfae5ac88b3c47fe69b1559786b45e95c5 Mon Sep 17 00:00:00 2001 From: Joe Marino Date: Thu, 11 Sep 2014 01:31:31 -0700 Subject: [PATCH 59/71] run Z max before LED init --- Marlin/Marlin_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 1bfd5028eeb4..007b19b4581c 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -533,8 +533,8 @@ void setup() #endif #ifdef MSM_Printeer - run_z_max(); led_init(); + run_z_max(); #endif } From 75b45a181e6636eb8feacceabd3989901064a780 Mon Sep 17 00:00:00 2001 From: Joe Marino Date: Thu, 11 Sep 2014 01:50:33 -0700 Subject: [PATCH 60/71] remve extra line in run_test.sh --- run_tests.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/run_tests.sh b/run_tests.sh index 8e866a78d9b4..1edda7b2defa 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -81,7 +81,6 @@ run MOTHERBOARD=81 ENABLE_AUTO_BED_LEVELING=1 run - MOTHERBOARD=81 run From 6bb5f5036f1bb0e5d475ff9a2e186332323e6097 Mon Sep 17 00:00:00 2001 From: Joe Marino Date: Wed, 17 Sep 2014 10:08:14 -0700 Subject: [PATCH 61/71] Syntax, comments and error corrections Per comments in code review: -Included additonal comments to improve implementation of FSR ABL. -Improved syntax and spacing consistency. -Fixed a few code errors -Replaced numerical values with constants/#defines --- Marlin/Configuration.h | 2 +- Marlin/Marlin_main.cpp | 164 +++++++++++++++++++++-------------------- Marlin/fsr_abl.cpp | 32 +++++--- Marlin/pins.h | 2 +- Marlin/temperature.cpp | 23 +++--- Marlin/temperature.h | 5 -- 6 files changed, 120 insertions(+), 108 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 480960feb130..e93be796f065 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -366,7 +366,6 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o // I wouldn't see a reason to go above 3 (=9 probing points on the bed) #define AUTO_BED_LEVELING_GRID_POINTS 3 -//154x106 #else // not AUTO_BED_LEVELING_GRID // with no grid, just probe 3 arbitrary points. A simple cross-product // is used to esimate the plane of the print bed @@ -489,6 +488,7 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o #define ABL_ADJUSTMENT 506 #define ABL_ADJUSTMENT_MIN -5 #define ABL_ADJUSTMENT_MAX 5 + #define MM_RETRACT_AFTER_FSR_ABL 3 #endif // Custom M code for MSM Printeer diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 007b19b4581c..fabbe8a8637c 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -930,7 +930,10 @@ static void run_z_probe() { zPosition += home_retract_mm(Z_AXIS); plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], zPosition, current_position[E_AXIS], feedrate/60, active_extruder); st_synchronize(); - #ifndef FSR_BED_LEVELING // no second tap if FSR_BED_LEVELING + #ifndef FSR_BED_LEVELING // due to the averageing used in FSR_BED_LEVELING, + // the second probing causes the average value to + // be too high and will not trigger properly, + // therefore FSR_BED_LEVELING skips the second probe // move back down slowly to find bed feedrate = homing_feedrate[Z_AXIS]/4; zPosition -= home_retract_mm(Z_AXIS) * 2; @@ -1074,26 +1077,30 @@ static void homeaxis(int axis) { current_position[axis] = 0; plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); - #ifdef FSR_BED_LEVELING // ensure Z-retract after FSR_BED_LEVELING homing - if (axis == Z_AXIS) { - destination[axis] = 3; - plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); - st_synchronize(); - } - #endif - #ifndef FSR_BED_LEVELING // no second tap for FSR_BED_LEVELING homing + #ifdef FSR_BED_LEVELING // ensure Z-retract after FSR_BED_LEVELING homing. + // + // due to the averageing used in FSR_BED_LEVELING, + // the second probing causes the average value to + // be too high and will not trigger properly, + // therefore FSR_BED_LEVELING skips the second probe + if (axis == Z_AXIS) { + destination[axis] = MM_RETRACT_AFTER_FSR_ABL; + plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); + st_synchronize(); + } + #else destination[axis] = -home_retract_mm(axis) * axis_home_dir; plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); st_synchronize(); destination[axis] = 2*home_retract_mm(axis) * axis_home_dir; - #ifdef DELTA - feedrate = homing_feedrate[axis]/10; - #else - feedrate = homing_feedrate[axis]/2 ; - #endif - plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); - st_synchronize(); + #ifdef DELTA + feedrate = homing_feedrate[axis]/10; + #else + feedrate = homing_feedrate[axis]/2 ; + #endif + plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); + st_synchronize(); #endif #ifdef DELTA // retrace by the amount specified in endstop_adj @@ -1165,7 +1172,7 @@ void refresh_cmd_timeout(void) #endif //FWRETRACT #ifdef MSM_Printeer - void run_z_max() + void run_z_max() // move bed to bottom (z-maximum) { enable_endstops(true); @@ -1190,7 +1197,7 @@ void refresh_cmd_timeout(void) #endif } - void led_init() + void led_init() // turn on all the lights when the board boots { pinMode(LED_GREEN_PIN,OUTPUT); digitalWrite(LED_GREEN_PIN,HIGH); @@ -1575,7 +1582,14 @@ void process_commands() float measured_z = probe_pt(xProbe, yProbe, z_before); #ifdef FSR_BED_LEVELING - // Fudges the value at the fourth point in a 4-pt measurement + // In testing we found it is best to apply the fudge amounts to the four corners of the probe grid + // but not the inside points. In a 3x3 grid, we probe + // 0 1 2 + // 3 4 5 + // 6 7 8 + // and thus the four points to fudge are { 0, 2, 6, 8 } + + // Fudges the value at the fist point in a 4-pt measurement // A negative input value increases distance between bed and nozzle // A positive input value decreases distance between bed and nozzle // M851 adjustment is applied after ABL transformation is applied @@ -1585,7 +1599,7 @@ void process_commands() SERIAL_PROTOCOLLN("A"); } - // Fudges the value at the fourth point in a 4-pt measurement + // Fudges the value at the second point in a 4-pt measurement // A negative input value increases distance between bed and nozzle // A positive input value decreases distance between bed and nozzle // M851 adjustment is applied after ABL transformation is applied @@ -1595,11 +1609,11 @@ void process_commands() SERIAL_PROTOCOLLN("B"); } - // Fudges the value at the fourth point in a 4-pt measurement + // Fudges the value at the third point in a 4-pt measurement // A negative input value increases distance between bed and nozzle // A positive input value decreases distance between bed and nozzle // M851 adjustment is applied after ABL transformation is applied - if ((AUTO_BED_LEVELING_GRID_POINTS == 2) && (probePointCounter == 2) || ((AUTO_BED_LEVELING_GRID_POINTS == 3) && (probePointCounter == 5))) + if ((AUTO_BED_LEVELING_GRID_POINTS == 2) && (probePointCounter == 2) || ((AUTO_BED_LEVELING_GRID_POINTS == 3) && (probePointCounter == 6))) { measured_z -= abl_C_offset; SERIAL_PROTOCOLLN("C"); @@ -1656,11 +1670,8 @@ void process_commands() clean_up_after_endstop_move(); - #ifdef FSR_BED_LEVELING - set_bed_level_equation_3pts(z_at_pt_1-abl_A_offset, z_at_pt_2-abl_B_offset, z_at_pt_3-abl_C_offset); // Higher values lower nozzle-bed distance - #else - set_bed_level_equation_3pts(z_at_pt_1, z_at_pt_2, z_at_pt_3); - #endif + set_bed_level_equation_3pts(z_at_pt_1, z_at_pt_2, z_at_pt_3); + #endif // AUTO_BED_LEVELING_GRID st_synchronize(); @@ -2387,10 +2398,7 @@ void process_commands() SERIAL_PROTOCOLPGM(MSG_Y_MAX); SERIAL_PROTOCOLLN(((READ(Y_MAX_PIN)^Y_MAX_ENDSTOP_INVERTING)?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN)); #endif - #ifdef FSR_BED_LEVELING - //SERIAL_PROTOCOLPGM(MSG_Z_MIN); - //SERIAL_PROTOCOLLN((fsr_z_endstop?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN)); - #elif defined(Z_MIN_PIN) && Z_MIN_PIN > -1 + #if defined(Z_MIN_PIN) && Z_MIN_PIN > -1 && !defined(FSR_BED_LEVELING) SERIAL_PROTOCOLPGM(MSG_Z_MIN); SERIAL_PROTOCOLLN(((READ(Z_MIN_PIN)^Z_MIN_ENDSTOP_INVERTING)?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN)); #endif @@ -2861,7 +2869,7 @@ void process_commands() { Config_PrintSettings(); } - + break; #ifdef ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED case 540: { @@ -2890,7 +2898,7 @@ void process_commands() { float value; if (code_seen('A')) // First point - { + { value = code_value(); if ((ABL_ADJUSTMENT_MIN <= value) && (value <= ABL_ADJUSTMENT_MAX)) { @@ -2910,44 +2918,13 @@ void process_commands() } } else if (code_seen('B')) // Second point - { - value = code_value(); - if ((ABL_ADJUSTMENT_MIN <= value) && (value <= ABL_ADJUSTMENT_MAX)) - { - abl_B_offset = value; // compare w/ line 278 of ConfigurationStore.cpp - SERIAL_ECHO_START; - SERIAL_ECHOLNPGM("ABL B offset has been set"); - SERIAL_PROTOCOLLN(""); - } - else - { - SERIAL_ECHO_START; - SERIAL_ECHOPGM("Invalid value. Must be between "); - SERIAL_ECHO(ABL_ADJUSTMENT_MIN); - SERIAL_ECHOPGM(" and "); - SERIAL_ECHO(ABL_ADJUSTMENT_MAX); - SERIAL_PROTOCOLLN(""); - } - } - else if (code_seen('C')) // Third point - { - value = code_value(); - if ((ABL_ADJUSTMENT_MIN <= value) && (value <= ABL_ADJUSTMENT_MAX)) - { - abl_C_offset = value; - SERIAL_ECHO_START; - SERIAL_ECHOLNPGM("ABL C offset has been set"); - SERIAL_PROTOCOLLN(""); - } - } - else if (code_seen('D')) // Fourth point (grid only) - { + { value = code_value(); if ((ABL_ADJUSTMENT_MIN <= value) && (value <= ABL_ADJUSTMENT_MAX)) { - abl_D_offset = value; + abl_B_offset = value; // compare w/ line 278 of ConfigurationStore.cpp SERIAL_ECHO_START; - SERIAL_ECHOLNPGM("ABL D offset has been set"); + SERIAL_ECHOLNPGM("ABL B offset has been set"); SERIAL_PROTOCOLLN(""); } else @@ -2959,24 +2936,55 @@ void process_commands() SERIAL_ECHO(ABL_ADJUSTMENT_MAX); SERIAL_PROTOCOLLN(""); } + } + else if (code_seen('C')) // Third point + { + value = code_value(); + if ((ABL_ADJUSTMENT_MIN <= value) && (value <= ABL_ADJUSTMENT_MAX)) + { + abl_C_offset = value; + SERIAL_ECHO_START; + SERIAL_ECHOLNPGM("ABL C offset has been set"); + SERIAL_PROTOCOLLN(""); + } + } + else if (code_seen('D')) // Fourth point (grid only) + { + value = code_value(); + if ((ABL_ADJUSTMENT_MIN <= value) && (value <= ABL_ADJUSTMENT_MAX)) + { + abl_D_offset = value; + SERIAL_ECHO_START; + SERIAL_ECHOLNPGM("ABL D offset has been set"); + SERIAL_PROTOCOLLN(""); } else { SERIAL_ECHO_START; - SERIAL_ECHOLNPGM("ABL offsets are currently"); - SERIAL_ECHOPGM("A: "); - SERIAL_ECHO(abl_A_offset); - SERIAL_ECHOPGM(", B: "); - SERIAL_ECHO(abl_B_offset); - SERIAL_ECHOPGM(", C: "); - SERIAL_ECHO(abl_C_offset); - SERIAL_ECHOPGM(", D: "); - SERIAL_ECHO(abl_D_offset); + SERIAL_ECHOPGM("Invalid value. Must be between "); + SERIAL_ECHO(ABL_ADJUSTMENT_MIN); + SERIAL_ECHOPGM(" and "); + SERIAL_ECHO(ABL_ADJUSTMENT_MAX); SERIAL_PROTOCOLLN(""); } - break; } - #endif + else // echo current ABL settings + { + SERIAL_ECHO_START; + SERIAL_ECHOLNPGM("ABL offsets are currently"); + SERIAL_ECHOPGM("A: "); + SERIAL_ECHO(abl_A_offset); + SERIAL_ECHOPGM(", B: "); + SERIAL_ECHO(abl_B_offset); + SERIAL_ECHOPGM(", C: "); + SERIAL_ECHO(abl_C_offset); + SERIAL_ECHOPGM(", D: "); + SERIAL_ECHO(abl_D_offset); + SERIAL_PROTOCOLLN(""); + } + break; + } + #endif // FSR_BED_LEVELING #ifdef CUSTOM_M_CODES case CUSTOM_M_CODE_REPORT_BUILD_INFO: diff --git a/Marlin/fsr_abl.cpp b/Marlin/fsr_abl.cpp index 9d0389bcf9c4..ef690b88c91e 100644 --- a/Marlin/fsr_abl.cpp +++ b/Marlin/fsr_abl.cpp @@ -4,15 +4,22 @@ #include "fsr_abl.h" #include "Marlin.h" -#include "temperature.h" +#include "temperature.h" // contains current_fsr_sample() -#ifdef FSR_BED_LEVELING && defined FSR_PIN && FSR_PIN > -1 - -// Public Variables +#ifdef FSR_BED_LEVELING + #ifndef FSR_PIN + #error You must define FSR_PIN + #endif + #if FSR_PIN < 0 + #error You must define FSR_PIN >= 0 + #endif // Private Variables (static preserves between function calls and prevents calling by extern) static int fsr_rolling_avg; static float fsr_weighting = 4.5; // Higher weighting means ave changes slower +static float fsr_upper_trigger = 1.25; // upper bound % of rolling average for trigger +static float fsr_lower_trigger = 0.65; // lower bound % of rolling average for trigger +static int current_sample; // Updates rolling average with most recent value from ADC void FSR_ABL_Reading() @@ -38,14 +45,15 @@ int FSR_ABL_Get_Avg() bool FSR_ABL_Trigger() { // Check filter for trigger conditions -if (((current_fsr_sample() > 1.25*fsr_rolling_avg) || (current_fsr_sample() < .65*fsr_rolling_avg) || (current_fsr_sample() > 520)) && (current_fsr_sample() > 50)){ - return(true); - } -else{ - // Do nothing but return false - return(false); - } + current_sample = current_fsr_sample(); + if (((current_sample > fsr_upper_trigger*fsr_rolling_avg) || (current_sample < fsr_lower_trigger*fsr_rolling_avg) || (current_sample > 520)) && (current_sample > 50)){ + return(true); + } + else { + // Do nothing but return false + return(false); + } } -#endif +#endif // FSR_BED_LEVELING diff --git a/Marlin/pins.h b/Marlin/pins.h index 176f77bbe0b9..4df296797f89 100644 --- a/Marlin/pins.h +++ b/Marlin/pins.h @@ -1600,7 +1600,7 @@ #define TEMP_BED_PIN 0 // Bed / Analog pin numbering #endif -#define TEMP_1_PIN -1 // Pin for FSR ABL (#40, bottom left of EXP1) +#define TEMP_1_PIN -1 #define TEMP_2_PIN -1 #define SDPOWER -1 diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index 539085c2b5d3..291bb27705a6 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -33,8 +33,8 @@ #include "ultralcd.h" #include "temperature.h" #include "watchdog.h" -#if defined FSR_BED_LEVELING -#include "fsr_abl.h" +#ifdef FSR_BED_LEVELING // ADC sampling for FSR_BED_LEVELING during ISR + #include "fsr_abl.h" #endif //=========================================================================== @@ -46,8 +46,9 @@ int current_temperature_raw[EXTRUDERS] = { 0 }; float current_temperature[EXTRUDERS] = { 0.0 }; int current_temperature_bed_raw = 0; float current_temperature_bed = 0.0; -#if defined FSR_BED_LEVELING -int current_fsr_value = 0; + +#ifdef FSR_BED_LEVELING + int current_fsr_value = 0; #endif #ifdef TEMP_SENSOR_1_AS_REDUNDANT @@ -692,9 +693,10 @@ static void updateTemperaturesFromRawValues() #ifdef TEMP_SENSOR_1_AS_REDUNDANT redundant_temperature = analog2temp(redundant_temperature_raw, 1); #endif - #ifdef FSR_BED_LEVELING - FSR_ABL_Reading(); - #endif + + #ifdef FSR_BED_LEVELING + FSR_ABL_Reading(); + #endif //Reset the watchdog after we know we have a temperature measurement. watchdog_reset(); @@ -1051,7 +1053,7 @@ ISR(TIMER0_COMPB_vect) static unsigned long raw_temp_1_value = 0; static unsigned long raw_temp_2_value = 0; static unsigned long raw_temp_bed_value = 0; - static unsigned char temp_state = 9; + static unsigned char temp_state = 10; static unsigned char pwm_count = (1 << SOFT_PWM_SCALE); static unsigned char soft_pwm_0; #if (EXTRUDERS > 1) || defined(HEATERS_PARALLEL) @@ -1174,8 +1176,7 @@ ISR(TIMER0_COMPB_vect) case 5: // Measure TEMP_1 #if defined(TEMP_1_PIN) && (TEMP_1_PIN > -1) #ifdef FSR_BED_LEVELING - raw_temp_1_sample = ADC; - raw_temp_1_value += raw_temp_1_sample; + raw_temp_1_value += ADC; #else raw_temp_1_value += ADC #endif @@ -1219,7 +1220,7 @@ ISR(TIMER0_COMPB_vect) break; case 9: // Measure FSR_ABL #if defined FSR_BED_LEVELING && FSR_PIN && FSR_PIN > -1 - raw_fsr_value = ADC; + raw_fsr_value = ADC; // raw value only, averaging occurs in fsr_abl.cpp #endif temp_state = 0; temp_count++; diff --git a/Marlin/temperature.h b/Marlin/temperature.h index 69c9a479f1c1..a586d113d8f4 100644 --- a/Marlin/temperature.h +++ b/Marlin/temperature.h @@ -39,7 +39,6 @@ extern float current_temperature[EXTRUDERS]; extern int current_temperature_raw[EXTRUDERS]; extern int current_temperature_bed_raw; #endif -extern int raw_temp_1_sample; extern int target_temperature_bed; extern float current_temperature_bed; #if defined FSR_BED_LEVELING @@ -93,10 +92,6 @@ FORCE_INLINE float degHotend(uint8_t extruder) { FORCE_INLINE int current_fsr_sample(){ return current_fsr_value; } - - FORCE_INLINE int rawTemp1Sample(){ - return raw_temp_1_sample; - } #endif FORCE_INLINE float degBed() { From 29548900fe55d07bddd8fc67fb72892014787a5f Mon Sep 17 00:00:00 2001 From: Joe Marino Date: Wed, 17 Sep 2014 15:52:01 -0700 Subject: [PATCH 62/71] minor spacing improvement --- Marlin/Marlin_main.cpp | 97 +++++++++++++++++++++--------------------- 1 file changed, 49 insertions(+), 48 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index fabbe8a8637c..e1f6e17e3d6d 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -1581,54 +1581,55 @@ void process_commands() } float measured_z = probe_pt(xProbe, yProbe, z_before); - #ifdef FSR_BED_LEVELING - // In testing we found it is best to apply the fudge amounts to the four corners of the probe grid - // but not the inside points. In a 3x3 grid, we probe - // 0 1 2 - // 3 4 5 - // 6 7 8 - // and thus the four points to fudge are { 0, 2, 6, 8 } - - // Fudges the value at the fist point in a 4-pt measurement - // A negative input value increases distance between bed and nozzle - // A positive input value decreases distance between bed and nozzle - // M851 adjustment is applied after ABL transformation is applied - if ((AUTO_BED_LEVELING_GRID_POINTS == 2) && (probePointCounter == 0) || ((AUTO_BED_LEVELING_GRID_POINTS == 3) && (probePointCounter == 0))) - { - measured_z -= abl_A_offset; - SERIAL_PROTOCOLLN("A"); - } - - // Fudges the value at the second point in a 4-pt measurement - // A negative input value increases distance between bed and nozzle - // A positive input value decreases distance between bed and nozzle - // M851 adjustment is applied after ABL transformation is applied - if ((AUTO_BED_LEVELING_GRID_POINTS == 2) && (probePointCounter == 1) || ((AUTO_BED_LEVELING_GRID_POINTS == 3) && (probePointCounter == 2))) - { - measured_z -= abl_B_offset; - SERIAL_PROTOCOLLN("B"); - } - - // Fudges the value at the third point in a 4-pt measurement - // A negative input value increases distance between bed and nozzle - // A positive input value decreases distance between bed and nozzle - // M851 adjustment is applied after ABL transformation is applied - if ((AUTO_BED_LEVELING_GRID_POINTS == 2) && (probePointCounter == 2) || ((AUTO_BED_LEVELING_GRID_POINTS == 3) && (probePointCounter == 6))) - { - measured_z -= abl_C_offset; - SERIAL_PROTOCOLLN("C"); - } - - // Fudges the value at the fourth point in a 4-pt measurement - // A negative input value increases distance between bed and nozzle - // A positive input value decreases distance between bed and nozzle - // M851 adjustment is applied after ABL transformation is applied - if ((AUTO_BED_LEVELING_GRID_POINTS == 2) && (probePointCounter == 3) || ((AUTO_BED_LEVELING_GRID_POINTS == 3) && (probePointCounter == 8))) - { - measured_z -= abl_D_offset; - SERIAL_PROTOCOLLN("D"); - } - #endif + + #ifdef FSR_BED_LEVELING + // In testing we found it is best to apply the fudge amounts to the four corners of the probe grid + // but not the inside points. In a 3x3 grid, we probe + // 0 1 2 + // 3 4 5 + // 6 7 8 + // and thus the four points to fudge are { 0, 2, 6, 8 } + + // Fudges the value at the fist point in a 4-pt measurement + // A negative input value increases distance between bed and nozzle + // A positive input value decreases distance between bed and nozzle + // M851 adjustment is applied after ABL transformation is applied + if ((AUTO_BED_LEVELING_GRID_POINTS == 2) && (probePointCounter == 0) || ((AUTO_BED_LEVELING_GRID_POINTS == 3) && (probePointCounter == 0))) + { + measured_z -= abl_A_offset; + SERIAL_PROTOCOLLN("A"); + } + + // Fudges the value at the second point in a 4-pt measurement + // A negative input value increases distance between bed and nozzle + // A positive input value decreases distance between bed and nozzle + // M851 adjustment is applied after ABL transformation is applied + if ((AUTO_BED_LEVELING_GRID_POINTS == 2) && (probePointCounter == 1) || ((AUTO_BED_LEVELING_GRID_POINTS == 3) && (probePointCounter == 2))) + { + measured_z -= abl_B_offset; + SERIAL_PROTOCOLLN("B"); + } + + // Fudges the value at the third point in a 4-pt measurement + // A negative input value increases distance between bed and nozzle + // A positive input value decreases distance between bed and nozzle + // M851 adjustment is applied after ABL transformation is applied + if ((AUTO_BED_LEVELING_GRID_POINTS == 2) && (probePointCounter == 2) || ((AUTO_BED_LEVELING_GRID_POINTS == 3) && (probePointCounter == 6))) + { + measured_z -= abl_C_offset; + SERIAL_PROTOCOLLN("C"); + } + + // Fudges the value at the fourth point in a 4-pt measurement + // A negative input value increases distance between bed and nozzle + // A positive input value decreases distance between bed and nozzle + // M851 adjustment is applied after ABL transformation is applied + if ((AUTO_BED_LEVELING_GRID_POINTS == 2) && (probePointCounter == 3) || ((AUTO_BED_LEVELING_GRID_POINTS == 3) && (probePointCounter == 8))) + { + measured_z -= abl_D_offset; + SERIAL_PROTOCOLLN("D"); + } + #endif eqnBVector[probePointCounter] = measured_z; From 608abeaeed92dab6e65d4a8f0f63dbd5fd928f04 Mon Sep 17 00:00:00 2001 From: Joe Marino Date: Thu, 18 Sep 2014 11:54:28 -0700 Subject: [PATCH 63/71] Missing break; and spacing improvement --- Marlin/temperature.cpp | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index 291bb27705a6..902b0d6e38c6 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -1175,11 +1175,7 @@ ISR(TIMER0_COMPB_vect) break; case 5: // Measure TEMP_1 #if defined(TEMP_1_PIN) && (TEMP_1_PIN > -1) - #ifdef FSR_BED_LEVELING - raw_temp_1_value += ADC; - #else - raw_temp_1_value += ADC - #endif + raw_temp_1_value += ADC; #endif temp_state = 6; break; @@ -1200,14 +1196,14 @@ ISR(TIMER0_COMPB_vect) #if defined(TEMP_2_PIN) && (TEMP_2_PIN > -1) raw_temp_2_value += ADC; #endif - temp_state = 8; - #ifndef FSR_BED_LEVELING - temp_state = 0; - temp_count++; - #endif + temp_state = 8; + #ifndef FSR_BED_LEVELING + temp_state = 0; + temp_count++; + #endif break; - case 8: // Prepare for FSR_ABL measurement - #if defined FSR_BED_LEVELING && FSR_PIN && FSR_PIN > -1 + case 8: // Prepare for FSR_ABL measurement + #if defined FSR_BED_LEVELING && FSR_PIN && FSR_PIN > -1 #if FSR_PIN > 7 ADCSRB = 1< -1 - raw_fsr_value = ADC; // raw value only, averaging occurs in fsr_abl.cpp - #endif - temp_state = 0; + break; + case 9: // Measure FSR_ABL + #if defined(FSR_BED_LEVELING) && defined(FSR_PIN) && FSR_PIN > -1 + raw_fsr_value = ADC; // raw value only, averaging occurs in fsr_abl.cpp + #endif + temp_state = 0; temp_count++; + break; case 10: //Startup, delay initial temp reading a tiny bit so the hardware can settle. temp_state = 0; break; @@ -1249,7 +1246,7 @@ ISR(TIMER0_COMPB_vect) #endif current_temperature_bed_raw = raw_temp_bed_value; - #ifdef FSR_BED_LEVELING + #ifdef FSR_BED_LEVELING current_fsr_value = raw_fsr_value; #endif } From b19a589c874ad8dfe0af14218858cade9716465d Mon Sep 17 00:00:00 2001 From: Joe Marino Date: Thu, 18 Sep 2014 13:22:46 -0700 Subject: [PATCH 64/71] Added comment to M119 --- Marlin/Marlin_main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index e1f6e17e3d6d..701f759d144d 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -2400,6 +2400,7 @@ void process_commands() SERIAL_PROTOCOLLN(((READ(Y_MAX_PIN)^Y_MAX_ENDSTOP_INVERTING)?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN)); #endif #if defined(Z_MIN_PIN) && Z_MIN_PIN > -1 && !defined(FSR_BED_LEVELING) + // FSR_BED_LEVEING trigger Z_MIN "instaneously," therefore cannot be displayed via M119 SERIAL_PROTOCOLPGM(MSG_Z_MIN); SERIAL_PROTOCOLLN(((READ(Z_MIN_PIN)^Z_MIN_ENDSTOP_INVERTING)?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN)); #endif From 170cbcaeaf1315028bb1cb9aea5600a2fc8ae810 Mon Sep 17 00:00:00 2001 From: Joe Marino Date: Thu, 18 Sep 2014 15:09:20 -0700 Subject: [PATCH 65/71] Delete Z_SAFE_HOMING_FIXED_POINT Z_SAFE_HOMING_FIXED_POINT was a custom feature for the Printeer and is not in Marlin_v1. This feature is not longer needed and therefore removed from C++ and automated testing files --- Marlin/Configuration.h | 18 ++---------------- Marlin/Marlin_main.cpp | 36 +++++++++--------------------------- Marlin/stepper.cpp | 14 +++++++------- run_tests.sh | 13 ++++--------- 4 files changed, 22 insertions(+), 59 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index e93be796f065..210d942d97db 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -323,8 +323,8 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o // Travel limits after homing #define X_MAX_POS 154 #define X_MIN_POS 0 -#define Y_MAX_POS 105 -#define Y_MIN_POS 0 +#define Y_MAX_POS 105 +#define Y_MIN_POS 0 #define Z_MAX_POS 125 #define Z_MIN_POS 0 @@ -418,20 +418,6 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o #define Z_SAFE_HOMING_X_POINT -10 // X point for Z homing when homing all axis (G28) #define Z_SAFE_HOMING_Y_POINT 121 // Y point for Z homing when homing all axis (G28) - - -// On Mission St Mfg's prototype printer, Z-homing and bed probing is only safe -// within a very narrow region. Hence Z_SAFE_HOMING_FIXED_POINT! -// -// This mode differs from regular Z_SAFE_HOMING in the following ways: -// - Before *any* Z home begins, first X & Y are homed and then the probe is -// moved in (x,y) to the safe-homing point defined above. -// Without this option set, "G28 Z0" will do a straight Z-home from -// anywhere in the bed area. That will cause mayhem on our printer. -// - G30 command is disabled, for the same reason. - //#define Z_SAFE_HOMING_FIXED_POINT - - #endif #endif // ENABLE_AUTO_BED_LEVELING diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 701f759d144d..577166023f1c 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -92,7 +92,7 @@ // G413 - Red LED ON // G414 - Red LED OFF // G415 - Button LED ON -// G416 - Button LED OFF +// G416 - Button LED OFF // M Codes // M0 - Unconditional stop - Wait for user to press a button on the LCD (Only if ULTRA_LCD is enabled) @@ -1329,10 +1329,6 @@ void process_commands() home_all_axis = !((code_seen(axis_codes[X_AXIS])) || (code_seen(axis_codes[Y_AXIS])) || (code_seen(axis_codes[Z_AXIS]))); - #ifdef Z_SAFE_HOMING_FIXED_POINT // Z home always triggers X & Y home first - home_all_axis |= code_seen(axis_codes[Z_AXIS]); - #endif - #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); @@ -1439,11 +1435,7 @@ void process_commands() HOMEAXIS(Z); } - // if X or Y or both hasn't homed, but we do need to Z-home, then - // ensure that at least probe is inside bed area. - // not that this condition can't occur when doing Z_SAFE_HOMING_FIXED_POINT - // because in that case, any Z-home always triggers an X & Y home first - #ifndef Z_SAFE_HOMING_FIXED_POINT + // Let's see if X and Y are homed and probe is inside bed area. if(code_seen(axis_codes[Z_AXIS])) { if ( (axis_known_position[X_AXIS]) && (axis_known_position[Y_AXIS]) \ && (current_position[X_AXIS]+X_PROBE_OFFSET_FROM_EXTRUDER >= X_MIN_POS) \ @@ -1469,7 +1461,6 @@ void process_commands() SERIAL_ECHOLNPGM(MSG_ZPROBE_OUT); } } - #endif // not Z_SAFE_HOMING_FIXED_POINT #endif // Z_SAFE_HOMING #endif // Z_HOME_DIR @@ -1693,15 +1684,6 @@ void process_commands() case 30: // G30 Single Z Probe { - - #ifdef Z_SAFE_HOMING_FIXED_POINT - #define G30_NOT_ALLOWED "G30 not allowed because of Z_SAFE_HOMING_FIXED_POINT" - LCD_MESSAGEPGM(G30_NOT_ALLOWED); - SERIAL_ECHO_START; - SERIAL_ECHOLNPGM(G30_NOT_ALLOWED); - break; // abort - #endif // Z_SAFE_HOMING_FIXED_POINT - engage_z_probe(); // Engage Z Servo endstop if available st_synchronize(); @@ -1756,32 +1738,32 @@ void process_commands() run_z_max(); } break; - case GREEN_LED_ON: + case GREEN_LED_ON: { digitalWrite(LED_GREEN_PIN,HIGH); SERIAL_PROTOCOLPGM("GREEN LED ON \n"); } break; - case GREEN_LED_OFF: + case GREEN_LED_OFF: { digitalWrite(LED_GREEN_PIN,LOW); SERIAL_PROTOCOLPGM("GREEN LED OFF \n"); } break; - case RED_LED_ON: - { + case RED_LED_ON: + { digitalWrite(LED_RED_PIN,HIGH); SERIAL_PROTOCOLPGM("RED LED ON \n"); } break; - case RED_LED_OFF: + case RED_LED_OFF: { digitalWrite(LED_RED_PIN,LOW); SERIAL_PROTOCOLPGM("RED LED OFF \n"); } break; - case BUTTON_LED_ON: - { + case BUTTON_LED_ON: + { digitalWrite(LED_BUTTON_PIN,HIGH); SERIAL_PROTOCOLPGM("BUTTON LED ON \n"); } diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index 382e80ea119a..4a7b01a479ae 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -207,8 +207,8 @@ void checkHitEndstops() endstop_x_hit=false; endstop_y_hit=false; endstop_z_hit=false; - #ifdef MSM_Printeer - endstop_z_max_hit=false; + #ifdef MSM_Printeer + endstop_z_max_hit=false; #endif #ifdef ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED if (abort_on_endstop_hit) @@ -516,13 +516,13 @@ ISR(TIMER1_COMPA_vect) count_direction[Z_AXIS]=-1; CHECK_ENDSTOPS { - #if defined FSR_BED_LEVELING && defined FSR_PIN && FSR_PIN > -1 + #if defined FSR_BED_LEVELING && defined FSR_PIN && FSR_PIN > -1 // Run endstop triggered logic, fsr_trigger signals endstop status - bool fsr_trigger = FSR_ABL_Trigger(); + bool fsr_trigger = FSR_ABL_Trigger(); if(fsr_trigger && old_z_min_endstop && (current_block->steps_z > 0)) { - endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS]; - endstop_z_hit=true; - step_events_completed = current_block->step_event_count; + endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS]; + endstop_z_hit=true; + step_events_completed = current_block->step_event_count; } old_z_min_endstop = fsr_trigger; // End of FSR ABL diff --git a/run_tests.sh b/run_tests.sh index 1edda7b2defa..c1c10a54ecfa 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -14,7 +14,6 @@ function print_vars echo " " DELTA=$DELTA echo " " MOTHERBOARD=$MOTHERBOARD echo " " ENABLE_AUTO_BED_LEVELING=$ENABLE_AUTO_BED_LEVELING - echo " " Z_SAFE_HOMING_FIXED_POINT=$Z_SAFE_HOMING_FIXED_POINT echo " " CUSTOM_M_CODES=$CUSTOM_M_CODES echo " " CUSTOM_G_CODES=$CUSTOM_G_CODES echo " " MSM_Printeer=$MSM_Printeer @@ -26,7 +25,6 @@ function reset_vars export DELTA= export MOTHERBOARD= export ENABLE_AUTO_BED_LEVELING= - export Z_SAFE_HOMING_FIXED_POINT= export CUSTOM_M_CODES= export CUSTOM_G_CODES= export MSM_Printeer= @@ -49,9 +47,9 @@ function run CFG=Marlin/Configuration.h cp $CFG $CFG.orig - cat $CFG.orig | ./set-defines.sh MOTHERBOARD ENABLE_AUTO_BED_LEVELING Z_SAFE_HOMING_FIXED_POINT CUSTOM_M_CODES MSM_Printeer FSR_BED_LEVELING > $CFG + cat $CFG.orig | ./set-defines.sh MOTHERBOARD ENABLE_AUTO_BED_LEVELING CUSTOM_M_CODES MSM_Printeer FSR_BED_LEVELING > $CFG echo "Current defines:" - grep -e MOTHERBOARD -e ENABLE_AUTO_BED_LEVELING -e Z_SAFE_HOMING_FIXED_POINT -e DELTA -e CUSTOM_M_CODES -e MSM_Printeer -e FSR_BED_LEVELING $CFG + grep -e MOTHERBOARD -e ENABLE_AUTO_BED_LEVELING -e DELTA -e CUSTOM_M_CODES -e MSM_Printeer -e FSR_BED_LEVELING $CFG sleep 2 (cd Marlin && make clean && make HARDWARE_MOTHERBOARD=$MOTHERBOARD AVR_TOOLS_PATH=$AVR_TOOLS_PATH ARDUINO_INSTALL_DIR=$ARDUINO_INSTALL_DIR) @@ -69,13 +67,10 @@ run MOTHERBOARD=81 ENABLE_AUTO_BED_LEVELING=1 CUSTOM_M_CODES=1 CUSTOM_G_CODES=1 MSM_Printeer=1 run -MOTHERBOARD=81 ENABLE_AUTO_BED_LEVELING=1 Z_SAFE_HOMING_FIXED_POINT=1 CUSTOM_M_CODES=1 MSM_Printeer=1 +MOTHERBOARD=81 ENABLE_AUTO_BED_LEVELING=1 CUSTOM_M_CODES=1 MSM_Printeer=1 run -MOTHERBOARD=81 ENABLE_AUTO_BED_LEVELING=1 Z_SAFE_HOMING_FIXED_POINT=1 CUSTOM_M_CODES=1 -run - -MOTHERBOARD=81 ENABLE_AUTO_BED_LEVELING=1 Z_SAFE_HOMING_FIXED_POINT=1 +MOTHERBOARD=81 ENABLE_AUTO_BED_LEVELING=1 CUSTOM_M_CODES=1 run MOTHERBOARD=81 ENABLE_AUTO_BED_LEVELING=1 From 85cf18bc4cee2f28650bf922c573b1318eda24e1 Mon Sep 17 00:00:00 2001 From: Joe Marino Date: Thu, 18 Sep 2014 16:32:00 -0700 Subject: [PATCH 66/71] Changed ABL Offset input process --- Marlin/Marlin.h | 1 + Marlin/Marlin_main.cpp | 166 ++++++++++++++++------------------------- 2 files changed, 66 insertions(+), 101 deletions(-) diff --git a/Marlin/Marlin.h b/Marlin/Marlin.h index b32020a0653d..49f44d024a81 100644 --- a/Marlin/Marlin.h +++ b/Marlin/Marlin.h @@ -249,6 +249,7 @@ extern void digipot_i2c_init(); #ifdef MSM_Printeer void run_z_max(); void led_init(); + bool update_ABL_adjustment(char abl_point, float &abl_point_offset); #endif #ifdef FSR_BED_LEVELING extern float abl_A_offset; diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 577166023f1c..df34d781dcf9 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -930,7 +930,7 @@ static void run_z_probe() { zPosition += home_retract_mm(Z_AXIS); plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], zPosition, current_position[E_AXIS], feedrate/60, active_extruder); st_synchronize(); - #ifndef FSR_BED_LEVELING // due to the averageing used in FSR_BED_LEVELING, + #ifndef FSR_BED_LEVELING // due to the averaging used in FSR_BED_LEVELING, // the second probing causes the average value to // be too high and will not trigger properly, // therefore FSR_BED_LEVELING skips the second probe @@ -1208,6 +1208,39 @@ void refresh_cmd_timeout(void) pinMode(LED_BUTTON_PIN, OUTPUT); digitalWrite(LED_BUTTON_PIN,HIGH); } + + void update_ABL_adjustment(char abl_point, float * abl_point_offset) + { + float point_value; + if (code_seen(abl_point)) + { + point_value = code_value(); + if ((ABL_ADJUSTMENT_MIN <= point_value) && (point_value <= ABL_ADJUSTMENT_MAX)) + { + * abl_point_offset = point_value; + SERIAL_ECHO_START; + SERIAL_PROTOCOLLN(""); + SERIAL_ECHOPGM("ABL "); + SERIAL_ECHO(abl_point); + SERIAL_ECHOPGM(" offset has been set"); + SERIAL_PROTOCOLLN(""); + } + else + { + SERIAL_ECHO_START; + SERIAL_PROTOCOLLN(""); + SERIAL_ECHOPGM("ERROR: Invalid value for ABL offset "); + SERIAL_ECHO(abl_point); + SERIAL_PROTOCOLLN(""); + SERIAL_ECHOPGM("Must be between "); + SERIAL_ECHO(ABL_ADJUSTMENT_MIN); + SERIAL_ECHOPGM(" and "); + SERIAL_ECHO(ABL_ADJUSTMENT_MAX); + SERIAL_PROTOCOLLN(""); + } + } + return; + } #endif void process_commands() @@ -2880,82 +2913,14 @@ void process_commands() break; case ABL_ADJUSTMENT: // Allows fudging of ABL values if necessary { - float value; - if (code_seen('A')) // First point - { - value = code_value(); - if ((ABL_ADJUSTMENT_MIN <= value) && (value <= ABL_ADJUSTMENT_MAX)) - { - abl_A_offset = value; // lower input values bring nozzle closer to bed - SERIAL_ECHO_START; - SERIAL_ECHOLNPGM("ABL A offset has been set"); - SERIAL_PROTOCOLLN(""); - } - else - { - SERIAL_ECHO_START; - SERIAL_ECHOPGM("Invalid value. Must be between "); - SERIAL_ECHO(ABL_ADJUSTMENT_MIN); - SERIAL_ECHOPGM(" and "); - SERIAL_ECHO(ABL_ADJUSTMENT_MAX); - SERIAL_PROTOCOLLN(""); - } - } - else if (code_seen('B')) // Second point - { - value = code_value(); - if ((ABL_ADJUSTMENT_MIN <= value) && (value <= ABL_ADJUSTMENT_MAX)) - { - abl_B_offset = value; // compare w/ line 278 of ConfigurationStore.cpp - SERIAL_ECHO_START; - SERIAL_ECHOLNPGM("ABL B offset has been set"); - SERIAL_PROTOCOLLN(""); - } - else - { - SERIAL_ECHO_START; - SERIAL_ECHOPGM("Invalid value. Must be between "); - SERIAL_ECHO(ABL_ADJUSTMENT_MIN); - SERIAL_ECHOPGM(" and "); - SERIAL_ECHO(ABL_ADJUSTMENT_MAX); - SERIAL_PROTOCOLLN(""); - } - } - else if (code_seen('C')) // Third point - { - value = code_value(); - if ((ABL_ADJUSTMENT_MIN <= value) && (value <= ABL_ADJUSTMENT_MAX)) - { - abl_C_offset = value; - SERIAL_ECHO_START; - SERIAL_ECHOLNPGM("ABL C offset has been set"); - SERIAL_PROTOCOLLN(""); - } - } - else if (code_seen('D')) // Fourth point (grid only) - { - value = code_value(); - if ((ABL_ADJUSTMENT_MIN <= value) && (value <= ABL_ADJUSTMENT_MAX)) - { - abl_D_offset = value; - SERIAL_ECHO_START; - SERIAL_ECHOLNPGM("ABL D offset has been set"); - SERIAL_PROTOCOLLN(""); - } - else - { - SERIAL_ECHO_START; - SERIAL_ECHOPGM("Invalid value. Must be between "); - SERIAL_ECHO(ABL_ADJUSTMENT_MIN); - SERIAL_ECHOPGM(" and "); - SERIAL_ECHO(ABL_ADJUSTMENT_MAX); - SERIAL_PROTOCOLLN(""); - } - } - else // echo current ABL settings - { + update_ABL_adjustment('A',&abl_A_offset); + update_ABL_adjustment('B',&abl_B_offset); + update_ABL_adjustment('C',&abl_C_offset); + update_ABL_adjustment('D',&abl_D_offset); SERIAL_ECHO_START; - SERIAL_ECHOLNPGM("ABL offsets are currently"); + SERIAL_PROTOCOLLN(""); + SERIAL_ECHOLNPGM("ABL offsets are:"); + SERIAL_PROTOCOLLN(""); SERIAL_ECHOPGM("A: "); SERIAL_ECHO(abl_A_offset); SERIAL_ECHOPGM(", B: "); @@ -2965,34 +2930,33 @@ void process_commands() SERIAL_ECHOPGM(", D: "); SERIAL_ECHO(abl_D_offset); SERIAL_PROTOCOLLN(""); - } - break; + break; } #endif // FSR_BED_LEVELING #ifdef CUSTOM_M_CODES case CUSTOM_M_CODE_REPORT_BUILD_INFO: { - // Print out some diagnostic info - SERIAL_ECHOPGM(MSG_MARLIN); - SERIAL_ECHOLNPGM(VERSION_STRING); - #ifdef STRING_VERSION_CONFIG_H - #ifdef STRING_CONFIG_H_AUTHOR - SERIAL_ECHO_START; - SERIAL_ECHOPGM(MSG_CONFIGURATION_VER); - SERIAL_ECHOPGM(STRING_VERSION_CONFIG_H); - SERIAL_ECHOPGM(MSG_AUTHOR); - SERIAL_ECHOLNPGM(STRING_CONFIG_H_AUTHOR); - SERIAL_ECHOPGM("Compiled: "); - SERIAL_ECHOLNPGM(__DATE__); - SERIAL_PROTOCOLLN(""); - #endif + // Print out some diagnostic info + SERIAL_ECHOPGM(MSG_MARLIN); + SERIAL_ECHOLNPGM(VERSION_STRING); + #ifdef STRING_VERSION_CONFIG_H + #ifdef STRING_CONFIG_H_AUTHOR + SERIAL_ECHO_START; + SERIAL_ECHOPGM(MSG_CONFIGURATION_VER); + SERIAL_ECHOPGM(STRING_VERSION_CONFIG_H); + SERIAL_ECHOPGM(MSG_AUTHOR); + SERIAL_ECHOLNPGM(STRING_CONFIG_H_AUTHOR); + SERIAL_ECHOPGM("Compiled: "); + SERIAL_ECHOLNPGM(__DATE__); + SERIAL_PROTOCOLLN(""); #endif - SERIAL_ECHO_START; - SERIAL_ECHOPGM(MSG_FREE_MEMORY); - SERIAL_ECHO(freeMemory()); - SERIAL_PROTOCOLLN(""); - break; + #endif + SERIAL_ECHO_START; + SERIAL_ECHOPGM(MSG_FREE_MEMORY); + SERIAL_ECHO(freeMemory()); + SERIAL_PROTOCOLLN(""); + break; } case CUSTOM_M_CODE_SET_Z_PROBE_OFFSET: { @@ -3019,10 +2983,10 @@ void process_commands() } else { - SERIAL_ECHO_START; - SERIAL_ECHOLNPGM("Z probe offset is currently "); - SERIAL_ECHO(-zprobe_zoffset); - SERIAL_PROTOCOLLN(""); + SERIAL_ECHO_START; + SERIAL_ECHOLNPGM("Z probe offset is currently "); + SERIAL_ECHO(-zprobe_zoffset); + SERIAL_PROTOCOLLN(""); } break; } From 1c1dada208ac3c3092ffae85a63fe0da77985353 Mon Sep 17 00:00:00 2001 From: Joe Marino Date: Fri, 19 Sep 2014 09:02:29 -0700 Subject: [PATCH 67/71] Equation spacing and comment line breaks --- Marlin/fsr_abl.cpp | 37 +++++++++++++++++++++---------------- Marlin/fsr_abl.h | 2 +- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/Marlin/fsr_abl.cpp b/Marlin/fsr_abl.cpp index ef690b88c91e..ac986cc39858 100644 --- a/Marlin/fsr_abl.cpp +++ b/Marlin/fsr_abl.cpp @@ -1,5 +1,6 @@ /* - fsr_abl.cpp contains the functions needed to operate automatic bed leveling with force sensing resistors. + fsr_abl.cpp contains the functions needed to operate automatic bed leveling + with force sensing resistors. */ #include "fsr_abl.h" @@ -14,7 +15,8 @@ #error You must define FSR_PIN >= 0 #endif -// Private Variables (static preserves between function calls and prevents calling by extern) +// Private Variables (static preserves between function calls and prevents +// calling by extern) static int fsr_rolling_avg; static float fsr_weighting = 4.5; // Higher weighting means ave changes slower static float fsr_upper_trigger = 1.25; // upper bound % of rolling average for trigger @@ -24,35 +26,38 @@ static int current_sample; // Updates rolling average with most recent value from ADC void FSR_ABL_Reading() { - fsr_rolling_avg = fsr_rolling_avg*fsr_weighting; - fsr_rolling_avg = fsr_rolling_avg+current_fsr_sample(); - fsr_rolling_avg = fsr_rolling_avg/(fsr_weighting+1); + fsr_rolling_avg = fsr_rolling_avg * fsr_weighting; + fsr_rolling_avg = fsr_rolling_avg + current_fsr_sample(); + fsr_rolling_avg = fsr_rolling_avg / (fsr_weighting + 1); } // Returns most recent sampled value from ADC int FSR_ABL_Get_Read() { - return(current_fsr_sample()); + return(current_fsr_sample()); } // Returns the current rolling average int FSR_ABL_Get_Avg() { - return(fsr_rolling_avg); + return(fsr_rolling_avg); } -// FSR_ABL_Trigger reads the adc and checks to see if this value meets the trigger conditions +// FSR_ABL_Trigger reads the ADC and checks to see if this value meets the +// trigger conditions bool FSR_ABL_Trigger() { // Check filter for trigger conditions - current_sample = current_fsr_sample(); - if (((current_sample > fsr_upper_trigger*fsr_rolling_avg) || (current_sample < fsr_lower_trigger*fsr_rolling_avg) || (current_sample > 520)) && (current_sample > 50)){ - return(true); - } - else { - // Do nothing but return false - return(false); - } + current_sample = current_fsr_sample(); + if (((current_sample > fsr_upper_trigger * fsr_rolling_avg) + || (current_sample < fsr_lower_trigger * fsr_rolling_avg) + || (current_sample > 520)) && (current_sample > 50)){ + return(true); + } + else { + // Do nothing but return false + return(false); + } } diff --git a/Marlin/fsr_abl.h b/Marlin/fsr_abl.h index e6f114bc2d55..dc6b12294a85 100644 --- a/Marlin/fsr_abl.h +++ b/Marlin/fsr_abl.h @@ -15,4 +15,4 @@ bool FSR_ABL_Trigger(); #endif -#endif +#endif // fsr_abl_h From 07d5ee6fe1c71078a28f3549d3a3ab5bc3b31fc6 Mon Sep 17 00:00:00 2001 From: Joe Marino Date: Fri, 19 Sep 2014 09:10:02 -0700 Subject: [PATCH 68/71] update_ABL_adj is for FSR_BED_LEVELING --- Marlin/Marlin_main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index df34d781dcf9..3f643b36f7d2 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -1208,7 +1208,9 @@ void refresh_cmd_timeout(void) pinMode(LED_BUTTON_PIN, OUTPUT); digitalWrite(LED_BUTTON_PIN,HIGH); } +#endif +#ifdef FSR_BED_LEVELING void update_ABL_adjustment(char abl_point, float * abl_point_offset) { float point_value; From c0ea6821bc42cffdae7de8754d018b7e4cccf2ce Mon Sep 17 00:00:00 2001 From: Joe Marino Date: Fri, 19 Sep 2014 10:21:59 -0700 Subject: [PATCH 69/71] Added error checking for FSR BED LEVELING --- Marlin/Configuration.h | 11 ++++++++++- Marlin/Marlin_main.cpp | 4 ---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 210d942d97db..6cfb76bbc22a 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -336,7 +336,8 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o #define ENABLE_AUTO_BED_LEVELING // Delete the comment to enable (remove // at the start of the line) #ifdef ENABLE_AUTO_BED_LEVELING -#define FSR_BED_LEVELING // Use force sensing resistors to perform ABL +#define FSR_BED_LEVELING // Use force sensing resistors to perform ABL_ADJUSTMENT + // Requires AUTO_BED_LEVELING_GRID_POINTS = 2 or 3 // There are 2 different ways to pick the X and Y locations to probe: // - "grid" mode @@ -379,6 +380,14 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o #endif // AUTO_BED_LEVELING_GRID + #ifdef FSR_BED_LEVELING // FSR BED LEVELING required GRID = 2 or 3 + #ifndef AUTO_BED_LEVELING_GRID_POINTS + #error FSR_BED_LEVELING requires AUTO_BED_LEVELING_GRID_POINTS + #endif + #if (AUTO_BED_LEVELING_GRID_POINTS != 2) && (AUTO_BED_LEVELING_GRID_POINTS != 3) + #error FSR_BED_LEVELING requires 2 or 3 AUTO_BED_LEVELING_GRID_POINTS + #endif + #endif // these are the offsets to the probe relative to the extruder tip (Hotend - Probe) #define X_PROBE_OFFSET_FROM_EXTRUDER 0 diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 3f643b36f7d2..2eeb9563b0ca 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -1623,7 +1623,6 @@ void process_commands() if ((AUTO_BED_LEVELING_GRID_POINTS == 2) && (probePointCounter == 0) || ((AUTO_BED_LEVELING_GRID_POINTS == 3) && (probePointCounter == 0))) { measured_z -= abl_A_offset; - SERIAL_PROTOCOLLN("A"); } // Fudges the value at the second point in a 4-pt measurement @@ -1633,7 +1632,6 @@ void process_commands() if ((AUTO_BED_LEVELING_GRID_POINTS == 2) && (probePointCounter == 1) || ((AUTO_BED_LEVELING_GRID_POINTS == 3) && (probePointCounter == 2))) { measured_z -= abl_B_offset; - SERIAL_PROTOCOLLN("B"); } // Fudges the value at the third point in a 4-pt measurement @@ -1643,7 +1641,6 @@ void process_commands() if ((AUTO_BED_LEVELING_GRID_POINTS == 2) && (probePointCounter == 2) || ((AUTO_BED_LEVELING_GRID_POINTS == 3) && (probePointCounter == 6))) { measured_z -= abl_C_offset; - SERIAL_PROTOCOLLN("C"); } // Fudges the value at the fourth point in a 4-pt measurement @@ -1653,7 +1650,6 @@ void process_commands() if ((AUTO_BED_LEVELING_GRID_POINTS == 2) && (probePointCounter == 3) || ((AUTO_BED_LEVELING_GRID_POINTS == 3) && (probePointCounter == 8))) { measured_z -= abl_D_offset; - SERIAL_PROTOCOLLN("D"); } #endif From 9111f4f061c2eefea5b65e6ee44e142c4879c3e1 Mon Sep 17 00:00:00 2001 From: Joe Marino Date: Fri, 19 Sep 2014 10:34:44 -0700 Subject: [PATCH 70/71] FSR ABL comment updates --- Marlin/Marlin_main.cpp | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 2eeb9563b0ca..802c14888f30 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -1609,14 +1609,16 @@ void process_commands() float measured_z = probe_pt(xProbe, yProbe, z_before); #ifdef FSR_BED_LEVELING - // In testing we found it is best to apply the fudge amounts to the four corners of the probe grid + // In testing we found it is effective to apply the fudge amounts to the four corners of the probe grid // but not the inside points. In a 3x3 grid, we probe - // 0 1 2 - // 3 4 5 - // 6 7 8 - // and thus the four points to fudge are { 0, 2, 6, 8 } - - // Fudges the value at the fist point in a 4-pt measurement + // + // ^ 6 7 8 + // | 3 4 5 + // y 0 1 2 + // x -> + // and thus the four points to fudge are { 0, 2, 6, 8 } + // These points correspond to { A, B, C, D} + // FSR BED LEVELING can also be used with a 2 x 2 grid. // A negative input value increases distance between bed and nozzle // A positive input value decreases distance between bed and nozzle // M851 adjustment is applied after ABL transformation is applied @@ -1624,29 +1626,14 @@ void process_commands() { measured_z -= abl_A_offset; } - - // Fudges the value at the second point in a 4-pt measurement - // A negative input value increases distance between bed and nozzle - // A positive input value decreases distance between bed and nozzle - // M851 adjustment is applied after ABL transformation is applied if ((AUTO_BED_LEVELING_GRID_POINTS == 2) && (probePointCounter == 1) || ((AUTO_BED_LEVELING_GRID_POINTS == 3) && (probePointCounter == 2))) { measured_z -= abl_B_offset; } - - // Fudges the value at the third point in a 4-pt measurement - // A negative input value increases distance between bed and nozzle - // A positive input value decreases distance between bed and nozzle - // M851 adjustment is applied after ABL transformation is applied if ((AUTO_BED_LEVELING_GRID_POINTS == 2) && (probePointCounter == 2) || ((AUTO_BED_LEVELING_GRID_POINTS == 3) && (probePointCounter == 6))) { measured_z -= abl_C_offset; } - - // Fudges the value at the fourth point in a 4-pt measurement - // A negative input value increases distance between bed and nozzle - // A positive input value decreases distance between bed and nozzle - // M851 adjustment is applied after ABL transformation is applied if ((AUTO_BED_LEVELING_GRID_POINTS == 2) && (probePointCounter == 3) || ((AUTO_BED_LEVELING_GRID_POINTS == 3) && (probePointCounter == 8))) { measured_z -= abl_D_offset; From d4e1838643e0ee7945423e9246627bd01b9ce13f Mon Sep 17 00:00:00 2001 From: Joe Marino Date: Fri, 19 Sep 2014 10:43:36 -0700 Subject: [PATCH 71/71] Additional comment for FSR_BED_LEVELING --- Marlin/Marlin_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 802c14888f30..ccb7f7ba6bb0 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -278,7 +278,7 @@ int EtoPPressure=0; float delta_segments_per_second= DELTA_SEGMENTS_PER_SECOND; #endif -#ifdef FSR_BED_LEVELING +#ifdef FSR_BED_LEVELING // See comments in G29 code for greater details float abl_A_offset; float abl_B_offset; float abl_C_offset;