@@ -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 ());
0 commit comments