Check probes only when deployed

Aim: Test probes in update_endstops only when activated

Changes:
Configurations
 Add define for FIX_MOUNTED_PROBE to handle the situation where formerly ENDSTOPS_ONLY_FOR_HOMING had to be set, or lowering the nozzle below Z_PROBE_OFFSET_FROM_EXTRUDER could give an "endstop hit" message.
 Add define for Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN to indicate a common situation, that we have a probe but it is connected to an endstop pin
 Add some comments
 Shift some entries to have related things together.

Conditionals.h
 We have a probe (HAS_Z_MIN_PROBE) if one of the pins is defined AND one of the probes is defined.

SanityCheck.h
 Add some tests if the probe is connected and if we have defined a probe.

stepper.cpp
 Changes to test the probe only when it is deployed (z_probe_is_active).
 Test update_endstops() when the probe is deployed.

MarlinMain.cpp
 a. set and reset z_probe_is_active in deploy_z_probe(), stow_z_probe() and dock_sled()
 b. set and reset z_probe_is_active in the case a z-servo is moved to a defined position. The only remaining unhandled servo move is in M280 where we do not end in a defined position. If you want to handle a probe use M401/402
 c. skip deploying/stowing when already deployed/stowed in the dedicated deploy/stow functions.
 d. Handle the new FIX_MOUNTED_PROBE in parallel to a servo driven probe/endstop.

 To do: In another PR. handle all probes in deploy/stow_z_probe.
 Sort out SERVO_LEVELING vs. HAS_SERVO_ENDSTOPS.
This commit is contained in:
AnHardt
2015-12-03 14:19:29 +01:00
committed by Scott Lahteine
parent 4634feaeab
commit 3f45a1acf9
23 changed files with 1198 additions and 641 deletions

View File

