2017-09-07 22:33:16 -05:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2020-02-03 08:00:57 -06:00
|
|
|
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2017-09-07 22:33:16 -05:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
2019-06-27 23:57:50 -05:00
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
2017-09-07 22:33:16 -05:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2020-07-22 22:20:14 -05:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2017-09-07 22:33:16 -05:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* motion.cpp
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "motion.h"
|
2017-09-08 15:35:25 -05:00
|
|
|
#include "endstops.h"
|
|
|
|
#include "stepper.h"
|
|
|
|
#include "planner.h"
|
|
|
|
#include "temperature.h"
|
2017-09-07 22:33:16 -05:00
|
|
|
|
|
|
|
#include "../gcode/gcode.h"
|
|
|
|
|
2017-09-08 15:35:25 -05:00
|
|
|
#include "../inc/MarlinConfig.h"
|
2017-09-07 22:33:16 -05:00
|
|
|
|
|
|
|
#if IS_SCARA
|
|
|
|
#include "../libs/buzzer.h"
|
2020-10-16 19:36:25 -05:00
|
|
|
#include "../lcd/marlinui.h"
|
2017-09-07 22:33:16 -05:00
|
|
|
#endif
|
|
|
|
|
2017-09-08 15:35:25 -05:00
|
|
|
#if HAS_BED_PROBE
|
|
|
|
#include "probe.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAS_LEVELING
|
|
|
|
#include "../feature/bedlevel/bedlevel.h"
|
|
|
|
#endif
|
|
|
|
|
2019-03-17 05:57:25 -05:00
|
|
|
#if ENABLED(BLTOUCH)
|
|
|
|
#include "../feature/bltouch.h"
|
|
|
|
#endif
|
|
|
|
|
2021-03-24 10:12:57 -05:00
|
|
|
#if HAS_STATUS_MESSAGE
|
2020-10-16 19:36:25 -05:00
|
|
|
#include "../lcd/marlinui.h"
|
2017-09-08 15:35:25 -05:00
|
|
|
#endif
|
|
|
|
|
2020-03-29 16:26:55 -05:00
|
|
|
#if HAS_FILAMENT_SENSOR
|
|
|
|
#include "../feature/runout.h"
|
|
|
|
#endif
|
|
|
|
|
2017-09-08 15:35:25 -05:00
|
|
|
#if ENABLED(SENSORLESS_HOMING)
|
2017-12-15 15:03:14 -06:00
|
|
|
#include "../feature/tmc_util.h"
|
2017-09-07 22:33:16 -05:00
|
|
|
#endif
|
|
|
|
|
2018-01-29 13:40:04 -06:00
|
|
|
#if ENABLED(FWRETRACT)
|
|
|
|
#include "../feature/fwretract.h"
|
|
|
|
#endif
|
|
|
|
|
2019-04-06 18:04:34 -05:00
|
|
|
#if ENABLED(BABYSTEP_DISPLAY_TOTAL)
|
|
|
|
#include "../feature/babystep.h"
|
|
|
|
#endif
|
|
|
|
|
2019-03-14 02:25:42 -05:00
|
|
|
#define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE)
|
|
|
|
#include "../core/debug_out.h"
|
|
|
|
|
2017-09-07 22:33:16 -05:00
|
|
|
// Relative Mode. Enable with G91, disable with G90.
|
2018-03-21 05:45:23 -05:00
|
|
|
bool relative_mode; // = false;
|
2017-09-07 22:33:16 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Cartesian Current Position
|
2017-11-02 23:59:42 -05:00
|
|
|
* Used to track the native machine position as moves are queued.
|
2019-03-04 19:09:51 -06:00
|
|
|
* Used by 'line_to_current_position' to do a move after changing it.
|
2018-09-16 21:24:15 -05:00
|
|
|
* Used by 'sync_plan_position' to update 'planner.position'.
|
2017-09-07 22:33:16 -05:00
|
|
|
*/
|
2021-05-18 22:46:59 -05:00
|
|
|
#ifdef Z_IDLE_HEIGHT
|
|
|
|
#define Z_INIT_POS Z_IDLE_HEIGHT
|
|
|
|
#else
|
|
|
|
#define Z_INIT_POS Z_HOME_POS
|
|
|
|
#endif
|
|
|
|
|
2021-06-05 02:18:47 -05:00
|
|
|
xyze_pos_t current_position = LOGICAL_AXIS_ARRAY(0, X_HOME_POS, Y_HOME_POS, Z_INIT_POS, I_HOME_POS, J_HOME_POS, K_HOME_POS);
|
2017-09-07 22:33:16 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Cartesian Destination
|
2017-11-08 22:13:33 -06:00
|
|
|
* The destination for a move, filled in by G-code movement commands,
|
2020-03-01 16:59:04 -06:00
|
|
|
* and expected by functions like 'prepare_line_to_destination'.
|
2019-09-14 03:05:10 -05:00
|
|
|
* G-codes can set destination using 'get_destination_from_command'
|
2017-09-07 22:33:16 -05:00
|
|
|
*/
|
2019-09-29 04:25:39 -05:00
|
|
|
xyze_pos_t destination; // {0}
|
2017-09-07 22:33:16 -05:00
|
|
|
|
2020-01-07 13:52:19 -06:00
|
|
|
// G60/G61 Position Save and Return
|
|
|
|
#if SAVED_POSITIONS
|
2020-01-30 03:18:45 -06:00
|
|
|
uint8_t saved_slots[(SAVED_POSITIONS + 7) >> 3];
|
2021-05-12 02:17:06 -05:00
|
|
|
xyze_pos_t stored_position[SAVED_POSITIONS];
|
2020-01-07 13:52:19 -06:00
|
|
|
#endif
|
|
|
|
|
2017-09-07 22:33:16 -05:00
|
|
|
// The active extruder (tool). Set with T<extruder> command.
|
2020-09-20 18:29:08 -05:00
|
|
|
#if HAS_MULTI_EXTRUDER
|
2020-01-07 13:52:19 -06:00
|
|
|
uint8_t active_extruder = 0; // = 0
|
2018-09-10 23:09:26 -05:00
|
|
|
#endif
|
2017-09-07 22:33:16 -05:00
|
|
|
|
2019-10-27 17:49:27 -05:00
|
|
|
#if ENABLED(LCD_SHOW_E_TOTAL)
|
|
|
|
float e_move_accumulator; // = 0
|
|
|
|
#endif
|
|
|
|
|
2017-09-08 15:35:25 -05:00
|
|
|
// Extruder offsets
|
2018-08-24 21:26:29 -05:00
|
|
|
#if HAS_HOTEND_OFFSET
|
2019-09-29 04:25:39 -05:00
|
|
|
xyz_pos_t hotend_offset[HOTENDS]; // Initialized by settings.load()
|
2019-03-08 22:13:24 -06:00
|
|
|
void reset_hotend_offsets() {
|
|
|
|
constexpr float tmp[XYZ][HOTENDS] = { HOTEND_OFFSET_X, HOTEND_OFFSET_Y, HOTEND_OFFSET_Z };
|
|
|
|
static_assert(
|
2019-09-29 04:25:39 -05:00
|
|
|
!tmp[X_AXIS][0] && !tmp[Y_AXIS][0] && !tmp[Z_AXIS][0],
|
2019-03-08 22:13:24 -06:00
|
|
|
"Offsets for the first hotend must be 0.0."
|
|
|
|
);
|
2019-09-29 04:25:39 -05:00
|
|
|
// Transpose from [XYZ][HOTENDS] to [HOTENDS][XYZ]
|
2021-05-18 22:51:19 -05:00
|
|
|
HOTEND_LOOP() LOOP_LINEAR_AXES(a) hotend_offset[e][a] = tmp[a][e];
|
2019-03-08 22:13:24 -06:00
|
|
|
#if ENABLED(DUAL_X_CARRIAGE)
|
2019-09-29 04:25:39 -05:00
|
|
|
hotend_offset[1].x = _MAX(X2_HOME_POS, X2_MAX_POS);
|
2019-03-08 22:13:24 -06:00
|
|
|
#endif
|
|
|
|
}
|
2017-09-08 15:35:25 -05:00
|
|
|
#endif
|
|
|
|
|
2017-09-07 22:33:16 -05:00
|
|
|
// The feedrate for the current move, often used as the default if
|
|
|
|
// no other feedrate is specified. Overridden for special moves.
|
|
|
|
// Set by the last G0 through G5 command's "F" parameter.
|
|
|
|
// Functions that override this for custom moves *must always* restore it!
|
2019-09-26 01:28:09 -05:00
|
|
|
feedRate_t feedrate_mm_s = MMM_TO_MMS(1500);
|
2017-09-08 15:35:25 -05:00
|
|
|
int16_t feedrate_percentage = 100;
|
|
|
|
|
|
|
|
// Cartesian conversion result goes here:
|
2019-09-29 04:25:39 -05:00
|
|
|
xyz_pos_t cartes;
|
2017-09-08 15:35:25 -05:00
|
|
|
|
|
|
|
#if IS_KINEMATIC
|
2019-03-08 22:13:24 -06:00
|
|
|
|
2021-06-05 02:18:47 -05:00
|
|
|
abce_pos_t delta;
|
2017-09-08 15:35:25 -05:00
|
|
|
|
2019-03-08 22:13:24 -06:00
|
|
|
#if HAS_SCARA_OFFSET
|
2019-09-29 04:25:39 -05:00
|
|
|
abc_pos_t scara_home_offset;
|
2019-03-08 22:13:24 -06:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAS_SOFTWARE_ENDSTOPS
|
2019-03-13 05:48:36 -05:00
|
|
|
float delta_max_radius, delta_max_radius_2;
|
2019-03-08 22:13:24 -06:00
|
|
|
#elif IS_SCARA
|
2019-03-13 05:48:36 -05:00
|
|
|
constexpr float delta_max_radius = SCARA_PRINTABLE_RADIUS,
|
|
|
|
delta_max_radius_2 = sq(SCARA_PRINTABLE_RADIUS);
|
2019-03-08 22:13:24 -06:00
|
|
|
#else // DELTA
|
2019-03-13 05:48:36 -05:00
|
|
|
constexpr float delta_max_radius = DELTA_PRINTABLE_RADIUS,
|
|
|
|
delta_max_radius_2 = sq(DELTA_PRINTABLE_RADIUS);
|
2019-03-08 22:13:24 -06:00
|
|
|
#endif
|
|
|
|
|
2018-11-03 03:56:33 -05:00
|
|
|
#endif
|
|
|
|
|
2017-09-08 15:35:25 -05:00
|
|
|
/**
|
|
|
|
* The workspace can be offset by some commands, or
|
|
|
|
* these offsets may be omitted to save on computation.
|
|
|
|
*/
|
2018-11-03 03:39:15 -05:00
|
|
|
#if HAS_POSITION_SHIFT
|
|
|
|
// The distance that XYZ has been offset by G92. Reset by G28.
|
2019-09-29 04:25:39 -05:00
|
|
|
xyz_pos_t position_shift{0};
|
2018-11-03 03:39:15 -05:00
|
|
|
#endif
|
|
|
|
#if HAS_HOME_OFFSET
|
|
|
|
// This offset is added to the configured home position.
|
|
|
|
// Set by M206, M428, or menu item. Saved to EEPROM.
|
2019-09-29 04:25:39 -05:00
|
|
|
xyz_pos_t home_offset{0};
|
2018-11-03 03:39:15 -05:00
|
|
|
#endif
|
|
|
|
#if HAS_HOME_OFFSET && HAS_POSITION_SHIFT
|
|
|
|
// The above two are combined to save on computes
|
2019-09-29 04:25:39 -05:00
|
|
|
xyz_pos_t workspace_offset{0};
|
2017-09-08 15:35:25 -05:00
|
|
|
#endif
|
|
|
|
|
2019-02-24 20:29:03 -06:00
|
|
|
#if HAS_ABL_NOT_UBL
|
2021-02-27 15:54:43 -06:00
|
|
|
feedRate_t xy_probe_feedrate_mm_s = MMM_TO_MMS(XY_PROBE_FEEDRATE);
|
2017-09-08 15:35:25 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Output the current position to serial
|
|
|
|
*/
|
|
|
|
|
2020-03-02 21:52:53 -06:00
|
|
|
inline void report_more_positions() {
|
2017-09-08 15:35:25 -05:00
|
|
|
stepper.report_positions();
|
2020-04-22 16:35:03 -05:00
|
|
|
TERN_(IS_SCARA, scara_report_positions());
|
2017-09-08 15:35:25 -05:00
|
|
|
}
|
|
|
|
|
2020-03-02 21:52:53 -06:00
|
|
|
// Report the logical position for a given machine position
|
|
|
|
inline void report_logical_position(const xyze_pos_t &rpos) {
|
|
|
|
const xyze_pos_t lpos = rpos.asLogical();
|
2021-05-24 16:38:57 -05:00
|
|
|
SERIAL_ECHOPAIR_P(
|
2021-06-05 02:18:47 -05:00
|
|
|
LIST_N(DOUBLE(LINEAR_AXES),
|
|
|
|
X_LBL, lpos.x,
|
|
|
|
SP_Y_LBL, lpos.y,
|
|
|
|
SP_Z_LBL, lpos.z,
|
|
|
|
SP_I_LBL, lpos.i,
|
|
|
|
SP_J_LBL, lpos.j,
|
|
|
|
SP_K_LBL, lpos.k
|
|
|
|
)
|
2021-05-24 16:38:57 -05:00
|
|
|
#if HAS_EXTRUDERS
|
|
|
|
, SP_E_LBL, lpos.e
|
|
|
|
#endif
|
|
|
|
);
|
2020-03-02 21:52:53 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Report the real current position according to the steppers.
|
|
|
|
// Forward kinematics and un-leveling are applied.
|
|
|
|
void report_real_position() {
|
|
|
|
get_cartesian_from_steppers();
|
2021-05-24 16:38:57 -05:00
|
|
|
xyze_pos_t npos = LOGICAL_AXIS_ARRAY(
|
|
|
|
planner.get_axis_position_mm(E_AXIS),
|
2021-06-05 02:18:47 -05:00
|
|
|
cartes.x, cartes.y, cartes.z,
|
|
|
|
planner.get_axis_position_mm(I_AXIS),
|
|
|
|
planner.get_axis_position_mm(J_AXIS),
|
|
|
|
planner.get_axis_position_mm(K_AXIS)
|
2021-05-24 16:38:57 -05:00
|
|
|
);
|
|
|
|
|
2021-05-18 22:46:59 -05:00
|
|
|
TERN_(HAS_POSITION_MODIFIERS, planner.unapply_modifiers(npos, true));
|
2021-05-24 16:38:57 -05:00
|
|
|
|
2020-03-02 21:52:53 -06:00
|
|
|
report_logical_position(npos);
|
2020-03-23 18:31:04 -05:00
|
|
|
report_more_positions();
|
2020-03-02 21:52:53 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Report the logical current position according to the most recent G-code command
|
2020-03-23 18:31:04 -05:00
|
|
|
void report_current_position() {
|
|
|
|
report_logical_position(current_position);
|
|
|
|
report_more_positions();
|
|
|
|
}
|
2020-03-02 21:52:53 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Report the logical current position according to the most recent G-code command.
|
|
|
|
* The planner.position always corresponds to the last G-code too. This makes M114
|
|
|
|
* suitable for debugging kinematics and leveling while avoiding planner sync that
|
|
|
|
* definitively interrupts the printing flow.
|
|
|
|
*/
|
|
|
|
void report_current_position_projected() {
|
|
|
|
report_logical_position(current_position);
|
|
|
|
stepper.report_a_position(planner.position);
|
|
|
|
}
|
|
|
|
|
2021-05-15 15:02:20 -05:00
|
|
|
#if ENABLED(AUTO_REPORT_POSITION)
|
|
|
|
//struct PositionReport { void report() { report_current_position_projected(); } };
|
|
|
|
AutoReporter<PositionReport> position_auto_reporter;
|
|
|
|
#endif
|
|
|
|
|
2021-04-16 01:59:28 -05:00
|
|
|
#if EITHER(FULL_REPORT_TO_HOST_FEATURE, REALTIME_REPORTING_COMMANDS)
|
|
|
|
|
|
|
|
M_StateEnum M_State_grbl = M_INIT;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Output the current grbl compatible state to serial while moving
|
|
|
|
*/
|
|
|
|
void report_current_grblstate_moving() { SERIAL_ECHOLNPAIR("S_XYZ:", int(M_State_grbl)); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Output the current position (processed) to serial while moving
|
|
|
|
*/
|
|
|
|
void report_current_position_moving() {
|
|
|
|
|
|
|
|
get_cartesian_from_steppers();
|
|
|
|
const xyz_pos_t lpos = cartes.asLogical();
|
|
|
|
SERIAL_ECHOPAIR("X:", lpos.x, " Y:", lpos.y, " Z:", lpos.z, " E:", current_position.e);
|
|
|
|
|
|
|
|
stepper.report_positions();
|
|
|
|
#if IS_SCARA
|
|
|
|
scara_report_positions();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
report_current_grblstate_moving();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a Grbl-compatible state from the current marlin_state
|
|
|
|
*/
|
|
|
|
M_StateEnum grbl_state_for_marlin_state() {
|
|
|
|
switch (marlin_state) {
|
|
|
|
case MF_INITIALIZING: return M_INIT;
|
|
|
|
case MF_SD_COMPLETE: return M_ALARM;
|
|
|
|
case MF_WAITING: return M_IDLE;
|
|
|
|
case MF_STOPPED: return M_END;
|
|
|
|
case MF_RUNNING: return M_RUNNING;
|
|
|
|
case MF_PAUSED: return M_HOLD;
|
|
|
|
case MF_KILLED: return M_ERROR;
|
|
|
|
default: return M_IDLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2017-09-07 22:33:16 -05:00
|
|
|
/**
|
2021-01-21 03:40:07 -06:00
|
|
|
* Run out the planner buffer and re-sync the current
|
|
|
|
* position from the last-updated stepper positions.
|
|
|
|
*/
|
|
|
|
void quickstop_stepper() {
|
|
|
|
planner.quick_stop();
|
|
|
|
planner.synchronize();
|
2021-05-21 08:25:54 -05:00
|
|
|
set_current_from_steppers_for_axis(ALL_AXES_ENUM);
|
2021-01-21 03:40:07 -06:00
|
|
|
sync_plan_position();
|
|
|
|
}
|
|
|
|
|
2021-04-16 01:59:28 -05:00
|
|
|
#if ENABLED(REALTIME_REPORTING_COMMANDS)
|
|
|
|
|
|
|
|
void quickpause_stepper() {
|
|
|
|
planner.quick_pause();
|
|
|
|
//planner.synchronize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void quickresume_stepper() {
|
|
|
|
planner.quick_resume();
|
|
|
|
//planner.synchronize();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2021-01-21 03:40:07 -06:00
|
|
|
/**
|
2017-09-07 22:33:16 -05:00
|
|
|
* Set the planner/stepper positions directly from current_position with
|
|
|
|
* no kinematic translation. Used for homing axes and cartesian/core syncing.
|
|
|
|
*/
|
|
|
|
void sync_plan_position() {
|
2019-03-14 02:25:42 -05:00
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_POS("sync_plan_position", current_position);
|
2019-09-29 04:25:39 -05:00
|
|
|
planner.set_position_mm(current_position);
|
2017-09-07 22:33:16 -05:00
|
|
|
}
|
|
|
|
|
2021-05-24 16:38:57 -05:00
|
|
|
#if HAS_EXTRUDERS
|
|
|
|
void sync_plan_position_e() { planner.set_e_position_mm(current_position.e); }
|
|
|
|
#endif
|
2017-09-07 22:33:16 -05:00
|
|
|
|
2017-09-08 15:35:25 -05:00
|
|
|
/**
|
|
|
|
* Get the stepper positions in the cartes[] array.
|
|
|
|
* Forward kinematics are applied for DELTA and SCARA.
|
|
|
|
*
|
|
|
|
* The result is in the current coordinate space with
|
|
|
|
* leveling applied. The coordinates need to be run through
|
|
|
|
* unapply_leveling to obtain the "ideal" coordinates
|
|
|
|
* suitable for current_position, etc.
|
|
|
|
*/
|
|
|
|
void get_cartesian_from_steppers() {
|
|
|
|
#if ENABLED(DELTA)
|
2021-03-03 17:57:24 -06:00
|
|
|
forward_kinematics(planner.get_axis_positions_mm());
|
2021-06-05 02:18:47 -05:00
|
|
|
#elif IS_SCARA
|
|
|
|
forward_kinematics(
|
|
|
|
planner.get_axis_position_degrees(A_AXIS), planner.get_axis_position_degrees(B_AXIS)
|
|
|
|
OPTARG(AXEL_TPARA, planner.get_axis_position_degrees(C_AXIS))
|
|
|
|
);
|
2019-09-29 04:25:39 -05:00
|
|
|
cartes.z = planner.get_axis_position_mm(Z_AXIS);
|
2021-06-05 02:18:47 -05:00
|
|
|
#else
|
|
|
|
LINEAR_AXIS_CODE(
|
|
|
|
cartes.x = planner.get_axis_position_mm(X_AXIS),
|
|
|
|
cartes.y = planner.get_axis_position_mm(Y_AXIS),
|
|
|
|
cartes.z = planner.get_axis_position_mm(Z_AXIS),
|
|
|
|
cartes.i = planner.get_axis_position_mm(I_AXIS),
|
|
|
|
cartes.j = planner.get_axis_position_mm(J_AXIS),
|
|
|
|
cartes.k = planner.get_axis_position_mm(K_AXIS)
|
|
|
|
);
|
2017-09-08 15:35:25 -05:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the current_position for an axis based on
|
|
|
|
* the stepper positions, removing any leveling that
|
|
|
|
* may have been applied.
|
2017-12-10 21:17:07 -06:00
|
|
|
*
|
|
|
|
* To prevent small shifts in axis position always call
|
2018-09-16 21:24:15 -05:00
|
|
|
* sync_plan_position after updating axes with this.
|
2017-12-10 21:17:07 -06:00
|
|
|
*
|
|
|
|
* To keep hosts in sync, always call report_current_position
|
|
|
|
* after updating the current_position.
|
2017-09-08 15:35:25 -05:00
|
|
|
*/
|
|
|
|
void set_current_from_steppers_for_axis(const AxisEnum axis) {
|
|
|
|
get_cartesian_from_steppers();
|
2020-03-01 10:41:14 -06:00
|
|
|
xyze_pos_t pos = cartes;
|
2021-05-24 16:38:57 -05:00
|
|
|
|
2021-06-05 02:18:47 -05:00
|
|
|
TERN_(HAS_EXTRUDERS, pos.e = planner.get_axis_position_mm(E_AXIS));
|
2018-09-16 21:24:15 -05:00
|
|
|
|
2021-06-05 02:18:47 -05:00
|
|
|
TERN_(HAS_POSITION_MODIFIERS, planner.unapply_modifiers(pos, true));
|
2020-03-01 10:41:14 -06:00
|
|
|
|
2021-05-21 08:25:54 -05:00
|
|
|
if (axis == ALL_AXES_ENUM)
|
2020-03-01 10:41:14 -06:00
|
|
|
current_position = pos;
|
2017-09-08 15:35:25 -05:00
|
|
|
else
|
2020-03-01 10:41:14 -06:00
|
|
|
current_position[axis] = pos[axis];
|
2017-09-08 15:35:25 -05:00
|
|
|
}
|
|
|
|
|
2017-09-07 22:33:16 -05:00
|
|
|
/**
|
|
|
|
* Move the planner to the current position from wherever it last moved
|
|
|
|
* (or from wherever it has been told it is located).
|
|
|
|
*/
|
2021-04-01 17:59:57 -05:00
|
|
|
void line_to_current_position(const_feedRate_t fr_mm_s/*=feedrate_mm_s*/) {
|
2021-06-05 02:18:47 -05:00
|
|
|
planner.buffer_line(current_position, fr_mm_s);
|
2017-09-07 22:33:16 -05:00
|
|
|
}
|
|
|
|
|
2021-05-21 08:23:09 -05:00
|
|
|
#if HAS_EXTRUDERS
|
2021-04-01 17:59:57 -05:00
|
|
|
void unscaled_e_move(const_float_t length, const_feedRate_t fr_mm_s) {
|
2020-04-22 16:35:03 -05:00
|
|
|
TERN_(HAS_FILAMENT_SENSOR, runout.reset());
|
2020-03-29 17:20:01 -05:00
|
|
|
current_position.e += length / planner.e_factor[active_extruder];
|
|
|
|
line_to_current_position(fr_mm_s);
|
|
|
|
planner.synchronize();
|
|
|
|
}
|
|
|
|
#endif
|
2020-03-29 16:26:55 -05:00
|
|
|
|
2017-09-07 22:33:16 -05:00
|
|
|
#if IS_KINEMATIC
|
|
|
|
|
|
|
|
/**
|
2019-09-26 01:28:09 -05:00
|
|
|
* Buffer a fast move without interpolation. Set current_position to destination
|
2017-09-07 22:33:16 -05:00
|
|
|
*/
|
2021-04-01 17:59:57 -05:00
|
|
|
void prepare_fast_move_to_destination(const_feedRate_t scaled_fr_mm_s/*=MMS_SCALED(feedrate_mm_s)*/) {
|
2019-09-26 01:28:09 -05:00
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_POS("prepare_fast_move_to_destination", destination);
|
2017-09-07 22:33:16 -05:00
|
|
|
|
2017-12-09 02:11:31 -06:00
|
|
|
#if UBL_SEGMENTED
|
2019-09-26 01:28:09 -05:00
|
|
|
// UBL segmented line will do Z-only moves in single segment
|
|
|
|
ubl.line_to_destination_segmented(scaled_fr_mm_s);
|
2017-09-07 22:33:16 -05:00
|
|
|
#else
|
2019-09-29 04:25:39 -05:00
|
|
|
if (current_position == destination) return;
|
2017-09-07 22:33:16 -05:00
|
|
|
|
2021-06-05 02:18:47 -05:00
|
|
|
planner.buffer_line(destination, scaled_fr_mm_s);
|
2017-09-07 22:33:16 -05:00
|
|
|
#endif
|
|
|
|
|
2019-09-29 04:25:39 -05:00
|
|
|
current_position = destination;
|
2017-09-07 22:33:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // IS_KINEMATIC
|
|
|
|
|
2020-05-17 18:45:30 -05:00
|
|
|
/**
|
|
|
|
* Do a fast or normal move to 'destination' with an optional FR.
|
|
|
|
* - Move at normal speed regardless of feedrate percentage.
|
|
|
|
* - Extrude the specified length regardless of flow percentage.
|
|
|
|
*/
|
2021-04-01 17:59:57 -05:00
|
|
|
void _internal_move_to_destination(const_feedRate_t fr_mm_s/*=0.0f*/
|
2021-05-23 21:33:22 -05:00
|
|
|
OPTARG(IS_KINEMATIC, const bool is_fast/*=false*/)
|
2019-09-26 01:28:09 -05:00
|
|
|
) {
|
|
|
|
const feedRate_t old_feedrate = feedrate_mm_s;
|
|
|
|
if (fr_mm_s) feedrate_mm_s = fr_mm_s;
|
|
|
|
|
|
|
|
const uint16_t old_pct = feedrate_percentage;
|
|
|
|
feedrate_percentage = 100;
|
|
|
|
|
2021-05-21 08:23:09 -05:00
|
|
|
#if HAS_EXTRUDERS
|
2020-05-17 18:45:30 -05:00
|
|
|
const float old_fac = planner.e_factor[active_extruder];
|
|
|
|
planner.e_factor[active_extruder] = 1.0f;
|
2019-09-29 04:32:24 -05:00
|
|
|
#endif
|
2019-09-26 01:28:09 -05:00
|
|
|
|
2021-04-12 20:58:34 -05:00
|
|
|
if (TERN0(IS_KINEMATIC, is_fast))
|
2021-05-02 17:05:15 -05:00
|
|
|
TERN(IS_KINEMATIC, prepare_fast_move_to_destination(), NOOP);
|
2021-04-12 20:15:41 -05:00
|
|
|
else
|
|
|
|
prepare_line_to_destination();
|
2019-09-26 01:28:09 -05:00
|
|
|
|
|
|
|
feedrate_mm_s = old_feedrate;
|
|
|
|
feedrate_percentage = old_pct;
|
2021-05-23 21:33:22 -05:00
|
|
|
TERN_(HAS_EXTRUDERS, planner.e_factor[active_extruder] = old_fac);
|
2019-09-26 01:28:09 -05:00
|
|
|
}
|
|
|
|
|
2017-09-08 15:35:25 -05:00
|
|
|
/**
|
2021-06-05 02:18:47 -05:00
|
|
|
* Plan a move to (X, Y, Z, [I, [J, [K]]]) and set the current_position
|
|
|
|
* Plan a move to (X, Y, Z) with separation of Z from other components.
|
2021-04-12 20:15:41 -05:00
|
|
|
*
|
2021-06-05 02:18:47 -05:00
|
|
|
* - If Z is moving up, the Z move is done before XY, etc.
|
|
|
|
* - If Z is moving down, the Z move is done after XY, etc.
|
2021-04-12 20:15:41 -05:00
|
|
|
* - Delta may lower Z first to get into the free motion zone.
|
|
|
|
* - Before returning, wait for the planner buffer to empty.
|
2017-09-08 15:35:25 -05:00
|
|
|
*/
|
2021-06-05 02:18:47 -05:00
|
|
|
void do_blocking_move_to(LINEAR_AXIS_ARGS(const float), const_feedRate_t fr_mm_s/*=0.0f*/) {
|
2020-07-08 21:44:21 -05:00
|
|
|
DEBUG_SECTION(log_move, "do_blocking_move_to", DEBUGGING(LEVELING));
|
2021-06-05 02:18:47 -05:00
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_XYZ("> ", LINEAR_AXIS_ARGS());
|
|
|
|
|
|
|
|
const feedRate_t xy_feedrate = fr_mm_s ?: feedRate_t(XY_PROBE_FEEDRATE_MM_S);
|
2017-09-08 15:35:25 -05:00
|
|
|
|
2021-06-05 02:18:47 -05:00
|
|
|
#if HAS_Z_AXIS
|
|
|
|
const feedRate_t z_feedrate = fr_mm_s ?: homing_feedrate(Z_AXIS);
|
|
|
|
#endif
|
2017-11-25 23:31:16 -06:00
|
|
|
|
2021-04-12 20:15:41 -05:00
|
|
|
#if EITHER(DELTA, IS_SCARA)
|
2021-06-05 02:18:47 -05:00
|
|
|
if (!position_is_reachable(x, y)) return;
|
2021-04-12 20:15:41 -05:00
|
|
|
destination = current_position; // sync destination at the start
|
|
|
|
#endif
|
2017-09-08 15:35:25 -05:00
|
|
|
|
2021-04-12 20:15:41 -05:00
|
|
|
#if ENABLED(DELTA)
|
2017-09-08 15:35:25 -05:00
|
|
|
|
2021-04-12 20:15:41 -05:00
|
|
|
REMEMBER(fr, feedrate_mm_s, xy_feedrate);
|
2017-09-08 15:35:25 -05:00
|
|
|
|
2019-09-29 04:25:39 -05:00
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_POS("destination = current_position", destination);
|
2017-09-08 15:35:25 -05:00
|
|
|
|
|
|
|
// when in the danger zone
|
2019-09-29 04:25:39 -05:00
|
|
|
if (current_position.z > delta_clip_start_height) {
|
2021-06-05 02:18:47 -05:00
|
|
|
if (z > delta_clip_start_height) { // staying in the danger zone
|
|
|
|
destination.set(x, y, z); // move directly (uninterpolated)
|
2019-09-29 04:25:39 -05:00
|
|
|
prepare_internal_fast_move_to_destination(); // set current_position from destination
|
2019-03-14 02:25:42 -05:00
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_POS("danger zone move", current_position);
|
2017-09-08 15:35:25 -05:00
|
|
|
return;
|
|
|
|
}
|
2019-09-29 04:25:39 -05:00
|
|
|
destination.z = delta_clip_start_height;
|
|
|
|
prepare_internal_fast_move_to_destination(); // set current_position from destination
|
2019-03-14 02:25:42 -05:00
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_POS("zone border move", current_position);
|
2017-09-08 15:35:25 -05:00
|
|
|
}
|
|
|
|
|
2021-06-05 02:18:47 -05:00
|
|
|
if (z > current_position.z) { // raising?
|
|
|
|
destination.z = z;
|
2019-09-29 04:25:39 -05:00
|
|
|
prepare_internal_fast_move_to_destination(z_feedrate); // set current_position from destination
|
2019-03-14 02:25:42 -05:00
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_POS("z raise move", current_position);
|
2017-09-08 15:35:25 -05:00
|
|
|
}
|
|
|
|
|
2021-06-05 02:18:47 -05:00
|
|
|
destination.set(x, y);
|
2019-09-29 04:25:39 -05:00
|
|
|
prepare_internal_move_to_destination(); // set current_position from destination
|
2019-03-14 02:25:42 -05:00
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_POS("xy move", current_position);
|
2017-09-08 15:35:25 -05:00
|
|
|
|
2021-06-05 02:18:47 -05:00
|
|
|
if (z < current_position.z) { // lowering?
|
|
|
|
destination.z = z;
|
2019-09-29 04:25:39 -05:00
|
|
|
prepare_internal_fast_move_to_destination(z_feedrate); // set current_position from destination
|
2019-03-14 02:25:42 -05:00
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_POS("z lower move", current_position);
|
2017-09-08 15:35:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#elif IS_SCARA
|
|
|
|
|
|
|
|
// If Z needs to raise, do it before moving XY
|
2021-06-05 02:18:47 -05:00
|
|
|
if (destination.z < z) {
|
|
|
|
destination.z = z;
|
2019-09-26 01:28:09 -05:00
|
|
|
prepare_internal_fast_move_to_destination(z_feedrate);
|
2017-09-08 15:35:25 -05:00
|
|
|
}
|
|
|
|
|
2021-06-05 02:18:47 -05:00
|
|
|
destination.set(x, y);
|
2019-09-26 01:28:09 -05:00
|
|
|
prepare_internal_fast_move_to_destination(xy_feedrate);
|
2017-09-08 15:35:25 -05:00
|
|
|
|
|
|
|
// If Z needs to lower, do it after moving XY
|
2021-06-05 02:18:47 -05:00
|
|
|
if (destination.z > z) {
|
|
|
|
destination.z = z;
|
2019-09-26 01:28:09 -05:00
|
|
|
prepare_internal_fast_move_to_destination(z_feedrate);
|
2017-09-08 15:35:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2021-06-05 02:18:47 -05:00
|
|
|
#if HAS_Z_AXIS
|
|
|
|
// If Z needs to raise, do it before moving XY
|
|
|
|
if (current_position.z < z) {
|
|
|
|
current_position.z = z;
|
|
|
|
line_to_current_position(z_feedrate);
|
|
|
|
}
|
|
|
|
#endif
|
2017-09-08 15:35:25 -05:00
|
|
|
|
2021-06-05 02:18:47 -05:00
|
|
|
current_position.set(x, y);
|
2019-02-25 14:28:01 -06:00
|
|
|
line_to_current_position(xy_feedrate);
|
2017-09-08 15:35:25 -05:00
|
|
|
|
2021-06-05 02:18:47 -05:00
|
|
|
#if HAS_Z_AXIS
|
|
|
|
// If Z needs to lower, do it after moving XY
|
|
|
|
if (current_position.z > z) {
|
|
|
|
current_position.z = z;
|
|
|
|
line_to_current_position(z_feedrate);
|
|
|
|
}
|
|
|
|
#endif
|
2017-09-08 15:35:25 -05:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2018-05-12 01:38:02 -05:00
|
|
|
planner.synchronize();
|
2017-09-08 15:35:25 -05:00
|
|
|
}
|
2019-10-06 23:58:19 -05:00
|
|
|
|
2021-04-01 17:59:57 -05:00
|
|
|
void do_blocking_move_to(const xy_pos_t &raw, const_feedRate_t fr_mm_s/*=0.0f*/) {
|
2021-06-05 02:18:47 -05:00
|
|
|
do_blocking_move_to(LINEAR_AXIS_LIST(raw.x, raw.y, current_position.z, current_position.i, current_position.j, current_position.k), fr_mm_s);
|
2019-10-06 23:58:19 -05:00
|
|
|
}
|
2021-04-01 17:59:57 -05:00
|
|
|
void do_blocking_move_to(const xyz_pos_t &raw, const_feedRate_t fr_mm_s/*=0.0f*/) {
|
2021-06-05 02:18:47 -05:00
|
|
|
do_blocking_move_to(LINEAR_AXIS_ELEM(raw), fr_mm_s);
|
2019-10-06 23:58:19 -05:00
|
|
|
}
|
2021-04-01 17:59:57 -05:00
|
|
|
void do_blocking_move_to(const xyze_pos_t &raw, const_feedRate_t fr_mm_s/*=0.0f*/) {
|
2021-06-05 02:18:47 -05:00
|
|
|
do_blocking_move_to(LINEAR_AXIS_ELEM(raw), fr_mm_s);
|
2019-10-06 23:58:19 -05:00
|
|
|
}
|
2021-04-01 17:59:57 -05:00
|
|
|
void do_blocking_move_to_x(const_float_t rx, const_feedRate_t fr_mm_s/*=0.0*/) {
|
2021-05-24 16:38:57 -05:00
|
|
|
do_blocking_move_to(
|
2021-06-05 02:18:47 -05:00
|
|
|
LINEAR_AXIS_LIST(rx, current_position.y, current_position.z, current_position.i, current_position.j, current_position.k),
|
2021-05-24 16:38:57 -05:00
|
|
|
fr_mm_s
|
|
|
|
);
|
2019-07-31 20:50:23 -05:00
|
|
|
}
|
2019-10-06 23:58:19 -05:00
|
|
|
|
2021-06-05 02:18:47 -05:00
|
|
|
#if HAS_Y_AXIS
|
|
|
|
void do_blocking_move_to_y(const_float_t ry, const_feedRate_t fr_mm_s/*=0.0*/) {
|
|
|
|
do_blocking_move_to(
|
|
|
|
LINEAR_AXIS_LIST(current_position.x, ry, current_position.z, current_position.i, current_position.j, current_position.k),
|
|
|
|
fr_mm_s
|
|
|
|
);
|
|
|
|
}
|
|
|
|
#endif
|
2019-10-06 23:58:19 -05:00
|
|
|
|
2021-06-05 02:18:47 -05:00
|
|
|
#if HAS_Z_AXIS
|
|
|
|
void do_blocking_move_to_z(const_float_t rz, const_feedRate_t fr_mm_s/*=0.0*/) {
|
|
|
|
do_blocking_move_to_xy_z(current_position, rz, fr_mm_s);
|
|
|
|
}
|
|
|
|
#endif
|
2017-09-08 15:35:25 -05:00
|
|
|
|
2021-06-06 01:30:39 -05:00
|
|
|
#if LINEAR_AXES >= 4
|
2021-06-05 02:18:47 -05:00
|
|
|
void do_blocking_move_to_i(const_float_t ri, const_feedRate_t fr_mm_s/*=0.0*/) {
|
|
|
|
do_blocking_move_to_xyz_i(current_position, ri, fr_mm_s);
|
|
|
|
}
|
|
|
|
void do_blocking_move_to_xyz_i(const xyze_pos_t &raw, const_float_t i, const_feedRate_t fr_mm_s/*=0.0f*/) {
|
2021-06-06 01:30:39 -05:00
|
|
|
do_blocking_move_to(
|
|
|
|
LINEAR_AXIS_LIST(raw.x, raw.y, raw.z, i, raw.j, raw.k),
|
|
|
|
fr_mm_s
|
|
|
|
);
|
2021-06-05 02:18:47 -05:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if LINEAR_AXES >= 5
|
|
|
|
void do_blocking_move_to_j(const_float_t rj, const_feedRate_t fr_mm_s/*=0.0*/) {
|
|
|
|
do_blocking_move_to_xyzi_j(current_position, rj, fr_mm_s);
|
|
|
|
}
|
|
|
|
void do_blocking_move_to_xyzi_j(const xyze_pos_t &raw, const_float_t j, const_feedRate_t fr_mm_s/*=0.0f*/) {
|
2021-06-06 01:30:39 -05:00
|
|
|
do_blocking_move_to(
|
|
|
|
LINEAR_AXIS_LIST(raw.x, raw.y, raw.z, raw.i, j, raw.k),
|
|
|
|
fr_mm_s
|
|
|
|
);
|
2021-06-05 02:18:47 -05:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if LINEAR_AXES >= 6
|
|
|
|
void do_blocking_move_to_k(const_float_t rk, const_feedRate_t fr_mm_s/*=0.0*/) {
|
|
|
|
do_blocking_move_to_xyzij_k(current_position, rk, fr_mm_s);
|
|
|
|
}
|
|
|
|
void do_blocking_move_to_xyzij_k(const xyze_pos_t &raw, const_float_t k, const_feedRate_t fr_mm_s/*=0.0f*/) {
|
2021-06-06 01:30:39 -05:00
|
|
|
do_blocking_move_to(
|
|
|
|
LINEAR_AXIS_LIST(raw.x, raw.y, raw.z, raw.i, raw.j, k),
|
|
|
|
fr_mm_s
|
|
|
|
);
|
2021-06-05 02:18:47 -05:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAS_Y_AXIS
|
|
|
|
void do_blocking_move_to_xy(const_float_t rx, const_float_t ry, const_feedRate_t fr_mm_s/*=0.0*/) {
|
|
|
|
do_blocking_move_to(
|
|
|
|
LINEAR_AXIS_LIST(rx, ry, current_position.z, current_position.i, current_position.j, current_position.k),
|
|
|
|
fr_mm_s
|
|
|
|
);
|
|
|
|
}
|
|
|
|
void do_blocking_move_to_xy(const xy_pos_t &raw, const_feedRate_t fr_mm_s/*=0.0f*/) {
|
|
|
|
do_blocking_move_to_xy(raw.x, raw.y, fr_mm_s);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAS_Z_AXIS
|
|
|
|
void do_blocking_move_to_xy_z(const xy_pos_t &raw, const_float_t z, const_feedRate_t fr_mm_s/*=0.0f*/) {
|
|
|
|
do_blocking_move_to(
|
|
|
|
LINEAR_AXIS_LIST(raw.x, raw.y, z, current_position.i, current_position.j, current_position.k),
|
|
|
|
fr_mm_s
|
|
|
|
);
|
|
|
|
}
|
|
|
|
void do_z_clearance(const_float_t zclear, const bool lower_allowed/*=false*/) {
|
|
|
|
float zdest = zclear;
|
|
|
|
if (!lower_allowed) NOLESS(zdest, current_position.z);
|
|
|
|
do_blocking_move_to_z(_MIN(zdest, Z_MAX_POS), TERN(HAS_BED_PROBE, z_probe_fast_mm_s, homing_feedrate(Z_AXIS)));
|
|
|
|
}
|
|
|
|
#endif
|
2020-07-08 21:44:21 -05:00
|
|
|
|
2017-09-08 15:35:25 -05:00
|
|
|
//
|
2019-02-25 14:28:01 -06:00
|
|
|
// Prepare to do endstop or probe moves with custom feedrates.
|
|
|
|
// - Save / restore current feedrate and multiplier
|
2017-09-08 15:35:25 -05:00
|
|
|
//
|
2019-02-25 14:28:01 -06:00
|
|
|
static float saved_feedrate_mm_s;
|
|
|
|
static int16_t saved_feedrate_percentage;
|
2019-09-23 20:58:01 -05:00
|
|
|
void remember_feedrate_and_scaling() {
|
2019-02-25 14:28:01 -06:00
|
|
|
saved_feedrate_mm_s = feedrate_mm_s;
|
|
|
|
saved_feedrate_percentage = feedrate_percentage;
|
2019-09-23 20:58:01 -05:00
|
|
|
}
|
|
|
|
void remember_feedrate_scaling_off() {
|
|
|
|
remember_feedrate_and_scaling();
|
2019-02-25 14:28:01 -06:00
|
|
|
feedrate_percentage = 100;
|
|
|
|
}
|
2019-09-23 20:58:01 -05:00
|
|
|
void restore_feedrate_and_scaling() {
|
2019-02-25 14:28:01 -06:00
|
|
|
feedrate_mm_s = saved_feedrate_mm_s;
|
|
|
|
feedrate_percentage = saved_feedrate_percentage;
|
2017-09-08 15:35:25 -05:00
|
|
|
}
|
|
|
|
|
2017-09-07 22:33:16 -05:00
|
|
|
#if HAS_SOFTWARE_ENDSTOPS
|
|
|
|
|
2018-11-03 03:56:33 -05:00
|
|
|
// Software Endstops are based on the configured limits.
|
2020-10-12 16:48:04 -05:00
|
|
|
soft_endstops_t soft_endstop = {
|
2020-10-13 14:54:56 -05:00
|
|
|
true, false,
|
2021-06-05 02:18:47 -05:00
|
|
|
LINEAR_AXIS_ARRAY(X_MIN_POS, Y_MIN_POS, Z_MIN_POS, I_MIN_POS, J_MIN_POS, K_MIN_POS),
|
|
|
|
LINEAR_AXIS_ARRAY(X_MAX_BED, Y_MAX_BED, Z_MAX_POS, I_MAX_POS, J_MAX_POS, K_MAX_POS)
|
2019-09-29 04:25:39 -05:00
|
|
|
};
|
2018-11-03 03:56:33 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Software endstops can be used to monitor the open end of
|
|
|
|
* an axis that has a hardware endstop on the other end. Or
|
|
|
|
* they can prevent axes from moving past endstops and grinding.
|
|
|
|
*
|
|
|
|
* To keep doing their job as the coordinate system changes,
|
|
|
|
* the software endstop positions must be refreshed to remain
|
|
|
|
* at the same positions relative to the machine.
|
|
|
|
*/
|
2019-03-08 22:13:24 -06:00
|
|
|
void update_software_endstops(const AxisEnum axis
|
2021-05-23 21:33:22 -05:00
|
|
|
OPTARG(HAS_HOTEND_OFFSET, const uint8_t old_tool_index/*=0*/)
|
|
|
|
OPTARG(HAS_HOTEND_OFFSET, const uint8_t new_tool_index/*=0*/)
|
2019-03-08 22:13:24 -06:00
|
|
|
) {
|
2018-11-03 03:56:33 -05:00
|
|
|
|
|
|
|
#if ENABLED(DUAL_X_CARRIAGE)
|
|
|
|
|
|
|
|
if (axis == X_AXIS) {
|
|
|
|
|
|
|
|
// In Dual X mode hotend_offset[X] is T1's home position
|
2019-09-29 04:25:39 -05:00
|
|
|
const float dual_max_x = _MAX(hotend_offset[1].x, X2_MAX_POS);
|
2018-11-03 03:56:33 -05:00
|
|
|
|
2019-03-08 22:13:24 -06:00
|
|
|
if (new_tool_index != 0) {
|
2018-11-03 03:56:33 -05:00
|
|
|
// T1 can move from X2_MIN_POS to X2_MAX_POS or X2 home position (whichever is larger)
|
2019-09-29 04:25:39 -05:00
|
|
|
soft_endstop.min.x = X2_MIN_POS;
|
|
|
|
soft_endstop.max.x = dual_max_x;
|
2018-11-03 03:56:33 -05:00
|
|
|
}
|
2020-10-16 16:59:55 -05:00
|
|
|
else if (idex_is_duplicating()) {
|
2018-11-03 03:56:33 -05:00
|
|
|
// In Duplication Mode, T0 can move as far left as X1_MIN_POS
|
|
|
|
// but not so far to the right that T1 would move past the end
|
2019-09-29 04:25:39 -05:00
|
|
|
soft_endstop.min.x = X1_MIN_POS;
|
|
|
|
soft_endstop.max.x = _MIN(X1_MAX_POS, dual_max_x - duplicate_extruder_x_offset);
|
2018-11-03 03:56:33 -05:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// In other modes, T0 can move from X1_MIN_POS to X1_MAX_POS
|
2019-09-29 04:25:39 -05:00
|
|
|
soft_endstop.min.x = X1_MIN_POS;
|
|
|
|
soft_endstop.max.x = X1_MAX_POS;
|
2018-11-03 03:56:33 -05:00
|
|
|
}
|
2019-03-13 05:48:36 -05:00
|
|
|
|
2018-11-03 03:56:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#elif ENABLED(DELTA)
|
|
|
|
|
2019-09-29 04:25:39 -05:00
|
|
|
soft_endstop.min[axis] = base_min_pos(axis);
|
2021-04-08 21:03:34 -05:00
|
|
|
soft_endstop.max[axis] = (axis == Z_AXIS) ? DIFF_TERN(HAS_BED_PROBE, delta_height, probe.offset.z) : base_max_pos(axis);
|
2018-11-03 03:56:33 -05:00
|
|
|
|
|
|
|
switch (axis) {
|
|
|
|
case X_AXIS:
|
|
|
|
case Y_AXIS:
|
|
|
|
// Get a minimum radius for clamping
|
2019-09-29 04:25:39 -05:00
|
|
|
delta_max_radius = _MIN(ABS(_MAX(soft_endstop.min.x, soft_endstop.min.y)), soft_endstop.max.x, soft_endstop.max.y);
|
2019-03-13 05:48:36 -05:00
|
|
|
delta_max_radius_2 = sq(delta_max_radius);
|
2018-11-03 03:56:33 -05:00
|
|
|
break;
|
|
|
|
case Z_AXIS:
|
2019-09-29 04:25:39 -05:00
|
|
|
delta_clip_start_height = soft_endstop.max[axis] - delta_safe_distance_from_top();
|
2018-11-03 03:56:33 -05:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
2019-03-08 22:13:24 -06:00
|
|
|
#elif HAS_HOTEND_OFFSET
|
|
|
|
|
|
|
|
// Software endstops are relative to the tool 0 workspace, so
|
|
|
|
// the movement limits must be shifted by the tool offset to
|
|
|
|
// retain the same physical limit when other tools are selected.
|
2021-01-04 23:48:42 -06:00
|
|
|
|
|
|
|
if (new_tool_index == old_tool_index || axis == Z_AXIS) { // The Z axis is "special" and shouldn't be modified
|
|
|
|
const float offs = (axis == Z_AXIS) ? 0 : hotend_offset[active_extruder][axis];
|
2019-09-29 04:25:39 -05:00
|
|
|
soft_endstop.min[axis] = base_min_pos(axis) + offs;
|
|
|
|
soft_endstop.max[axis] = base_max_pos(axis) + offs;
|
2019-03-08 22:13:24 -06:00
|
|
|
}
|
2021-01-04 23:48:42 -06:00
|
|
|
else {
|
|
|
|
const float diff = hotend_offset[new_tool_index][axis] - hotend_offset[old_tool_index][axis];
|
|
|
|
soft_endstop.min[axis] += diff;
|
|
|
|
soft_endstop.max[axis] += diff;
|
|
|
|
}
|
2019-03-08 22:13:24 -06:00
|
|
|
|
2018-11-03 03:56:33 -05:00
|
|
|
#else
|
|
|
|
|
2019-09-29 04:25:39 -05:00
|
|
|
soft_endstop.min[axis] = base_min_pos(axis);
|
|
|
|
soft_endstop.max[axis] = base_max_pos(axis);
|
2018-11-03 03:56:33 -05:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2020-10-12 16:48:04 -05:00
|
|
|
if (DEBUGGING(LEVELING))
|
2021-05-18 22:51:19 -05:00
|
|
|
SERIAL_ECHOLNPAIR("Axis ", AS_CHAR(AXIS_CHAR(axis)), " min:", soft_endstop.min[axis], " max:", soft_endstop.max[axis]);
|
2020-10-12 16:48:04 -05:00
|
|
|
}
|
2018-11-03 03:56:33 -05:00
|
|
|
|
2019-03-13 05:48:36 -05:00
|
|
|
/**
|
|
|
|
* Constrain the given coordinates to the software endstops.
|
|
|
|
*
|
|
|
|
* For DELTA/SCARA the XY constraint is based on the smallest
|
|
|
|
* radius within the set software endstops.
|
|
|
|
*/
|
2019-09-29 04:25:39 -05:00
|
|
|
void apply_motion_limits(xyz_pos_t &target) {
|
2019-03-08 22:13:24 -06:00
|
|
|
|
2020-10-12 16:48:04 -05:00
|
|
|
if (!soft_endstop._enabled) return;
|
2019-03-08 22:13:24 -06:00
|
|
|
|
2019-03-13 05:48:36 -05:00
|
|
|
#if IS_KINEMATIC
|
2019-03-08 22:13:24 -06:00
|
|
|
|
2020-04-22 16:35:03 -05:00
|
|
|
if (TERN0(DELTA, !all_axes_homed())) return;
|
2020-01-11 17:06:52 -06:00
|
|
|
|
2020-04-23 21:42:38 -05:00
|
|
|
#if BOTH(HAS_HOTEND_OFFSET, DELTA)
|
2019-03-13 05:48:36 -05:00
|
|
|
// The effector center position will be the target minus the hotend offset.
|
2019-09-29 04:25:39 -05:00
|
|
|
const xy_pos_t offs = hotend_offset[active_extruder];
|
2019-03-13 05:48:36 -05:00
|
|
|
#else
|
|
|
|
// SCARA needs to consider the angle of the arm through the entire move, so for now use no tool offset.
|
2019-09-29 04:25:39 -05:00
|
|
|
constexpr xy_pos_t offs{0};
|
2019-03-13 05:48:36 -05:00
|
|
|
#endif
|
2019-03-08 22:13:24 -06:00
|
|
|
|
2020-11-29 19:06:40 -06:00
|
|
|
if (TERN1(IS_SCARA, axis_was_homed(X_AXIS) && axis_was_homed(Y_AXIS))) {
|
2020-01-11 17:06:52 -06:00
|
|
|
const float dist_2 = HYPOT2(target.x - offs.x, target.y - offs.y);
|
|
|
|
if (dist_2 > delta_max_radius_2)
|
2020-03-02 13:22:48 -06:00
|
|
|
target *= float(delta_max_radius / SQRT(dist_2)); // 200 / 300 = 0.66
|
2020-01-11 17:06:52 -06:00
|
|
|
}
|
2019-03-08 22:13:24 -06:00
|
|
|
|
2019-03-13 05:48:36 -05:00
|
|
|
#else
|
2019-03-08 22:13:24 -06:00
|
|
|
|
2020-11-29 19:06:40 -06:00
|
|
|
if (axis_was_homed(X_AXIS)) {
|
2020-01-11 17:06:52 -06:00
|
|
|
#if !HAS_SOFTWARE_ENDSTOPS || ENABLED(MIN_SOFTWARE_ENDSTOP_X)
|
|
|
|
NOLESS(target.x, soft_endstop.min.x);
|
|
|
|
#endif
|
|
|
|
#if !HAS_SOFTWARE_ENDSTOPS || ENABLED(MAX_SOFTWARE_ENDSTOP_X)
|
|
|
|
NOMORE(target.x, soft_endstop.max.x);
|
|
|
|
#endif
|
|
|
|
}
|
2019-03-08 22:13:24 -06:00
|
|
|
|
2021-06-05 02:18:47 -05:00
|
|
|
#if HAS_Y_AXIS
|
|
|
|
if (axis_was_homed(Y_AXIS)) {
|
|
|
|
#if !HAS_SOFTWARE_ENDSTOPS || ENABLED(MIN_SOFTWARE_ENDSTOP_Y)
|
|
|
|
NOLESS(target.y, soft_endstop.min.y);
|
|
|
|
#endif
|
|
|
|
#if !HAS_SOFTWARE_ENDSTOPS || ENABLED(MAX_SOFTWARE_ENDSTOP_Y)
|
|
|
|
NOMORE(target.y, soft_endstop.max.y);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAS_Z_AXIS
|
|
|
|
if (axis_was_homed(Z_AXIS)) {
|
|
|
|
#if !HAS_SOFTWARE_ENDSTOPS || ENABLED(MIN_SOFTWARE_ENDSTOP_Z)
|
|
|
|
NOLESS(target.z, soft_endstop.min.z);
|
2020-01-11 17:06:52 -06:00
|
|
|
#endif
|
2021-06-05 02:18:47 -05:00
|
|
|
#if !HAS_SOFTWARE_ENDSTOPS || ENABLED(MAX_SOFTWARE_ENDSTOP_Z)
|
|
|
|
NOMORE(target.z, soft_endstop.max.z);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
2021-06-06 01:30:39 -05:00
|
|
|
#if LINEAR_AXES >= 4
|
2021-06-05 02:18:47 -05:00
|
|
|
if (axis_was_homed(I_AXIS)) {
|
|
|
|
#if !HAS_SOFTWARE_ENDSTOPS || ENABLED(MIN_SOFTWARE_ENDSTOP_I)
|
|
|
|
NOLESS(target.i, soft_endstop.min.i);
|
|
|
|
#endif
|
|
|
|
#if !HAS_SOFTWARE_ENDSTOPS || ENABLED(MAX_SOFTWARE_ENDSTOP_I)
|
|
|
|
NOMORE(target.i, soft_endstop.max.i);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if LINEAR_AXES >= 5
|
|
|
|
if (axis_was_homed(J_AXIS)) {
|
|
|
|
#if !HAS_SOFTWARE_ENDSTOPS || ENABLED(MIN_SOFTWARE_ENDSTOP_J)
|
|
|
|
NOLESS(target.j, soft_endstop.min.j);
|
|
|
|
#endif
|
|
|
|
#if !HAS_SOFTWARE_ENDSTOPS || ENABLED(MAX_SOFTWARE_ENDSTOP_J)
|
|
|
|
NOMORE(target.j, soft_endstop.max.j);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if LINEAR_AXES >= 6
|
|
|
|
if (axis_was_homed(K_AXIS)) {
|
|
|
|
#if !HAS_SOFTWARE_ENDSTOPS || ENABLED(MIN_SOFTWARE_ENDSTOP_K)
|
|
|
|
NOLESS(target.k, soft_endstop.min.k);
|
|
|
|
#endif
|
|
|
|
#if !HAS_SOFTWARE_ENDSTOPS || ENABLED(MAX_SOFTWARE_ENDSTOP_K)
|
|
|
|
NOMORE(target.k, soft_endstop.max.k);
|
2020-01-11 17:06:52 -06:00
|
|
|
#endif
|
|
|
|
}
|
2019-03-08 22:13:24 -06:00
|
|
|
#endif
|
2019-03-13 05:48:36 -05:00
|
|
|
}
|
2019-03-08 22:13:24 -06:00
|
|
|
|
2020-10-12 16:48:04 -05:00
|
|
|
#else // !HAS_SOFTWARE_ENDSTOPS
|
|
|
|
|
|
|
|
soft_endstops_t soft_endstop;
|
|
|
|
|
|
|
|
#endif // !HAS_SOFTWARE_ENDSTOPS
|
2017-09-07 22:33:16 -05:00
|
|
|
|
2017-12-09 02:11:31 -06:00
|
|
|
#if !UBL_SEGMENTED
|
2020-03-01 16:59:04 -06:00
|
|
|
|
|
|
|
FORCE_INLINE void segment_idle(millis_t &next_idle_ms) {
|
|
|
|
const millis_t ms = millis();
|
|
|
|
if (ELAPSED(ms, next_idle_ms)) {
|
|
|
|
next_idle_ms = ms + 200UL;
|
2020-03-02 21:52:53 -06:00
|
|
|
return idle();
|
2020-03-01 16:59:04 -06:00
|
|
|
}
|
2020-03-02 21:52:53 -06:00
|
|
|
thermalManager.manage_heater(); // Returns immediately on most calls
|
2020-03-01 16:59:04 -06:00
|
|
|
}
|
|
|
|
|
2017-11-08 19:49:51 -06:00
|
|
|
#if IS_KINEMATIC
|
2017-09-07 22:33:16 -05:00
|
|
|
|
2018-04-05 15:47:56 -05:00
|
|
|
#if IS_SCARA
|
|
|
|
/**
|
|
|
|
* Before raising this value, use M665 S[seg_per_sec] to decrease
|
|
|
|
* the number of segments-per-second. Default is 200. Some deltas
|
|
|
|
* do better with 160 or lower. It would be good to know how many
|
|
|
|
* segments-per-second are actually possible for SCARA on AVR.
|
|
|
|
*
|
|
|
|
* Longer segments result in less kinematic overhead
|
|
|
|
* but may produce jagged lines. Try 0.5mm, 1.0mm, and 2.0mm
|
|
|
|
* and compare the difference.
|
|
|
|
*/
|
2018-07-01 15:20:28 -05:00
|
|
|
#define SCARA_MIN_SEGMENT_LENGTH 0.5f
|
2017-09-08 15:35:25 -05:00
|
|
|
#endif
|
|
|
|
|
2017-09-07 22:33:16 -05:00
|
|
|
/**
|
|
|
|
* Prepare a linear move in a DELTA or SCARA setup.
|
|
|
|
*
|
2020-03-01 16:59:04 -06:00
|
|
|
* Called from prepare_line_to_destination as the
|
2017-12-09 02:10:54 -06:00
|
|
|
* default Delta/SCARA segmenter.
|
|
|
|
*
|
2017-09-07 22:33:16 -05:00
|
|
|
* This calls planner.buffer_line several times, adding
|
|
|
|
* small incremental moves for DELTA or SCARA.
|
2017-11-08 19:49:51 -06:00
|
|
|
*
|
|
|
|
* For Unified Bed Leveling (Delta or Segmented Cartesian)
|
2019-09-26 01:28:09 -05:00
|
|
|
* the ubl.line_to_destination_segmented method replaces this.
|
2017-12-09 02:10:54 -06:00
|
|
|
*
|
|
|
|
* For Auto Bed Leveling (Bilinear) with SEGMENT_LEVELED_MOVES
|
|
|
|
* this is replaced by segmented_line_to_destination below.
|
2017-09-07 22:33:16 -05:00
|
|
|
*/
|
2019-09-26 01:28:09 -05:00
|
|
|
inline bool line_to_destination_kinematic() {
|
2017-09-07 22:33:16 -05:00
|
|
|
|
|
|
|
// Get the top feedrate of the move in the XY plane
|
2019-09-26 01:28:09 -05:00
|
|
|
const float scaled_fr_mm_s = MMS_SCALED(feedrate_mm_s);
|
2017-09-07 22:33:16 -05:00
|
|
|
|
2019-09-29 04:25:39 -05:00
|
|
|
const xyze_float_t diff = destination - current_position;
|
2017-11-29 15:30:42 -06:00
|
|
|
|
2017-09-07 22:33:16 -05:00
|
|
|
// If the move is only in Z/E don't split up the move
|
2019-09-29 04:25:39 -05:00
|
|
|
if (!diff.x && !diff.y) {
|
2021-06-05 02:18:47 -05:00
|
|
|
planner.buffer_line(destination, scaled_fr_mm_s);
|
2017-12-24 22:56:23 -06:00
|
|
|
return false; // caller will update current_position
|
2017-09-07 22:33:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fail if attempting move outside printable radius
|
2019-09-29 04:25:39 -05:00
|
|
|
if (!position_is_reachable(destination)) return true;
|
2017-09-07 22:33:16 -05:00
|
|
|
|
|
|
|
// Get the linear distance in XYZ
|
2019-09-29 04:25:39 -05:00
|
|
|
float cartesian_mm = diff.magnitude();
|
2017-09-07 22:33:16 -05:00
|
|
|
|
|
|
|
// If the move is very short, check the E move distance
|
2019-09-29 04:25:39 -05:00
|
|
|
if (UNEAR_ZERO(cartesian_mm)) cartesian_mm = ABS(diff.e);
|
2017-09-07 22:33:16 -05:00
|
|
|
|
|
|
|
// No E move either? Game over.
|
|
|
|
if (UNEAR_ZERO(cartesian_mm)) return true;
|
|
|
|
|
|
|
|
// Minimum number of seconds to move the given distance
|
2019-09-26 01:28:09 -05:00
|
|
|
const float seconds = cartesian_mm / scaled_fr_mm_s;
|
2017-09-07 22:33:16 -05:00
|
|
|
|
|
|
|
// The number of segments-per-second times the duration
|
|
|
|
// gives the number of segments
|
2021-03-04 17:34:38 -06:00
|
|
|
uint16_t segments = segments_per_second * seconds;
|
2017-09-07 22:33:16 -05:00
|
|
|
|
2018-04-05 15:47:56 -05:00
|
|
|
// For SCARA enforce a minimum segment size
|
2017-09-07 22:33:16 -05:00
|
|
|
#if IS_SCARA
|
2019-09-14 03:05:10 -05:00
|
|
|
NOMORE(segments, cartesian_mm * RECIPROCAL(SCARA_MIN_SEGMENT_LENGTH));
|
2017-09-07 22:33:16 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// At least one segment is required
|
2018-05-17 18:40:22 -05:00
|
|
|
NOLESS(segments, 1U);
|
2017-09-07 22:33:16 -05:00
|
|
|
|
|
|
|
// The approximate length of each segment
|
2018-07-01 15:20:28 -05:00
|
|
|
const float inv_segments = 1.0f / float(segments),
|
2018-09-16 21:24:15 -05:00
|
|
|
cartesian_segment_mm = cartesian_mm * inv_segments;
|
2019-09-29 04:25:39 -05:00
|
|
|
const xyze_float_t segment_distance = diff * inv_segments;
|
2018-09-17 17:30:04 -05:00
|
|
|
|
2018-09-16 21:24:15 -05:00
|
|
|
#if ENABLED(SCARA_FEEDRATE_SCALING)
|
2019-09-26 01:28:09 -05:00
|
|
|
const float inv_duration = scaled_fr_mm_s / cartesian_segment_mm;
|
2018-04-05 15:47:56 -05:00
|
|
|
#endif
|
2017-09-07 22:33:16 -05:00
|
|
|
|
2018-04-05 15:47:56 -05:00
|
|
|
/*
|
|
|
|
SERIAL_ECHOPAIR("mm=", cartesian_mm);
|
|
|
|
SERIAL_ECHOPAIR(" seconds=", seconds);
|
|
|
|
SERIAL_ECHOPAIR(" segments=", segments);
|
2018-09-16 21:24:15 -05:00
|
|
|
SERIAL_ECHOPAIR(" segment_mm=", cartesian_segment_mm);
|
2018-06-30 13:44:27 -05:00
|
|
|
SERIAL_EOL();
|
2018-04-05 15:47:56 -05:00
|
|
|
//*/
|
|
|
|
|
2018-09-16 21:24:15 -05:00
|
|
|
// Get the current position as starting point
|
2019-09-29 04:25:39 -05:00
|
|
|
xyze_pos_t raw = current_position;
|
2017-09-07 22:33:16 -05:00
|
|
|
|
|
|
|
// Calculate and execute the segments
|
2020-03-01 16:59:04 -06:00
|
|
|
millis_t next_idle_ms = millis() + 200UL;
|
2017-12-01 21:43:44 -06:00
|
|
|
while (--segments) {
|
2020-03-01 16:59:04 -06:00
|
|
|
segment_idle(next_idle_ms);
|
2019-09-29 04:25:39 -05:00
|
|
|
raw += segment_distance;
|
2021-06-05 02:18:47 -05:00
|
|
|
if (!planner.buffer_line(raw, scaled_fr_mm_s, active_extruder, cartesian_segment_mm OPTARG(SCARA_FEEDRATE_SCALING, inv_duration))) break;
|
2017-09-07 22:33:16 -05:00
|
|
|
}
|
|
|
|
|
2017-12-21 21:43:39 -06:00
|
|
|
// Ensure last segment arrives at target location.
|
2021-06-05 02:18:47 -05:00
|
|
|
planner.buffer_line(destination, scaled_fr_mm_s, active_extruder, cartesian_segment_mm OPTARG(SCARA_FEEDRATE_SCALING, inv_duration));
|
2017-09-07 22:33:16 -05:00
|
|
|
|
2017-12-24 22:56:23 -06:00
|
|
|
return false; // caller will update current_position
|
2017-09-07 22:33:16 -05:00
|
|
|
}
|
|
|
|
|
2017-11-08 19:49:51 -06:00
|
|
|
#else // !IS_KINEMATIC
|
2017-09-07 22:33:16 -05:00
|
|
|
|
2017-11-29 15:30:42 -06:00
|
|
|
#if ENABLED(SEGMENT_LEVELED_MOVES)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepare a segmented move on a CARTESIAN setup.
|
|
|
|
*
|
|
|
|
* This calls planner.buffer_line several times, adding
|
|
|
|
* small incremental moves. This allows the planner to
|
|
|
|
* apply more detailed bed leveling to the full move.
|
|
|
|
*/
|
2021-04-01 17:59:57 -05:00
|
|
|
inline void segmented_line_to_destination(const_feedRate_t fr_mm_s, const float segment_size=LEVELED_SEGMENT_LENGTH) {
|
2017-11-29 15:30:42 -06:00
|
|
|
|
2019-09-29 04:25:39 -05:00
|
|
|
const xyze_float_t diff = destination - current_position;
|
2017-11-29 15:30:42 -06:00
|
|
|
|
|
|
|
// If the move is only in Z/E don't split up the move
|
2019-09-29 04:25:39 -05:00
|
|
|
if (!diff.x && !diff.y) {
|
2021-06-05 02:18:47 -05:00
|
|
|
planner.buffer_line(destination, fr_mm_s);
|
2017-11-29 15:30:42 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the linear distance in XYZ
|
|
|
|
// If the move is very short, check the E move distance
|
|
|
|
// No E move either? Game over.
|
2019-09-29 04:25:39 -05:00
|
|
|
float cartesian_mm = diff.magnitude();
|
|
|
|
if (UNEAR_ZERO(cartesian_mm)) cartesian_mm = ABS(diff.e);
|
2017-11-29 15:30:42 -06:00
|
|
|
if (UNEAR_ZERO(cartesian_mm)) return;
|
|
|
|
|
|
|
|
// The length divided by the segment size
|
|
|
|
// At least one segment is required
|
|
|
|
uint16_t segments = cartesian_mm / segment_size;
|
2018-05-17 18:40:22 -05:00
|
|
|
NOLESS(segments, 1U);
|
2017-11-29 15:30:42 -06:00
|
|
|
|
|
|
|
// The approximate length of each segment
|
2018-07-01 15:20:28 -05:00
|
|
|
const float inv_segments = 1.0f / float(segments),
|
2019-09-29 04:25:39 -05:00
|
|
|
cartesian_segment_mm = cartesian_mm * inv_segments;
|
|
|
|
const xyze_float_t segment_distance = diff * inv_segments;
|
2017-11-29 15:30:42 -06:00
|
|
|
|
2018-09-16 21:24:15 -05:00
|
|
|
#if ENABLED(SCARA_FEEDRATE_SCALING)
|
2019-09-26 01:28:09 -05:00
|
|
|
const float inv_duration = scaled_fr_mm_s / cartesian_segment_mm;
|
2018-09-16 21:24:15 -05:00
|
|
|
#endif
|
|
|
|
|
2017-11-29 15:30:42 -06:00
|
|
|
// SERIAL_ECHOPAIR("mm=", cartesian_mm);
|
|
|
|
// SERIAL_ECHOLNPAIR(" segments=", segments);
|
2018-02-04 00:26:05 -06:00
|
|
|
// SERIAL_ECHOLNPAIR(" segment_mm=", cartesian_segment_mm);
|
2017-11-29 15:30:42 -06:00
|
|
|
|
|
|
|
// Get the raw current position as starting point
|
2019-09-29 04:25:39 -05:00
|
|
|
xyze_pos_t raw = current_position;
|
2017-11-29 15:30:42 -06:00
|
|
|
|
|
|
|
// Calculate and execute the segments
|
2020-03-01 16:59:04 -06:00
|
|
|
millis_t next_idle_ms = millis() + 200UL;
|
2017-12-01 21:43:44 -06:00
|
|
|
while (--segments) {
|
2020-03-01 16:59:04 -06:00
|
|
|
segment_idle(next_idle_ms);
|
2019-09-29 04:25:39 -05:00
|
|
|
raw += segment_distance;
|
2021-06-05 02:18:47 -05:00
|
|
|
if (!planner.buffer_line(raw, fr_mm_s, active_extruder, cartesian_segment_mm OPTARG(SCARA_FEEDRATE_SCALING, inv_duration))) break;
|
2017-11-29 15:30:42 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Since segment_distance is only approximate,
|
|
|
|
// the final move must be to the exact destination.
|
2021-06-05 02:18:47 -05:00
|
|
|
planner.buffer_line(destination, fr_mm_s, active_extruder, cartesian_segment_mm OPTARG(SCARA_FEEDRATE_SCALING, inv_duration));
|
2017-11-29 15:30:42 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // SEGMENT_LEVELED_MOVES
|
|
|
|
|
2017-09-07 22:33:16 -05:00
|
|
|
/**
|
|
|
|
* Prepare a linear move in a Cartesian setup.
|
2017-11-08 19:49:51 -06:00
|
|
|
*
|
|
|
|
* When a mesh-based leveling system is active, moves are segmented
|
|
|
|
* according to the configuration of the leveling system.
|
2017-09-07 22:33:16 -05:00
|
|
|
*
|
2019-09-29 04:25:39 -05:00
|
|
|
* Return true if 'current_position' was set to 'destination'
|
2017-09-07 22:33:16 -05:00
|
|
|
*/
|
2020-03-01 16:59:04 -06:00
|
|
|
inline bool line_to_destination_cartesian() {
|
2019-09-26 01:28:09 -05:00
|
|
|
const float scaled_fr_mm_s = MMS_SCALED(feedrate_mm_s);
|
2017-11-08 19:49:51 -06:00
|
|
|
#if HAS_MESH
|
2019-09-29 04:25:39 -05:00
|
|
|
if (planner.leveling_active && planner.leveling_active_at_z(destination.z)) {
|
2017-11-07 17:13:53 -06:00
|
|
|
#if ENABLED(AUTO_BED_LEVELING_UBL)
|
2019-09-26 01:28:09 -05:00
|
|
|
ubl.line_to_destination_cartesian(scaled_fr_mm_s, active_extruder); // UBL's motion routine needs to know about
|
|
|
|
return true; // all moves, including Z-only moves.
|
2017-11-29 15:30:42 -06:00
|
|
|
#elif ENABLED(SEGMENT_LEVELED_MOVES)
|
2019-09-26 01:28:09 -05:00
|
|
|
segmented_line_to_destination(scaled_fr_mm_s);
|
2017-12-24 22:56:23 -06:00
|
|
|
return false; // caller will update current_position
|
2017-11-07 17:13:53 -06:00
|
|
|
#else
|
2017-11-08 19:49:51 -06:00
|
|
|
/**
|
|
|
|
* For MBL and ABL-BILINEAR only segment moves when X or Y are involved.
|
|
|
|
* Otherwise fall through to do a direct single move.
|
|
|
|
*/
|
2019-09-29 04:25:39 -05:00
|
|
|
if (xy_pos_t(current_position) != xy_pos_t(destination)) {
|
2017-11-07 17:13:53 -06:00
|
|
|
#if ENABLED(MESH_BED_LEVELING)
|
2019-09-26 01:28:09 -05:00
|
|
|
mbl.line_to_destination(scaled_fr_mm_s);
|
2017-11-07 17:13:53 -06:00
|
|
|
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
|
2019-09-26 01:28:09 -05:00
|
|
|
bilinear_line_to_destination(scaled_fr_mm_s);
|
2017-11-07 17:13:53 -06:00
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
2017-11-08 19:49:51 -06:00
|
|
|
}
|
|
|
|
#endif // HAS_MESH
|
2017-10-13 17:21:25 -05:00
|
|
|
|
2021-06-05 02:18:47 -05:00
|
|
|
planner.buffer_line(destination, scaled_fr_mm_s);
|
2017-12-24 22:56:23 -06:00
|
|
|
return false; // caller will update current_position
|
2017-09-07 22:33:16 -05:00
|
|
|
}
|
|
|
|
|
2017-11-08 19:49:51 -06:00
|
|
|
#endif // !IS_KINEMATIC
|
2017-12-09 02:11:31 -06:00
|
|
|
#endif // !UBL_SEGMENTED
|
2017-09-07 22:33:16 -05:00
|
|
|
|
2019-03-13 00:42:50 -05:00
|
|
|
#if HAS_DUPLICATION_MODE
|
2020-10-16 16:59:55 -05:00
|
|
|
bool extruder_duplication_enabled;
|
2019-04-04 02:44:07 -05:00
|
|
|
#if ENABLED(MULTI_NOZZLE_DUPLICATION)
|
|
|
|
uint8_t duplication_e_mask; // = 0
|
|
|
|
#endif
|
2017-09-07 22:33:16 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLED(DUAL_X_CARRIAGE)
|
|
|
|
|
|
|
|
DualXMode dual_x_carriage_mode = DEFAULT_DUAL_X_CARRIAGE_MODE;
|
2020-10-16 16:59:55 -05:00
|
|
|
float inactive_extruder_x = X2_MAX_POS, // Used in mode 0 & 1
|
2021-03-24 04:11:43 -05:00
|
|
|
duplicate_extruder_x_offset = DEFAULT_DUPLICATION_X_OFFSET; // Used in mode 2 & 3
|
2020-10-16 16:59:55 -05:00
|
|
|
xyz_pos_t raised_parked_position; // Used in mode 1
|
2021-03-24 04:11:43 -05:00
|
|
|
bool active_extruder_parked = false; // Used in mode 1, 2 & 3
|
2020-10-16 16:59:55 -05:00
|
|
|
millis_t delayed_move_time = 0; // Used in mode 1
|
2021-03-24 04:11:43 -05:00
|
|
|
celsius_t duplicate_extruder_temp_offset = 0; // Used in mode 2 & 3
|
2020-10-16 16:59:55 -05:00
|
|
|
bool idex_mirrored_mode = false; // Used in mode 3
|
2017-09-07 22:33:16 -05:00
|
|
|
|
2020-07-14 17:58:37 -05:00
|
|
|
float x_home_pos(const uint8_t extruder) {
|
2017-09-07 22:33:16 -05:00
|
|
|
if (extruder == 0)
|
2021-03-03 17:57:24 -06:00
|
|
|
return X_HOME_POS;
|
2017-09-07 22:33:16 -05:00
|
|
|
else
|
|
|
|
/**
|
|
|
|
* In dual carriage mode the extruder offset provides an override of the
|
|
|
|
* second X-carriage position when homed - otherwise X2_HOME_POS is used.
|
|
|
|
* This allows soft recalibration of the second extruder home position
|
|
|
|
* without firmware reflash (through the M218 command).
|
|
|
|
*/
|
2019-09-29 04:25:39 -05:00
|
|
|
return hotend_offset[1].x > 0 ? hotend_offset[1].x : X2_HOME_POS;
|
2017-09-07 22:33:16 -05:00
|
|
|
}
|
|
|
|
|
2020-10-16 16:59:55 -05:00
|
|
|
void idex_set_mirrored_mode(const bool mirr) {
|
|
|
|
idex_mirrored_mode = mirr;
|
|
|
|
stepper.set_directions();
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_duplication_enabled(const bool dupe, const int8_t tool_index/*=-1*/) {
|
|
|
|
extruder_duplication_enabled = dupe;
|
|
|
|
if (tool_index >= 0) active_extruder = tool_index;
|
|
|
|
stepper.set_directions();
|
|
|
|
}
|
|
|
|
|
|
|
|
void idex_set_parked(const bool park/*=true*/) {
|
|
|
|
delayed_move_time = 0;
|
|
|
|
active_extruder_parked = park;
|
|
|
|
if (park) raised_parked_position = current_position; // Remember current raised toolhead position for use by unpark
|
|
|
|
}
|
|
|
|
|
2017-09-07 22:33:16 -05:00
|
|
|
/**
|
|
|
|
* Prepare a linear move in a dual X axis setup
|
2017-10-13 17:21:25 -05:00
|
|
|
*
|
|
|
|
* Return true if current_position[] was set to destination[]
|
2017-09-07 22:33:16 -05:00
|
|
|
*/
|
2017-12-09 08:00:47 -06:00
|
|
|
inline bool dual_x_carriage_unpark() {
|
2017-09-07 22:33:16 -05:00
|
|
|
if (active_extruder_parked) {
|
|
|
|
switch (dual_x_carriage_mode) {
|
2020-10-16 16:59:55 -05:00
|
|
|
|
|
|
|
case DXC_FULL_CONTROL_MODE: break;
|
|
|
|
|
|
|
|
case DXC_AUTO_PARK_MODE: {
|
2019-09-29 04:25:39 -05:00
|
|
|
if (current_position.e == destination.e) {
|
2017-09-07 22:33:16 -05:00
|
|
|
// This is a travel move (with no extrusion)
|
|
|
|
// Skip it, but keep track of the current position
|
|
|
|
// (so it can be used as the start of the next non-travel move)
|
|
|
|
if (delayed_move_time != 0xFFFFFFFFUL) {
|
2019-09-29 04:25:39 -05:00
|
|
|
current_position = destination;
|
|
|
|
NOLESS(raised_parked_position.z, destination.z);
|
2021-01-03 22:22:21 -06:00
|
|
|
delayed_move_time = millis() + 1000UL;
|
2017-09-07 22:33:16 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2020-10-16 16:59:55 -05:00
|
|
|
//
|
|
|
|
// Un-park the active extruder
|
|
|
|
//
|
|
|
|
const feedRate_t fr_zfast = planner.settings.max_feedrate_mm_s[Z_AXIS];
|
|
|
|
// 1. Move to the raised parked XYZ. Presumably the tool is already at XY.
|
2021-06-05 02:18:47 -05:00
|
|
|
xyze_pos_t raised = raised_parked_position; raised.e = current_position.e;
|
|
|
|
if (planner.buffer_line(raised, fr_zfast)) {
|
2020-10-16 16:59:55 -05:00
|
|
|
// 2. Move to the current native XY and raised Z. Presumably this is a null move.
|
2021-06-05 02:18:47 -05:00
|
|
|
xyze_pos_t curpos = current_position; curpos.z = raised_parked_position.z;
|
|
|
|
if (planner.buffer_line(curpos, PLANNER_XY_FEEDRATE())) {
|
2020-10-16 16:59:55 -05:00
|
|
|
// 3. Lower Z back down
|
|
|
|
line_to_current_position(fr_zfast);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stepper.set_directions();
|
|
|
|
|
|
|
|
idex_set_parked(false);
|
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("idex_set_parked(false)");
|
|
|
|
} break;
|
|
|
|
|
2019-03-15 22:46:27 -05:00
|
|
|
case DXC_MIRRORED_MODE:
|
2017-09-07 22:33:16 -05:00
|
|
|
case DXC_DUPLICATION_MODE:
|
|
|
|
if (active_extruder == 0) {
|
2021-06-05 02:18:47 -05:00
|
|
|
// Restore planner to parked head (T1) X position
|
|
|
|
xyze_pos_t pos_now = current_position;
|
|
|
|
pos_now.x = inactive_extruder_x;
|
|
|
|
planner.set_position_mm(pos_now);
|
|
|
|
|
|
|
|
// Keep the same X or add the duplication X offset
|
|
|
|
xyze_pos_t new_pos = pos_now;
|
2019-09-29 04:25:39 -05:00
|
|
|
if (dual_x_carriage_mode == DXC_DUPLICATION_MODE)
|
|
|
|
new_pos.x += duplicate_extruder_x_offset;
|
2021-06-05 02:18:47 -05:00
|
|
|
|
|
|
|
// Move duplicate extruder into the correct position
|
2020-10-16 16:59:55 -05:00
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Set planner X", inactive_extruder_x, " ... Line to X", new_pos.x);
|
2019-09-29 04:25:39 -05:00
|
|
|
if (!planner.buffer_line(new_pos, planner.settings.max_feedrate_mm_s[X_AXIS], 1)) break;
|
2018-05-12 01:38:02 -05:00
|
|
|
planner.synchronize();
|
2020-10-16 16:59:55 -05:00
|
|
|
|
2021-06-05 02:18:47 -05:00
|
|
|
sync_plan_position(); // Extra sync for good measure
|
|
|
|
set_duplication_enabled(true); // Enable Duplication
|
|
|
|
idex_set_parked(false); // No longer parked
|
2020-10-16 16:59:55 -05:00
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("set_duplication_enabled(true)\nidex_set_parked(false)");
|
2017-09-07 22:33:16 -05:00
|
|
|
}
|
2019-03-14 02:25:42 -05:00
|
|
|
else if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Active extruder not 0");
|
2017-09-07 22:33:16 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-12-09 08:00:47 -06:00
|
|
|
return false;
|
2017-09-07 22:33:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // DUAL_X_CARRIAGE
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepare a single move and get ready for the next one
|
|
|
|
*
|
|
|
|
* This may result in several calls to planner.buffer_line to
|
|
|
|
* do smaller moves for DELTA, SCARA, mesh moves, etc.
|
2017-11-10 20:49:37 -06:00
|
|
|
*
|
2019-09-29 04:25:39 -05:00
|
|
|
* Make sure current_position.e and destination.e are good
|
2017-11-10 20:49:37 -06:00
|
|
|
* before calling or cold/lengthy extrusion may get missed.
|
2019-09-26 01:28:09 -05:00
|
|
|
*
|
|
|
|
* Before exit, current_position is set to destination.
|
2017-09-07 22:33:16 -05:00
|
|
|
*/
|
2020-03-01 16:59:04 -06:00
|
|
|
void prepare_line_to_destination() {
|
2019-03-13 05:48:36 -05:00
|
|
|
apply_motion_limits(destination);
|
2017-09-07 22:33:16 -05:00
|
|
|
|
2019-03-16 23:43:06 -05:00
|
|
|
#if EITHER(PREVENT_COLD_EXTRUSION, PREVENT_LENGTHY_EXTRUDE)
|
2017-09-07 22:33:16 -05:00
|
|
|
|
2019-10-27 17:36:33 -05:00
|
|
|
if (!DEBUGGING(DRYRUN) && destination.e != current_position.e) {
|
|
|
|
bool ignore_e = false;
|
|
|
|
|
|
|
|
#if ENABLED(PREVENT_COLD_EXTRUSION)
|
|
|
|
ignore_e = thermalManager.tooColdToExtrude(active_extruder);
|
2020-02-26 03:02:03 -06:00
|
|
|
if (ignore_e) SERIAL_ECHO_MSG(STR_ERR_COLD_EXTRUDE_STOP);
|
2019-10-27 17:36:33 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLED(PREVENT_LENGTHY_EXTRUDE)
|
|
|
|
const float e_delta = ABS(destination.e - current_position.e) * planner.e_factor[active_extruder];
|
|
|
|
if (e_delta > (EXTRUDE_MAXLENGTH)) {
|
|
|
|
#if ENABLED(MIXING_EXTRUDER)
|
|
|
|
float collector[MIXING_STEPPERS];
|
|
|
|
mixer.refresh_collector(1.0, mixer.get_current_vtool(), collector);
|
|
|
|
MIXER_STEPPER_LOOP(e) {
|
|
|
|
if (e_delta * collector[e] > (EXTRUDE_MAXLENGTH)) {
|
|
|
|
ignore_e = true;
|
2020-02-26 03:02:03 -06:00
|
|
|
SERIAL_ECHO_MSG(STR_ERR_LONG_EXTRUDE_STOP);
|
2019-10-27 17:36:33 -05:00
|
|
|
break;
|
|
|
|
}
|
2019-05-01 21:55:58 -05:00
|
|
|
}
|
2019-10-27 17:36:33 -05:00
|
|
|
#else
|
|
|
|
ignore_e = true;
|
2020-02-26 03:02:03 -06:00
|
|
|
SERIAL_ECHO_MSG(STR_ERR_LONG_EXTRUDE_STOP);
|
2019-10-27 17:36:33 -05:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (ignore_e) {
|
|
|
|
current_position.e = destination.e; // Behave as if the E move really took place
|
|
|
|
planner.set_e_position_mm(destination.e); // Prevent the planner from complaining too
|
2017-09-07 22:33:16 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-09 22:50:32 -06:00
|
|
|
#endif // PREVENT_COLD_EXTRUSION || PREVENT_LENGTHY_EXTRUDE
|
2017-09-07 22:33:16 -05:00
|
|
|
|
2020-04-22 16:35:03 -05:00
|
|
|
if (TERN0(DUAL_X_CARRIAGE, dual_x_carriage_unpark())) return;
|
2017-12-09 08:00:47 -06:00
|
|
|
|
2017-09-07 22:33:16 -05:00
|
|
|
if (
|
2017-12-09 02:11:31 -06:00
|
|
|
#if UBL_SEGMENTED
|
2019-09-26 01:28:09 -05:00
|
|
|
#if IS_KINEMATIC // UBL using Kinematic / Cartesian cases as a workaround for now.
|
|
|
|
ubl.line_to_destination_segmented(MMS_SCALED(feedrate_mm_s))
|
2018-09-02 10:18:59 -05:00
|
|
|
#else
|
2020-03-01 16:59:04 -06:00
|
|
|
line_to_destination_cartesian()
|
2018-09-02 10:18:59 -05:00
|
|
|
#endif
|
2017-09-07 22:33:16 -05:00
|
|
|
#elif IS_KINEMATIC
|
2019-09-26 01:28:09 -05:00
|
|
|
line_to_destination_kinematic()
|
2017-09-07 22:33:16 -05:00
|
|
|
#else
|
2020-03-01 16:59:04 -06:00
|
|
|
line_to_destination_cartesian()
|
2017-09-07 22:33:16 -05:00
|
|
|
#endif
|
|
|
|
) return;
|
|
|
|
|
2019-09-29 04:25:39 -05:00
|
|
|
current_position = destination;
|
2017-09-07 22:33:16 -05:00
|
|
|
}
|
2017-09-08 15:35:25 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
#if HAS_ENDSTOPS
|
2019-03-11 20:57:54 -05:00
|
|
|
|
2021-05-18 22:56:05 -05:00
|
|
|
linear_axis_bits_t axis_homed, axis_trusted; // = 0
|
|
|
|
|
|
|
|
linear_axis_bits_t axes_should_home(linear_axis_bits_t axis_bits/*=linear_bits*/) {
|
|
|
|
auto set_should = [](linear_axis_bits_t &b, AxisEnum a) {
|
|
|
|
if (TEST(b, a) && TERN(HOME_AFTER_DEACTIVATE, axis_is_trusted, axis_was_homed)(a))
|
|
|
|
CBI(b, a);
|
|
|
|
};
|
2021-05-24 16:38:57 -05:00
|
|
|
// Clear test bits that are trusted
|
|
|
|
LINEAR_AXIS_CODE(
|
2021-06-05 02:18:47 -05:00
|
|
|
set_should(axis_bits, X_AXIS), set_should(axis_bits, Y_AXIS), set_should(axis_bits, Z_AXIS),
|
|
|
|
set_should(axis_bits, I_AXIS), set_should(axis_bits, J_AXIS), set_should(axis_bits, K_AXIS)
|
2021-05-24 16:38:57 -05:00
|
|
|
);
|
2021-02-25 04:49:34 -06:00
|
|
|
return axis_bits;
|
2017-09-08 15:35:25 -05:00
|
|
|
}
|
|
|
|
|
2021-05-18 22:56:05 -05:00
|
|
|
bool homing_needed_error(linear_axis_bits_t axis_bits/*=linear_bits*/) {
|
2021-02-25 04:49:34 -06:00
|
|
|
if ((axis_bits = axes_should_home(axis_bits))) {
|
2021-06-06 01:30:39 -05:00
|
|
|
PGM_P home_first = GET_TEXT(MSG_HOME_FIRST);
|
2021-02-25 04:49:34 -06:00
|
|
|
char msg[strlen_P(home_first)+1];
|
|
|
|
sprintf_P(msg, home_first,
|
2021-05-24 16:38:57 -05:00
|
|
|
LINEAR_AXIS_LIST(
|
|
|
|
TEST(axis_bits, X_AXIS) ? "X" : "",
|
|
|
|
TEST(axis_bits, Y_AXIS) ? "Y" : "",
|
2021-06-05 02:18:47 -05:00
|
|
|
TEST(axis_bits, Z_AXIS) ? "Z" : "",
|
|
|
|
TEST(axis_bits, I_AXIS) ? AXIS4_STR : "",
|
|
|
|
TEST(axis_bits, J_AXIS) ? AXIS5_STR : "",
|
|
|
|
TEST(axis_bits, K_AXIS) ? AXIS6_STR : ""
|
2021-05-24 16:38:57 -05:00
|
|
|
)
|
2021-02-25 04:49:34 -06:00
|
|
|
);
|
|
|
|
SERIAL_ECHO_START();
|
|
|
|
SERIAL_ECHOLN(msg);
|
2021-03-24 10:12:57 -05:00
|
|
|
TERN_(HAS_STATUS_MESSAGE, ui.set_status(msg));
|
2021-02-25 04:49:34 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2017-09-08 15:35:25 -05:00
|
|
|
}
|
|
|
|
|
2018-03-01 01:37:31 -06:00
|
|
|
/**
|
2021-02-25 04:49:34 -06:00
|
|
|
* Homing bump feedrate (mm/s)
|
2018-03-01 01:37:31 -06:00
|
|
|
*/
|
2021-02-25 04:49:34 -06:00
|
|
|
feedRate_t get_homing_bump_feedrate(const AxisEnum axis) {
|
|
|
|
#if HOMING_Z_WITH_PROBE
|
2021-02-27 15:54:43 -06:00
|
|
|
if (axis == Z_AXIS) return MMM_TO_MMS(Z_PROBE_FEEDRATE_SLOW);
|
2021-02-25 04:49:34 -06:00
|
|
|
#endif
|
|
|
|
static const uint8_t homing_bump_divisor[] PROGMEM = HOMING_BUMP_DIVISOR;
|
|
|
|
uint8_t hbd = pgm_read_byte(&homing_bump_divisor[axis]);
|
|
|
|
if (hbd < 1) {
|
|
|
|
hbd = 10;
|
|
|
|
SERIAL_ECHO_MSG("Warning: Homing Bump Divisor < 1");
|
2018-12-07 15:34:21 -06:00
|
|
|
}
|
2021-02-25 04:49:34 -06:00
|
|
|
return homing_feedrate(axis) / float(hbd);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if ENABLED(SENSORLESS_HOMING)
|
|
|
|
/**
|
|
|
|
* Set sensorless homing if the axis has it, accounting for Core Kinematics.
|
|
|
|
*/
|
|
|
|
sensorless_t start_sensorless_homing_per_axis(const AxisEnum axis) {
|
|
|
|
sensorless_t stealth_states { false };
|
2019-08-04 22:22:58 -05:00
|
|
|
|
|
|
|
switch (axis) {
|
|
|
|
default: break;
|
2021-02-25 04:49:34 -06:00
|
|
|
#if X_SENSORLESS
|
|
|
|
case X_AXIS:
|
|
|
|
stealth_states.x = tmc_enable_stallguard(stepperX);
|
|
|
|
#if AXIS_HAS_STALLGUARD(X2)
|
|
|
|
stealth_states.x2 = tmc_enable_stallguard(stepperX2);
|
|
|
|
#endif
|
|
|
|
#if EITHER(CORE_IS_XY, MARKFORGED_XY) && Y_SENSORLESS
|
|
|
|
stealth_states.y = tmc_enable_stallguard(stepperY);
|
|
|
|
#elif CORE_IS_XZ && Z_SENSORLESS
|
|
|
|
stealth_states.z = tmc_enable_stallguard(stepperZ);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#if Y_SENSORLESS
|
|
|
|
case Y_AXIS:
|
|
|
|
stealth_states.y = tmc_enable_stallguard(stepperY);
|
|
|
|
#if AXIS_HAS_STALLGUARD(Y2)
|
|
|
|
stealth_states.y2 = tmc_enable_stallguard(stepperY2);
|
|
|
|
#endif
|
|
|
|
#if EITHER(CORE_IS_XY, MARKFORGED_XY) && X_SENSORLESS
|
|
|
|
stealth_states.x = tmc_enable_stallguard(stepperX);
|
|
|
|
#elif CORE_IS_YZ && Z_SENSORLESS
|
|
|
|
stealth_states.z = tmc_enable_stallguard(stepperZ);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#if Z_SENSORLESS
|
|
|
|
case Z_AXIS:
|
|
|
|
stealth_states.z = tmc_enable_stallguard(stepperZ);
|
|
|
|
#if AXIS_HAS_STALLGUARD(Z2)
|
|
|
|
stealth_states.z2 = tmc_enable_stallguard(stepperZ2);
|
|
|
|
#endif
|
|
|
|
#if AXIS_HAS_STALLGUARD(Z3)
|
|
|
|
stealth_states.z3 = tmc_enable_stallguard(stepperZ3);
|
|
|
|
#endif
|
|
|
|
#if AXIS_HAS_STALLGUARD(Z4)
|
|
|
|
stealth_states.z4 = tmc_enable_stallguard(stepperZ4);
|
|
|
|
#endif
|
|
|
|
#if CORE_IS_XZ && X_SENSORLESS
|
|
|
|
stealth_states.x = tmc_enable_stallguard(stepperX);
|
|
|
|
#elif CORE_IS_YZ && Y_SENSORLESS
|
|
|
|
stealth_states.y = tmc_enable_stallguard(stepperY);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
#endif
|
2019-08-04 22:22:58 -05:00
|
|
|
}
|
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
#if ENABLED(SPI_ENDSTOPS)
|
|
|
|
switch (axis) {
|
|
|
|
case X_AXIS: if (ENABLED(X_SPI_SENSORLESS)) endstops.tmc_spi_homing.x = true; break;
|
2021-06-06 01:30:39 -05:00
|
|
|
#if HAS_Y_AXIS
|
|
|
|
case Y_AXIS: if (ENABLED(Y_SPI_SENSORLESS)) endstops.tmc_spi_homing.y = true; break;
|
|
|
|
#endif
|
|
|
|
#if HAS_Z_AXIS
|
|
|
|
case Z_AXIS: if (ENABLED(Z_SPI_SENSORLESS)) endstops.tmc_spi_homing.z = true; break;
|
|
|
|
#endif
|
|
|
|
#if LINEAR_AXES >= 4
|
|
|
|
case I_AXIS: if (ENABLED(I_SPI_SENSORLESS)) endstops.tmc_spi_homing.i = true; break;
|
|
|
|
#endif
|
|
|
|
#if LINEAR_AXES >= 5
|
|
|
|
case J_AXIS: if (ENABLED(J_SPI_SENSORLESS)) endstops.tmc_spi_homing.j = true; break;
|
|
|
|
#endif
|
|
|
|
#if LINEAR_AXES >= 6
|
|
|
|
case K_AXIS: if (ENABLED(K_SPI_SENSORLESS)) endstops.tmc_spi_homing.k = true; break;
|
|
|
|
#endif
|
2021-02-25 04:49:34 -06:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
#endif
|
2019-08-04 22:22:58 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
TERN_(IMPROVE_HOMING_RELIABILITY, sg_guard_period = millis() + default_sg_guard_duration);
|
2018-12-07 15:34:21 -06:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
return stealth_states;
|
2018-03-01 01:37:31 -06:00
|
|
|
}
|
2019-08-04 22:22:58 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
void end_sensorless_homing_per_axis(const AxisEnum axis, sensorless_t enable_stealth) {
|
2019-08-04 22:22:58 -05:00
|
|
|
switch (axis) {
|
|
|
|
default: break;
|
2021-02-25 04:49:34 -06:00
|
|
|
#if X_SENSORLESS
|
|
|
|
case X_AXIS:
|
|
|
|
tmc_disable_stallguard(stepperX, enable_stealth.x);
|
|
|
|
#if AXIS_HAS_STALLGUARD(X2)
|
|
|
|
tmc_disable_stallguard(stepperX2, enable_stealth.x2);
|
|
|
|
#endif
|
|
|
|
#if EITHER(CORE_IS_XY, MARKFORGED_XY) && Y_SENSORLESS
|
|
|
|
tmc_disable_stallguard(stepperY, enable_stealth.y);
|
|
|
|
#elif CORE_IS_XZ && Z_SENSORLESS
|
|
|
|
tmc_disable_stallguard(stepperZ, enable_stealth.z);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#if Y_SENSORLESS
|
|
|
|
case Y_AXIS:
|
|
|
|
tmc_disable_stallguard(stepperY, enable_stealth.y);
|
|
|
|
#if AXIS_HAS_STALLGUARD(Y2)
|
|
|
|
tmc_disable_stallguard(stepperY2, enable_stealth.y2);
|
|
|
|
#endif
|
|
|
|
#if EITHER(CORE_IS_XY, MARKFORGED_XY) && X_SENSORLESS
|
|
|
|
tmc_disable_stallguard(stepperX, enable_stealth.x);
|
|
|
|
#elif CORE_IS_YZ && Z_SENSORLESS
|
|
|
|
tmc_disable_stallguard(stepperZ, enable_stealth.z);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#if Z_SENSORLESS
|
|
|
|
case Z_AXIS:
|
|
|
|
tmc_disable_stallguard(stepperZ, enable_stealth.z);
|
|
|
|
#if AXIS_HAS_STALLGUARD(Z2)
|
|
|
|
tmc_disable_stallguard(stepperZ2, enable_stealth.z2);
|
|
|
|
#endif
|
|
|
|
#if AXIS_HAS_STALLGUARD(Z3)
|
|
|
|
tmc_disable_stallguard(stepperZ3, enable_stealth.z3);
|
|
|
|
#endif
|
|
|
|
#if AXIS_HAS_STALLGUARD(Z4)
|
|
|
|
tmc_disable_stallguard(stepperZ4, enable_stealth.z4);
|
|
|
|
#endif
|
|
|
|
#if CORE_IS_XZ && X_SENSORLESS
|
|
|
|
tmc_disable_stallguard(stepperX, enable_stealth.x);
|
|
|
|
#elif CORE_IS_YZ && Y_SENSORLESS
|
|
|
|
tmc_disable_stallguard(stepperY, enable_stealth.y);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
#endif
|
2019-08-04 22:22:58 -05:00
|
|
|
}
|
2018-03-01 01:37:31 -06:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
#if ENABLED(SPI_ENDSTOPS)
|
|
|
|
switch (axis) {
|
|
|
|
case X_AXIS: if (ENABLED(X_SPI_SENSORLESS)) endstops.tmc_spi_homing.x = false; break;
|
2021-06-06 01:30:39 -05:00
|
|
|
#if HAS_Y_AXIS
|
|
|
|
case Y_AXIS: if (ENABLED(Y_SPI_SENSORLESS)) endstops.tmc_spi_homing.y = false; break;
|
|
|
|
#endif
|
|
|
|
#if HAS_Z_AXIS
|
|
|
|
case Z_AXIS: if (ENABLED(Z_SPI_SENSORLESS)) endstops.tmc_spi_homing.z = false; break;
|
|
|
|
#endif
|
|
|
|
#if LINEAR_AXES >= 4
|
|
|
|
case I_AXIS: if (ENABLED(I_SPI_SENSORLESS)) endstops.tmc_spi_homing.i = false; break;
|
|
|
|
#endif
|
|
|
|
#if LINEAR_AXES >= 5
|
|
|
|
case J_AXIS: if (ENABLED(J_SPI_SENSORLESS)) endstops.tmc_spi_homing.j = false; break;
|
|
|
|
#endif
|
|
|
|
#if LINEAR_AXES >= 6
|
|
|
|
case K_AXIS: if (ENABLED(K_SPI_SENSORLESS)) endstops.tmc_spi_homing.k = false; break;
|
|
|
|
#endif
|
2021-02-25 04:49:34 -06:00
|
|
|
default: break;
|
|
|
|
}
|
2020-12-30 19:13:47 -06:00
|
|
|
#endif
|
|
|
|
}
|
2018-03-28 21:26:43 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
#endif // SENSORLESS_HOMING
|
2020-07-03 09:53:22 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
/**
|
|
|
|
* Home an individual linear axis
|
|
|
|
*/
|
|
|
|
void do_homing_move(const AxisEnum axis, const float distance, const feedRate_t fr_mm_s=0.0, const bool final_approach=true) {
|
|
|
|
DEBUG_SECTION(log_move, "do_homing_move", DEBUGGING(LEVELING));
|
2018-09-16 21:24:15 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
const feedRate_t home_fr_mm_s = fr_mm_s ?: homing_feedrate(axis);
|
2017-09-08 15:35:25 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
if (DEBUGGING(LEVELING)) {
|
2021-05-24 16:38:57 -05:00
|
|
|
DEBUG_ECHOPAIR("...(", AS_CHAR(AXIS_CHAR(axis)), ", ", distance, ", ");
|
2021-02-25 04:49:34 -06:00
|
|
|
if (fr_mm_s)
|
|
|
|
DEBUG_ECHO(fr_mm_s);
|
|
|
|
else
|
|
|
|
DEBUG_ECHOPAIR("[", home_fr_mm_s, "]");
|
|
|
|
DEBUG_ECHOLNPGM(")");
|
|
|
|
}
|
2017-09-08 15:35:25 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
// Only do some things when moving towards an endstop
|
|
|
|
const int8_t axis_home_dir = TERN0(DUAL_X_CARRIAGE, axis == X_AXIS)
|
2021-05-19 00:21:34 -05:00
|
|
|
? TOOL_X_HOME_DIR(active_extruder) : home_dir(axis);
|
2021-02-25 04:49:34 -06:00
|
|
|
const bool is_home_dir = (axis_home_dir > 0) == (distance > 0);
|
2017-09-08 15:35:25 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
#if ENABLED(SENSORLESS_HOMING)
|
|
|
|
sensorless_t stealth_states;
|
2018-07-26 05:04:09 -05:00
|
|
|
#endif
|
2017-09-08 15:35:25 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
if (is_home_dir) {
|
2017-09-08 15:35:25 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
if (TERN0(HOMING_Z_WITH_PROBE, axis == Z_AXIS)) {
|
2021-02-25 08:28:27 -06:00
|
|
|
#if BOTH(HAS_HEATED_BED, WAIT_FOR_BED_HEATER)
|
2021-02-25 04:49:34 -06:00
|
|
|
// Wait for bed to heat back up between probing points
|
|
|
|
thermalManager.wait_for_bed_heating();
|
|
|
|
#endif
|
2017-09-08 15:35:25 -05:00
|
|
|
|
2021-02-25 08:28:27 -06:00
|
|
|
#if BOTH(HAS_HOTEND, WAIT_FOR_HOTEND)
|
|
|
|
// Wait for the hotend to heat back up between probing points
|
|
|
|
thermalManager.wait_for_hotend_heating(active_extruder);
|
|
|
|
#endif
|
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
TERN_(HAS_QUIET_PROBING, if (final_approach) probe.set_probing_paused(true));
|
|
|
|
}
|
2017-09-08 15:35:25 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
// Disable stealthChop if used. Enable diag1 pin on driver.
|
|
|
|
TERN_(SENSORLESS_HOMING, stealth_states = start_sensorless_homing_per_axis(axis));
|
2017-09-08 15:35:25 -05:00
|
|
|
}
|
|
|
|
|
2021-03-03 17:46:32 -06:00
|
|
|
#if EITHER(MORGAN_SCARA, MP_SCARA)
|
2021-02-25 04:49:34 -06:00
|
|
|
// Tell the planner the axis is at 0
|
|
|
|
current_position[axis] = 0;
|
|
|
|
sync_plan_position();
|
|
|
|
current_position[axis] = distance;
|
|
|
|
line_to_current_position(home_fr_mm_s);
|
|
|
|
#else
|
|
|
|
// Get the ABC or XYZ positions in mm
|
|
|
|
abce_pos_t target = planner.get_axis_positions_mm();
|
2017-09-08 15:35:25 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
target[axis] = 0; // Set the single homing axis to 0
|
|
|
|
planner.set_machine_position_mm(target); // Update the machine position
|
2017-09-08 15:35:25 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
#if HAS_DIST_MM_ARG
|
|
|
|
const xyze_float_t cart_dist_mm{0};
|
|
|
|
#endif
|
2017-09-08 15:35:25 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
// Set delta/cartesian axes directly
|
|
|
|
target[axis] = distance; // The move will be towards the endstop
|
2021-06-05 02:18:47 -05:00
|
|
|
planner.buffer_segment(target OPTARG(HAS_DIST_MM_ARG, cart_dist_mm), home_fr_mm_s, active_extruder);
|
2021-02-25 04:49:34 -06:00
|
|
|
#endif
|
2017-09-08 15:35:25 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
planner.synchronize();
|
2017-09-08 15:35:25 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
if (is_home_dir) {
|
2017-09-08 15:35:25 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
#if HOMING_Z_WITH_PROBE && HAS_QUIET_PROBING
|
|
|
|
if (axis == Z_AXIS && final_approach) probe.set_probing_paused(false);
|
2017-09-08 15:35:25 -05:00
|
|
|
#endif
|
2019-04-06 18:04:34 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
endstops.validate_homing_move();
|
2019-10-24 12:20:09 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
// Re-enable stealthChop if used. Disable diag1 pin on driver.
|
|
|
|
TERN_(SENSORLESS_HOMING, end_sensorless_homing_per_axis(axis, stealth_states));
|
|
|
|
}
|
2019-03-14 02:25:42 -05:00
|
|
|
}
|
2017-09-08 15:35:25 -05:00
|
|
|
|
2020-07-06 17:32:33 -05:00
|
|
|
/**
|
2021-02-25 04:49:34 -06:00
|
|
|
* Set an axis to be unhomed. (Unless we are on a machine - e.g. a cheap Chinese CNC machine -
|
|
|
|
* that has no endstops. Such machines should always be considered to be in a "known" and
|
|
|
|
* "trusted" position).
|
2020-07-06 17:32:33 -05:00
|
|
|
*/
|
2021-02-25 04:49:34 -06:00
|
|
|
void set_axis_never_homed(const AxisEnum axis) {
|
2021-05-24 16:38:57 -05:00
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR(">>> set_axis_never_homed(", AS_CHAR(AXIS_CHAR(axis)), ")");
|
2020-04-20 08:08:00 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
set_axis_untrusted(axis);
|
|
|
|
set_axis_unhomed(axis);
|
2020-04-20 08:08:00 -05:00
|
|
|
|
2021-05-24 16:38:57 -05:00
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("<<< set_axis_never_homed(", AS_CHAR(AXIS_CHAR(axis)), ")");
|
2020-04-20 08:08:00 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
TERN_(I2C_POSITION_ENCODERS, I2CPEM.unhomed(axis));
|
|
|
|
}
|
2020-12-04 23:58:39 -06:00
|
|
|
|
2021-02-25 09:23:30 -06:00
|
|
|
#ifdef TMC_HOME_PHASE
|
2021-02-25 04:49:34 -06:00
|
|
|
/**
|
|
|
|
* Move the axis back to its home_phase if set and driver is capable (TMC)
|
|
|
|
*
|
|
|
|
* Improves homing repeatability by homing to stepper coil's nearest absolute
|
|
|
|
* phase position. Trinamic drivers use a stepper phase table with 1024 values
|
|
|
|
* spanning 4 full steps with 256 positions each (ergo, 1024 positions).
|
|
|
|
*/
|
|
|
|
void backout_to_tmc_homing_phase(const AxisEnum axis) {
|
|
|
|
const xyz_long_t home_phase = TMC_HOME_PHASE;
|
2020-04-20 08:08:00 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
// check if home phase is disabled for this axis.
|
|
|
|
if (home_phase[axis] < 0) return;
|
2020-04-20 08:08:00 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
int16_t phasePerUStep, // TMC µsteps(phase) per Marlin µsteps
|
|
|
|
phaseCurrent, // The TMC µsteps(phase) count of the current position
|
|
|
|
effectorBackoutDir, // Direction in which the effector mm coordinates move away from endstop.
|
|
|
|
stepperBackoutDir; // Direction in which the TMC µstep count(phase) move away from endstop.
|
2020-04-20 08:08:00 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
#define PHASE_PER_MICROSTEP(N) (256 / _MAX(1, N##_MICROSTEPS))
|
2020-04-20 08:08:00 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
switch (axis) {
|
|
|
|
#ifdef X_MICROSTEPS
|
|
|
|
case X_AXIS:
|
|
|
|
phasePerUStep = PHASE_PER_MICROSTEP(X);
|
|
|
|
phaseCurrent = stepperX.get_microstep_counter();
|
|
|
|
effectorBackoutDir = -X_HOME_DIR;
|
|
|
|
stepperBackoutDir = INVERT_X_DIR ? effectorBackoutDir : -effectorBackoutDir;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef Y_MICROSTEPS
|
|
|
|
case Y_AXIS:
|
|
|
|
phasePerUStep = PHASE_PER_MICROSTEP(Y);
|
|
|
|
phaseCurrent = stepperY.get_microstep_counter();
|
|
|
|
effectorBackoutDir = -Y_HOME_DIR;
|
|
|
|
stepperBackoutDir = INVERT_Y_DIR ? effectorBackoutDir : -effectorBackoutDir;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef Z_MICROSTEPS
|
|
|
|
case Z_AXIS:
|
|
|
|
phasePerUStep = PHASE_PER_MICROSTEP(Z);
|
|
|
|
phaseCurrent = stepperZ.get_microstep_counter();
|
|
|
|
effectorBackoutDir = -Z_HOME_DIR;
|
|
|
|
stepperBackoutDir = INVERT_Z_DIR ? effectorBackoutDir : -effectorBackoutDir;
|
|
|
|
break;
|
|
|
|
#endif
|
2021-06-05 02:18:47 -05:00
|
|
|
#ifdef I_MICROSTEPS
|
|
|
|
case I_AXIS:
|
|
|
|
phasePerUStep = PHASE_PER_MICROSTEP(I);
|
|
|
|
phaseCurrent = stepperI.get_microstep_counter();
|
|
|
|
effectorBackoutDir = -I_HOME_DIR;
|
|
|
|
stepperBackoutDir = INVERT_I_DIR ? effectorBackoutDir : -effectorBackoutDir;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef J_MICROSTEPS
|
|
|
|
case J_AXIS:
|
|
|
|
phasePerUStep = PHASE_PER_MICROSTEP(J);
|
|
|
|
phaseCurrent = stepperJ.get_microstep_counter();
|
|
|
|
effectorBackoutDir = -J_HOME_DIR;
|
|
|
|
stepperBackoutDir = INVERT_J_DIR ? effectorBackoutDir : -effectorBackoutDir;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef K_MICROSTEPS
|
|
|
|
case K_AXIS:
|
|
|
|
phasePerUStep = PHASE_PER_MICROSTEP(K);
|
|
|
|
phaseCurrent = stepperK.get_microstep_counter();
|
|
|
|
effectorBackoutDir = -K_HOME_DIR;
|
|
|
|
stepperBackoutDir = INVERT_K_DIR ? effectorBackoutDir : -effectorBackoutDir;
|
|
|
|
break;
|
|
|
|
#endif
|
2021-02-25 04:49:34 -06:00
|
|
|
default: return;
|
|
|
|
}
|
2020-04-20 08:08:00 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
// Phase distance to nearest home phase position when moving in the backout direction from endstop(may be negative).
|
|
|
|
int16_t phaseDelta = (home_phase[axis] - phaseCurrent) * stepperBackoutDir;
|
2020-04-20 08:08:00 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
// Check if home distance within endstop assumed repeatability noise of .05mm and warn.
|
|
|
|
if (ABS(phaseDelta) * planner.steps_to_mm[axis] / phasePerUStep < 0.05f)
|
|
|
|
SERIAL_ECHOLNPAIR("Selected home phase ", home_phase[axis],
|
|
|
|
" too close to endstop trigger phase ", phaseCurrent,
|
2021-05-24 16:38:57 -05:00
|
|
|
". Pick a different phase for ", AS_CHAR(AXIS_CHAR(axis)));
|
2020-04-20 08:08:00 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
// Skip to next if target position is behind current. So it only moves away from endstop.
|
|
|
|
if (phaseDelta < 0) phaseDelta += 1024;
|
2017-09-08 15:35:25 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
// Convert TMC µsteps(phase) to whole Marlin µsteps to effector backout direction to mm
|
|
|
|
const float mmDelta = int16_t(phaseDelta / phasePerUStep) * effectorBackoutDir * planner.steps_to_mm[axis];
|
2017-09-08 15:35:25 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
// Optional debug messages
|
|
|
|
if (DEBUGGING(LEVELING)) {
|
|
|
|
DEBUG_ECHOLNPAIR(
|
2021-05-24 16:38:57 -05:00
|
|
|
"Endstop ", AS_CHAR(AXIS_CHAR(axis)), " hit at Phase:", phaseCurrent,
|
2021-02-25 04:49:34 -06:00
|
|
|
" Delta:", phaseDelta, " Distance:", mmDelta
|
|
|
|
);
|
|
|
|
}
|
2017-09-08 15:35:25 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
if (mmDelta != 0) {
|
|
|
|
// Retrace by the amount computed in mmDelta.
|
|
|
|
do_homing_move(axis, mmDelta, get_homing_bump_feedrate(axis));
|
|
|
|
}
|
2018-06-02 20:39:00 -05:00
|
|
|
}
|
2017-09-08 15:35:25 -05:00
|
|
|
#endif
|
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
/**
|
|
|
|
* Home an individual "raw axis" to its endstop.
|
|
|
|
* This applies to XYZ on Cartesian and Core robots, and
|
|
|
|
* to the individual ABC steppers on DELTA and SCARA.
|
|
|
|
*
|
|
|
|
* At the end of the procedure the axis is marked as
|
|
|
|
* homed and the current position of that axis is updated.
|
|
|
|
* Kinematic robots should wait till all axes are homed
|
|
|
|
* before updating the current position.
|
|
|
|
*/
|
2018-07-28 19:30:14 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
void homeaxis(const AxisEnum axis) {
|
2020-03-25 03:18:48 -05:00
|
|
|
|
2021-03-03 17:46:32 -06:00
|
|
|
#if EITHER(MORGAN_SCARA, MP_SCARA)
|
2021-02-25 04:49:34 -06:00
|
|
|
// Only Z homing (with probe) is permitted
|
|
|
|
if (axis != Z_AXIS) { BUZZ(100, 880); return; }
|
|
|
|
#else
|
|
|
|
#define _CAN_HOME(A) (axis == _AXIS(A) && ( \
|
|
|
|
ENABLED(A##_SPI_SENSORLESS) \
|
2021-06-05 02:18:47 -05:00
|
|
|
|| TERN0(HAS_Z_AXIS, TERN0(HOMING_Z_WITH_PROBE, _AXIS(A) == Z_AXIS)) \
|
2021-05-19 00:21:34 -05:00
|
|
|
|| TERN0(A##_HOME_TO_MIN, A##_MIN_PIN > -1) \
|
|
|
|
|| TERN0(A##_HOME_TO_MAX, A##_MAX_PIN > -1) \
|
2021-02-25 04:49:34 -06:00
|
|
|
))
|
2021-06-05 02:18:47 -05:00
|
|
|
if (LINEAR_AXIS_GANG(
|
|
|
|
!_CAN_HOME(X),
|
|
|
|
&& !_CAN_HOME(Y),
|
|
|
|
&& !_CAN_HOME(Z),
|
|
|
|
&& !_CAN_HOME(I),
|
|
|
|
&& !_CAN_HOME(J),
|
|
|
|
&& !_CAN_HOME(K))
|
|
|
|
) return;
|
2021-02-25 04:49:34 -06:00
|
|
|
#endif
|
2017-09-08 15:35:25 -05:00
|
|
|
|
2021-05-24 16:38:57 -05:00
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR(">>> homeaxis(", AS_CHAR(AXIS_CHAR(axis)), ")");
|
2017-09-08 15:35:25 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
const int axis_home_dir = TERN0(DUAL_X_CARRIAGE, axis == X_AXIS)
|
2021-05-19 00:21:34 -05:00
|
|
|
? TOOL_X_HOME_DIR(active_extruder) : home_dir(axis);
|
2021-02-25 04:49:34 -06:00
|
|
|
|
|
|
|
//
|
|
|
|
// Homing Z with a probe? Raise Z (maybe) and deploy the Z probe.
|
|
|
|
//
|
|
|
|
if (TERN0(HOMING_Z_WITH_PROBE, axis == Z_AXIS && probe.deploy()))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Set flags for X, Y, Z motor locking
|
|
|
|
#if HAS_EXTRA_ENDSTOPS
|
2020-07-12 13:16:56 -05:00
|
|
|
switch (axis) {
|
2021-02-25 04:49:34 -06:00
|
|
|
TERN_(X_DUAL_ENDSTOPS, case X_AXIS:)
|
|
|
|
TERN_(Y_DUAL_ENDSTOPS, case Y_AXIS:)
|
|
|
|
TERN_(Z_MULTI_ENDSTOPS, case Z_AXIS:)
|
|
|
|
stepper.set_separate_multi_axis(true);
|
|
|
|
default: break;
|
2020-07-12 13:16:56 -05:00
|
|
|
}
|
2021-02-25 04:49:34 -06:00
|
|
|
#endif
|
|
|
|
|
|
|
|
//
|
|
|
|
// Deploy BLTouch or tare the probe just before probing
|
|
|
|
//
|
|
|
|
#if HOMING_Z_WITH_PROBE
|
|
|
|
if (axis == Z_AXIS) {
|
|
|
|
if (TERN0(BLTOUCH, bltouch.deploy())) return; // BLTouch was deployed above, but get the alarm state.
|
|
|
|
if (TERN0(PROBE_TARE, probe.tare())) return;
|
2020-07-12 13:16:56 -05:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
//
|
2021-06-06 01:30:39 -05:00
|
|
|
// Back away to prevent an early sensorless trigger
|
2021-02-25 04:49:34 -06:00
|
|
|
//
|
|
|
|
#if DISABLED(DELTA) && defined(SENSORLESS_BACKOFF_MM)
|
2021-06-06 01:30:39 -05:00
|
|
|
const xyz_float_t backoff = SENSORLESS_BACKOFF_MM;
|
|
|
|
if ((TERN0(X_SENSORLESS, axis == X_AXIS) || TERN0(Y_SENSORLESS, axis == Y_AXIS) || TERN0(Z_SENSORLESS, axis == Z_AXIS) || TERN0(I_SENSORLESS, axis == I_AXIS) || TERN0(J_SENSORLESS, axis == J_AXIS) || TERN0(K_SENSORLESS, axis == K_AXIS)) && backoff[axis]) {
|
2021-02-25 04:49:34 -06:00
|
|
|
const float backoff_length = -ABS(backoff[axis]) * axis_home_dir;
|
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Sensorless backoff: ", backoff_length, "mm");
|
|
|
|
do_homing_move(axis, backoff_length, homing_feedrate(axis));
|
|
|
|
}
|
2018-07-26 05:04:09 -05:00
|
|
|
#endif
|
2018-07-27 18:30:08 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
// Determine if a homing bump will be done and the bumps distance
|
|
|
|
// When homing Z with probe respect probe clearance
|
2021-06-05 02:18:47 -05:00
|
|
|
const bool use_probe_bump = TERN0(HOMING_Z_WITH_PROBE, axis == Z_AXIS && home_bump_mm(axis));
|
2021-02-25 04:49:34 -06:00
|
|
|
const float bump = axis_home_dir * (
|
2021-06-05 02:18:47 -05:00
|
|
|
use_probe_bump ? _MAX(TERN0(HOMING_Z_WITH_PROBE, Z_CLEARANCE_BETWEEN_PROBES), home_bump_mm(axis)) : home_bump_mm(axis)
|
2021-02-25 04:49:34 -06:00
|
|
|
);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Fast move towards endstop until triggered
|
|
|
|
//
|
|
|
|
const float move_length = 1.5f * max_length(TERN(DELTA, Z_AXIS, axis)) * axis_home_dir;
|
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Home Fast: ", move_length, "mm");
|
|
|
|
do_homing_move(axis, move_length, 0.0, !use_probe_bump);
|
2018-07-28 19:30:14 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
#if BOTH(HOMING_Z_WITH_PROBE, BLTOUCH_SLOW_MODE)
|
|
|
|
if (axis == Z_AXIS) bltouch.stow(); // Intermediate STOW (in LOW SPEED MODE)
|
2018-07-28 19:30:14 -05:00
|
|
|
#endif
|
2017-09-08 15:35:25 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
// If a second homing move is configured...
|
|
|
|
if (bump) {
|
|
|
|
// Move away from the endstop by the axis HOMING_BUMP_MM
|
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Move Away: ", -bump, "mm");
|
2021-03-01 07:10:00 -06:00
|
|
|
do_homing_move(axis, -bump, TERN(HOMING_Z_WITH_PROBE, (axis == Z_AXIS ? z_probe_fast_mm_s : 0), 0), false);
|
2021-02-25 04:49:34 -06:00
|
|
|
|
|
|
|
#if ENABLED(DETECT_BROKEN_ENDSTOP)
|
|
|
|
// Check for a broken endstop
|
|
|
|
EndstopEnum es;
|
|
|
|
switch (axis) {
|
|
|
|
default:
|
|
|
|
case X_AXIS: es = X_ENDSTOP; break;
|
|
|
|
case Y_AXIS: es = Y_ENDSTOP; break;
|
|
|
|
case Z_AXIS: es = Z_ENDSTOP; break;
|
2021-06-06 01:30:39 -05:00
|
|
|
#if LINEAR_AXES >= 4
|
|
|
|
case I_AXIS: es = I_ENDSTOP; break;
|
|
|
|
#endif
|
|
|
|
#if LINEAR_AXES >= 5
|
|
|
|
case J_AXIS: es = J_ENDSTOP; break;
|
|
|
|
#endif
|
|
|
|
#if LINEAR_AXES >= 6
|
|
|
|
case K_AXIS: es = K_ENDSTOP; break;
|
|
|
|
#endif
|
2018-07-13 23:12:43 -05:00
|
|
|
}
|
2021-02-25 04:49:34 -06:00
|
|
|
if (TEST(endstops.state(), es)) {
|
2021-05-24 16:38:57 -05:00
|
|
|
SERIAL_ECHO_MSG("Bad ", AS_CHAR(AXIS_CHAR(axis)), " Endstop?");
|
2021-02-25 04:49:34 -06:00
|
|
|
kill(GET_TEXT(MSG_KILL_HOMING_FAILED));
|
2018-07-13 23:12:43 -05:00
|
|
|
}
|
2021-02-25 04:49:34 -06:00
|
|
|
#endif
|
2020-01-19 23:35:07 -06:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
#if BOTH(HOMING_Z_WITH_PROBE, BLTOUCH_SLOW_MODE)
|
|
|
|
if (axis == Z_AXIS && bltouch.deploy()) return; // Intermediate DEPLOY (in LOW SPEED MODE)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Slow move towards endstop until triggered
|
|
|
|
const float rebump = bump * 2;
|
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Re-bump: ", rebump, "mm");
|
|
|
|
do_homing_move(axis, rebump, get_homing_bump_feedrate(axis), true);
|
2020-01-19 23:35:07 -06:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
#if BOTH(HOMING_Z_WITH_PROBE, BLTOUCH)
|
|
|
|
if (axis == Z_AXIS) bltouch.stow(); // The final STOW
|
|
|
|
#endif
|
|
|
|
}
|
2020-01-19 23:35:07 -06:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
#if HAS_EXTRA_ENDSTOPS
|
|
|
|
const bool pos_dir = axis_home_dir > 0;
|
|
|
|
#if ENABLED(X_DUAL_ENDSTOPS)
|
|
|
|
if (axis == X_AXIS) {
|
|
|
|
const float adj = ABS(endstops.x2_endstop_adj);
|
2020-01-19 23:35:07 -06:00
|
|
|
if (adj) {
|
2021-02-25 04:49:34 -06:00
|
|
|
if (pos_dir ? (endstops.x2_endstop_adj > 0) : (endstops.x2_endstop_adj < 0)) stepper.set_x_lock(true); else stepper.set_x2_lock(true);
|
2020-01-19 23:35:07 -06:00
|
|
|
do_homing_move(axis, pos_dir ? -adj : adj);
|
2021-02-25 04:49:34 -06:00
|
|
|
stepper.set_x_lock(false);
|
|
|
|
stepper.set_x2_lock(false);
|
2020-01-19 23:35:07 -06:00
|
|
|
}
|
2021-02-25 04:49:34 -06:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if ENABLED(Y_DUAL_ENDSTOPS)
|
|
|
|
if (axis == Y_AXIS) {
|
|
|
|
const float adj = ABS(endstops.y2_endstop_adj);
|
|
|
|
if (adj) {
|
|
|
|
if (pos_dir ? (endstops.y2_endstop_adj > 0) : (endstops.y2_endstop_adj < 0)) stepper.set_y_lock(true); else stepper.set_y2_lock(true);
|
|
|
|
do_homing_move(axis, pos_dir ? -adj : adj);
|
|
|
|
stepper.set_y_lock(false);
|
|
|
|
stepper.set_y2_lock(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2020-01-19 23:35:07 -06:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
#if ENABLED(Z_MULTI_ENDSTOPS)
|
|
|
|
if (axis == Z_AXIS) {
|
2020-01-19 23:35:07 -06:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
#if NUM_Z_STEPPER_DRIVERS == 2
|
2020-01-19 23:35:07 -06:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
const float adj = ABS(endstops.z2_endstop_adj);
|
|
|
|
if (adj) {
|
|
|
|
if (pos_dir ? (endstops.z2_endstop_adj > 0) : (endstops.z2_endstop_adj < 0)) stepper.set_z1_lock(true); else stepper.set_z2_lock(true);
|
|
|
|
do_homing_move(axis, pos_dir ? -adj : adj);
|
|
|
|
stepper.set_z1_lock(false);
|
|
|
|
stepper.set_z2_lock(false);
|
|
|
|
}
|
2020-01-19 23:35:07 -06:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
#else
|
2020-01-19 23:35:07 -06:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
// Handy arrays of stepper lock function pointers
|
|
|
|
|
|
|
|
typedef void (*adjustFunc_t)(const bool);
|
|
|
|
|
|
|
|
adjustFunc_t lock[] = {
|
|
|
|
stepper.set_z1_lock, stepper.set_z2_lock, stepper.set_z3_lock
|
|
|
|
#if NUM_Z_STEPPER_DRIVERS >= 4
|
|
|
|
, stepper.set_z4_lock
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
float adj[] = {
|
|
|
|
0, endstops.z2_endstop_adj, endstops.z3_endstop_adj
|
|
|
|
#if NUM_Z_STEPPER_DRIVERS >= 4
|
|
|
|
, endstops.z4_endstop_adj
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
adjustFunc_t tempLock;
|
|
|
|
float tempAdj;
|
|
|
|
|
|
|
|
// Manual bubble sort by adjust value
|
|
|
|
if (adj[1] < adj[0]) {
|
|
|
|
tempLock = lock[0], tempAdj = adj[0];
|
|
|
|
lock[0] = lock[1], adj[0] = adj[1];
|
|
|
|
lock[1] = tempLock, adj[1] = tempAdj;
|
2020-01-19 23:35:07 -06:00
|
|
|
}
|
|
|
|
if (adj[2] < adj[1]) {
|
|
|
|
tempLock = lock[1], tempAdj = adj[1];
|
|
|
|
lock[1] = lock[2], adj[1] = adj[2];
|
|
|
|
lock[2] = tempLock, adj[2] = tempAdj;
|
|
|
|
}
|
|
|
|
#if NUM_Z_STEPPER_DRIVERS >= 4
|
2021-02-25 04:49:34 -06:00
|
|
|
if (adj[3] < adj[2]) {
|
|
|
|
tempLock = lock[2], tempAdj = adj[2];
|
|
|
|
lock[2] = lock[3], adj[2] = adj[3];
|
|
|
|
lock[3] = tempLock, adj[3] = tempAdj;
|
|
|
|
}
|
|
|
|
if (adj[2] < adj[1]) {
|
|
|
|
tempLock = lock[1], tempAdj = adj[1];
|
|
|
|
lock[1] = lock[2], adj[1] = adj[2];
|
|
|
|
lock[2] = tempLock, adj[2] = tempAdj;
|
|
|
|
}
|
2020-01-19 23:35:07 -06:00
|
|
|
#endif
|
2021-02-25 04:49:34 -06:00
|
|
|
if (adj[1] < adj[0]) {
|
|
|
|
tempLock = lock[0], tempAdj = adj[0];
|
|
|
|
lock[0] = lock[1], adj[0] = adj[1];
|
|
|
|
lock[1] = tempLock, adj[1] = tempAdj;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pos_dir) {
|
|
|
|
// normalize adj to smallest value and do the first move
|
|
|
|
(*lock[0])(true);
|
|
|
|
do_homing_move(axis, adj[1] - adj[0]);
|
|
|
|
// lock the second stepper for the final correction
|
|
|
|
(*lock[1])(true);
|
|
|
|
do_homing_move(axis, adj[2] - adj[1]);
|
|
|
|
#if NUM_Z_STEPPER_DRIVERS >= 4
|
|
|
|
// lock the third stepper for the final correction
|
|
|
|
(*lock[2])(true);
|
|
|
|
do_homing_move(axis, adj[3] - adj[2]);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
#if NUM_Z_STEPPER_DRIVERS >= 4
|
|
|
|
(*lock[3])(true);
|
|
|
|
do_homing_move(axis, adj[2] - adj[3]);
|
|
|
|
#endif
|
|
|
|
(*lock[2])(true);
|
|
|
|
do_homing_move(axis, adj[1] - adj[2]);
|
|
|
|
(*lock[1])(true);
|
|
|
|
do_homing_move(axis, adj[0] - adj[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
stepper.set_z1_lock(false);
|
|
|
|
stepper.set_z2_lock(false);
|
|
|
|
stepper.set_z3_lock(false);
|
2020-01-19 23:35:07 -06:00
|
|
|
#if NUM_Z_STEPPER_DRIVERS >= 4
|
2021-02-25 04:49:34 -06:00
|
|
|
stepper.set_z4_lock(false);
|
2020-01-19 23:35:07 -06:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
2021-02-25 04:49:34 -06:00
|
|
|
}
|
|
|
|
#endif
|
2018-06-19 11:55:49 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
// Reset flags for X, Y, Z motor locking
|
|
|
|
switch (axis) {
|
|
|
|
default: break;
|
|
|
|
TERN_(X_DUAL_ENDSTOPS, case X_AXIS:)
|
|
|
|
TERN_(Y_DUAL_ENDSTOPS, case Y_AXIS:)
|
|
|
|
TERN_(Z_MULTI_ENDSTOPS, case Z_AXIS:)
|
|
|
|
stepper.set_separate_multi_axis(false);
|
2018-06-19 11:55:49 -05:00
|
|
|
}
|
2021-03-03 17:46:32 -06:00
|
|
|
|
|
|
|
#endif // HAS_EXTRA_ENDSTOPS
|
2018-06-19 11:55:49 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
#ifdef TMC_HOME_PHASE
|
|
|
|
// move back to homing phase if configured and capable
|
|
|
|
backout_to_tmc_homing_phase(axis);
|
|
|
|
#endif
|
2017-09-08 15:35:25 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
#if IS_SCARA
|
2020-04-20 08:08:00 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
set_axis_is_at_home(axis);
|
|
|
|
sync_plan_position();
|
2017-09-08 15:35:25 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
#elif ENABLED(DELTA)
|
2017-09-08 15:35:25 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
// Delta has already moved all three towers up in G28
|
|
|
|
// so here it re-homes each tower in turn.
|
|
|
|
// Delta homing treats the axes as normal linear axes.
|
2017-09-08 15:35:25 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
const float adjDistance = delta_endstop_adj[axis],
|
|
|
|
minDistance = (MIN_STEPS_PER_SEGMENT) * planner.steps_to_mm[axis];
|
2017-09-08 15:35:25 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
// Retrace by the amount specified in delta_endstop_adj if more than min steps.
|
|
|
|
if (adjDistance * (Z_HOME_DIR) < 0 && ABS(adjDistance) > minDistance) { // away from endstop, more than min distance
|
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("adjDistance:", adjDistance);
|
|
|
|
do_homing_move(axis, adjDistance, get_homing_bump_feedrate(axis));
|
|
|
|
}
|
2020-04-20 08:08:00 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
#else // CARTESIAN / CORE / MARKFORGED_XY
|
|
|
|
|
|
|
|
set_axis_is_at_home(axis);
|
|
|
|
sync_plan_position();
|
2017-09-08 15:35:25 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
destination[axis] = current_position[axis];
|
2017-09-08 15:35:25 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_POS("> AFTER set_axis_is_at_home", current_position);
|
2017-09-08 15:35:25 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
#endif
|
2017-09-08 15:35:25 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
// Put away the Z probe
|
|
|
|
#if HOMING_Z_WITH_PROBE
|
|
|
|
if (axis == Z_AXIS && probe.stow()) return;
|
|
|
|
#endif
|
2017-09-08 15:35:25 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
#if DISABLED(DELTA) && defined(HOMING_BACKOFF_POST_MM)
|
|
|
|
const xyz_float_t endstop_backoff = HOMING_BACKOFF_POST_MM;
|
|
|
|
if (endstop_backoff[axis]) {
|
|
|
|
current_position[axis] -= ABS(endstop_backoff[axis]) * axis_home_dir;
|
|
|
|
line_to_current_position(
|
|
|
|
#if HOMING_Z_WITH_PROBE
|
|
|
|
(axis == Z_AXIS) ? z_probe_fast_mm_s :
|
|
|
|
#endif
|
|
|
|
homing_feedrate(axis)
|
|
|
|
);
|
|
|
|
|
|
|
|
#if ENABLED(SENSORLESS_HOMING)
|
|
|
|
planner.synchronize();
|
|
|
|
if (false
|
|
|
|
#if EITHER(IS_CORE, MARKFORGED_XY)
|
|
|
|
|| axis != NORMAL_AXIS
|
|
|
|
#endif
|
|
|
|
) safe_delay(200); // Short delay to allow belts to spring back
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Clear retracted status if homing the Z axis
|
|
|
|
#if ENABLED(FWRETRACT)
|
|
|
|
if (axis == Z_AXIS) fwretract.current_hop = 0.0;
|
|
|
|
#endif
|
|
|
|
|
2021-05-24 16:38:57 -05:00
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("<<< homeaxis(", AS_CHAR(AXIS_CHAR(axis)), ")");
|
2021-02-25 04:49:34 -06:00
|
|
|
|
|
|
|
} // homeaxis()
|
|
|
|
|
|
|
|
#endif // HAS_ENDSTOPS
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set an axis' current position to its home position (after homing).
|
|
|
|
*
|
|
|
|
* For Core and Cartesian robots this applies one-to-one when an
|
|
|
|
* individual axis has been homed.
|
|
|
|
*
|
|
|
|
* DELTA should wait until all homing is done before setting the XYZ
|
|
|
|
* current_position to home, because homing is a single operation.
|
|
|
|
* In the case where the axis positions are trusted and previously
|
|
|
|
* homed, DELTA could home to X or Y individually by moving either one
|
|
|
|
* to the center. However, homing Z always homes XY and Z.
|
|
|
|
*
|
|
|
|
* SCARA should wait until all XY homing is done before setting the XY
|
|
|
|
* current_position to home, because neither X nor Y is at home until
|
|
|
|
* both are at home. Z can however be homed individually.
|
|
|
|
*
|
|
|
|
* Callers must sync the planner position after calling this!
|
|
|
|
*/
|
|
|
|
void set_axis_is_at_home(const AxisEnum axis) {
|
2021-05-24 16:38:57 -05:00
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR(">>> set_axis_is_at_home(", AS_CHAR(AXIS_CHAR(axis)), ")");
|
2021-02-25 04:49:34 -06:00
|
|
|
|
|
|
|
set_axis_trusted(axis);
|
|
|
|
set_axis_homed(axis);
|
|
|
|
|
|
|
|
#if ENABLED(DUAL_X_CARRIAGE)
|
|
|
|
if (axis == X_AXIS && (active_extruder == 1 || dual_x_carriage_mode == DXC_DUPLICATION_MODE)) {
|
|
|
|
current_position.x = x_home_pos(active_extruder);
|
|
|
|
return;
|
|
|
|
}
|
2017-09-08 15:35:25 -05:00
|
|
|
#endif
|
|
|
|
|
2021-03-03 17:46:32 -06:00
|
|
|
#if EITHER(MORGAN_SCARA, AXEL_TPARA)
|
2021-02-25 04:49:34 -06:00
|
|
|
scara_set_axis_is_at_home(axis);
|
|
|
|
#elif ENABLED(DELTA)
|
2021-04-08 21:03:34 -05:00
|
|
|
current_position[axis] = (axis == Z_AXIS) ? DIFF_TERN(HAS_BED_PROBE, delta_height, probe.offset.z) : base_home_pos(axis);
|
2021-02-25 04:49:34 -06:00
|
|
|
#else
|
|
|
|
current_position[axis] = base_home_pos(axis);
|
2018-07-27 18:30:08 -05:00
|
|
|
#endif
|
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
/**
|
|
|
|
* Z Probe Z Homing? Account for the probe's Z offset.
|
|
|
|
*/
|
2021-05-19 00:21:34 -05:00
|
|
|
#if HAS_BED_PROBE && Z_HOME_TO_MIN
|
2021-02-25 04:49:34 -06:00
|
|
|
if (axis == Z_AXIS) {
|
|
|
|
#if HOMING_Z_WITH_PROBE
|
|
|
|
|
|
|
|
current_position.z -= probe.offset.z;
|
|
|
|
|
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("*** Z HOMED WITH PROBE (Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN) ***\n> probe.offset.z = ", probe.offset.z);
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("*** Z HOMED TO ENDSTOP ***");
|
2020-03-23 20:32:36 -05:00
|
|
|
|
|
|
|
#endif
|
2019-07-31 20:50:23 -05:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
TERN_(I2C_POSITION_ENCODERS, I2CPEM.homed(axis));
|
|
|
|
|
|
|
|
TERN_(BABYSTEP_DISPLAY_TOTAL, babystep.reset_total(axis));
|
2018-01-29 13:40:04 -06:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
#if HAS_POSITION_SHIFT
|
|
|
|
position_shift[axis] = 0;
|
|
|
|
update_workspace_offset(axis);
|
|
|
|
#endif
|
2019-03-14 02:25:42 -05:00
|
|
|
|
2021-02-25 04:49:34 -06:00
|
|
|
if (DEBUGGING(LEVELING)) {
|
|
|
|
#if HAS_HOME_OFFSET
|
2021-05-24 16:38:57 -05:00
|
|
|
DEBUG_ECHOLNPAIR("> home_offset[", AS_CHAR(AXIS_CHAR(axis)), "] = ", home_offset[axis]);
|
2021-02-25 04:49:34 -06:00
|
|
|
#endif
|
|
|
|
DEBUG_POS("", current_position);
|
2021-05-24 16:38:57 -05:00
|
|
|
DEBUG_ECHOLNPAIR("<<< set_axis_is_at_home(", AS_CHAR(AXIS_CHAR(axis)), ")");
|
2021-02-25 04:49:34 -06:00
|
|
|
}
|
|
|
|
}
|
2017-09-08 15:35:25 -05:00
|
|
|
|
2018-11-03 03:56:33 -05:00
|
|
|
#if HAS_WORKSPACE_OFFSET
|
|
|
|
void update_workspace_offset(const AxisEnum axis) {
|
|
|
|
workspace_offset[axis] = home_offset[axis] + position_shift[axis];
|
2021-05-18 22:51:19 -05:00
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Axis ", AS_CHAR(AXIS_CHAR(axis)), " home_offset = ", home_offset[axis], " position_shift = ", position_shift[axis]);
|
2017-09-08 15:35:25 -05:00
|
|
|
}
|
2018-11-03 03:56:33 -05:00
|
|
|
#endif
|
2017-09-08 15:35:25 -05:00
|
|
|
|
|
|
|
#if HAS_M206_COMMAND
|
|
|
|
/**
|
2018-01-22 06:10:35 -06:00
|
|
|
* Change the home offset for an axis.
|
|
|
|
* Also refreshes the workspace offset.
|
2017-09-08 15:35:25 -05:00
|
|
|
*/
|
|
|
|
void set_home_offset(const AxisEnum axis, const float v) {
|
|
|
|
home_offset[axis] = v;
|
2018-11-03 03:56:33 -05:00
|
|
|
update_workspace_offset(axis);
|
2017-09-08 15:35:25 -05:00
|
|
|
}
|
2021-02-25 04:49:34 -06:00
|
|
|
#endif
|