Переглянути джерело

PTC: Extend options, fix probing bugs (#18253)

rudihorn 4 роки тому
джерело
коміт
3bf990ec34
Аккаунт користувача з таким Email не знайдено

+ 31
- 0
Marlin/Configuration_adv.h Переглянути файл

@@ -1662,6 +1662,37 @@
1662 1662
     // Enable additional compensation using hotend temperature
1663 1663
     // Note: this values cannot be calibrated automatically but have to be set manually
1664 1664
     //#define USE_TEMP_EXT_COMPENSATION
1665
+
1666
+    // Probe temperature calibration generates a table of values starting at PTC_SAMPLE_START
1667
+    // (e.g. 30), in steps of PTC_SAMPLE_RES (e.g. 5) with PTC_SAMPLE_COUNT (e.g. 10) samples.
1668
+
1669
+    // #define PTC_SAMPLE_START  30.0f
1670
+    // #define PTC_SAMPLE_RES    5.0f
1671
+    // #define PTC_SAMPLE_COUNT  10U
1672
+
1673
+    // Bed temperature calibration builds a similar table.
1674
+
1675
+    // #define BTC_SAMPLE_START  60.0f
1676
+    // #define BTC_SAMPLE_RES    5.0f
1677
+    // #define BTC_SAMPLE_COUNT  10U
1678
+
1679
+    // The temperature the probe should be at while taking measurements during bed temperature
1680
+    // calibration.
1681
+    // #define BTC_PROBE_TEMP 30.0f
1682
+
1683
+    // Height above Z=0.0f to raise the nozzle. Lowering this can help the probe to heat faster.
1684
+    // Note: the Z=0.0f offset is determined by the probe offset which can be set using M851.
1685
+    // #define PTC_PROBE_HEATING_OFFSET 0.5f
1686
+
1687
+    // Height to raise the Z-probe between heating and taking the next measurement. Some probes
1688
+    // may fail to untrigger if they have been triggered for a long time, which can be solved by
1689
+    // increasing the height the probe is raised to.
1690
+    // #define PTC_PROBE_RAISE 15U
1691
+
1692
+    // If the probe is outside of the defined range, use linear extrapolation using the closest 
1693
+    // point and the PTC_LINEAR_EXTRAPOLATION'th next point. E.g. if set to 4 it will use data[0]
1694
+    // and data[4] to perform linear extrapolation for values below PTC_SAMPLE_START.
1695
+    // #define PTC_LINEAR_EXTRAPOLATION 4
1665 1696
   #endif
1666 1697
 #endif
1667 1698
 

+ 28
- 15
Marlin/src/feature/probe_temp_comp.cpp Переглянути файл

@@ -165,28 +165,41 @@ void ProbeTempComp::compensate_measurement(const TempSensorID tsi, const float &
165 165
 }
166 166
 
167 167
 float ProbeTempComp::get_offset_for_temperature(const TempSensorID tsi, const float &temp) {
168
-
169 168
   const uint8_t measurements = cali_info[tsi].measurements;
170 169
   const float start_temp = cali_info[tsi].start_temp,
171
-                end_temp = cali_info[tsi].end_temp,
172 170
                 res_temp = cali_info[tsi].temp_res;
173 171
   const int16_t * const data = sensor_z_offsets[tsi];
174 172
 
175
-  if (temp <= start_temp) return 0.0f;
176
-  if (temp >= end_temp) return static_cast<float>(data[measurements - 1]) / 1000.0f;
173
+  auto point = [&](uint8_t i) {
174
+    return xy_float_t({start_temp + i*res_temp, static_cast<float>(data[i])});
175
+  };
176
+
177
+  auto linear_interp = [](float x, xy_float_t p1, xy_float_t p2) {
178
+    return (p2.y - p1.y) / (p2.x - p2.y) * (x - p1.x) + p1.y;
179
+  };
177 180
 
178 181
   // Linear interpolation
179
-  int16_t val1 = 0, val2 = data[0];
180
-  uint8_t idx = 0;
181
-  float meas_temp = start_temp + res_temp;
182
-  while (meas_temp < temp) {
183
-    if (++idx >= measurements) return static_cast<float>(val2) / 1000.0f;
184
-    meas_temp += res_temp;
185
-    val1 = val2;
186
-    val2 = data[idx];
187
-  }
188
-  const float factor = (meas_temp - temp) / static_cast<float>(res_temp);
189
-  return (static_cast<float>(val2) - static_cast<float>(val2 - val1) * factor) / 1000.0f;
182
+  uint8_t idx = static_cast<uint8_t>(temp - start_temp / res_temp);
183
+
184
+  // offset in um
185
+  float offset = 0.0f;
186
+
187
+  #if !defined(PTC_LINEAR_EXTRAPOLATION) || PTC_LINEAR_EXTRAPOLATION <= 0
188
+    if (idx < 0)
189
+      offset = 0.0f;
190
+    else if (idx > measurements - 2)
191
+      offset = static_cast<float>(data[measurements - 1]);
192
+  #else
193
+    if (idx < 0) 
194
+      offset = linear_interp(temp, point(0), point(PTC_LINEAR_EXTRAPOLATION));
195
+    else if (idx > measurements - 2) 
196
+      offset = linear_interp(temp, point(measurements - PTC_LINEAR_EXTRAPOLATION - 1), point(measurements - 1));
197
+  #endif
198
+    else
199
+      offset = linear_interp(temp, point(idx), point(idx + 1));
200
+
201
+  // return offset in mm
202
+  return offset / 1000.0f;
190 203
 }
191 204
 
192 205
 bool ProbeTempComp::linear_regression(const TempSensorID tsi, float &k, float &d) {

+ 38
- 3
Marlin/src/feature/probe_temp_comp.h Переглянути файл

@@ -45,9 +45,44 @@ typedef struct {
45 45
  * measurement errors/shifts due to changed temperature.
46 46
  */
47 47
 
48
+// Probe temperature calibration constants
49
+#ifndef PTC_SAMPLE_COUNT
50
+  #define PTC_SAMPLE_COUNT 10U
51
+#endif
52
+#ifndef PTC_SAMPLE_RES
53
+  #define PTC_SAMPLE_RES 5.0f
54
+#endif
55
+#ifndef PTC_SAMPLE_START
56
+  #define PTC_SAMPLE_START 30.0f
57
+#endif
58
+#define PTC_SAMPLE_END ((PTC_SAMPLE_START) + (PTC_SAMPLE_COUNT) * (PTC_SAMPLE_RES))
59
+
60
+// Bed temperature calibration constants
61
+#ifndef BTC_PROBE_TEMP
62
+  #define BTC_PROBE_TEMP 30.0f
63
+#endif
64
+#ifndef BTC_SAMPLE_COUNT
65
+  #define BTC_SAMPLE_COUNT 10U
66
+#endif
67
+#ifndef BTC_SAMPLE_STEP
68
+  #define BTC_SAMPLE_RES 5.0f
69
+#endif
70
+#ifndef BTC_SAMPLE_START
71
+  #define BTC_SAMPLE_START 60.0f
72
+#endif
73
+#define BTC_SAMPLE_END ((BTC_SAMPLE_START) + (BTC_SAMPLE_COUNT) * (BTC_SAMPLE_RES))
74
+
75
+#ifndef PTC_PROBE_HEATING_OFFSET
76
+  #define PTC_PROBE_HEATING_OFFSET 0.5f
77
+#endif
78
+
79
+#ifndef PTC_PROBE_RAISE
80
+  #define PTC_PROBE_RAISE 10.0f
81
+#endif
82
+
48 83
 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
84
+    {  PTC_SAMPLE_COUNT, PTC_SAMPLE_RES, PTC_SAMPLE_START, PTC_SAMPLE_END },       // Probe
85
+    {  BTC_SAMPLE_COUNT, BTC_SAMPLE_RES, BTC_SAMPLE_START, BTC_SAMPLE_END },       // Bed
51 86
   #if ENABLED(USE_TEMP_EXT_COMPENSATION)
52 87
     {  20,  5, 180, 180 +  5 * 20 }        // Extruder
53 88
   #endif
@@ -66,7 +101,7 @@ class ProbeTempComp {
66 101
                             //measure_point    = { 12.0f, 7.3f };   // Coordinates for the MK52 magnetic heatbed
67 102
 
68 103
     static constexpr int  probe_calib_bed_temp = BED_MAX_TARGET,  // Bed temperature while calibrating probe
69
-                          bed_calib_probe_temp = 30;                // Probe temperature while calibrating bed
104
+                          bed_calib_probe_temp = BTC_PROBE_TEMP;  // Probe temperature while calibrating bed
70 105
 
71 106
     static int16_t *sensor_z_offsets[TSI_COUNT],
72 107
                    z_offsets_probe[cali_info_init[TSI_PROBE].measurements], // (µm)

+ 3
- 3
Marlin/src/gcode/calibrate/G76_M871.cpp Переглянути файл

@@ -105,7 +105,7 @@ void GcodeSuite::G76() {
105 105
 
106 106
   auto g76_probe = [](const TempSensorID sid, uint16_t &targ, const xy_pos_t &nozpos) {
107 107
     do_blocking_move_to_z(5.0); // Raise nozzle before probing
108
-    const float measured_z = probe.probe_at_point(nozpos, PROBE_PT_NONE, 0, false);  // verbose=0, probe_relative=false
108
+    const float measured_z = probe.probe_at_point(nozpos, PROBE_PT_STOW, 0, false);  // verbose=0, probe_relative=false
109 109
     if (isnan(measured_z))
110 110
       SERIAL_ECHOLNPGM("!Received NAN. Aborting.");
111 111
     else {
@@ -132,8 +132,8 @@ void GcodeSuite::G76() {
132 132
   planner.synchronize();
133 133
 
134 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
135
+            probe_pos_xyz = xyz_pos_t(temp_comp.measure_point) + xyz_pos_t({ 0.0f, 0.0f, PTC_PROBE_HEATING_OFFSET }),
136
+              noz_pos_xyz = probe_pos_xyz - xy_pos_t(probe.offset_xy); // Nozzle position based on probe position
137 137
 
138 138
   if (do_bed_cal || do_probe_cal) {
139 139
     // Ensure park position is reachable

Завантаження…
Відмінити
Зберегти