@ -462,6 +462,10 @@ void serial_echopair_P(const char* s_P, unsigned long v) { serialprintPGM(s_P);
float extrude_min_temp = EXTRUDE_MINTEMP;
#endif
#if ENABLED(HAS_Z_MIN_PROBE)
extern volatile bool z_probe_is_active;
#endif
#if ENABLED(SDSUPPORT)
#include "SdFatUtil.h"
int freeMemory() { return SdFatUtil::FreeRam(); }
@ -619,12 +623,26 @@ void servo_init() {
servo[3].detach();
#endif
// Set position of Servo Endstops that are defined
#if HAS_SERVO_ENDSTOPS
#if HAS_SERVO_ENDSTOPS
z_probe_is_active = false;
/**
* Set position of all defined Servo Endstops
*
* ** UNSAFE! - NEEDS UPDATE! **
*
* The servo might be deployed and positioned too low to stow
* when starting up the machine or rebooting the board.
* There's no way to know where the nozzle is positioned until
* homing has been done - no homing with z-probe without init!
*
*/
for (int i = 0; i < 3; i++)
if (servo_endstop_id[i] >= 0)
servo[servo_endstop_id[i]].move(servo_endstop_angle[i][1]);
#endif
#endif // HAS_SERVO_ENDSTOPS
}
@ -1458,6 +1476,8 @@ static void setup_for_endstop_move() {
refresh_cmd_timeout();
}
#if ENABLED(HAS_Z_MIN_PROBE)
static void deploy_z_probe() {
#if ENABLED(DEBUG_LEVELING_FEATURE)
@ -1466,6 +1486,8 @@ static void setup_for_endstop_move() {
}
#endif
if (z_probe_is_active) return;
#if HAS_SERVO_ENDSTOPS
// Engage Z Servo endstop if enabled
@ -1505,20 +1527,19 @@ static void setup_for_endstop_move() {
if (Z_PROBE_ALLEN_KEY_DEPLOY_3_FEEDRATE != Z_PROBE_ALLEN_KEY_DEPLOY_2_FEEDRATE)
feedrate = Z_PROBE_ALLEN_KEY_DEPLOY_3_FEEDRATE;
// Move to trigger deployment
if (Z_PROBE_ALLEN_KEY_DEPLOY_3_FEEDRATE != Z_PROBE_ALLEN_KEY_DEPLOY_2_FEEDRATE)
feedrate = Z_PROBE_ALLEN_KEY_DEPLOY_3_FEEDRATE;
if (Z_PROBE_ALLEN_KEY_DEPLOY_3_X != Z_PROBE_ALLEN_KEY_DEPLOY_2_X)
destination[X_AXIS] = Z_PROBE_ALLEN_KEY_DEPLOY_3_X;
if (Z_PROBE_ALLEN_KEY_DEPLOY_3_Y != Z_PROBE_ALLEN_KEY_DEPLOY_2_Y)
destination[Y_AXIS] = Z_PROBE_ALLEN_KEY_DEPLOY_3_Y;
if (Z_PROBE_ALLEN_KEY_DEPLOY_3_Z != Z_PROBE_ALLEN_KEY_DEPLOY_2_Z)
destination[Z_AXIS] = Z_PROBE_ALLEN_KEY_DEPLOY_3_Z;
// Move to trigger deployment
if (Z_PROBE_ALLEN_KEY_DEPLOY_3_FEEDRATE != Z_PROBE_ALLEN_KEY_DEPLOY_2_FEEDRATE)
feedrate = Z_PROBE_ALLEN_KEY_DEPLOY_3_FEEDRATE;
if (Z_PROBE_ALLEN_KEY_DEPLOY_3_X != Z_PROBE_ALLEN_KEY_DEPLOY_2_X)
destination[X_AXIS] = Z_PROBE_ALLEN_KEY_DEPLOY_3_X;
if (Z_PROBE_ALLEN_KEY_DEPLOY_3_Y != Z_PROBE_ALLEN_KEY_DEPLOY_2_Y)
destination[Y_AXIS] = Z_PROBE_ALLEN_KEY_DEPLOY_3_Y;
if (Z_PROBE_ALLEN_KEY_DEPLOY_3_Z != Z_PROBE_ALLEN_KEY_DEPLOY_2_Z)
destination[Z_AXIS] = Z_PROBE_ALLEN_KEY_DEPLOY_3_Z;
prepare_move_raw();
#endif
}
prepare_move_raw();
#endif
}
// Partially Home X,Y for safety
destination[X_AXIS] = destination[X_AXIS] * 0.75;
@ -1545,6 +1566,12 @@ static void setup_for_endstop_move() {
#endif // Z_PROBE_ALLEN_KEY
#if ENABLED(FIX_MOUNTED_PROBE)
// Noting to be done. Just set z_probe_is_active
#endif
z_probe_is_active = true;
}
static void stow_z_probe(bool doRaise = true) {
@ -1554,6 +1581,8 @@ static void setup_for_endstop_move() {
}
#endif
if (!z_probe_is_active) return;
#if HAS_SERVO_ENDSTOPS
// Retract Z Servo endstop if enabled
@ -1638,7 +1667,14 @@ static void setup_for_endstop_move() {
Stop();
}
#endif // Z_PROBE_ALLEN_KEY
#if ENABLED(FIX_MOUNTED_PROBE)
// Noting to be done. Just set z_probe_is_active
#endif
z_probe_is_active = false;
}
#endif // HAS_Z_MIN_PROBE
enum ProbeAction {
ProbeStay = 0,
@ -1825,6 +1861,9 @@ static void setup_for_endstop_move() {
SERIAL_EOL;
}
#endif
if (z_probe_is_active == dock) return;
if (!axis_known_position[X_AXIS] || !axis_known_position[Y_AXIS]) {
LCD_MESSAGEPGM(MSG_POSITION_UNKNOWN);
SERIAL_ECHO_START;
@ -1847,6 +1886,8 @@ static void setup_for_endstop_move() {
digitalWrite(SLED_PIN, HIGH); // turn on magnet
}
do_blocking_move_to_x(oldXpos); // return to position before docking
z_probe_is_active = dock;
}
#endif // Z_PROBE_SLED
@ -1887,9 +1928,7 @@ static void homeaxis(AxisEnum axis) {
if (axis == Z_AXIS) {
if (axis_home_dir < 0) dock_sled(false);
}
#endif
#if SERVO_LEVELING && DISABLED(Z_PROBE_SLED)
#elif SERVO_LEVELING || ENABLED(FIX_MOUNTED_PROBE)
// Deploy a Z probe if there is one, and homing towards the bed
if (axis == Z_AXIS) {
@ -1900,8 +1939,10 @@ static void homeaxis(AxisEnum axis) {
#if HAS_SERVO_ENDSTOPS
// Engage Servo endstop if enabled
if (axis != Z_AXIS && servo_endstop_id[axis] >= 0)
if (axis != Z_AXIS && servo_endstop_id[axis] >= 0) {
servo[servo_endstop_id[axis]].move(servo_endstop_angle[axis][0]);
z_probe_is_active = true;
}
#endif
// Set a flag for Z motor locking
@ -2034,9 +2075,7 @@ static void homeaxis(AxisEnum axis) {
if (axis == Z_AXIS) {
if (axis_home_dir < 0) dock_sled(true);
}
#endif
#if SERVO_LEVELING && DISABLED(Z_PROBE_SLED)
#elif SERVO_LEVELING || ENABLED(FIX_MOUNTED_PROBE)
// Deploy a Z probe if there is one, and homing towards the bed
if (axis == Z_AXIS) {
@ -2063,6 +2102,7 @@ static void homeaxis(AxisEnum axis) {
}
#endif
servo[servo_endstop_id[axis]].move(servo_endstop_angle[axis][1]);
z_probe_is_active = false;
}
#endif
}
@ -3195,7 +3235,7 @@ inline void gcode_G28() {
#if ENABLED(Z_PROBE_ALLEN_KEY)
stow_z_probe();
#elif Z_RAISE_AFTER_PROBING > 0
raise_z_after_probing();
raise_z_after_probing(); // ???
#endif
#else // !DELTA
if (verbose_level > 0)
@ -3279,6 +3319,9 @@ inline void gcode_G28() {
}
#endif
enqueue_and_echo_commands_P(PSTR(Z_PROBE_END_SCRIPT));
#if ENABLED(HAS_Z_MIN_PROBE)
z_probe_is_active = false;
#endif
st_synchronize();
#endif
@ -3292,7 +3335,7 @@ inline void gcode_G28() {
}
#if DISABLED(Z_PROBE_SLED)
#if DISABLED(Z_PROBE_SLED) // could be avoided
/**
* G30: Do a single Z probe at the current XY
@ -3301,11 +3344,11 @@ inline void gcode_G28() {
#if HAS_SERVO_ENDSTOPS
raise_z_for_servo();
#endif
deploy_z_probe(); // Engage Z Servo endstop if available
deploy_z_probe(); // Engage Z Servo endstop if available. Z_PROBE_SLED is missed her.
st_synchronize();
// TODO: clear the leveling matrix or the planner will be set incorrectly
setup_for_endstop_move();
setup_for_endstop_move(); // to late. Must be done before deploying.
feedrate = homing_feedrate[Z_AXIS];
@ -3318,12 +3361,12 @@ inline void gcode_G28() {
SERIAL_PROTOCOL(current_position[Z_AXIS] + 0.0001);
SERIAL_EOL;
clean_up_after_endstop_move();
clean_up_after_endstop_move(); // to early. must be done after the stowing.
#if HAS_SERVO_ENDSTOPS
raise_z_for_servo();
#endif
stow_z_probe(false); // Retract Z Servo endstop if available
stow_z_probe(false); // Retract Z Servo endstop if available. Z_PROBE_SLED is missed her.
}
#endif //!Z_PROBE_SLED