My Marlin configs for Fabrikator Mini and CTC i3 Pro B
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

probe_temp_comp.h 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. #include "../inc/MarlinConfig.h"
  24. enum TempSensorID : uint8_t {
  25. #if ENABLED(PTC_PROBE)
  26. TSI_PROBE,
  27. #endif
  28. #if ENABLED(PTC_BED)
  29. TSI_BED,
  30. #endif
  31. #if ENABLED(PTC_HOTEND)
  32. TSI_EXT,
  33. #endif
  34. TSI_COUNT
  35. };
  36. typedef struct {
  37. uint8_t measurements; // Max. number of measurements to be stored (35 - 80°C)
  38. celsius_t temp_resolution, // Resolution in °C between measurements
  39. start_temp; // Base measurement; z-offset == 0
  40. } temp_calib_t;
  41. /**
  42. * Probe temperature compensation implementation.
  43. * Z-probes like the P.I.N.D.A V2 allow for compensation of
  44. * measurement errors/shifts due to changed temperature.
  45. */
  46. class ProbeTempComp {
  47. public:
  48. static constexpr temp_calib_t cali_info[TSI_COUNT] = {
  49. #if ENABLED(PTC_PROBE)
  50. { PTC_PROBE_COUNT, PTC_PROBE_RES, PTC_PROBE_START }, // Probe
  51. #endif
  52. #if ENABLED(PTC_BED)
  53. { PTC_BED_COUNT, PTC_BED_RES, PTC_BED_START }, // Bed
  54. #endif
  55. #if ENABLED(PTC_HOTEND)
  56. { PTC_HOTEND_COUNT, PTC_HOTEND_RES, PTC_HOTEND_START }, // Extruder
  57. #endif
  58. };
  59. static int16_t *sensor_z_offsets[TSI_COUNT];
  60. #if ENABLED(PTC_PROBE)
  61. static int16_t z_offsets_probe[PTC_PROBE_COUNT]; // (µm)
  62. #endif
  63. #if ENABLED(PTC_BED)
  64. static int16_t z_offsets_bed[PTC_BED_COUNT]; // (µm)
  65. #endif
  66. #if ENABLED(PTC_HOTEND)
  67. static int16_t z_offsets_hotend[PTC_HOTEND_COUNT]; // (µm)
  68. #endif
  69. static void reset_index() { calib_idx = 0; };
  70. static uint8_t get_index() { return calib_idx; }
  71. static void reset();
  72. static void clear_all_offsets() {
  73. TERN_(PTC_PROBE, clear_offsets(TSI_PROBE));
  74. TERN_(PTC_BED, clear_offsets(TSI_BED));
  75. TERN_(PTC_HOTEND, clear_offsets(TSI_EXT));
  76. }
  77. static bool set_offset(const TempSensorID tsi, const uint8_t idx, const int16_t offset);
  78. static void print_offsets();
  79. static void prepare_new_calibration(const_float_t init_meas_z);
  80. static void push_back_new_measurement(const TempSensorID tsi, const_float_t meas_z);
  81. static bool finish_calibration(const TempSensorID tsi);
  82. static void set_enabled(const bool ena) { enabled = ena; }
  83. // Apply all temperature compensation adjustments
  84. static void apply_compensation(float &meas_z);
  85. private:
  86. static uint8_t calib_idx;
  87. static bool enabled;
  88. static void clear_offsets(const TempSensorID tsi);
  89. /**
  90. * Base value. Temperature compensation values will be deltas
  91. * to this value, set at first probe.
  92. */
  93. static float init_measurement;
  94. /**
  95. * Fit a linear function in measured temperature offsets
  96. * to allow generating values of higher temperatures.
  97. */
  98. static bool linear_regression(const TempSensorID tsi, float &k, float &d);
  99. static void compensate_measurement(const TempSensorID tsi, const celsius_t temp, float &meas_z);
  100. };
  101. extern ProbeTempComp ptc;