Просмотр исходного кода

⚡️ Apply PTC on all probing (#23764)

Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
tombrazier 3 лет назад
Родитель
Сommit
8f8427ec8f
Аккаунт пользователя с таким Email не найден

+ 9
- 0
Marlin/src/feature/probe_temp_comp.cpp Просмотреть файл

28
 
28
 
29
 #include "probe_temp_comp.h"
29
 #include "probe_temp_comp.h"
30
 #include <math.h>
30
 #include <math.h>
31
+#include "../module/temperature.h"
31
 
32
 
32
 ProbeTempComp ptc;
33
 ProbeTempComp ptc;
33
 
34
 
62
 
63
 
63
 uint8_t ProbeTempComp::calib_idx; // = 0
64
 uint8_t ProbeTempComp::calib_idx; // = 0
64
 float ProbeTempComp::init_measurement; // = 0.0
65
 float ProbeTempComp::init_measurement; // = 0.0
66
+bool ProbeTempComp::enabled = true;
65
 
67
 
66
 void ProbeTempComp::reset() {
68
 void ProbeTempComp::reset() {
67
   TERN_(PTC_PROBE, LOOP_L_N(i, PTC_PROBE_COUNT) z_offsets_probe[i] = z_offsets_probe_default[i]);
69
   TERN_(PTC_PROBE, LOOP_L_N(i, PTC_PROBE_COUNT) z_offsets_probe[i] = z_offsets_probe_default[i]);
169
   return true;
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
 void ProbeTempComp::compensate_measurement(const TempSensorID tsi, const celsius_t temp, float &meas_z) {
181
 void ProbeTempComp::compensate_measurement(const TempSensorID tsi, const celsius_t temp, float &meas_z) {
173
   const uint8_t measurements = cali_info[tsi].measurements;
182
   const uint8_t measurements = cali_info[tsi].measurements;
174
   const celsius_t start_temp = cali_info[tsi].start_temp,
183
   const celsius_t start_temp = cali_info[tsi].start_temp,

+ 9
- 2
Marlin/src/feature/probe_temp_comp.h Просмотреть файл

77
     static void reset_index() { calib_idx = 0; };
77
     static void reset_index() { calib_idx = 0; };
78
     static uint8_t get_index() { return calib_idx; }
78
     static uint8_t get_index() { return calib_idx; }
79
     static void reset();
79
     static void reset();
80
-    static void clear_offsets(const TempSensorID tsi);
81
     static void clear_all_offsets() {
80
     static void clear_all_offsets() {
82
       TERN_(PTC_PROBE, clear_offsets(TSI_PROBE));
81
       TERN_(PTC_PROBE, clear_offsets(TSI_PROBE));
83
       TERN_(PTC_BED, clear_offsets(TSI_BED));
82
       TERN_(PTC_BED, clear_offsets(TSI_BED));
88
     static void prepare_new_calibration(const_float_t init_meas_z);
87
     static void prepare_new_calibration(const_float_t init_meas_z);
89
     static void push_back_new_measurement(const TempSensorID tsi, const_float_t meas_z);
88
     static void push_back_new_measurement(const TempSensorID tsi, const_float_t meas_z);
90
     static bool finish_calibration(const TempSensorID tsi);
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
   private:
95
   private:
94
     static uint8_t calib_idx;
96
     static uint8_t calib_idx;
97
+    static bool enabled;
98
+
99
+    static void clear_offsets(const TempSensorID tsi);
95
 
100
 
96
     /**
101
     /**
97
      * Base value. Temperature compensation values will be deltas
102
      * Base value. Temperature compensation values will be deltas
104
      * to allow generating values of higher temperatures.
109
      * to allow generating values of higher temperatures.
105
      */
110
      */
106
     static bool linear_regression(const TempSensorID tsi, float &k, float &d);
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
 extern ProbeTempComp ptc;
116
 extern ProbeTempComp ptc;

+ 0
- 9
Marlin/src/gcode/bedlevel/abl/G29.cpp Просмотреть файл

36
 #include "../../../module/probe.h"
36
 #include "../../../module/probe.h"
37
 #include "../../queue.h"
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
 #if HAS_STATUS_MESSAGE
39
 #if HAS_STATUS_MESSAGE
45
   #include "../../../lcd/marlinui.h"
40
   #include "../../../lcd/marlinui.h"
46
 #endif
41
 #endif
658
             break; // Breaks out of both loops
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
           #if ENABLED(AUTO_BED_LEVELING_LINEAR)
656
           #if ENABLED(AUTO_BED_LEVELING_LINEAR)
666
 
657
 
667
             abl.mean += abl.measured_z;
658
             abl.mean += abl.measured_z;

+ 2
- 0
Marlin/src/gcode/calibrate/G76_M871.cpp Просмотреть файл

109
 
109
 
110
     auto g76_probe = [](const TempSensorID sid, celsius_t &targ, const xy_pos_t &nozpos) {
110
     auto g76_probe = [](const TempSensorID sid, celsius_t &targ, const xy_pos_t &nozpos) {
111
       do_z_clearance(5.0); // Raise nozzle before probing
111
       do_z_clearance(5.0); // Raise nozzle before probing
112
+      ptc.set_enabled(false);
112
       const float measured_z = probe.probe_at_point(nozpos, PROBE_PT_STOW, 0, false);  // verbose=0, probe_relative=false
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
       if (isnan(measured_z))
115
       if (isnan(measured_z))
114
         SERIAL_ECHOLNPGM("!Received NAN. Aborting.");
116
         SERIAL_ECHOLNPGM("!Received NAN. Aborting.");
115
       else {
117
       else {

+ 11
- 1
Marlin/src/gcode/calibrate/M48.cpp Просмотреть файл

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

+ 8
- 0
Marlin/src/gcode/probe/G30.cpp Просмотреть файл

29
 #include "../../module/probe.h"
29
 #include "../../module/probe.h"
30
 #include "../../feature/bedlevel/bedlevel.h"
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
  * G30: Do a single Z probe at the current XY
37
  * G30: Do a single Z probe at the current XY
34
  *
38
  *
37
  *   X   Probe X position (default current X)
41
  *   X   Probe X position (default current X)
38
  *   Y   Probe Y position (default current Y)
42
  *   Y   Probe Y position (default current Y)
39
  *   E   Engage the probe for each probe (default 1)
43
  *   E   Engage the probe for each probe (default 1)
44
+ *   C   Enable probe temperature compensation (0 or 1, default 1)
40
  */
45
  */
41
 void GcodeSuite::G30() {
46
 void GcodeSuite::G30() {
42
 
47
 
51
   remember_feedrate_scaling_off();
56
   remember_feedrate_scaling_off();
52
 
57
 
53
   const ProbePtRaise raise_after = parser.boolval('E', true) ? PROBE_PT_STOW : PROBE_PT_NONE;
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
   const float measured_z = probe.probe_at_point(pos, raise_after, 1);
61
   const float measured_z = probe.probe_at_point(pos, raise_after, 1);
62
+  TERN_(HAS_PTC, ptc.set_enabled(true));
55
   if (!isnan(measured_z))
63
   if (!isnan(measured_z))
56
     SERIAL_ECHOLNPGM("Bed X: ", pos.x, " Y: ", pos.y, " Z: ", measured_z);
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 Просмотреть файл

62
   if (LCD_HEIGHT >= 4)
62
   if (LCD_HEIGHT >= 4)
63
     STATIC_ITEM(MSG_MOVE_NOZZLE_TO_BED, SS_CENTER|SS_INVERT);
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
   STATIC_ITEM(MSG_ZPROBE_ZOFFSET, SS_LEFT, ftostr42_52(calculated_z_offset));
66
   STATIC_ITEM(MSG_ZPROBE_ZOFFSET, SS_LEFT, ftostr42_52(calculated_z_offset));
67
 
67
 
68
   SUBMENU(MSG_MOVE_1MM,  []{ _goto_manual_move_z( 1);    });
68
   SUBMENU(MSG_MOVE_1MM,  []{ _goto_manual_move_z( 1);    });

+ 8
- 1
Marlin/src/module/probe.cpp Просмотреть файл

77
   #include "servo.h"
77
   #include "servo.h"
78
 #endif
78
 #endif
79
 
79
 
80
+#if HAS_PTC
81
+  #include "../feature/probe_temp_comp.h"
82
+#endif
83
+
80
 #if ENABLED(EXTENSIBLE_UI)
84
 #if ENABLED(EXTENSIBLE_UI)
81
   #include "../lcd/extui/ui_api.h"
85
   #include "../lcd/extui/ui_api.h"
82
 #elif ENABLED(DWIN_CREALITY_LCD_ENHANCED)
86
 #elif ENABLED(DWIN_CREALITY_LCD_ENHANCED)
801
   do_blocking_move_to(npos, feedRate_t(XY_PROBE_FEEDRATE_MM_S));
805
   do_blocking_move_to(npos, feedRate_t(XY_PROBE_FEEDRATE_MM_S));
802
 
806
 
803
   float measured_z = NAN;
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
   if (!isnan(measured_z)) {
812
   if (!isnan(measured_z)) {
806
     const bool big_raise = raise_after == PROBE_PT_BIG_RAISE;
813
     const bool big_raise = raise_after == PROBE_PT_BIG_RAISE;
807
     if (big_raise || raise_after == PROBE_PT_RAISE)
814
     if (big_raise || raise_after == PROBE_PT_RAISE)

Загрузка…
Отмена
Сохранить