⚡️ Apply PTC on all probing (#23764)
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
This commit is contained in:
parent
a9682f2e97
commit
8f8427ec8f
|
@ -28,6 +28,7 @@
|
|||
|
||||
#include "probe_temp_comp.h"
|
||||
#include <math.h>
|
||||
#include "../module/temperature.h"
|
||||
|
||||
ProbeTempComp ptc;
|
||||
|
||||
|
@ -62,6 +63,7 @@ constexpr temp_calib_t ProbeTempComp::cali_info[TSI_COUNT];
|
|||
|
||||
uint8_t ProbeTempComp::calib_idx; // = 0
|
||||
float ProbeTempComp::init_measurement; // = 0.0
|
||||
bool ProbeTempComp::enabled = true;
|
||||
|
||||
void ProbeTempComp::reset() {
|
||||
TERN_(PTC_PROBE, LOOP_L_N(i, PTC_PROBE_COUNT) z_offsets_probe[i] = z_offsets_probe_default[i]);
|
||||
|
@ -169,6 +171,13 @@ bool ProbeTempComp::finish_calibration(const TempSensorID tsi) {
|
|||
return true;
|
||||
}
|
||||
|
||||
void ProbeTempComp::apply_compensation(float &meas_z) {
|
||||
if (!enabled) return;
|
||||
TERN_(PTC_BED, compensate_measurement(TSI_BED, thermalManager.degBed(), meas_z));
|
||||
TERN_(PTC_PROBE, compensate_measurement(TSI_PROBE, thermalManager.degProbe(), meas_z));
|
||||
TERN_(PTC_HOTEND, compensate_measurement(TSI_EXT, thermalManager.degHotend(0), meas_z));
|
||||
}
|
||||
|
||||
void ProbeTempComp::compensate_measurement(const TempSensorID tsi, const celsius_t temp, float &meas_z) {
|
||||
const uint8_t measurements = cali_info[tsi].measurements;
|
||||
const celsius_t start_temp = cali_info[tsi].start_temp,
|
||||
|
|
|
@ -77,7 +77,6 @@ class ProbeTempComp {
|
|||
static void reset_index() { calib_idx = 0; };
|
||||
static uint8_t get_index() { return calib_idx; }
|
||||
static void reset();
|
||||
static void clear_offsets(const TempSensorID tsi);
|
||||
static void clear_all_offsets() {
|
||||
TERN_(PTC_PROBE, clear_offsets(TSI_PROBE));
|
||||
TERN_(PTC_BED, clear_offsets(TSI_BED));
|
||||
|
@ -88,10 +87,16 @@ class ProbeTempComp {
|
|||
static void prepare_new_calibration(const_float_t init_meas_z);
|
||||
static void push_back_new_measurement(const TempSensorID tsi, const_float_t meas_z);
|
||||
static bool finish_calibration(const TempSensorID tsi);
|
||||
static void compensate_measurement(const TempSensorID tsi, const celsius_t temp, float &meas_z);
|
||||
static void set_enabled(const bool ena) { enabled = ena; }
|
||||
|
||||
// Apply all temperature compensation adjustments
|
||||
static void apply_compensation(float &meas_z);
|
||||
|
||||
private:
|
||||
static uint8_t calib_idx;
|
||||
static bool enabled;
|
||||
|
||||
static void clear_offsets(const TempSensorID tsi);
|
||||
|
||||
/**
|
||||
* Base value. Temperature compensation values will be deltas
|
||||
|
@ -104,6 +109,8 @@ class ProbeTempComp {
|
|||
* to allow generating values of higher temperatures.
|
||||
*/
|
||||
static bool linear_regression(const TempSensorID tsi, float &k, float &d);
|
||||
|
||||
static void compensate_measurement(const TempSensorID tsi, const celsius_t temp, float &meas_z);
|
||||
};
|
||||
|
||||
extern ProbeTempComp ptc;
|
||||
|
|
|
@ -36,11 +36,6 @@
|
|||
#include "../../../module/probe.h"
|
||||
#include "../../queue.h"
|
||||
|
||||
#if HAS_PTC
|
||||
#include "../../../feature/probe_temp_comp.h"
|
||||
#include "../../../module/temperature.h"
|
||||
#endif
|
||||
|
||||
#if HAS_STATUS_MESSAGE
|
||||
#include "../../../lcd/marlinui.h"
|
||||
#endif
|
||||
|
@ -658,10 +653,6 @@ G29_TYPE GcodeSuite::G29() {
|
|||
break; // Breaks out of both loops
|
||||
}
|
||||
|
||||
TERN_(PTC_BED, ptc.compensate_measurement(TSI_BED, thermalManager.degBed(), abl.measured_z));
|
||||
TERN_(PTC_PROBE, ptc.compensate_measurement(TSI_PROBE, thermalManager.degProbe(), abl.measured_z));
|
||||
TERN_(PTC_HOTEND, ptc.compensate_measurement(TSI_EXT, thermalManager.degHotend(0), abl.measured_z));
|
||||
|
||||
#if ENABLED(AUTO_BED_LEVELING_LINEAR)
|
||||
|
||||
abl.mean += abl.measured_z;
|
||||
|
|
|
@ -109,7 +109,9 @@ static void say_failed_to_calibrate() { SERIAL_ECHOPGM("!Failed to calibra
|
|||
|
||||
auto g76_probe = [](const TempSensorID sid, celsius_t &targ, const xy_pos_t &nozpos) {
|
||||
do_z_clearance(5.0); // Raise nozzle before probing
|
||||
ptc.set_enabled(false);
|
||||
const float measured_z = probe.probe_at_point(nozpos, PROBE_PT_STOW, 0, false); // verbose=0, probe_relative=false
|
||||
ptc.set_enabled(true);
|
||||
if (isnan(measured_z))
|
||||
SERIAL_ECHOLNPGM("!Received NAN. Aborting.");
|
||||
else {
|
||||
|
|
|
@ -35,11 +35,15 @@
|
|||
#include "../../module/planner.h"
|
||||
#endif
|
||||
|
||||
#if HAS_PTC
|
||||
#include "../../feature/probe_temp_comp.h"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* M48: Z probe repeatability measurement function.
|
||||
*
|
||||
* Usage:
|
||||
* M48 <P#> <X#> <Y#> <V#> <E> <L#> <S>
|
||||
* M48 <P#> <X#> <Y#> <V#> <E> <L#> <S> <C#>
|
||||
* P = Number of sampled points (4-50, default 10)
|
||||
* X = Sample X position
|
||||
* Y = Sample Y position
|
||||
|
@ -47,6 +51,7 @@
|
|||
* E = Engage Z probe for each reading
|
||||
* L = Number of legs of movement before probe
|
||||
* S = Schizoid (Or Star if you prefer)
|
||||
* C = Enable probe temperature compensation (0 or 1, default 1)
|
||||
*
|
||||
* This function requires the machine to be homed before invocation.
|
||||
*/
|
||||
|
@ -107,6 +112,8 @@ void GcodeSuite::M48() {
|
|||
set_bed_leveling_enabled(false);
|
||||
#endif
|
||||
|
||||
TERN_(HAS_PTC, ptc.set_enabled(!parser.seen('C') || parser.value_bool()));
|
||||
|
||||
// Work with reasonable feedrates
|
||||
remember_feedrate_scaling_off();
|
||||
|
||||
|
@ -269,6 +276,9 @@ void GcodeSuite::M48() {
|
|||
// Re-enable bed level correction if it had been on
|
||||
TERN_(HAS_LEVELING, set_bed_leveling_enabled(was_enabled));
|
||||
|
||||
// Re-enable probe temperature correction
|
||||
TERN_(HAS_PTC, ptc.set_enabled(true));
|
||||
|
||||
report_current_position();
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,10 @@
|
|||
#include "../../module/probe.h"
|
||||
#include "../../feature/bedlevel/bedlevel.h"
|
||||
|
||||
#if HAS_PTC
|
||||
#include "../../feature/probe_temp_comp.h"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* G30: Do a single Z probe at the current XY
|
||||
*
|
||||
|
@ -37,6 +41,7 @@
|
|||
* X Probe X position (default current X)
|
||||
* Y Probe Y position (default current Y)
|
||||
* E Engage the probe for each probe (default 1)
|
||||
* C Enable probe temperature compensation (0 or 1, default 1)
|
||||
*/
|
||||
void GcodeSuite::G30() {
|
||||
|
||||
|
@ -51,7 +56,10 @@ void GcodeSuite::G30() {
|
|||
remember_feedrate_scaling_off();
|
||||
|
||||
const ProbePtRaise raise_after = parser.boolval('E', true) ? PROBE_PT_STOW : PROBE_PT_NONE;
|
||||
|
||||
TERN_(HAS_PTC, ptc.set_enabled(!parser.seen('C') || parser.value_bool()));
|
||||
const float measured_z = probe.probe_at_point(pos, raise_after, 1);
|
||||
TERN_(HAS_PTC, ptc.set_enabled(true));
|
||||
if (!isnan(measured_z))
|
||||
SERIAL_ECHOLNPGM("Bed X: ", pos.x, " Y: ", pos.y, " Z: ", measured_z);
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ void probe_offset_wizard_menu() {
|
|||
if (LCD_HEIGHT >= 4)
|
||||
STATIC_ITEM(MSG_MOVE_NOZZLE_TO_BED, SS_CENTER|SS_INVERT);
|
||||
|
||||
STATIC_ITEM_P(PSTR("Z="), SS_CENTER, ftostr42_52(current_position.z));
|
||||
STATIC_ITEM_P(PSTR("Z"), SS_CENTER, ftostr42_52(current_position.z));
|
||||
STATIC_ITEM(MSG_ZPROBE_ZOFFSET, SS_LEFT, ftostr42_52(calculated_z_offset));
|
||||
|
||||
SUBMENU(MSG_MOVE_1MM, []{ _goto_manual_move_z( 1); });
|
||||
|
|
|
@ -77,6 +77,10 @@
|
|||
#include "servo.h"
|
||||
#endif
|
||||
|
||||
#if HAS_PTC
|
||||
#include "../feature/probe_temp_comp.h"
|
||||
#endif
|
||||
|
||||
#if ENABLED(EXTENSIBLE_UI)
|
||||
#include "../lcd/extui/ui_api.h"
|
||||
#elif ENABLED(DWIN_CREALITY_LCD_ENHANCED)
|
||||
|
@ -801,7 +805,10 @@ float Probe::probe_at_point(const_float_t rx, const_float_t ry, const ProbePtRai
|
|||
do_blocking_move_to(npos, feedRate_t(XY_PROBE_FEEDRATE_MM_S));
|
||||
|
||||
float measured_z = NAN;
|
||||
if (!deploy()) measured_z = run_z_probe(sanity_check) + offset.z;
|
||||
if (!deploy()) {
|
||||
measured_z = run_z_probe(sanity_check) + offset.z;
|
||||
TERN_(HAS_PTC, ptc.apply_compensation(measured_z));
|
||||
}
|
||||
if (!isnan(measured_z)) {
|
||||
const bool big_raise = raise_after == PROBE_PT_BIG_RAISE;
|
||||
if (big_raise || raise_after == PROBE_PT_RAISE)
|
||||
|
|
Loading…
Reference in a new issue