|
@@ -43,6 +43,7 @@
|
43
|
43
|
#include "ConfigurationStore.h"
|
44
|
44
|
#include "language.h"
|
45
|
45
|
#include "pins_arduino.h"
|
|
46
|
+#include "math.h"
|
46
|
47
|
|
47
|
48
|
#ifdef BLINKM
|
48
|
49
|
#include "BlinkM.h"
|
|
@@ -191,6 +192,7 @@ float endstop_adj[3]={0,0,0};
|
191
|
192
|
#endif
|
192
|
193
|
float min_pos[3] = { X_MIN_POS, Y_MIN_POS, Z_MIN_POS };
|
193
|
194
|
float max_pos[3] = { X_MAX_POS, Y_MAX_POS, Z_MAX_POS };
|
|
195
|
+bool axis_known_position[3] = {false, false, false};
|
194
|
196
|
|
195
|
197
|
// Extruder offset
|
196
|
198
|
#if EXTRUDERS > 1
|
|
@@ -949,16 +951,11 @@ static void homeaxis(int axis) {
|
949
|
951
|
current_position[axis] = 0;
|
950
|
952
|
plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
|
951
|
953
|
|
|
954
|
+
|
952
|
955
|
// Engage Servo endstop if enabled
|
953
|
956
|
#ifdef SERVO_ENDSTOPS
|
954
|
957
|
#if defined (ENABLE_AUTO_BED_LEVELING) && (PROBE_SERVO_DEACTIVATION_DELAY > 0)
|
955
|
958
|
if (axis==Z_AXIS) {
|
956
|
|
- #if defined (Z_RAISE_BEFORE_HOMING) && (Z_RAISE_BEFORE_HOMING > 0)
|
957
|
|
- destination[axis] = Z_RAISE_BEFORE_HOMING * axis_home_dir * (-1); // Set destination away from bed
|
958
|
|
- feedrate = max_feedrate[axis];
|
959
|
|
- plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate, active_extruder);
|
960
|
|
- st_synchronize();
|
961
|
|
- #endif
|
962
|
959
|
engage_z_probe();
|
963
|
960
|
}
|
964
|
961
|
else
|
|
@@ -1000,6 +997,7 @@ static void homeaxis(int axis) {
|
1000
|
997
|
destination[axis] = current_position[axis];
|
1001
|
998
|
feedrate = 0.0;
|
1002
|
999
|
endstops_hit_on_purpose();
|
|
1000
|
+ axis_known_position[axis] = true;
|
1003
|
1001
|
|
1004
|
1002
|
// Retract Servo endstop if enabled
|
1005
|
1003
|
#ifdef SERVO_ENDSTOPS
|
|
@@ -1208,12 +1206,6 @@ void process_commands()
|
1208
|
1206
|
HOMEAXIS(Y);
|
1209
|
1207
|
}
|
1210
|
1208
|
|
1211
|
|
- #if Z_HOME_DIR < 0 // If homing towards BED do Z last
|
1212
|
|
- if((home_all_axis) || (code_seen(axis_codes[Z_AXIS]))) {
|
1213
|
|
- HOMEAXIS(Z);
|
1214
|
|
- }
|
1215
|
|
- #endif
|
1216
|
|
-
|
1217
|
1209
|
if(code_seen(axis_codes[X_AXIS]))
|
1218
|
1210
|
{
|
1219
|
1211
|
if(code_value_long() != 0) {
|
|
@@ -1226,14 +1218,74 @@ void process_commands()
|
1226
|
1218
|
current_position[Y_AXIS]=code_value()+add_homeing[1];
|
1227
|
1219
|
}
|
1228
|
1220
|
}
|
|
1221
|
+
|
|
1222
|
+ #if Z_HOME_DIR < 0 // If homing towards BED do Z last
|
|
1223
|
+ #ifndef Z_SAFE_HOMING
|
|
1224
|
+ if((home_all_axis) || (code_seen(axis_codes[Z_AXIS]))) {
|
|
1225
|
+ #if defined (Z_RAISE_BEFORE_HOMING) && (Z_RAISE_BEFORE_HOMING > 0)
|
|
1226
|
+ destination[Z_AXIS] = Z_RAISE_BEFORE_HOMING * home_dir(Z_AXIS) * (-1); // Set destination away from bed
|
|
1227
|
+ feedrate = max_feedrate[Z_AXIS];
|
|
1228
|
+ plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate, active_extruder);
|
|
1229
|
+ st_synchronize();
|
|
1230
|
+ #endif
|
|
1231
|
+ HOMEAXIS(Z);
|
|
1232
|
+ }
|
|
1233
|
+ #else // Z Safe mode activated.
|
|
1234
|
+ if(home_all_axis) {
|
|
1235
|
+ destination[X_AXIS] = round(Z_SAFE_HOMING_X_POINT - X_PROBE_OFFSET_FROM_EXTRUDER);
|
|
1236
|
+ destination[Y_AXIS] = round(Z_SAFE_HOMING_Y_POINT - Y_PROBE_OFFSET_FROM_EXTRUDER);
|
|
1237
|
+ destination[Z_AXIS] = Z_RAISE_BEFORE_HOMING * home_dir(Z_AXIS) * (-1); // Set destination away from bed
|
|
1238
|
+ feedrate = XY_TRAVEL_SPEED;
|
|
1239
|
+ current_position[Z_AXIS] = 0;
|
|
1240
|
+
|
|
1241
|
+ plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
|
|
1242
|
+ plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate, active_extruder);
|
|
1243
|
+ st_synchronize();
|
|
1244
|
+ current_position[X_AXIS] = destination[X_AXIS];
|
|
1245
|
+ current_position[Y_AXIS] = destination[Y_AXIS];
|
1229
|
1246
|
|
|
1247
|
+ HOMEAXIS(Z);
|
|
1248
|
+ }
|
|
1249
|
+ // Let's see if X and Y are homed and probe is inside bed area.
|
|
1250
|
+ if(code_seen(axis_codes[Z_AXIS])) {
|
|
1251
|
+ if ( (axis_known_position[X_AXIS]) && (axis_known_position[Y_AXIS]) \
|
|
1252
|
+ && (current_position[X_AXIS]+X_PROBE_OFFSET_FROM_EXTRUDER >= X_MIN_POS) \
|
|
1253
|
+ && (current_position[X_AXIS]+X_PROBE_OFFSET_FROM_EXTRUDER <= X_MAX_POS) \
|
|
1254
|
+ && (current_position[Y_AXIS]+Y_PROBE_OFFSET_FROM_EXTRUDER >= Y_MIN_POS) \
|
|
1255
|
+ && (current_position[Y_AXIS]+Y_PROBE_OFFSET_FROM_EXTRUDER <= Y_MAX_POS)) {
|
|
1256
|
+
|
|
1257
|
+ current_position[Z_AXIS] = 0;
|
|
1258
|
+ plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
|
|
1259
|
+ destination[Z_AXIS] = Z_RAISE_BEFORE_HOMING * home_dir(Z_AXIS) * (-1); // Set destination away from bed
|
|
1260
|
+ feedrate = max_feedrate[Z_AXIS];
|
|
1261
|
+ plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate, active_extruder);
|
|
1262
|
+ st_synchronize();
|
|
1263
|
+
|
|
1264
|
+ HOMEAXIS(Z);
|
|
1265
|
+ } else if (!((axis_known_position[X_AXIS]) && (axis_known_position[Y_AXIS]))) {
|
|
1266
|
+ LCD_MESSAGEPGM(MSG_POSITION_UNKNOWN);
|
|
1267
|
+ SERIAL_ECHO_START;
|
|
1268
|
+ SERIAL_ECHOLNPGM(MSG_POSITION_UNKNOWN);
|
|
1269
|
+ } else {
|
|
1270
|
+ LCD_MESSAGEPGM(MSG_ZPROBE_OUT);
|
|
1271
|
+ SERIAL_ECHO_START;
|
|
1272
|
+ SERIAL_ECHOLNPGM(MSG_ZPROBE_OUT);
|
|
1273
|
+ }
|
|
1274
|
+ }
|
|
1275
|
+ #endif
|
|
1276
|
+ #endif
|
|
1277
|
+
|
|
1278
|
+
|
|
1279
|
+
|
1230
|
1280
|
if(code_seen(axis_codes[Z_AXIS])) {
|
1231
|
1281
|
if(code_value_long() != 0) {
|
1232
|
1282
|
current_position[Z_AXIS]=code_value()+add_homeing[2];
|
1233
|
1283
|
}
|
1234
|
1284
|
}
|
1235
|
1285
|
#ifdef ENABLE_AUTO_BED_LEVELING
|
1236
|
|
- current_position[Z_AXIS] -= Z_PROBE_OFFSET_FROM_EXTRUDER; //Add Z_Probe offset (the distance is negative)
|
|
1286
|
+ if((home_all_axis) || (code_seen(axis_codes[Z_AXIS]))) {
|
|
1287
|
+ current_position[Z_AXIS] -= Z_PROBE_OFFSET_FROM_EXTRUDER; //Add Z_Probe offset (the distance is negative)
|
|
1288
|
+ }
|
1237
|
1289
|
#endif
|
1238
|
1290
|
plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
|
1239
|
1291
|
#endif // else DELTA
|
|
@@ -1275,9 +1327,9 @@ void process_commands()
|
1275
|
1327
|
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]);
|
1276
|
1328
|
|
1277
|
1329
|
engage_z_probe(); // Engage Z Servo endstop if available
|
1278
|
|
-
|
1279
|
1330
|
run_z_probe();
|
1280
|
1331
|
float z_at_xLeft_yBack = current_position[Z_AXIS];
|
|
1332
|
+ retract_z_probe();
|
1281
|
1333
|
|
1282
|
1334
|
SERIAL_PROTOCOLPGM("Bed x: ");
|
1283
|
1335
|
SERIAL_PROTOCOL(LEFT_PROBE_BED_POSITION);
|
|
@@ -1290,9 +1342,12 @@ void process_commands()
|
1290
|
1342
|
// prob 2
|
1291
|
1343
|
do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] + Z_RAISE_BETWEEN_PROBINGS);
|
1292
|
1344
|
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]);
|
|
1345
|
+
|
|
1346
|
+ engage_z_probe(); // Engage Z Servo endstop if available
|
1293
|
1347
|
run_z_probe();
|
1294
|
1348
|
float z_at_xLeft_yFront = current_position[Z_AXIS];
|
1295
|
|
-
|
|
1349
|
+ retract_z_probe();
|
|
1350
|
+
|
1296
|
1351
|
SERIAL_PROTOCOLPGM("Bed x: ");
|
1297
|
1352
|
SERIAL_PROTOCOL(LEFT_PROBE_BED_POSITION);
|
1298
|
1353
|
SERIAL_PROTOCOLPGM(" y: ");
|
|
@@ -1305,9 +1360,12 @@ void process_commands()
|
1305
|
1360
|
do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] + Z_RAISE_BETWEEN_PROBINGS);
|
1306
|
1361
|
// the current position will be updated by the blocking move so the head will not lower on this next call.
|
1307
|
1362
|
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]);
|
|
1363
|
+
|
|
1364
|
+ engage_z_probe(); // Engage Z Servo endstop if available
|
1308
|
1365
|
run_z_probe();
|
1309
|
1366
|
float z_at_xRight_yFront = current_position[Z_AXIS];
|
1310
|
|
-
|
|
1367
|
+ retract_z_probe(); // Retract Z Servo endstop if available
|
|
1368
|
+
|
1311
|
1369
|
SERIAL_PROTOCOLPGM("Bed x: ");
|
1312
|
1370
|
SERIAL_PROTOCOL(RIGHT_PROBE_BED_POSITION);
|
1313
|
1371
|
SERIAL_PROTOCOLPGM(" y: ");
|
|
@@ -1320,8 +1378,6 @@ void process_commands()
|
1320
|
1378
|
|
1321
|
1379
|
set_bed_level_equation(z_at_xLeft_yFront, z_at_xRight_yFront, z_at_xLeft_yBack);
|
1322
|
1380
|
|
1323
|
|
- retract_z_probe(); // Retract Z Servo endstop if available
|
1324
|
|
-
|
1325
|
1381
|
st_synchronize();
|
1326
|
1382
|
|
1327
|
1383
|
// The following code correct the Z height difference from z-probe position and hotend tip position.
|