Browse Source

⚡️ Apply PTC on all probing (#23764)

Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
tombrazier 2 years ago
parent
commit
8f8427ec8f
No account linked to committer's email address

+ 9
- 0
Marlin/src/feature/probe_temp_comp.cpp View File

@@ -28,6 +28,7 @@
28 28
 
29 29
 #include "probe_temp_comp.h"
30 30
 #include <math.h>
31
+#include "../module/temperature.h"
31 32
 
32 33
 ProbeTempComp ptc;
33 34
 
@@ -62,6 +63,7 @@ constexpr temp_calib_t ProbeTempComp::cali_info[TSI_COUNT];
62 63
 
63 64
 uint8_t ProbeTempComp::calib_idx; // = 0
64 65
 float ProbeTempComp::init_measurement; // = 0.0
66
+bool ProbeTempComp::enabled = true;
65 67
 
66 68
 void ProbeTempComp::reset() {
67 69
   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) {
169 171
   return true;
170 172
 }
171 173
 
174
+void ProbeTempComp::apply_compensation(float &meas_z) {
175
+  if (!enabled) return;
176
+  TERN_(PTC_BED,    compensate_measurement(TSI_BED,   thermalManager.degBed(),     meas_z));
177
+  TERN_(PTC_PROBE,  compensate_measurement(TSI_PROBE, thermalManager.degProbe(),   meas_z));
178
+  TERN_(PTC_HOTEND, compensate_measurement(TSI_EXT,   thermalManager.degHotend(0), meas_z));
179
+}
180
+
172 181
 void ProbeTempComp::compensate_measurement(const TempSensorID tsi, const celsius_t temp, float &meas_z) {
173 182
   const uint8_t measurements = cali_info[tsi].measurements;
174 183
   const celsius_t start_temp = cali_info[tsi].start_temp,

+ 9
- 2
Marlin/src/feature/probe_temp_comp.h View File

@@ -77,7 +77,6 @@ class ProbeTempComp {
77 77
     static void reset_index() { calib_idx = 0; };
78 78
     static uint8_t get_index() { return calib_idx; }
79 79
     static void reset();
80
-    static void clear_offsets(const TempSensorID tsi);
81 80
     static void clear_all_offsets() {
82 81
       TERN_(PTC_PROBE, clear_offsets(TSI_PROBE));
83 82
       TERN_(PTC_BED, clear_offsets(TSI_BED));
@@ -88,10 +87,16 @@ class ProbeTempComp {
88 87
     static void prepare_new_calibration(const_float_t init_meas_z);
89 88
     static void push_back_new_measurement(const TempSensorID tsi, const_float_t meas_z);
90 89
     static bool finish_calibration(const TempSensorID tsi);
91
-    static void compensate_measurement(const TempSensorID tsi, const celsius_t temp, float &meas_z);
90
+    static void set_enabled(const bool ena) { enabled = ena; }
91
+
92
+    // Apply all temperature compensation adjustments
93
+    static void apply_compensation(float &meas_z);
92 94
 
93 95
   private:
94 96
     static uint8_t calib_idx;
97
+    static bool enabled;
98
+
99
+    static void clear_offsets(const TempSensorID tsi);
95 100
 
96 101
     /**
97 102
      * Base value. Temperature compensation values will be deltas
@@ -104,6 +109,8 @@ class ProbeTempComp {
104 109
      * to allow generating values of higher temperatures.
105 110
      */
106 111
     static bool linear_regression(const TempSensorID tsi, float &k, float &d);
112
+
113
+    static void compensate_measurement(const TempSensorID tsi, const celsius_t temp, float &meas_z);
107 114
 };
108 115
 
109 116
 extern ProbeTempComp ptc;

+ 0
- 9
Marlin/src/gcode/bedlevel/abl/G29.cpp View File

@@ -36,11 +36,6 @@
36 36
 #include "../../../module/probe.h"
37 37
 #include "../../queue.h"
38 38
 
39
-#if HAS_PTC
40
-  #include "../../../feature/probe_temp_comp.h"
41
-  #include "../../../module/temperature.h"
42
-#endif
43
-
44 39
 #if HAS_STATUS_MESSAGE
45 40
   #include "../../../lcd/marlinui.h"
46 41
 #endif
@@ -658,10 +653,6 @@ G29_TYPE GcodeSuite::G29() {
658 653
             break; // Breaks out of both loops
659 654
           }
660 655
 
661
-          TERN_(PTC_BED,    ptc.compensate_measurement(TSI_BED,   thermalManager.degBed(),     abl.measured_z));
662
-          TERN_(PTC_PROBE,  ptc.compensate_measurement(TSI_PROBE, thermalManager.degProbe(),   abl.measured_z));
663
-          TERN_(PTC_HOTEND, ptc.compensate_measurement(TSI_EXT,   thermalManager.degHotend(0), abl.measured_z));
664
-
665 656
           #if ENABLED(AUTO_BED_LEVELING_LINEAR)
666 657
 
667 658
             abl.mean += abl.measured_z;

+ 2
- 0
Marlin/src/gcode/calibrate/G76_M871.cpp View File

@@ -109,7 +109,9 @@ static void say_failed_to_calibrate()       { SERIAL_ECHOPGM("!Failed to calibra
109 109
 
110 110
     auto g76_probe = [](const TempSensorID sid, celsius_t &targ, const xy_pos_t &nozpos) {
111 111
       do_z_clearance(5.0); // Raise nozzle before probing
112
+      ptc.set_enabled(false);
112 113
       const float measured_z = probe.probe_at_point(nozpos, PROBE_PT_STOW, 0, false);  // verbose=0, probe_relative=false
114
+      ptc.set_enabled(true);
113 115
       if (isnan(measured_z))
114 116
         SERIAL_ECHOLNPGM("!Received NAN. Aborting.");
115 117
       else {

+ 11
- 1
Marlin/src/gcode/calibrate/M48.cpp View File

@@ -35,11 +35,15 @@
35 35
   #include "../../module/planner.h"
36 36
 #endif
37 37
 
38
+#if HAS_PTC
39
+  #include "../../feature/probe_temp_comp.h"
40
+#endif
41
+
38 42
 /**
39 43
  * M48: Z probe repeatability measurement function.
40 44
  *
41 45
  * Usage:
42
- *   M48 <P#> <X#> <Y#> <V#> <E> <L#> <S>
46
+ *   M48 <P#> <X#> <Y#> <V#> <E> <L#> <S> <C#>
43 47
  *     P = Number of sampled points (4-50, default 10)
44 48
  *     X = Sample X position
45 49
  *     Y = Sample Y position
@@ -47,6 +51,7 @@
47 51
  *     E = Engage Z probe for each reading
48 52
  *     L = Number of legs of movement before probe
49 53
  *     S = Schizoid (Or Star if you prefer)
54
+ *     C = Enable probe temperature compensation (0 or 1, default 1)
50 55
  *
51 56
  * This function requires the machine to be homed before invocation.
52 57
  */
@@ -107,6 +112,8 @@ void GcodeSuite::M48() {
107 112
     set_bed_leveling_enabled(false);
108 113
   #endif
109 114
 
115
+  TERN_(HAS_PTC, ptc.set_enabled(!parser.seen('C') || parser.value_bool()));
116
+
110 117
   // Work with reasonable feedrates
111 118
   remember_feedrate_scaling_off();
112 119
 
@@ -269,6 +276,9 @@ void GcodeSuite::M48() {
269 276
   // Re-enable bed level correction if it had been on
270 277
   TERN_(HAS_LEVELING, set_bed_leveling_enabled(was_enabled));
271 278
 
279
+  // Re-enable probe temperature correction
280
+  TERN_(HAS_PTC, ptc.set_enabled(true));
281
+
272 282
   report_current_position();
273 283
 }
274 284
 

+ 8
- 0
Marlin/src/gcode/probe/G30.cpp View File

@@ -29,6 +29,10 @@
29 29
 #include "../../module/probe.h"
30 30
 #include "../../feature/bedlevel/bedlevel.h"
31 31
 
32
+#if HAS_PTC
33
+  #include "../../feature/probe_temp_comp.h"
34
+#endif
35
+
32 36
 /**
33 37
  * G30: Do a single Z probe at the current XY
34 38
  *
@@ -37,6 +41,7 @@
37 41
  *   X   Probe X position (default current X)
38 42
  *   Y   Probe Y position (default current Y)
39 43
  *   E   Engage the probe for each probe (default 1)
44
+ *   C   Enable probe temperature compensation (0 or 1, default 1)
40 45
  */
41 46
 void GcodeSuite::G30() {
42 47
 
@@ -51,7 +56,10 @@ void GcodeSuite::G30() {
51 56
   remember_feedrate_scaling_off();
52 57
 
53 58
   const ProbePtRaise raise_after = parser.boolval('E', true) ? PROBE_PT_STOW : PROBE_PT_NONE;
59
+
60
+  TERN_(HAS_PTC, ptc.set_enabled(!parser.seen('C') || parser.value_bool()));
54 61
   const float measured_z = probe.probe_at_point(pos, raise_after, 1);
62
+  TERN_(HAS_PTC, ptc.set_enabled(true));
55 63
   if (!isnan(measured_z))
56 64
     SERIAL_ECHOLNPGM("Bed X: ", pos.x, " Y: ", pos.y, " Z: ", measured_z);
57 65
 

+ 1
- 1
Marlin/src/lcd/menu/menu_probe_offset.cpp View File

@@ -62,7 +62,7 @@ void probe_offset_wizard_menu() {
62 62
   if (LCD_HEIGHT >= 4)
63 63
     STATIC_ITEM(MSG_MOVE_NOZZLE_TO_BED, SS_CENTER|SS_INVERT);
64 64
 
65
-  STATIC_ITEM_P(PSTR("Z="), SS_CENTER, ftostr42_52(current_position.z));
65
+  STATIC_ITEM_P(PSTR("Z"), SS_CENTER, ftostr42_52(current_position.z));
66 66
   STATIC_ITEM(MSG_ZPROBE_ZOFFSET, SS_LEFT, ftostr42_52(calculated_z_offset));
67 67
 
68 68
   SUBMENU(MSG_MOVE_1MM,  []{ _goto_manual_move_z( 1);    });

+ 8
- 1
Marlin/src/module/probe.cpp View File

@@ -77,6 +77,10 @@
77 77
   #include "servo.h"
78 78
 #endif
79 79
 
80
+#if HAS_PTC
81
+  #include "../feature/probe_temp_comp.h"
82
+#endif
83
+
80 84
 #if ENABLED(EXTENSIBLE_UI)
81 85
   #include "../lcd/extui/ui_api.h"
82 86
 #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
801 805
   do_blocking_move_to(npos, feedRate_t(XY_PROBE_FEEDRATE_MM_S));
802 806
 
803 807
   float measured_z = NAN;
804
-  if (!deploy()) measured_z = run_z_probe(sanity_check) + offset.z;
808
+  if (!deploy()) {
809
+    measured_z = run_z_probe(sanity_check) + offset.z;
810
+    TERN_(HAS_PTC, ptc.apply_compensation(measured_z));
811
+  }
805 812
   if (!isnan(measured_z)) {
806 813
     const bool big_raise = raise_after == PROBE_PT_BIG_RAISE;
807 814
     if (big_raise || raise_after == PROBE_PT_RAISE)

Loading…
Cancel
Save