Skip to content

Commit d6f39a6

Browse files
authored
Fix G76 probe height / position (#17392)
1 parent 1d81bb7 commit d6f39a6

6 files changed

Lines changed: 67 additions & 66 deletions

File tree

Marlin/Configuration_adv.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,18 +1600,11 @@
16001600
// Add additional compensation depending on hotend temperature
16011601
// Note: this values cannot be calibrated and have to be set manually
16021602
#if ENABLED(PROBE_TEMP_COMPENSATION)
1603-
// Max temperature that can be reached by heated bed.
1604-
// This is required only for the calibration process.
1605-
#define PTC_MAX_BED_TEMP BED_MAXTEMP
1606-
16071603
// Park position to wait for probe cooldown
1608-
#define PTC_PARK_POS_X 0.0F
1609-
#define PTC_PARK_POS_Y 0.0F
1610-
#define PTC_PARK_POS_Z 100.0F
1604+
#define PTC_PARK_POS { 0, 0, 100 }
16111605

16121606
// Probe position to probe and wait for probe to reach target temperature
1613-
#define PTC_PROBE_POS_X 90.0F
1614-
#define PTC_PROBE_POS_Y 100.0F
1607+
#define PTC_PROBE_POS { 90, 100 }
16151608

16161609
// Enable additional compensation using hotend temperature
16171610
// Note: this values cannot be calibrated automatically but have to be set manually

Marlin/src/feature/probe_temp_comp.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929

3030
ProbeTempComp temp_comp;
3131

32-
int16_t ProbeTempComp::z_offsets_probe[ProbeTempComp::cali_info_init[TSI_PROBE].measurements], // = {0}
33-
ProbeTempComp::z_offsets_bed[ProbeTempComp::cali_info_init[TSI_BED].measurements]; // = {0}
32+
int16_t ProbeTempComp::z_offsets_probe[cali_info_init[TSI_PROBE].measurements], // = {0}
33+
ProbeTempComp::z_offsets_bed[cali_info_init[TSI_BED].measurements]; // = {0}
3434

3535
#if ENABLED(USE_TEMP_EXT_COMPENSATION)
36-
int16_t ProbeTempComp::z_offsets_ext[ProbeTempComp::cali_info_init[TSI_EXT].measurements]; // = {0}
36+
int16_t ProbeTempComp::z_offsets_ext[cali_info_init[TSI_EXT].measurements]; // = {0}
3737
#endif
3838

3939
int16_t *ProbeTempComp::sensor_z_offsets[TSI_COUNT] = {
@@ -44,9 +44,9 @@ int16_t *ProbeTempComp::sensor_z_offsets[TSI_COUNT] = {
4444
};
4545

4646
const temp_calib_t ProbeTempComp::cali_info[TSI_COUNT] = {
47-
ProbeTempComp::cali_info_init[TSI_PROBE], ProbeTempComp::cali_info_init[TSI_BED]
47+
cali_info_init[TSI_PROBE], cali_info_init[TSI_BED]
4848
#if ENABLED(USE_TEMP_EXT_COMPENSATION)
49-
, ProbeTempComp::cali_info_init[TSI_EXT]
49+
, cali_info_init[TSI_EXT]
5050
#endif
5151
};
5252

Marlin/src/feature/probe_temp_comp.h

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,30 +44,28 @@ typedef struct {
4444
* Z-probes like the P.I.N.D.A V2 allow for compensation of
4545
* measurement errors/shifts due to changed temperature.
4646
*/
47+
48+
static constexpr temp_calib_t cali_info_init[TSI_COUNT] = {
49+
{ 10, 5, 30, 30 + 10 * 5 }, // Probe
50+
{ 10, 5, 60, 60 + 10 * 5 }, // Bed
51+
#if ENABLED(USE_TEMP_EXT_COMPENSATION)
52+
{ 20, 5, 180, 180 + 5 * 20 } // Extruder
53+
#endif
54+
};
55+
4756
class ProbeTempComp {
4857
public:
4958

50-
static constexpr temp_calib_t cali_info_init[TSI_COUNT] = {
51-
{ 10, 5, 30, 30 + 10 * 5 }, // Probe
52-
{ 10, 5, 60, 60 + 10 * 5 }, // Bed
53-
#if ENABLED(USE_TEMP_EXT_COMPENSATION)
54-
{ 20, 5, 180, 180 + 5 * 20 } // Extruder
55-
#endif
56-
};
5759
static const temp_calib_t cali_info[TSI_COUNT];
5860

5961
// Where to park nozzle to wait for probe cooldown
60-
static constexpr float park_point_x = PTC_PARK_POS_X,
61-
park_point_y = PTC_PARK_POS_Y,
62-
park_point_z = PTC_PARK_POS_Z,
63-
// XY coordinates of nozzle for probing the bed
64-
measure_point_x = PTC_PROBE_POS_X, // Coordinates to probe
65-
measure_point_y = PTC_PROBE_POS_Y;
66-
//measure_point_x = 12.0f, // Coordinates to probe on MK52 magnetic heatbed
67-
//measure_point_y = 7.3f;
68-
69-
static constexpr int max_bed_temp = PTC_MAX_BED_TEMP, // Max temperature to avoid heating errors
70-
probe_calib_bed_temp = max_bed_temp, // Bed temperature while calibrating probe
62+
static constexpr xyz_pos_t park_point = PTC_PARK_POS;
63+
64+
// XY coordinates of nozzle for probing the bed
65+
static constexpr xy_pos_t measure_point = PTC_PROBE_POS; // Coordinates to probe
66+
//measure_point = { 12.0f, 7.3f }; // Coordinates for the MK52 magnetic heatbed
67+
68+
static constexpr int probe_calib_bed_temp = BED_MAXTEMP - 10, // Bed temperature while calibrating probe
7169
bed_calib_probe_temp = 30; // Probe temperature while calibrating bed
7270

7371
static int16_t *sensor_z_offsets[TSI_COUNT],

Marlin/src/gcode/calibrate/G76_M871.cpp

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,19 @@ void GcodeSuite::G76() {
103103
return false;
104104
};
105105

106-
auto g76_probe = [](const xy_pos_t &xypos) {
106+
auto g76_probe = [](const TempSensorID sid, uint16_t &targ, const xy_pos_t &nozpos) {
107107
do_blocking_move_to_z(5.0); // Raise nozzle before probing
108-
const float measured_z = probe.probe_at_point(xypos, PROBE_PT_NONE, 0, false); // verbose=0, probe_relative=false
108+
const float measured_z = probe.probe_at_point(nozpos, PROBE_PT_NONE, 0, false); // verbose=0, probe_relative=false
109109
if (isnan(measured_z))
110110
SERIAL_ECHOLNPGM("!Received NAN. Aborting.");
111-
else
111+
else {
112112
SERIAL_ECHOLNPAIR_F("Measured: ", measured_z);
113+
if (targ == cali_info_init[sid].start_temp)
114+
temp_comp.prepare_new_calibration(measured_z);
115+
else
116+
temp_comp.push_back_new_measurement(sid, measured_z);
117+
targ += cali_info_init[sid].temp_res;
118+
}
113119
return measured_z;
114120
};
115121

@@ -125,8 +131,9 @@ void GcodeSuite::G76() {
125131
// Synchronize with planner
126132
planner.synchronize();
127133

128-
const xyz_pos_t parkpos = { temp_comp.park_point_x, temp_comp.park_point_y, temp_comp.park_point_z };
129-
const xy_pos_t ppos = { temp_comp.measure_point_x, temp_comp.measure_point_y };
134+
const xyz_pos_t parkpos = temp_comp.park_point,
135+
probe_pos_xyz = temp_comp.measure_point + xyz_pos_t({ 0.0f, 0.0f, 0.5f }),
136+
noz_pos_xyz = probe_pos_xyz - probe.offset_xy; // Nozzle position based on probe position
130137

131138
if (do_bed_cal || do_probe_cal) {
132139
// Ensure park position is reachable
@@ -135,7 +142,7 @@ void GcodeSuite::G76() {
135142
SERIAL_ECHOLNPGM("!Park");
136143
else {
137144
// Ensure probe position is reachable
138-
reachable = probe.can_reach(ppos);
145+
reachable = probe.can_reach(probe_pos_xyz);
139146
if (!reachable) SERIAL_ECHOLNPGM("!Probe");
140147
}
141148

@@ -149,8 +156,6 @@ void GcodeSuite::G76() {
149156

150157
remember_feedrate_scaling_off();
151158

152-
// Nozzle position based on probe position
153-
const xy_pos_t noz_pos = ppos - probe.offset_xy;
154159

155160
/******************************************
156161
* Calibrate bed temperature offsets
@@ -159,9 +164,13 @@ void GcodeSuite::G76() {
159164
// Report temperatures every second and handle heating timeouts
160165
millis_t next_temp_report = millis() + 1000;
161166

167+
auto report_targets = [&](const uint16_t tb, const uint16_t tp) {
168+
SERIAL_ECHOLNPAIR("Target Bed:", tb, " Probe:", tp);
169+
};
170+
162171
if (do_bed_cal) {
163172

164-
uint16_t target_bed = temp_comp.cali_info_init[TSI_BED].start_temp,
173+
uint16_t target_bed = cali_info_init[TSI_BED].start_temp,
165174
target_probe = temp_comp.bed_calib_probe_temp;
166175

167176
SERIAL_ECHOLNPGM("Waiting for cooling.");
@@ -176,7 +185,7 @@ void GcodeSuite::G76() {
176185
for (;;) {
177186
thermalManager.setTargetBed(target_bed);
178187

179-
SERIAL_ECHOLNPAIR("Target Bed:", target_bed, " Probe:", target_probe);
188+
report_targets(target_bed, target_probe);
180189

181190
// Park nozzle
182191
do_blocking_move_to(parkpos);
@@ -188,21 +197,13 @@ void GcodeSuite::G76() {
188197
}
189198

190199
// Move the nozzle to the probing point and wait for the probe to reach target temp
191-
do_blocking_move_to_xy(noz_pos);
200+
do_blocking_move_to(noz_pos_xyz);
192201
SERIAL_ECHOLNPGM("Waiting for probe heating.");
193202
while (thermalManager.degProbe() < target_probe)
194203
report_temps(next_temp_report);
195204

196-
const float measured_z = g76_probe(noz_pos);
197-
if (isnan(measured_z)) break;
198-
199-
if (target_bed == temp_comp.cali_info_init[TSI_BED].start_temp)
200-
temp_comp.prepare_new_calibration(measured_z);
201-
else
202-
temp_comp.push_back_new_measurement(TSI_BED, measured_z);
203-
204-
target_bed += temp_comp.cali_info_init[TSI_BED].temp_res;
205-
if (target_bed > temp_comp.max_bed_temp) break;
205+
const float measured_z = g76_probe(TSI_BED, target_bed, noz_pos_xyz);
206+
if (isnan(measured_z) || target_bed > BED_MAXTEMP - 10) break;
206207
}
207208

208209
SERIAL_ECHOLNPAIR("Retrieved measurements: ", temp_comp.get_index());
@@ -231,7 +232,9 @@ void GcodeSuite::G76() {
231232
const uint16_t target_bed = temp_comp.probe_calib_bed_temp;
232233
thermalManager.setTargetBed(target_bed);
233234

234-
uint16_t target_probe = temp_comp.cali_info_init[TSI_PROBE].start_temp;
235+
uint16_t target_probe = cali_info_init[TSI_PROBE].start_temp;
236+
237+
report_targets(target_bed, target_probe);
235238

236239
// Wait for heatbed to reach target temp and probe to cool below target temp
237240
wait_for_temps(target_bed, target_probe, next_temp_report);
@@ -244,7 +247,7 @@ void GcodeSuite::G76() {
244247
bool timeout = false;
245248
for (;;) {
246249
// Move probe to probing point and wait for it to reach target temperature
247-
do_blocking_move_to_xy(noz_pos);
250+
do_blocking_move_to(noz_pos_xyz);
248251

249252
SERIAL_ECHOLNPAIR("Waiting for probe heating. Bed:", target_bed, " Probe:", target_probe);
250253
const millis_t probe_timeout_ms = millis() + 900UL * 1000UL;
@@ -257,16 +260,8 @@ void GcodeSuite::G76() {
257260
}
258261
if (timeout) break;
259262

260-
const float measured_z = g76_probe(noz_pos);
261-
if (isnan(measured_z)) break;
262-
263-
if (target_probe == temp_comp.cali_info_init[TSI_PROBE].start_temp)
264-
temp_comp.prepare_new_calibration(measured_z);
265-
else
266-
temp_comp.push_back_new_measurement(TSI_PROBE, measured_z);
267-
268-
target_probe += temp_comp.cali_info_init[TSI_PROBE].temp_res;
269-
if (target_probe > temp_comp.cali_info_init[TSI_PROBE].end_temp) break;
263+
const float measured_z = g76_probe(TSI_PROBE, target_probe, noz_pos_xyz);
264+
if (isnan(measured_z) || target_probe > cali_info_init[TSI_PROBE].end_temp) break;
270265
}
271266

272267
SERIAL_ECHOLNPAIR("Retrieved measurements: ", temp_comp.get_index());

Marlin/src/inc/SanityCheck.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,21 @@
491491
#error "DUGS_UI_MOVE_DIS_OPTION is spelled DGUS_UI_MOVE_DIS_OPTION. Please update Configuration_adv.h."
492492
#endif
493493

494+
/**
495+
* Probe temp compensation requirements
496+
*/
497+
#if ENABLED(PROBE_TEMP_COMPENSATION)
498+
#if defined(PTC_PARK_POS_X) || defined(PTC_PARK_POS_Y) || defined(PTC_PARK_POS_Z)
499+
#error "PTC_PARK_POS_[XYZ] is now PTC_PARK_POS (array). Please update Configuration_adv.h."
500+
#elif !defined(PTC_PARK_POS)
501+
#error "PROBE_TEMP_COMPENSATION requires PTC_PARK_POS."
502+
#elif defined(PTC_PROBE_POS_X) || defined(PTC_PROBE_POS_Y)
503+
#error "PTC_PROBE_POS_[XY] is now PTC_PROBE_POS (array). Please update Configuration_adv.h."
504+
#elif !defined(PTC_PROBE_POS)
505+
#error "PROBE_TEMP_COMPENSATION requires PTC_PROBE_POS."
506+
#endif
507+
#endif
508+
494509
/**
495510
* Marlin release, version and default string
496511
*/

buildroot/share/tests/rambo-tests

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ opt_set GRID_MAX_POINTS_X 16
5050
opt_set FANMUX0_PIN 53
5151
opt_disable USE_WATCHDOG
5252
opt_enable REPRAP_DISCOUNT_SMART_CONTROLLER LCD_PROGRESS_BAR LCD_PROGRESS_BAR_TEST \
53-
FIX_MOUNTED_PROBE Z_SAFE_HOMING CODEPENDENT_XY_HOMING PIDTEMPBED \
53+
FIX_MOUNTED_PROBE Z_SAFE_HOMING CODEPENDENT_XY_HOMING PIDTEMPBED PROBE_TEMP_COMPENSATION \
5454
PROBING_HEATERS_OFF PROBING_FANS_OFF PROBING_STEPPERS_OFF WAIT_FOR_BED_HEATER \
5555
EEPROM_SETTINGS SDSUPPORT SD_REPRINT_LAST_SELECTED_FILE BINARY_FILE_TRANSFER \
5656
BLINKM PCA9632 RGB_LED RGB_LED_R_PIN RGB_LED_G_PIN RGB_LED_B_PIN LED_CONTROL_MENU \

0 commit comments

Comments
 (0)