2019-02-06 23:20:17 +00:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2020-02-03 14:00:57 +00:00
|
|
|
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2019-02-06 23:20:17 +00:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
2019-06-28 04:57:50 +00:00
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
2019-02-06 23:20:17 +00: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
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-01-03 01:01:38 +00:00
|
|
|
#include "../../MarlinCore.h"
|
2019-02-06 23:20:17 +00:00
|
|
|
|
|
|
|
#if ENABLED(CALIBRATION_GCODE)
|
|
|
|
|
|
|
|
#include "../gcode.h"
|
2019-05-21 02:34:08 +00:00
|
|
|
|
|
|
|
#if ENABLED(BACKLASH_GCODE)
|
|
|
|
#include "../../feature/backlash.h"
|
|
|
|
#endif
|
|
|
|
|
2019-02-06 23:20:17 +00:00
|
|
|
#include "../../lcd/ultralcd.h"
|
|
|
|
#include "../../module/motion.h"
|
|
|
|
#include "../../module/planner.h"
|
|
|
|
#include "../../module/tool_change.h"
|
|
|
|
#include "../../module/endstops.h"
|
2019-02-14 22:45:31 +00:00
|
|
|
#include "../../feature/bedlevel/bedlevel.h"
|
2019-02-06 23:20:17 +00:00
|
|
|
|
2020-03-28 03:00:27 +00:00
|
|
|
#if !AXIS_CAN_CALIBRATE(X)
|
|
|
|
#undef CALIBRATION_MEASURE_LEFT
|
|
|
|
#undef CALIBRATION_MEASURE_RIGHT
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !AXIS_CAN_CALIBRATE(Y)
|
|
|
|
#undef CALIBRATION_MEASURE_FRONT
|
|
|
|
#undef CALIBRATION_MEASURE_BACK
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !AXIS_CAN_CALIBRATE(Z)
|
|
|
|
#undef CALIBRATION_MEASURE_AT_TOP_EDGES
|
|
|
|
#endif
|
|
|
|
|
2019-02-06 23:20:17 +00:00
|
|
|
/**
|
|
|
|
* G425 backs away from the calibration object by various distances
|
|
|
|
* depending on the confidence level:
|
|
|
|
*
|
|
|
|
* UNKNOWN - No real notion on where the calibration object is on the bed
|
|
|
|
* UNCERTAIN - Measurement may be uncertain due to backlash
|
|
|
|
* CERTAIN - Measurement obtained with backlash compensation
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CALIBRATION_MEASUREMENT_UNKNOWN
|
|
|
|
#define CALIBRATION_MEASUREMENT_UNKNOWN 5.0 // mm
|
|
|
|
#endif
|
|
|
|
#ifndef CALIBRATION_MEASUREMENT_UNCERTAIN
|
|
|
|
#define CALIBRATION_MEASUREMENT_UNCERTAIN 1.0 // mm
|
|
|
|
#endif
|
|
|
|
#ifndef CALIBRATION_MEASUREMENT_CERTAIN
|
|
|
|
#define CALIBRATION_MEASUREMENT_CERTAIN 0.5 // mm
|
|
|
|
#endif
|
|
|
|
|
2020-03-08 04:20:41 +00:00
|
|
|
#if BOTH(CALIBRATION_MEASURE_LEFT, CALIBRATION_MEASURE_RIGHT)
|
|
|
|
#define HAS_X_CENTER 1
|
|
|
|
#endif
|
|
|
|
#if BOTH(CALIBRATION_MEASURE_FRONT, CALIBRATION_MEASURE_BACK)
|
|
|
|
#define HAS_Y_CENTER 1
|
|
|
|
#endif
|
2019-02-06 23:20:17 +00:00
|
|
|
|
|
|
|
enum side_t : uint8_t { TOP, RIGHT, FRONT, LEFT, BACK, NUM_SIDES };
|
|
|
|
|
2019-09-29 09:25:39 +00:00
|
|
|
static constexpr xyz_pos_t true_center CALIBRATION_OBJECT_CENTER;
|
|
|
|
static constexpr xyz_float_t dimensions CALIBRATION_OBJECT_DIMENSIONS;
|
|
|
|
static constexpr xy_float_t nod = { CALIBRATION_NOZZLE_OUTER_DIAMETER, CALIBRATION_NOZZLE_OUTER_DIAMETER };
|
2019-02-14 22:45:31 +00:00
|
|
|
|
2019-09-29 09:25:39 +00:00
|
|
|
struct measurements_t {
|
|
|
|
xyz_pos_t obj_center = true_center; // Non-static must be assigned from xyz_pos_t
|
2019-02-06 23:20:17 +00:00
|
|
|
|
2019-09-29 09:25:39 +00:00
|
|
|
float obj_side[NUM_SIDES], backlash[NUM_SIDES];
|
|
|
|
xyz_float_t pos_error;
|
2019-02-06 23:20:17 +00:00
|
|
|
|
2019-09-29 09:25:39 +00:00
|
|
|
xy_float_t nozzle_outer_dimension = nod;
|
2019-02-06 23:20:17 +00:00
|
|
|
};
|
|
|
|
|
2019-02-14 22:45:31 +00:00
|
|
|
#define TEMPORARY_SOFT_ENDSTOP_STATE(enable) REMEMBER(tes, soft_endstops_enabled, enable);
|
2019-02-06 23:20:17 +00:00
|
|
|
|
|
|
|
#if ENABLED(BACKLASH_GCODE)
|
2019-05-04 04:53:15 +00:00
|
|
|
#define TEMPORARY_BACKLASH_CORRECTION(value) REMEMBER(tbst, backlash.correction, value)
|
2019-02-06 23:20:17 +00:00
|
|
|
#else
|
2019-02-14 22:45:31 +00:00
|
|
|
#define TEMPORARY_BACKLASH_CORRECTION(value)
|
2019-02-06 23:20:17 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLED(BACKLASH_GCODE) && defined(BACKLASH_SMOOTHING_MM)
|
2019-05-04 04:53:15 +00:00
|
|
|
#define TEMPORARY_BACKLASH_SMOOTHING(value) REMEMBER(tbsm, backlash.smoothing_mm, value)
|
2019-02-06 23:20:17 +00:00
|
|
|
#else
|
|
|
|
#define TEMPORARY_BACKLASH_SMOOTHING(value)
|
|
|
|
#endif
|
|
|
|
|
2019-09-29 09:25:39 +00:00
|
|
|
inline void calibration_move() {
|
|
|
|
do_blocking_move_to(current_position, MMM_TO_MMS(CALIBRATION_FEEDRATE_TRAVEL));
|
2019-02-06 23:20:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Move to the exact center above the calibration object
|
|
|
|
*
|
|
|
|
* m in - Measurement record
|
|
|
|
* uncertainty in - How far away from the object top to park
|
|
|
|
*/
|
|
|
|
inline void park_above_object(measurements_t &m, const float uncertainty) {
|
2019-02-14 22:45:31 +00:00
|
|
|
// Move to safe distance above calibration object
|
2019-09-29 09:25:39 +00:00
|
|
|
current_position.z = m.obj_center.z + dimensions.z / 2 + uncertainty;
|
|
|
|
calibration_move();
|
2019-02-06 23:20:17 +00:00
|
|
|
|
2019-02-14 22:45:31 +00:00
|
|
|
// Move to center of calibration object in XY
|
2019-09-29 09:25:39 +00:00
|
|
|
current_position = xy_pos_t(m.obj_center);
|
|
|
|
calibration_move();
|
2019-02-06 23:20:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if HOTENDS > 1
|
|
|
|
inline void set_nozzle(measurements_t &m, const uint8_t extruder) {
|
|
|
|
if (extruder != active_extruder) {
|
|
|
|
park_above_object(m, CALIBRATION_MEASUREMENT_UNKNOWN);
|
|
|
|
tool_change(extruder);
|
|
|
|
}
|
|
|
|
}
|
2019-03-09 04:13:24 +00:00
|
|
|
#endif
|
2019-02-06 23:20:17 +00:00
|
|
|
|
2019-03-09 04:13:24 +00:00
|
|
|
#if HAS_HOTEND_OFFSET
|
2019-02-06 23:20:17 +00:00
|
|
|
|
|
|
|
inline void normalize_hotend_offsets() {
|
2020-03-14 04:18:16 +00:00
|
|
|
LOOP_S_L_N(e, 1, HOTENDS)
|
2019-09-29 09:25:39 +00:00
|
|
|
hotend_offset[e] -= hotend_offset[0];
|
|
|
|
hotend_offset[0].reset();
|
2019-02-06 23:20:17 +00:00
|
|
|
}
|
|
|
|
|
2019-03-09 04:13:24 +00:00
|
|
|
#endif
|
2019-02-06 23:20:17 +00:00
|
|
|
|
|
|
|
inline bool read_calibration_pin() {
|
2020-02-04 14:32:43 +00:00
|
|
|
return (
|
|
|
|
#if PIN_EXISTS(CALIBRATION)
|
|
|
|
READ(CALIBRATION_PIN) != CALIBRATION_PIN_INVERTING
|
|
|
|
#elif HAS_CUSTOM_PROBE_PIN
|
|
|
|
READ(Z_MIN_PROBE_PIN) != Z_MIN_PROBE_ENDSTOP_INVERTING
|
|
|
|
#else
|
|
|
|
READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING
|
|
|
|
#endif
|
|
|
|
);
|
2019-02-06 23:20:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Move along axis in the specified dir until the probe value becomes stop_state,
|
|
|
|
* then return the axis value.
|
|
|
|
*
|
|
|
|
* axis in - Axis along which the measurement will take place
|
|
|
|
* dir in - Direction along that axis (-1 or 1)
|
|
|
|
* stop_state in - Move until probe pin becomes this value
|
|
|
|
* fast in - Fast vs. precise measurement
|
|
|
|
*/
|
|
|
|
float measuring_movement(const AxisEnum axis, const int dir, const bool stop_state, const bool fast) {
|
2019-09-26 06:28:09 +00:00
|
|
|
const float step = fast ? 0.25 : CALIBRATION_MEASUREMENT_RESOLUTION;
|
|
|
|
const feedRate_t mms = fast ? MMM_TO_MMS(CALIBRATION_FEEDRATE_FAST) : MMM_TO_MMS(CALIBRATION_FEEDRATE_SLOW);
|
|
|
|
const float limit = fast ? 50 : 5;
|
2019-02-06 23:20:17 +00:00
|
|
|
|
2019-09-29 09:25:39 +00:00
|
|
|
destination = current_position;
|
2019-02-06 23:20:17 +00:00
|
|
|
for (float travel = 0; travel < limit; travel += step) {
|
|
|
|
destination[axis] += dir * step;
|
2019-02-14 08:21:42 +00:00
|
|
|
do_blocking_move_to(destination, mms);
|
2019-02-06 23:20:17 +00:00
|
|
|
planner.synchronize();
|
2019-09-26 06:28:09 +00:00
|
|
|
if (read_calibration_pin() == stop_state) break;
|
2019-02-06 23:20:17 +00:00
|
|
|
}
|
|
|
|
return destination[axis];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Move along axis until the probe is triggered. Move toolhead to its starting
|
|
|
|
* point and return the measured value.
|
|
|
|
*
|
|
|
|
* axis in - Axis along which the measurement will take place
|
|
|
|
* dir in - Direction along that axis (-1 or 1)
|
|
|
|
* stop_state in - Move until probe pin becomes this value
|
2019-05-09 16:45:55 +00:00
|
|
|
* backlash_ptr in/out - When not nullptr, measure and record axis backlash
|
2019-02-06 23:20:17 +00:00
|
|
|
* uncertainty in - If uncertainty is CALIBRATION_MEASUREMENT_UNKNOWN, do a fast probe.
|
|
|
|
*/
|
|
|
|
inline float measure(const AxisEnum axis, const int dir, const bool stop_state, float * const backlash_ptr, const float uncertainty) {
|
|
|
|
const bool fast = uncertainty == CALIBRATION_MEASUREMENT_UNKNOWN;
|
|
|
|
|
|
|
|
// Save position
|
2019-09-29 09:25:39 +00:00
|
|
|
destination = current_position;
|
2019-02-06 23:20:17 +00:00
|
|
|
const float start_pos = destination[axis];
|
|
|
|
const float measured_pos = measuring_movement(axis, dir, stop_state, fast);
|
|
|
|
// Measure backlash
|
|
|
|
if (backlash_ptr && !fast) {
|
|
|
|
const float release_pos = measuring_movement(axis, -dir, !stop_state, fast);
|
|
|
|
*backlash_ptr = ABS(release_pos - measured_pos);
|
|
|
|
}
|
|
|
|
// Return to starting position
|
|
|
|
destination[axis] = start_pos;
|
2019-02-14 08:21:42 +00:00
|
|
|
do_blocking_move_to(destination, MMM_TO_MMS(CALIBRATION_FEEDRATE_TRAVEL));
|
2019-02-06 23:20:17 +00:00
|
|
|
return measured_pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Probe one side of the calibration object
|
|
|
|
*
|
|
|
|
* m in/out - Measurement record, m.obj_center and m.obj_side will be updated.
|
|
|
|
* uncertainty in - How far away from the calibration object to begin probing
|
|
|
|
* side in - Side of probe where probe will occur
|
|
|
|
* probe_top_at_edge in - When probing sides, probe top of calibration object nearest edge
|
|
|
|
* to find out height of edge
|
|
|
|
*/
|
|
|
|
inline void probe_side(measurements_t &m, const float uncertainty, const side_t side, const bool probe_top_at_edge=false) {
|
2019-09-29 09:25:39 +00:00
|
|
|
const xyz_float_t dimensions = CALIBRATION_OBJECT_DIMENSIONS;
|
2019-02-06 23:20:17 +00:00
|
|
|
AxisEnum axis;
|
2020-03-28 03:00:27 +00:00
|
|
|
float dir = 1;
|
2019-02-06 23:20:17 +00:00
|
|
|
|
|
|
|
park_above_object(m, uncertainty);
|
|
|
|
|
2019-02-12 22:25:49 +00:00
|
|
|
switch (side) {
|
2020-03-28 03:00:27 +00:00
|
|
|
#if AXIS_CAN_CALIBRATE(Z)
|
|
|
|
case TOP: {
|
|
|
|
const float measurement = measure(Z_AXIS, -1, true, &m.backlash[TOP], uncertainty);
|
|
|
|
m.obj_center.z = measurement - dimensions.z / 2;
|
|
|
|
m.obj_side[TOP] = measurement;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if AXIS_CAN_CALIBRATE(X)
|
|
|
|
case LEFT: axis = X_AXIS; break;
|
|
|
|
case RIGHT: axis = X_AXIS; dir = -1; break;
|
|
|
|
#endif
|
|
|
|
#if AXIS_CAN_CALIBRATE(Y)
|
|
|
|
case FRONT: axis = Y_AXIS; break;
|
|
|
|
case BACK: axis = Y_AXIS; dir = -1; break;
|
|
|
|
#endif
|
2019-09-29 09:25:39 +00:00
|
|
|
default: return;
|
2019-02-06 23:20:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (probe_top_at_edge) {
|
2020-03-28 03:00:27 +00:00
|
|
|
#if AXIS_CAN_CALIBRATE(Z)
|
|
|
|
// Probe top nearest the side we are probing
|
|
|
|
current_position[axis] = m.obj_center[axis] + (-dir) * (dimensions[axis] / 2 - m.nozzle_outer_dimension[axis]);
|
|
|
|
calibration_move();
|
|
|
|
m.obj_side[TOP] = measure(Z_AXIS, -1, true, &m.backlash[TOP], uncertainty);
|
|
|
|
m.obj_center.z = m.obj_side[TOP] - dimensions.z / 2;
|
|
|
|
#endif
|
2019-02-06 23:20:17 +00:00
|
|
|
}
|
|
|
|
|
2020-04-17 15:24:20 +00:00
|
|
|
if ((AXIS_CAN_CALIBRATE(X) && axis == X_AXIS) || (AXIS_CAN_CALIBRATE(Y) && axis == Y_AXIS)) {
|
2020-03-28 03:00:27 +00:00
|
|
|
// Move to safe distance to the side of the calibration object
|
|
|
|
current_position[axis] = m.obj_center[axis] + (-dir) * (dimensions[axis] / 2 + m.nozzle_outer_dimension[axis] / 2 + uncertainty);
|
|
|
|
calibration_move();
|
2019-02-06 23:20:17 +00:00
|
|
|
|
2020-03-28 03:00:27 +00:00
|
|
|
// Plunge below the side of the calibration object and measure
|
|
|
|
current_position.z = m.obj_side[TOP] - (CALIBRATION_NOZZLE_TIP_HEIGHT) * 0.7f;
|
|
|
|
calibration_move();
|
|
|
|
const float measurement = measure(axis, dir, true, &m.backlash[side], uncertainty);
|
|
|
|
m.obj_center[axis] = measurement + dir * (dimensions[axis] / 2 + m.nozzle_outer_dimension[axis] / 2);
|
|
|
|
m.obj_side[side] = measurement;
|
|
|
|
}
|
2019-02-06 23:20:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Probe all sides of the calibration calibration object
|
|
|
|
*
|
|
|
|
* m in/out - Measurement record: center, backlash and error values be updated.
|
|
|
|
* uncertainty in - How far away from the calibration object to begin probing
|
|
|
|
*/
|
|
|
|
inline void probe_sides(measurements_t &m, const float uncertainty) {
|
2020-03-28 03:00:27 +00:00
|
|
|
#if ENABLED(CALIBRATION_MEASURE_AT_TOP_EDGES)
|
2019-02-06 23:20:17 +00:00
|
|
|
constexpr bool probe_top_at_edge = true;
|
|
|
|
#else
|
2019-02-14 22:45:31 +00:00
|
|
|
// Probing at the exact center only works if the center is flat. Probing on a washer
|
|
|
|
// or bolt will require probing the top near the side edges, away from the center.
|
2019-02-06 23:20:17 +00:00
|
|
|
constexpr bool probe_top_at_edge = false;
|
|
|
|
probe_side(m, uncertainty, TOP);
|
|
|
|
#endif
|
|
|
|
|
2020-03-28 03:00:27 +00:00
|
|
|
#if ENABLED(CALIBRATION_MEASURE_RIGHT)
|
2019-02-06 23:20:17 +00:00
|
|
|
probe_side(m, uncertainty, RIGHT, probe_top_at_edge);
|
|
|
|
#endif
|
2019-02-14 22:45:31 +00:00
|
|
|
|
2020-03-28 03:00:27 +00:00
|
|
|
#if ENABLED(CALIBRATION_MEASURE_FRONT)
|
2019-02-06 23:20:17 +00:00
|
|
|
probe_side(m, uncertainty, FRONT, probe_top_at_edge);
|
|
|
|
#endif
|
2019-02-14 22:45:31 +00:00
|
|
|
|
2020-03-28 03:00:27 +00:00
|
|
|
#if ENABLED(CALIBRATION_MEASURE_LEFT)
|
2019-02-06 23:20:17 +00:00
|
|
|
probe_side(m, uncertainty, LEFT, probe_top_at_edge);
|
|
|
|
#endif
|
2020-03-28 03:00:27 +00:00
|
|
|
#if ENABLED(CALIBRATION_MEASURE_BACK)
|
2019-02-06 23:20:17 +00:00
|
|
|
probe_side(m, uncertainty, BACK, probe_top_at_edge);
|
|
|
|
#endif
|
|
|
|
|
2019-02-14 22:45:31 +00:00
|
|
|
// Compute the measured center of the calibration object.
|
2019-02-06 23:20:17 +00:00
|
|
|
#if HAS_X_CENTER
|
2019-09-29 09:25:39 +00:00
|
|
|
m.obj_center.x = (m.obj_side[LEFT] + m.obj_side[RIGHT]) / 2;
|
2019-02-06 23:20:17 +00:00
|
|
|
#endif
|
|
|
|
#if HAS_Y_CENTER
|
2019-09-29 09:25:39 +00:00
|
|
|
m.obj_center.y = (m.obj_side[FRONT] + m.obj_side[BACK]) / 2;
|
2019-02-06 23:20:17 +00:00
|
|
|
#endif
|
|
|
|
|
2019-02-14 22:45:31 +00:00
|
|
|
// Compute the outside diameter of the nozzle at the height
|
|
|
|
// at which it makes contact with the calibration object
|
2019-02-06 23:20:17 +00:00
|
|
|
#if HAS_X_CENTER
|
2019-09-29 09:25:39 +00:00
|
|
|
m.nozzle_outer_dimension.x = m.obj_side[RIGHT] - m.obj_side[LEFT] - dimensions.x;
|
2019-02-06 23:20:17 +00:00
|
|
|
#endif
|
|
|
|
#if HAS_Y_CENTER
|
2019-09-29 09:25:39 +00:00
|
|
|
m.nozzle_outer_dimension.y = m.obj_side[BACK] - m.obj_side[FRONT] - dimensions.y;
|
2019-02-06 23:20:17 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
park_above_object(m, uncertainty);
|
|
|
|
|
2019-02-14 22:45:31 +00:00
|
|
|
// The difference between the known and the measured location
|
|
|
|
// of the calibration object is the positional error
|
2019-09-29 09:25:39 +00:00
|
|
|
m.pos_error.x = (0
|
2019-09-14 08:05:10 +00:00
|
|
|
#if HAS_X_CENTER
|
2019-09-29 09:25:39 +00:00
|
|
|
+ true_center.x - m.obj_center.x
|
2019-09-14 08:05:10 +00:00
|
|
|
#endif
|
|
|
|
);
|
2019-09-29 09:25:39 +00:00
|
|
|
m.pos_error.y = (0
|
2019-09-14 08:05:10 +00:00
|
|
|
#if HAS_Y_CENTER
|
2019-09-29 09:25:39 +00:00
|
|
|
+ true_center.y - m.obj_center.y
|
2019-09-14 08:05:10 +00:00
|
|
|
#endif
|
|
|
|
);
|
2019-09-29 09:25:39 +00:00
|
|
|
m.pos_error.z = true_center.z - m.obj_center.z;
|
2019-02-06 23:20:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if ENABLED(CALIBRATION_REPORTING)
|
|
|
|
inline void report_measured_faces(const measurements_t &m) {
|
|
|
|
SERIAL_ECHOLNPGM("Sides:");
|
2020-03-28 03:00:27 +00:00
|
|
|
#if AXIS_CAN_CALIBRATE(Z)
|
|
|
|
SERIAL_ECHOLNPAIR(" Top: ", m.obj_side[TOP]);
|
|
|
|
#endif
|
2019-02-06 23:20:17 +00:00
|
|
|
#if ENABLED(CALIBRATION_MEASURE_LEFT)
|
|
|
|
SERIAL_ECHOLNPAIR(" Left: ", m.obj_side[LEFT]);
|
|
|
|
#endif
|
|
|
|
#if ENABLED(CALIBRATION_MEASURE_RIGHT)
|
|
|
|
SERIAL_ECHOLNPAIR(" Right: ", m.obj_side[RIGHT]);
|
|
|
|
#endif
|
|
|
|
#if ENABLED(CALIBRATION_MEASURE_FRONT)
|
|
|
|
SERIAL_ECHOLNPAIR(" Front: ", m.obj_side[FRONT]);
|
|
|
|
#endif
|
|
|
|
#if ENABLED(CALIBRATION_MEASURE_BACK)
|
|
|
|
SERIAL_ECHOLNPAIR(" Back: ", m.obj_side[BACK]);
|
|
|
|
#endif
|
|
|
|
SERIAL_EOL();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void report_measured_center(const measurements_t &m) {
|
|
|
|
SERIAL_ECHOLNPGM("Center:");
|
|
|
|
#if HAS_X_CENTER
|
2019-11-29 10:45:07 +00:00
|
|
|
SERIAL_ECHOLNPAIR_P(SP_X_STR, m.obj_center.x);
|
2019-02-06 23:20:17 +00:00
|
|
|
#endif
|
|
|
|
#if HAS_Y_CENTER
|
2019-11-29 10:45:07 +00:00
|
|
|
SERIAL_ECHOLNPAIR_P(SP_Y_STR, m.obj_center.y);
|
2019-02-06 23:20:17 +00:00
|
|
|
#endif
|
2019-11-29 10:45:07 +00:00
|
|
|
SERIAL_ECHOLNPAIR_P(SP_Z_STR, m.obj_center.z);
|
2019-02-06 23:20:17 +00:00
|
|
|
SERIAL_EOL();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void report_measured_backlash(const measurements_t &m) {
|
|
|
|
SERIAL_ECHOLNPGM("Backlash:");
|
2020-03-28 03:00:27 +00:00
|
|
|
#if AXIS_CAN_CALIBRATE(X)
|
|
|
|
#if ENABLED(CALIBRATION_MEASURE_LEFT)
|
|
|
|
SERIAL_ECHOLNPAIR(" Left: ", m.backlash[LEFT]);
|
|
|
|
#endif
|
|
|
|
#if ENABLED(CALIBRATION_MEASURE_RIGHT)
|
|
|
|
SERIAL_ECHOLNPAIR(" Right: ", m.backlash[RIGHT]);
|
|
|
|
#endif
|
2019-02-06 23:20:17 +00:00
|
|
|
#endif
|
2020-03-28 03:00:27 +00:00
|
|
|
#if AXIS_CAN_CALIBRATE(Y)
|
|
|
|
#if ENABLED(CALIBRATION_MEASURE_FRONT)
|
|
|
|
SERIAL_ECHOLNPAIR(" Front: ", m.backlash[FRONT]);
|
|
|
|
#endif
|
|
|
|
#if ENABLED(CALIBRATION_MEASURE_BACK)
|
|
|
|
SERIAL_ECHOLNPAIR(" Back: ", m.backlash[BACK]);
|
|
|
|
#endif
|
2019-02-06 23:20:17 +00:00
|
|
|
#endif
|
2020-03-28 03:00:27 +00:00
|
|
|
#if AXIS_CAN_CALIBRATE(Z)
|
|
|
|
SERIAL_ECHOLNPAIR(" Top: ", m.backlash[TOP]);
|
2019-02-06 23:20:17 +00:00
|
|
|
#endif
|
|
|
|
SERIAL_EOL();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void report_measured_positional_error(const measurements_t &m) {
|
|
|
|
SERIAL_CHAR('T');
|
|
|
|
SERIAL_ECHO(int(active_extruder));
|
|
|
|
SERIAL_ECHOLNPGM(" Positional Error:");
|
|
|
|
#if HAS_X_CENTER
|
2019-11-29 10:45:07 +00:00
|
|
|
SERIAL_ECHOLNPAIR_P(SP_X_STR, m.pos_error.x);
|
2019-02-06 23:20:17 +00:00
|
|
|
#endif
|
|
|
|
#if HAS_Y_CENTER
|
2019-11-29 10:45:07 +00:00
|
|
|
SERIAL_ECHOLNPAIR_P(SP_Y_STR, m.pos_error.y);
|
2019-02-06 23:20:17 +00:00
|
|
|
#endif
|
2020-03-28 03:00:27 +00:00
|
|
|
if (AXIS_CAN_CALIBRATE(Z)) SERIAL_ECHOLNPAIR_P(SP_Z_STR, m.pos_error.z);
|
2019-02-06 23:20:17 +00:00
|
|
|
SERIAL_EOL();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void report_measured_nozzle_dimensions(const measurements_t &m) {
|
|
|
|
SERIAL_ECHOLNPGM("Nozzle Tip Outer Dimensions:");
|
2019-09-14 08:05:10 +00:00
|
|
|
#if HAS_X_CENTER || HAS_Y_CENTER
|
|
|
|
#if HAS_X_CENTER
|
2019-11-29 10:45:07 +00:00
|
|
|
SERIAL_ECHOLNPAIR_P(SP_X_STR, m.nozzle_outer_dimension.x);
|
2019-09-14 08:05:10 +00:00
|
|
|
#endif
|
|
|
|
#if HAS_Y_CENTER
|
2019-11-29 10:45:07 +00:00
|
|
|
SERIAL_ECHOLNPAIR_P(SP_Y_STR, m.nozzle_outer_dimension.y);
|
2019-09-14 08:05:10 +00:00
|
|
|
#endif
|
2019-06-29 05:23:57 +00:00
|
|
|
#else
|
|
|
|
UNUSED(m);
|
2019-02-06 23:20:17 +00:00
|
|
|
#endif
|
|
|
|
SERIAL_EOL();
|
|
|
|
}
|
|
|
|
|
2019-03-12 01:48:49 +00:00
|
|
|
#if HAS_HOTEND_OFFSET
|
2019-02-06 23:20:17 +00:00
|
|
|
//
|
|
|
|
// This function requires normalize_hotend_offsets() to be called
|
|
|
|
//
|
|
|
|
inline void report_hotend_offsets() {
|
2020-03-14 04:18:16 +00:00
|
|
|
LOOP_S_L_N(e, 1, HOTENDS)
|
2019-11-29 10:45:07 +00:00
|
|
|
SERIAL_ECHOLNPAIR_P(PSTR("T"), int(e), PSTR(" Hotend Offset X"), hotend_offset[e].x, SP_Y_STR, hotend_offset[e].y, SP_Z_STR, hotend_offset[e].z);
|
2019-02-06 23:20:17 +00:00
|
|
|
}
|
|
|
|
#endif
|
2019-09-14 08:05:10 +00:00
|
|
|
|
2019-02-06 23:20:17 +00:00
|
|
|
#endif // CALIBRATION_REPORTING
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Probe around the calibration object to measure backlash
|
|
|
|
*
|
|
|
|
* m in/out - Measurement record, updated with new readings
|
|
|
|
* uncertainty in - How far away from the object to begin probing
|
|
|
|
*/
|
|
|
|
inline void calibrate_backlash(measurements_t &m, const float uncertainty) {
|
|
|
|
// Backlash compensation should be off while measuring backlash
|
|
|
|
|
|
|
|
{
|
2019-02-14 22:45:31 +00:00
|
|
|
// New scope for TEMPORARY_BACKLASH_CORRECTION
|
2019-03-29 19:07:43 +00:00
|
|
|
TEMPORARY_BACKLASH_CORRECTION(all_off);
|
2019-02-14 22:45:31 +00:00
|
|
|
TEMPORARY_BACKLASH_SMOOTHING(0.0f);
|
2019-02-06 23:20:17 +00:00
|
|
|
|
|
|
|
probe_sides(m, uncertainty);
|
|
|
|
|
|
|
|
#if ENABLED(BACKLASH_GCODE)
|
2020-03-28 03:00:27 +00:00
|
|
|
|
2019-02-06 23:20:17 +00:00
|
|
|
#if HAS_X_CENTER
|
2019-09-29 09:25:39 +00:00
|
|
|
backlash.distance_mm.x = (m.backlash[LEFT] + m.backlash[RIGHT]) / 2;
|
2019-02-06 23:20:17 +00:00
|
|
|
#elif ENABLED(CALIBRATION_MEASURE_LEFT)
|
2019-09-29 09:25:39 +00:00
|
|
|
backlash.distance_mm.x = m.backlash[LEFT];
|
2019-02-06 23:20:17 +00:00
|
|
|
#elif ENABLED(CALIBRATION_MEASURE_RIGHT)
|
2019-09-29 09:25:39 +00:00
|
|
|
backlash.distance_mm.x = m.backlash[RIGHT];
|
2019-02-06 23:20:17 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAS_Y_CENTER
|
2019-09-29 09:25:39 +00:00
|
|
|
backlash.distance_mm.y = (m.backlash[FRONT] + m.backlash[BACK]) / 2;
|
2019-02-06 23:20:17 +00:00
|
|
|
#elif ENABLED(CALIBRATION_MEASURE_FRONT)
|
2019-09-29 09:25:39 +00:00
|
|
|
backlash.distance_mm.y = m.backlash[FRONT];
|
2019-02-06 23:20:17 +00:00
|
|
|
#elif ENABLED(CALIBRATION_MEASURE_BACK)
|
2019-09-29 09:25:39 +00:00
|
|
|
backlash.distance_mm.y = m.backlash[BACK];
|
2019-02-06 23:20:17 +00:00
|
|
|
#endif
|
|
|
|
|
2020-03-28 03:00:27 +00:00
|
|
|
if (AXIS_CAN_CALIBRATE(Z)) backlash.distance_mm.z = m.backlash[TOP];
|
2019-02-06 23:20:17 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#if ENABLED(BACKLASH_GCODE)
|
|
|
|
// Turn on backlash compensation and move in all
|
2020-03-28 03:00:27 +00:00
|
|
|
// allowed directions to take up any backlash
|
2019-02-06 23:20:17 +00:00
|
|
|
{
|
2019-02-14 22:45:31 +00:00
|
|
|
// New scope for TEMPORARY_BACKLASH_CORRECTION
|
2019-03-29 19:07:43 +00:00
|
|
|
TEMPORARY_BACKLASH_CORRECTION(all_on);
|
2019-02-14 22:45:31 +00:00
|
|
|
TEMPORARY_BACKLASH_SMOOTHING(0.0f);
|
2020-03-28 03:00:27 +00:00
|
|
|
const xyz_float_t move = { AXIS_CAN_CALIBRATE(X) * 3, AXIS_CAN_CALIBRATE(Y) * 3, AXIS_CAN_CALIBRATE(Z) * 3 };
|
2019-09-29 09:25:39 +00:00
|
|
|
current_position += move; calibration_move();
|
|
|
|
current_position -= move; calibration_move();
|
2019-02-06 23:20:17 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void update_measurements(measurements_t &m, const AxisEnum axis) {
|
|
|
|
current_position[axis] += m.pos_error[axis];
|
2019-02-14 22:45:31 +00:00
|
|
|
m.obj_center[axis] = true_center[axis];
|
2019-02-06 23:20:17 +00:00
|
|
|
m.pos_error[axis] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Probe around the calibration object. Adjust the position and toolhead offset
|
|
|
|
* using the deviation from the known position of the calibration object.
|
|
|
|
*
|
|
|
|
* m in/out - Measurement record, updated with new readings
|
|
|
|
* uncertainty in - How far away from the object to begin probing
|
|
|
|
* extruder in - What extruder to probe
|
|
|
|
*
|
|
|
|
* Prerequisites:
|
|
|
|
* - Call calibrate_backlash() beforehand for best accuracy
|
|
|
|
*/
|
|
|
|
inline void calibrate_toolhead(measurements_t &m, const float uncertainty, const uint8_t extruder) {
|
2019-03-29 19:07:43 +00:00
|
|
|
TEMPORARY_BACKLASH_CORRECTION(all_on);
|
2019-02-14 22:45:31 +00:00
|
|
|
TEMPORARY_BACKLASH_SMOOTHING(0.0f);
|
2019-02-06 23:20:17 +00:00
|
|
|
|
|
|
|
#if HOTENDS > 1
|
|
|
|
set_nozzle(m, extruder);
|
2019-06-29 05:23:57 +00:00
|
|
|
#else
|
|
|
|
UNUSED(extruder);
|
2019-02-06 23:20:17 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
probe_sides(m, uncertainty);
|
|
|
|
|
2019-02-14 22:45:31 +00:00
|
|
|
// Adjust the hotend offset
|
2019-03-09 04:13:24 +00:00
|
|
|
#if HAS_HOTEND_OFFSET
|
2020-03-28 03:00:27 +00:00
|
|
|
if (ENABLED(HAS_X_CENTER) && AXIS_CAN_CALIBRATE(X)) hotend_offset[extruder].x += m.pos_error.x;
|
|
|
|
if (ENABLED(HAS_Y_CENTER) && AXIS_CAN_CALIBRATE(Y)) hotend_offset[extruder].y += m.pos_error.y;
|
|
|
|
if (AXIS_CAN_CALIBRATE(Z)) hotend_offset[extruder].z += m.pos_error.z;
|
2019-02-06 23:20:17 +00:00
|
|
|
normalize_hotend_offsets();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Correct for positional error, so the object
|
|
|
|
// is at the known actual spot
|
|
|
|
planner.synchronize();
|
2020-03-28 03:00:27 +00:00
|
|
|
if (ENABLED(HAS_X_CENTER) && AXIS_CAN_CALIBRATE(X)) update_measurements(m, X_AXIS);
|
|
|
|
if (ENABLED(HAS_Y_CENTER) && AXIS_CAN_CALIBRATE(Y)) update_measurements(m, Y_AXIS);
|
|
|
|
if (AXIS_CAN_CALIBRATE(Z)) update_measurements(m, Z_AXIS);
|
2019-02-06 23:20:17 +00:00
|
|
|
|
|
|
|
sync_plan_position();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Probe around the calibration object for all toolheads, adjusting the coordinate
|
|
|
|
* system for the first nozzle and the nozzle offset for subsequent nozzles.
|
|
|
|
*
|
|
|
|
* m in/out - Measurement record, updated with new readings
|
|
|
|
* uncertainty in - How far away from the object to begin probing
|
|
|
|
*/
|
|
|
|
inline void calibrate_all_toolheads(measurements_t &m, const float uncertainty) {
|
2019-03-29 19:07:43 +00:00
|
|
|
TEMPORARY_BACKLASH_CORRECTION(all_on);
|
2019-02-14 22:45:31 +00:00
|
|
|
TEMPORARY_BACKLASH_SMOOTHING(0.0f);
|
2019-02-06 23:20:17 +00:00
|
|
|
|
|
|
|
HOTEND_LOOP() calibrate_toolhead(m, uncertainty, e);
|
|
|
|
|
2019-03-09 04:13:24 +00:00
|
|
|
#if HAS_HOTEND_OFFSET
|
2019-02-06 23:20:17 +00:00
|
|
|
normalize_hotend_offsets();
|
2019-03-09 04:13:24 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HOTENDS > 1
|
2019-02-06 23:20:17 +00:00
|
|
|
set_nozzle(m, 0);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Perform a full auto-calibration routine:
|
|
|
|
*
|
|
|
|
* 1) For each nozzle, touch top and sides of object to determine object position and
|
|
|
|
* nozzle offsets. Do a fast but rough search over a wider area.
|
|
|
|
* 2) With the first nozzle, touch top and sides of object to determine backlash values
|
|
|
|
* for all axis (if BACKLASH_GCODE is enabled)
|
|
|
|
* 3) For each nozzle, touch top and sides of object slowly to determine precise
|
|
|
|
* position of object. Adjust coordinate system and nozzle offsets so probed object
|
|
|
|
* location corresponds to known object location with a high degree of precision.
|
|
|
|
*/
|
|
|
|
inline void calibrate_all() {
|
|
|
|
measurements_t m;
|
|
|
|
|
2019-03-09 04:13:24 +00:00
|
|
|
#if HAS_HOTEND_OFFSET
|
|
|
|
reset_hotend_offsets();
|
2019-02-06 23:20:17 +00:00
|
|
|
#endif
|
|
|
|
|
2019-03-29 19:07:43 +00:00
|
|
|
TEMPORARY_BACKLASH_CORRECTION(all_on);
|
2019-02-14 22:45:31 +00:00
|
|
|
TEMPORARY_BACKLASH_SMOOTHING(0.0f);
|
2019-02-06 23:20:17 +00:00
|
|
|
|
2019-02-14 22:45:31 +00:00
|
|
|
// Do a fast and rough calibration of the toolheads
|
2019-02-06 23:20:17 +00:00
|
|
|
calibrate_all_toolheads(m, CALIBRATION_MEASUREMENT_UNKNOWN);
|
|
|
|
|
|
|
|
#if ENABLED(BACKLASH_GCODE)
|
|
|
|
calibrate_backlash(m, CALIBRATION_MEASUREMENT_UNCERTAIN);
|
|
|
|
#endif
|
|
|
|
|
2019-02-14 22:45:31 +00:00
|
|
|
// Cycle the toolheads so the servos settle into their "natural" positions
|
2019-02-06 23:20:17 +00:00
|
|
|
#if HOTENDS > 1
|
|
|
|
HOTEND_LOOP() set_nozzle(m, e);
|
|
|
|
#endif
|
|
|
|
|
2019-02-14 22:45:31 +00:00
|
|
|
// Do a slow and precise calibration of the toolheads
|
2019-02-06 23:20:17 +00:00
|
|
|
calibrate_all_toolheads(m, CALIBRATION_MEASUREMENT_UNCERTAIN);
|
|
|
|
|
2019-09-29 09:25:39 +00:00
|
|
|
current_position.x = X_CENTER;
|
|
|
|
calibration_move(); // Park nozzle away from calibration object
|
2019-02-06 23:20:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* G425: Perform calibration with calibration object.
|
|
|
|
*
|
|
|
|
* B - Perform calibration of backlash only.
|
|
|
|
* T<extruder> - Perform calibration of toolhead only.
|
|
|
|
* V - Probe object and print position, error, backlash and hotend offset.
|
|
|
|
* U - Uncertainty, how far to start probe away from the object (mm)
|
|
|
|
*
|
|
|
|
* no args - Perform entire calibration sequence (backlash + position on all toolheads)
|
|
|
|
*/
|
|
|
|
void GcodeSuite::G425() {
|
2019-02-14 22:45:31 +00:00
|
|
|
TEMPORARY_SOFT_ENDSTOP_STATE(false);
|
|
|
|
TEMPORARY_BED_LEVELING_STATE(false);
|
|
|
|
|
2019-02-06 23:20:17 +00:00
|
|
|
if (axis_unhomed_error()) return;
|
|
|
|
|
|
|
|
measurements_t m;
|
|
|
|
|
|
|
|
float uncertainty = parser.seenval('U') ? parser.value_float() : CALIBRATION_MEASUREMENT_UNCERTAIN;
|
|
|
|
|
|
|
|
if (parser.seen('B'))
|
|
|
|
calibrate_backlash(m, uncertainty);
|
|
|
|
else if (parser.seen('T'))
|
|
|
|
calibrate_toolhead(m, uncertainty, parser.has_value() ? parser.value_int() : active_extruder);
|
|
|
|
#if ENABLED(CALIBRATION_REPORTING)
|
|
|
|
else if (parser.seen('V')) {
|
|
|
|
probe_sides(m, uncertainty);
|
|
|
|
SERIAL_EOL();
|
|
|
|
report_measured_faces(m);
|
|
|
|
report_measured_center(m);
|
|
|
|
report_measured_backlash(m);
|
|
|
|
report_measured_nozzle_dimensions(m);
|
|
|
|
report_measured_positional_error(m);
|
2019-03-12 01:48:49 +00:00
|
|
|
#if HAS_HOTEND_OFFSET
|
2019-02-06 23:20:17 +00:00
|
|
|
normalize_hotend_offsets();
|
|
|
|
report_hotend_offsets();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
else
|
|
|
|
calibrate_all();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // CALIBRATION_GCODE
|