My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

probe_temp_compensation.h 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2019 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. class ProbeTempComp {
  44. public:
  45. static constexpr temp_calib_t cali_info_init[TSI_COUNT] = {
  46. { 30, 10, 5, 30 + 10 * 5 }, // Probe
  47. { 60, 10, 5, 60 + 10 * 5 }, // Bed
  48. #if ENABLED(USE_TEMP_EXT_COMPENSATION)
  49. { 180, 5, 20, 180 + 5 * 20 } // Extruder
  50. #endif
  51. };
  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_X, PTC_PARK_POS_Y, PTC_PARK_POS_Z };
  55. static constexpr int max_bed_temp = PTC_MAX_BED_TEMP, // Max temperature to avoid heating errors
  56. // XY coordinates of nozzle for probing the bed
  57. measure_point_x = PTC_PROBE_POS_X, // X-coordinate to probe
  58. measure_point_y = PTC_PROBE_POS_Y, // Y-coordinate to probe
  59. //measure_point_x = 12.0f, // X-coordinate to probe on MK52 magnetic heatbed
  60. //measure_point_y = 7.3f, // Y-coordinate to probe on MK52 magnetic heatbed
  61. probe_calib_bed_temp = max_bed_temp, // Bed temperature while calibrating probe
  62. bed_calib_probe_temp = 30; // Probe temperature while calibrating bed
  63. static int16_t *sensor_z_offsets[TSI_COUNT],
  64. z_offsets_probe[cali_info_init[TSI_PROBE].measurements], // (µm)
  65. z_offsets_bed[cali_info_init[TSI_BED].measurements]; // (µm)
  66. #if ENABLED(USE_TEMP_EXT_COMPENSATION)
  67. static int16_t z_offsets_ext[cali_info_init[TSI_EXT].measurements]; // (µm)
  68. #endif
  69. static inline void reset_index() { calib_idx = 0; };
  70. static inline uint8_t get_index() { return calib_idx; }
  71. static void clear_offsets(const TempSensorID tsi);
  72. static inline void clear_all_offsets() {
  73. clear_offsets(TSI_BED);
  74. clear_offsets(TSI_PROBE);
  75. #if ENABLED(USE_TEMP_EXT_COMPENSATION)
  76. clear_offsets(TSI_EXT);
  77. #endif
  78. }
  79. static bool set_offset(const TempSensorID tsi, const uint8_t idx, const int16_t offset);
  80. static void print_offsets();
  81. static void prepare_new_calibration(const float &init_meas_z);
  82. static void push_back_new_measurement(const TempSensorID tsi, const float &meas_z);
  83. static bool finish_calibration(const TempSensorID tsi);
  84. static void compensate_measurement(const TempSensorID tsi, const float &temp, float &meas_z);
  85. private:
  86. static uint8_t calib_idx;
  87. /**
  88. * Base value. Temperature compensation values will be deltas
  89. * to this value, set at first probe.
  90. */
  91. static float init_measurement;
  92. static float get_offset_for_temperature(const TempSensorID tsi, const float &temp);
  93. /**
  94. * Fit a linear function in measured temperature offsets
  95. * to allow generating values of higher temperatures.
  96. */
  97. static bool linear_regression(const TempSensorID tsi, float &k, float &d);
  98. };
  99. extern ProbeTempComp temp_comp;