diff --git a/Grbl_Esp32/src/Machine/Axes.cpp b/Grbl_Esp32/src/Machine/Axes.cpp index 45e1a8bc..0ae8b55f 100644 --- a/Grbl_Esp32/src/Machine/Axes.cpp +++ b/Grbl_Esp32/src/Machine/Axes.cpp @@ -28,6 +28,8 @@ namespace Machine { _sharedStepperDisable.report("Shared stepper disable"); } + release_all_motors(); + // certain motors need features to be turned on. Check them here for (uint8_t axis = X_AXIS; axis < _numberAxis; axis++) { auto a = _axis[axis]; @@ -80,24 +82,24 @@ namespace Machine { // Put the motors in the given axes into homing mode, returning a // mask of which motors (considering gangs) can do homing. - MotorMask Axes::set_homing_mode(AxisMask homing_mask, bool isHoming) { + MotorMask Axes::set_homing_mode(AxisMask axisMask, bool isHoming) { release_all_motors(); // On homing transitions, cancel all motor lockouts - MotorMask can_home = 0; + MotorMask motorsCanHome = 0; for (uint8_t axis = X_AXIS; axis < _numberAxis; axis++) { - if (bitnum_is_true(homing_mask, axis)) { + if (bitnum_is_true(axisMask, axis)) { auto a = _axis[axis]; if (a != nullptr) { for (uint8_t gang = 0; gang < Axis::MAX_NUMBER_GANGED; gang++) { if (a->_gangs[gang]->_motor->set_homing_mode(isHoming)) { - set_bitnum(can_home, gang * 16 + axis); + set_bitnum(motorsCanHome, gang * 16 + axis); } } } } } - return can_home; + return motorsCanHome; } void Axes::release_all_motors() { _motorLockoutMask = 0xffffffff; } diff --git a/Grbl_Esp32/src/Machine/Axes.h b/Grbl_Esp32/src/Machine/Axes.h index 00d4d465..14aec9ea 100644 --- a/Grbl_Esp32/src/Machine/Axes.h +++ b/Grbl_Esp32/src/Machine/Axes.h @@ -33,7 +33,7 @@ namespace Machine { // During homing, this is used to stop stepping on motors that have // reached their limit switches, by clearing bits in the mask. - MotorMask _motorLockoutMask = 0; + MotorMask _motorLockoutMask = 0xffffffff; public: Axes(); diff --git a/Grbl_Esp32/src/Machine/Homing.cpp b/Grbl_Esp32/src/Machine/Homing.cpp index 207e889b..6048c7d4 100644 --- a/Grbl_Esp32/src/Machine/Homing.cpp +++ b/Grbl_Esp32/src/Machine/Homing.cpp @@ -52,7 +52,7 @@ namespace Machine { AxisMask axesMask = 0; // Find the axis that will take the longest for (int axis = 0; axis < n_axis; axis++) { - if (bits_are_false(motors, axis | (axis << 16))) { + if (bitnum_is_false(motors, axis) && bitnum_is_false(motors, axis + 16)) { continue; } @@ -89,10 +89,6 @@ namespace Machine { travel = std::max(travel, axisConfig->_gangs[1]->_endstops->_pulloff); } } - - // We know that endstop is not nullptr because we checked for a - // valid endstop configuration before starting to home. - travel = endstop->_pulloff; } // First we compute the maximum-time-to-completion vector; later we will @@ -107,11 +103,11 @@ namespace Machine { } } // Scale the target array, currently in units of time, back to positions - // When approaching a small fudge factor to ensure that the limit is reached - + // When approaching add a fudge factor (scaler) to ensure that the limit is reached - // but no fudge factor when pulling off. for (int axis = 0; axis < n_axis; axis++) { if (bitnum_is_true(axesMask, axis)) { - auto homing = config->_axes->_axis[axis]->_homing; + auto homing = axes->_axis[axis]->_homing; auto scaler = approach ? (seek ? homing->_seek_scaler : homing->_feed_scaler) : 1.0; target[axis] *= limitingRate * scaler; } @@ -148,6 +144,8 @@ namespace Machine { uint32_t settling_ms = plan_move(remainingMotors, approach, seek); + config->_axes->release_all_motors(); + do { if (approach) { // Check limit state. Lock out cycle axes when they change.