|
@@ -1443,65 +1443,69 @@ void set_axis_not_trusted(const AxisEnum axis) {
|
1443
|
1443
|
TERN_(I2C_POSITION_ENCODERS, I2CPEM.unhomed(axis));
|
1444
|
1444
|
}
|
1445
|
1445
|
|
1446
|
|
-/**
|
1447
|
|
- * Move the axis back to its home_phase if set and driver is capable (TMC)
|
1448
|
|
- *
|
1449
|
|
- * Improves homing repeatability by homing to stepper coil's nearest absolute
|
1450
|
|
- * phase position. Trinamic drivers use a stepper phase table with 1024 values
|
1451
|
|
- * spanning 4 full steps with 256 positions each (ergo, 1024 positions).
|
1452
|
|
- */
|
1453
|
|
-void backout_to_tmc_homing_phase(const AxisEnum axis) {
|
1454
|
|
- #ifdef TMC_HOME_PHASE
|
1455
|
|
- const abc_long_t home_phase = TMC_HOME_PHASE;
|
|
1446
|
+#ifdef TMC_HOME_PHASE
|
|
1447
|
+ /**
|
|
1448
|
+ * Move the axis back to its home_phase if set and driver is capable (TMC)
|
|
1449
|
+ *
|
|
1450
|
+ * Improves homing repeatability by homing to stepper coil's nearest absolute
|
|
1451
|
+ * phase position. Trinamic drivers use a stepper phase table with 1024 values
|
|
1452
|
+ * spanning 4 full steps with 256 positions each (ergo, 1024 positions).
|
|
1453
|
+ */
|
|
1454
|
+ void backout_to_tmc_homing_phase(const AxisEnum axis) {
|
|
1455
|
+ const xyz_long_t home_phase = TMC_HOME_PHASE;
|
1456
|
1456
|
|
1457
|
1457
|
// check if home phase is disabled for this axis.
|
1458
|
1458
|
if (home_phase[axis] < 0) return;
|
1459
|
1459
|
|
1460
|
|
- int16_t axisMicrostepSize;
|
1461
|
|
- int16_t phaseCurrent;
|
1462
|
|
- bool invertDir;
|
|
1460
|
+ int16_t phasePerUStep, // TMC µsteps(phase) per Marlin µsteps
|
|
1461
|
+ phaseCurrent, // The TMC µsteps(phase) count of the current position
|
|
1462
|
+ effectorBackoutDir, // Direction in which the effector mm coordinates move away from endstop.
|
|
1463
|
+ stepperBackoutDir; // Direction in which the TMC µstep count(phase) move away from endstop.
|
1463
|
1464
|
|
1464
|
1465
|
switch (axis) {
|
1465
|
1466
|
#ifdef X_MICROSTEPS
|
1466
|
1467
|
case X_AXIS:
|
1467
|
|
- axisMicrostepSize = 256 / (X_MICROSTEPS);
|
|
1468
|
+ phasePerUStep = 256 / (X_MICROSTEPS);
|
1468
|
1469
|
phaseCurrent = stepperX.get_microstep_counter();
|
1469
|
|
- invertDir = INVERT_X_DIR;
|
|
1470
|
+ effectorBackoutDir = -X_HOME_DIR;
|
|
1471
|
+ stepperBackoutDir = INVERT_X_DIR ? effectorBackoutDir : -effectorBackoutDir;
|
1470
|
1472
|
break;
|
1471
|
1473
|
#endif
|
1472
|
1474
|
#ifdef Y_MICROSTEPS
|
1473
|
1475
|
case Y_AXIS:
|
1474
|
|
- axisMicrostepSize = 256 / (Y_MICROSTEPS);
|
|
1476
|
+ phasePerUStep = 256 / (Y_MICROSTEPS);
|
1475
|
1477
|
phaseCurrent = stepperY.get_microstep_counter();
|
1476
|
|
- invertDir = INVERT_Y_DIR;
|
|
1478
|
+ effectorBackoutDir = -Y_HOME_DIR;
|
|
1479
|
+ stepperBackoutDir = INVERT_Y_DIR ? effectorBackoutDir : -effectorBackoutDir;
|
1477
|
1480
|
break;
|
1478
|
1481
|
#endif
|
1479
|
1482
|
#ifdef Z_MICROSTEPS
|
1480
|
1483
|
case Z_AXIS:
|
1481
|
|
- axisMicrostepSize = 256 / (Z_MICROSTEPS);
|
|
1484
|
+ phasePerUStep = 256 / (Z_MICROSTEPS);
|
1482
|
1485
|
phaseCurrent = stepperZ.get_microstep_counter();
|
1483
|
|
- invertDir = INVERT_Z_DIR;
|
|
1486
|
+ effectorBackoutDir = -Z_HOME_DIR;
|
|
1487
|
+ stepperBackoutDir = INVERT_Z_DIR ? effectorBackoutDir : -effectorBackoutDir;
|
1484
|
1488
|
break;
|
1485
|
1489
|
#endif
|
1486
|
1490
|
default: return;
|
1487
|
1491
|
}
|
1488
|
1492
|
|
1489
|
|
- // Depending on invert dir measure the distance to nearest home phase.
|
1490
|
|
- int16_t phaseDelta = (invertDir ? -1 : 1) * (home_phase[axis] - phaseCurrent);
|
|
1493
|
+ // Phase distance to nearest home phase position when moving in the backout direction from endstop(may be negative).
|
|
1494
|
+ int16_t phaseDelta = (home_phase[axis] - phaseCurrent) * stepperBackoutDir;
|
1491
|
1495
|
|
1492
|
1496
|
// Check if home distance within endstop assumed repeatability noise of .05mm and warn.
|
1493
|
|
- if (ABS(phaseDelta) * planner.steps_to_mm[axis] / axisMicrostepSize < 0.05f)
|
1494
|
|
- DEBUG_ECHOLNPAIR("Selected home phase ", home_phase[axis],
|
|
1497
|
+ if (ABS(phaseDelta) * planner.steps_to_mm[axis] / phasePerUStep < 0.05f)
|
|
1498
|
+ SERIAL_ECHOLNPAIR("Selected home phase ", home_phase[axis],
|
1495
|
1499
|
" too close to endstop trigger phase ", phaseCurrent,
|
1496
|
1500
|
". Pick a different phase for ", axis_codes[axis]);
|
1497
|
1501
|
|
1498
|
1502
|
// Skip to next if target position is behind current. So it only moves away from endstop.
|
1499
|
1503
|
if (phaseDelta < 0) phaseDelta += 1024;
|
1500
|
1504
|
|
1501
|
|
- // Get the integer µsteps to target. Unreachable phase? Consistently stop at the µstep before / after based on invertDir.
|
1502
|
|
- const float mmDelta = -(int16_t(phaseDelta / axisMicrostepSize) * planner.steps_to_mm[axis] * (Z_HOME_DIR));
|
|
1505
|
+ // Convert TMC µsteps(phase) to whole Marlin µsteps to effector backout direction to mm
|
|
1506
|
+ const float mmDelta = int16_t(phaseDelta / phasePerUStep) * effectorBackoutDir * planner.steps_to_mm[axis];
|
1503
|
1507
|
|
1504
|
|
- // optional debug messages.
|
|
1508
|
+ // Optional debug messages
|
1505
|
1509
|
if (DEBUGGING(LEVELING)) {
|
1506
|
1510
|
DEBUG_ECHOLNPAIR(
|
1507
|
1511
|
"Endstop ", axis_codes[axis], " hit at Phase:", phaseCurrent,
|
|
@@ -1510,14 +1514,11 @@ void backout_to_tmc_homing_phase(const AxisEnum axis) {
|
1510
|
1514
|
}
|
1511
|
1515
|
|
1512
|
1516
|
if (mmDelta != 0) {
|
1513
|
|
- // retrace by the amount computed in mmDelta.
|
|
1517
|
+ // Retrace by the amount computed in mmDelta.
|
1514
|
1518
|
do_homing_move(axis, mmDelta, get_homing_bump_feedrate(axis));
|
1515
|
1519
|
}
|
1516
|
|
- #else
|
1517
|
|
- UNUSED(axis);
|
1518
|
|
- #endif
|
1519
|
|
-}
|
1520
|
|
-
|
|
1520
|
+ }
|
|
1521
|
+#endif
|
1521
|
1522
|
|
1522
|
1523
|
/**
|
1523
|
1524
|
* Home an individual "raw axis" to its endstop.
|
|
@@ -1748,8 +1749,10 @@ void homeaxis(const AxisEnum axis) {
|
1748
|
1749
|
}
|
1749
|
1750
|
#endif
|
1750
|
1751
|
|
1751
|
|
- // move back to homing phase if configured and capable
|
1752
|
|
- backout_to_tmc_homing_phase(axis);
|
|
1752
|
+ #ifdef TMC_HOME_PHASE
|
|
1753
|
+ // move back to homing phase if configured and capable
|
|
1754
|
+ backout_to_tmc_homing_phase(axis);
|
|
1755
|
+ #endif
|
1753
|
1756
|
|
1754
|
1757
|
#if IS_SCARA
|
1755
|
1758
|
|