From ad2c6488c7720e83febce85c43e711b83a2ca8c6 Mon Sep 17 00:00:00 2001 From: Gabe Rosenhouse Date: Sun, 16 Feb 2014 10:38:29 -0800 Subject: [PATCH 1/3] Add probe_pt(), useful for auto bed leveling --- Marlin/Marlin_main.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 7c7a0b0442..5152dc9532 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -978,6 +978,27 @@ static void retract_z_probe() { #endif } +/// Probe bed height at position (x,y), returns the measured z value +static float probe_pt(float x, float y, float z_before) { + // move to right place + do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], z_before); + do_blocking_move_to(x - X_PROBE_OFFSET_FROM_EXTRUDER, y - Y_PROBE_OFFSET_FROM_EXTRUDER, current_position[Z_AXIS]); + + engage_z_probe(); // Engage Z Servo endstop if available + run_z_probe(); + float measured_z = current_position[Z_AXIS]; + retract_z_probe(); + + SERIAL_PROTOCOLPGM("Bed x: "); + SERIAL_PROTOCOL(x); + SERIAL_PROTOCOLPGM(" y: "); + SERIAL_PROTOCOL(y); + SERIAL_PROTOCOLPGM(" z: "); + SERIAL_PROTOCOL(measured_z); + SERIAL_PROTOCOLPGM("\n"); + return measured_z; +} + #endif // #ifdef ENABLE_AUTO_BED_LEVELING static void homeaxis(int axis) { From c4fbb44d6d42b84137a89ab7aa5ab7143116184d Mon Sep 17 00:00:00 2001 From: Gabe Rosenhouse Date: Sun, 16 Feb 2014 10:40:36 -0800 Subject: [PATCH 2/3] Refactor 3-point auto bed leveling to use probe_pt() --- Marlin/Marlin_main.cpp | 49 +++--------------------------------------- 1 file changed, 3 insertions(+), 46 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 5152dc9532..783b6da76c 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -1490,56 +1490,13 @@ void process_commands() // prob 1 - do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], Z_RAISE_BEFORE_PROBING); - do_blocking_move_to(LEFT_PROBE_BED_POSITION - X_PROBE_OFFSET_FROM_EXTRUDER, BACK_PROBE_BED_POSITION - Y_PROBE_OFFSET_FROM_EXTRUDER, current_position[Z_AXIS]); - - engage_z_probe(); // Engage Z Servo endstop if available - run_z_probe(); - float z_at_xLeft_yBack = current_position[Z_AXIS]; - retract_z_probe(); - - SERIAL_PROTOCOLPGM("Bed x: "); - SERIAL_PROTOCOL(LEFT_PROBE_BED_POSITION); - SERIAL_PROTOCOLPGM(" y: "); - SERIAL_PROTOCOL(BACK_PROBE_BED_POSITION); - SERIAL_PROTOCOLPGM(" z: "); - SERIAL_PROTOCOL(current_position[Z_AXIS]); - SERIAL_PROTOCOLPGM("\n"); + float z_at_xLeft_yBack = probe_pt(LEFT_PROBE_BED_POSITION, BACK_PROBE_BED_POSITION, Z_RAISE_BEFORE_PROBING); // prob 2 - do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] + Z_RAISE_BETWEEN_PROBINGS); - do_blocking_move_to(LEFT_PROBE_BED_POSITION - X_PROBE_OFFSET_FROM_EXTRUDER, FRONT_PROBE_BED_POSITION - Y_PROBE_OFFSET_FROM_EXTRUDER, current_position[Z_AXIS]); - - engage_z_probe(); // Engage Z Servo endstop if available - run_z_probe(); - float z_at_xLeft_yFront = current_position[Z_AXIS]; - retract_z_probe(); - - SERIAL_PROTOCOLPGM("Bed x: "); - SERIAL_PROTOCOL(LEFT_PROBE_BED_POSITION); - SERIAL_PROTOCOLPGM(" y: "); - SERIAL_PROTOCOL(FRONT_PROBE_BED_POSITION); - SERIAL_PROTOCOLPGM(" z: "); - SERIAL_PROTOCOL(current_position[Z_AXIS]); - SERIAL_PROTOCOLPGM("\n"); + float z_at_xLeft_yFront = probe_pt(LEFT_PROBE_BED_POSITION, FRONT_PROBE_BED_POSITION, current_position[Z_AXIS] + Z_RAISE_BETWEEN_PROBINGS); // prob 3 - do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] + Z_RAISE_BETWEEN_PROBINGS); - // the current position will be updated by the blocking move so the head will not lower on this next call. - do_blocking_move_to(RIGHT_PROBE_BED_POSITION - X_PROBE_OFFSET_FROM_EXTRUDER, FRONT_PROBE_BED_POSITION - Y_PROBE_OFFSET_FROM_EXTRUDER, current_position[Z_AXIS]); - - engage_z_probe(); // Engage Z Servo endstop if available - run_z_probe(); - float z_at_xRight_yFront = current_position[Z_AXIS]; - retract_z_probe(); // Retract Z Servo endstop if available - - SERIAL_PROTOCOLPGM("Bed x: "); - SERIAL_PROTOCOL(RIGHT_PROBE_BED_POSITION); - SERIAL_PROTOCOLPGM(" y: "); - SERIAL_PROTOCOL(FRONT_PROBE_BED_POSITION); - SERIAL_PROTOCOLPGM(" z: "); - SERIAL_PROTOCOL(current_position[Z_AXIS]); - SERIAL_PROTOCOLPGM("\n"); + float z_at_xRight_yFront = probe_pt(RIGHT_PROBE_BED_POSITION, FRONT_PROBE_BED_POSITION, current_position[Z_AXIS] + Z_RAISE_BETWEEN_PROBINGS); clean_up_after_endstop_move(); From 0f7393a13e44958ed60371936c0bd2f699d1a137 Mon Sep 17 00:00:00 2001 From: Gabe Rosenhouse Date: Sun, 16 Feb 2014 10:42:29 -0800 Subject: [PATCH 3/3] Refactor 'accurate' auto bed leveling to use probe_pt() --- Marlin/Marlin_main.cpp | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 783b6da76c..9032713750 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -1436,31 +1436,20 @@ void process_commands() for (int xCount=0; xCount < ACCURATE_BED_LEVELING_POINTS; xCount++) { + float z_before; if (probePointCounter == 0) { // raise before probing - do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], Z_RAISE_BEFORE_PROBING); + z_before = Z_RAISE_BEFORE_PROBING; } else { // raise extruder - do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] + Z_RAISE_BETWEEN_PROBINGS); + z_before = current_position[Z_AXIS] + Z_RAISE_BETWEEN_PROBINGS; } + float measured_z = probe_pt(xProbe, yProbe, z_before); - do_blocking_move_to(xProbe - X_PROBE_OFFSET_FROM_EXTRUDER, yProbe - Y_PROBE_OFFSET_FROM_EXTRUDER, current_position[Z_AXIS]); - - engage_z_probe(); // Engage Z Servo endstop if available - run_z_probe(); - eqnBVector[probePointCounter] = current_position[Z_AXIS]; - retract_z_probe(); - - SERIAL_PROTOCOLPGM("Bed x: "); - SERIAL_PROTOCOL(xProbe); - SERIAL_PROTOCOLPGM(" y: "); - SERIAL_PROTOCOL(yProbe); - SERIAL_PROTOCOLPGM(" z: "); - SERIAL_PROTOCOL(current_position[Z_AXIS]); - SERIAL_PROTOCOLPGM("\n"); + eqnBVector[probePointCounter] = measured_z; eqnAMatrix[probePointCounter + 0*ACCURATE_BED_LEVELING_POINTS*ACCURATE_BED_LEVELING_POINTS] = xProbe; eqnAMatrix[probePointCounter + 1*ACCURATE_BED_LEVELING_POINTS*ACCURATE_BED_LEVELING_POINTS] = yProbe;