Merge pull request #3082 from thinkyhead/updated_2820

This is quite comprehensive. If probes are disabled in any case when they shouldn't be, I'm sure we will hear about it soon.
This commit is contained in:
Scott Lahteine
2016-03-20 17:10:38 -07:00
23 changed files with 1198 additions and 641 deletions

View File

@ -465,6 +465,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,
@ -1830,6 +1866,9 @@ static void unknown_position_error() {
SERIAL_EOL;
}
#endif
if (z_probe_is_active == dock) return;
if (!axis_known_position[X_AXIS] || !axis_known_position[Y_AXIS]) {
unknown_position_error();
return;
@ -1850,6 +1889,8 @@ static void unknown_position_error() {
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
@ -1890,9 +1931,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) {
@ -1903,8 +1942,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
@ -2037,9 +2078,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) {
@ -2066,6 +2105,7 @@ static void homeaxis(AxisEnum axis) {
}
#endif
servo[servo_endstop_id[axis]].move(servo_endstop_angle[axis][1]);
z_probe_is_active = false;
}
#endif
}
@ -3194,7 +3234,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)
@ -3278,6 +3318,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
@ -3291,7 +3334,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
@ -3300,11 +3343,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];
@ -3317,12 +3360,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