My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

probe_temp_comp.h 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. #include "../inc/MarlinConfig.h"
  24. enum TempSensorID : uint8_t {
  25. TSI_PROBE,
  26. TSI_BED,
  27. #if ENABLED(USE_TEMP_EXT_COMPENSATION)
  28. TSI_EXT,
  29. #endif
  30. TSI_COUNT
  31. };
  32. typedef struct {
  33. uint8_t measurements; // Max. number of measurements to be stored (35 - 80°C)
  34. float temp_res, // Resolution in °C between measurements
  35. start_temp, // Base measurement; z-offset == 0
  36. end_temp;
  37. } temp_calib_t;
  38. /**
  39. * Probe temperature compensation implementation.
  40. * Z-probes like the P.I.N.D.A V2 allow for compensation of
  41. * measurement errors/shifts due to changed temperature.
  42. */
  43. static constexpr temp_calib_t cali_info_init[TSI_COUNT] = {
  44. { 10, 5, 30, 30 + 10 * 5 }, // Probe
  45. { 10, 5, 60, 60 + 10 * 5 }, // Bed
  46. #if ENABLED(USE_TEMP_EXT_COMPENSATION)
  47. { 20, 5, 180, 180 + 5 * 20 } // Extruder
  48. #endif
  49. };
  50. class ProbeTempComp {
  51. public:
  52. static const temp_calib_t cali_info[TSI_COUNT];
  53. // Where to park nozzle to wait for probe cooldown
  54. static constexpr xyz_pos_t park_point = PTC_PARK_POS;
  55. // XY coordinates of nozzle for probing the bed
  56. static constexpr xy_pos_t measure_point = PTC_PROBE_POS; // Coordinates to probe
  57. //measure_point = { 12.0f, 7.3f }; // Coordinates for the MK52 magnetic heatbed
  58. static constexpr int probe_calib_bed_temp = BED_MAX_TARGET, // Bed temperature while calibrating probe
  59. bed_calib_probe_temp = 30; // Probe temperature while calibrating bed
  60. static int16_t *sensor_z_offsets[TSI_COUNT],
  61. z_offsets_probe[cali_info_init[TSI_PROBE].measurements], // (µm)
  62. z_offsets_bed[cali_info_init[TSI_BED].measurements]; // (µm)
  63. #if ENABLED(USE_TEMP_EXT_COMPENSATION)
  64. static int16_t z_offsets_ext[cali_info_init[TSI_EXT].measurements]; // (µm)
  65. #endif
  66. static inline void reset_index() { calib_idx = 0; };
  67. static inline uint8_t get_index() { return calib_idx; }
  68. static void clear_offsets(const TempSensorID tsi);
  69. static inline void clear_all_offsets() {
  70. clear_offsets(TSI_BED);
  71. clear_offsets(TSI_PROBE);
  72. TERN_(USE_TEMP_EXT_COMPENSATION, clear_offsets(TSI_EXT));
  73. }
  74. static bool set_offset(const TempSensorID tsi, const uint8_t idx, const int16_t offset);
  75. static void print_offsets();
  76. static void prepare_new_calibration(const float &init_meas_z);
  77. static void push_back_new_measurement(const TempSensorID tsi, const float &meas_z);
  78. static bool finish_calibration(const TempSensorID tsi);
  79. static void compensate_measurement(const TempSensorID tsi, const float &temp, float &meas_z);
  80. private:
  81. static uint8_t calib_idx;
  82. /**
  83. * Base value. Temperature compensation values will be deltas
  84. * to this value, set at first probe.
  85. */
  86. static float init_measurement;
  87. static float get_offset_for_temperature(const TempSensorID tsi, const float &temp);
  88. /**
  89. * Fit a linear function in measured temperature offsets
  90. * to allow generating values of higher temperatures.
  91. */
  92. static bool linear_regression(const TempSensorID tsi, float &k, float &d);
  93. };
  94. extern ProbeTempComp temp_comp;