2017-09-06 06:28:31 -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-06 06:28:31 -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-06 06:28:31 -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-06 06:28:31 -05:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2017-09-08 15:35:25 -05:00
|
|
|
/**
|
|
|
|
* G29.cpp - Mesh Bed Leveling
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "../../../inc/MarlinConfig.h"
|
|
|
|
|
|
|
|
#if ENABLED(MESH_BED_LEVELING)
|
|
|
|
|
|
|
|
#include "../../../feature/bedlevel/bedlevel.h"
|
2017-09-07 22:33:16 -05:00
|
|
|
|
2017-09-08 15:35:25 -05:00
|
|
|
#include "../../gcode.h"
|
|
|
|
#include "../../queue.h"
|
|
|
|
|
|
|
|
#include "../../../libs/buzzer.h"
|
2020-10-16 19:36:25 -05:00
|
|
|
#include "../../../lcd/marlinui.h"
|
2017-09-08 15:35:25 -05:00
|
|
|
#include "../../../module/motion.h"
|
|
|
|
#include "../../../module/stepper.h"
|
2019-07-28 01:29:03 -05:00
|
|
|
|
2019-07-27 22:44:05 -05:00
|
|
|
#if ENABLED(EXTENSIBLE_UI)
|
2020-03-13 16:29:29 -05:00
|
|
|
#include "../../../lcd/extui/ui_api.h"
|
2019-07-27 22:44:05 -05:00
|
|
|
#endif
|
2017-09-06 06:28:31 -05:00
|
|
|
|
|
|
|
// Save 130 bytes with non-duplication of PSTR
|
2018-11-29 16:58:58 -06:00
|
|
|
inline void echo_not_entered(const char c) { SERIAL_CHAR(c); SERIAL_ECHOLNPGM(" not entered."); }
|
2017-09-06 06:28:31 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* G29: Mesh-based Z probe, probes a grid and produces a
|
|
|
|
* mesh to compensate for variable bed height
|
|
|
|
*
|
|
|
|
* Parameters With MESH_BED_LEVELING:
|
|
|
|
*
|
2018-11-19 09:08:15 -06:00
|
|
|
* S0 Report the current mesh values
|
2017-09-06 06:28:31 -05:00
|
|
|
* S1 Start probing mesh points
|
|
|
|
* S2 Probe the next mesh point
|
2018-11-19 09:08:15 -06:00
|
|
|
* S3 In Jn Zn.nn Manually modify a single point
|
2017-09-06 06:28:31 -05:00
|
|
|
* S4 Zn.nn Set z offset. Positive away from bed, negative closer to bed.
|
|
|
|
* S5 Reset and disable mesh
|
|
|
|
*/
|
2017-09-08 15:35:25 -05:00
|
|
|
void GcodeSuite::G29() {
|
2017-09-06 06:28:31 -05:00
|
|
|
|
|
|
|
static int mbl_probe_index = -1;
|
|
|
|
|
2018-04-20 01:14:50 -05:00
|
|
|
MeshLevelingState state = (MeshLevelingState)parser.byteval('S', (int8_t)MeshReport);
|
2017-09-06 06:28:31 -05:00
|
|
|
if (!WITHIN(state, 0, 5)) {
|
2018-11-29 16:58:58 -06:00
|
|
|
SERIAL_ECHOLNPGM("S out of range (0-5).");
|
2017-09-06 06:28:31 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-19 09:08:15 -06:00
|
|
|
int8_t ix, iy;
|
2017-09-06 06:28:31 -05:00
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
case MeshReport:
|
2018-11-29 16:58:58 -06:00
|
|
|
SERIAL_ECHOPGM("Mesh Bed Leveling ");
|
2017-09-06 06:28:31 -05:00
|
|
|
if (leveling_is_valid()) {
|
2018-11-12 17:04:00 -06:00
|
|
|
serialprintln_onoff(planner.leveling_active);
|
2018-01-06 20:50:21 -06:00
|
|
|
mbl.report_mesh();
|
2017-09-06 06:28:31 -05:00
|
|
|
}
|
|
|
|
else
|
2018-11-29 16:58:58 -06:00
|
|
|
SERIAL_ECHOLNPGM("has no data.");
|
2017-09-06 06:28:31 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MeshStart:
|
|
|
|
mbl.reset();
|
|
|
|
mbl_probe_index = 0;
|
2020-01-26 00:02:06 -06:00
|
|
|
if (!ui.wait_for_move) {
|
2021-01-17 12:08:40 -06:00
|
|
|
queue.inject_P(parser.seen('N') ? PSTR("G28" TERN(G28_L0_ENSURES_LEVELING_OFF, "L0", "") "\nG29S2") : PSTR("G29S2"));
|
2018-04-20 01:14:50 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
state = MeshNext;
|
2017-09-06 06:28:31 -05:00
|
|
|
|
|
|
|
case MeshNext:
|
|
|
|
if (mbl_probe_index < 0) {
|
2018-11-29 16:58:58 -06:00
|
|
|
SERIAL_ECHOLNPGM("Start mesh probing with \"G29 S1\" first.");
|
2017-09-06 06:28:31 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// For each G29 S2...
|
|
|
|
if (mbl_probe_index == 0) {
|
2018-04-12 22:36:38 -05:00
|
|
|
// Move close to the bed before the first point
|
2021-03-24 09:14:11 -05:00
|
|
|
do_blocking_move_to_z(MANUAL_PROBE_START_Z);
|
2017-09-06 06:28:31 -05:00
|
|
|
}
|
|
|
|
else {
|
2018-04-20 01:14:50 -05:00
|
|
|
// Save Z for the previous mesh position
|
2019-09-29 04:25:39 -05:00
|
|
|
mbl.set_zigzag_z(mbl_probe_index - 1, current_position.z);
|
2020-10-12 16:48:04 -05:00
|
|
|
SET_SOFT_ENDSTOP_LOOSE(false);
|
2017-09-06 06:28:31 -05:00
|
|
|
}
|
|
|
|
// If there's another point to sample, move there with optional lift.
|
|
|
|
if (mbl_probe_index < GRID_MAX_POINTS) {
|
2020-10-12 16:48:04 -05:00
|
|
|
// Disable software endstops to allow manual adjustment
|
|
|
|
// If G29 is left hanging without completion they won't be re-enabled!
|
|
|
|
SET_SOFT_ENDSTOP_LOOSE(true);
|
2018-11-19 09:08:15 -06:00
|
|
|
mbl.zigzag(mbl_probe_index++, ix, iy);
|
2019-09-29 04:25:39 -05:00
|
|
|
_manual_goto_xy({ mbl.index_to_xpos[ix], mbl.index_to_ypos[iy] });
|
2017-09-06 06:28:31 -05:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// One last "return to the bed" (as originally coded) at completion
|
2019-09-29 04:25:39 -05:00
|
|
|
current_position.z = MANUAL_PROBE_HEIGHT;
|
2017-09-06 06:28:31 -05:00
|
|
|
line_to_current_position();
|
2018-05-12 01:38:02 -05:00
|
|
|
planner.synchronize();
|
2017-09-06 06:28:31 -05:00
|
|
|
|
|
|
|
// After recording the last point, activate home and activate
|
|
|
|
mbl_probe_index = -1;
|
2018-11-29 16:58:58 -06:00
|
|
|
SERIAL_ECHOLNPGM("Mesh probing done.");
|
2017-09-06 06:28:31 -05:00
|
|
|
BUZZ(100, 659);
|
|
|
|
BUZZ(100, 698);
|
2017-11-27 12:57:55 -06:00
|
|
|
|
2019-05-26 15:29:54 -05:00
|
|
|
home_all_axes();
|
2017-11-27 02:12:29 -06:00
|
|
|
set_bed_leveling_enabled(true);
|
2017-11-27 12:57:55 -06:00
|
|
|
|
2017-11-27 02:12:29 -06:00
|
|
|
#if ENABLED(MESH_G28_REST_ORIGIN)
|
2019-09-29 04:25:39 -05:00
|
|
|
current_position.z = 0;
|
2019-09-26 01:28:09 -05:00
|
|
|
line_to_current_position(homing_feedrate(Z_AXIS));
|
2018-05-12 01:38:02 -05:00
|
|
|
planner.synchronize();
|
2017-11-27 02:12:29 -06:00
|
|
|
#endif
|
2017-11-27 12:57:55 -06:00
|
|
|
|
2020-04-22 16:35:03 -05:00
|
|
|
TERN_(LCD_BED_LEVELING, ui.wait_for_move = false);
|
2017-09-06 06:28:31 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MeshSet:
|
2018-11-19 09:08:15 -06:00
|
|
|
if (parser.seenval('I')) {
|
|
|
|
ix = parser.value_int();
|
|
|
|
if (!WITHIN(ix, 0, GRID_MAX_POINTS_X - 1)) {
|
2021-02-08 00:37:24 -06:00
|
|
|
SERIAL_ECHOLNPAIR("I out of range (0-", GRID_MAX_POINTS_X - 1, ")");
|
2017-09-06 06:28:31 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2018-11-10 01:32:29 -06:00
|
|
|
else
|
2018-11-19 09:08:15 -06:00
|
|
|
return echo_not_entered('J');
|
2017-09-06 06:28:31 -05:00
|
|
|
|
2018-11-19 09:08:15 -06:00
|
|
|
if (parser.seenval('J')) {
|
|
|
|
iy = parser.value_int();
|
|
|
|
if (!WITHIN(iy, 0, GRID_MAX_POINTS_Y - 1)) {
|
2021-02-08 00:37:24 -06:00
|
|
|
SERIAL_ECHOLNPAIR("J out of range (0-", GRID_MAX_POINTS_Y - 1, ")");
|
2017-09-06 06:28:31 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2018-11-10 01:32:29 -06:00
|
|
|
else
|
2018-11-19 09:08:15 -06:00
|
|
|
return echo_not_entered('J');
|
2017-09-06 06:28:31 -05:00
|
|
|
|
2019-03-13 00:45:52 -05:00
|
|
|
if (parser.seenval('Z')) {
|
2018-11-19 09:08:15 -06:00
|
|
|
mbl.z_values[ix][iy] = parser.value_linear_units();
|
2020-04-22 16:35:03 -05:00
|
|
|
TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(ix, iy, mbl.z_values[ix][iy]));
|
2019-03-13 00:45:52 -05:00
|
|
|
}
|
2018-11-10 01:32:29 -06:00
|
|
|
else
|
|
|
|
return echo_not_entered('Z');
|
2017-09-06 06:28:31 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MeshSetZOffset:
|
2017-11-27 02:12:29 -06:00
|
|
|
if (parser.seenval('Z'))
|
2017-09-06 06:28:31 -05:00
|
|
|
mbl.z_offset = parser.value_linear_units();
|
2018-11-10 01:32:29 -06:00
|
|
|
else
|
|
|
|
return echo_not_entered('Z');
|
2017-09-06 06:28:31 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MeshReset:
|
|
|
|
reset_bed_level();
|
|
|
|
break;
|
|
|
|
|
|
|
|
} // switch(state)
|
|
|
|
|
2021-02-04 23:22:42 -06:00
|
|
|
if (state == MeshNext)
|
2021-02-08 00:37:24 -06:00
|
|
|
SERIAL_ECHOLNPAIR("MBL G29 point ", _MIN(mbl_probe_index, GRID_MAX_POINTS), " of ", GRID_MAX_POINTS);
|
2017-11-27 02:12:29 -06:00
|
|
|
|
2017-09-06 06:28:31 -05:00
|
|
|
report_current_position();
|
|
|
|
}
|
2017-09-08 15:35:25 -05:00
|
|
|
|
|
|
|
#endif // MESH_BED_LEVELING
|