My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

probe_temp_comp.h 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. 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. // Probe temperature calibration constants
  44. #ifndef PTC_SAMPLE_COUNT
  45. #define PTC_SAMPLE_COUNT 10U
  46. #endif
  47. #ifndef PTC_SAMPLE_RES
  48. #define PTC_SAMPLE_RES 5.0f
  49. #endif
  50. #ifndef PTC_SAMPLE_START
  51. #define PTC_SAMPLE_START 30.0f
  52. #endif
  53. #define PTC_SAMPLE_END ((PTC_SAMPLE_START) + (PTC_SAMPLE_COUNT) * (PTC_SAMPLE_RES))
  54. // Bed temperature calibration constants
  55. #ifndef BTC_PROBE_TEMP
  56. #define BTC_PROBE_TEMP 30.0f
  57. #endif
  58. #ifndef BTC_SAMPLE_COUNT
  59. #define BTC_SAMPLE_COUNT 10U
  60. #endif
  61. #ifndef BTC_SAMPLE_STEP
  62. #define BTC_SAMPLE_RES 5.0f
  63. #endif
  64. #ifndef BTC_SAMPLE_START
  65. #define BTC_SAMPLE_START 60.0f
  66. #endif
  67. #define BTC_SAMPLE_END ((BTC_SAMPLE_START) + (BTC_SAMPLE_COUNT) * (BTC_SAMPLE_RES))
  68. #ifndef PTC_PROBE_HEATING_OFFSET
  69. #define PTC_PROBE_HEATING_OFFSET 0.5f
  70. #endif
  71. #ifndef PTC_PROBE_RAISE
  72. #define PTC_PROBE_RAISE 10.0f
  73. #endif
  74. static constexpr temp_calib_t cali_info_init[TSI_COUNT] = {
  75. { PTC_SAMPLE_COUNT, PTC_SAMPLE_RES, PTC_SAMPLE_START, PTC_SAMPLE_END }, // Probe
  76. { BTC_SAMPLE_COUNT, BTC_SAMPLE_RES, BTC_SAMPLE_START, BTC_SAMPLE_END }, // Bed
  77. #if ENABLED(USE_TEMP_EXT_COMPENSATION)
  78. { 20, 5, 180, 180 + 5 * 20 } // Extruder
  79. #endif
  80. };
  81. class ProbeTempComp {
  82. public:
  83. static const temp_calib_t cali_info[TSI_COUNT];
  84. // Where to park nozzle to wait for probe cooldown
  85. static constexpr xyz_pos_t park_point = PTC_PARK_POS;
  86. // XY coordinates of nozzle for probing the bed
  87. static constexpr xy_pos_t measure_point = PTC_PROBE_POS; // Coordinates to probe
  88. //measure_point = { 12.0f, 7.3f }; // Coordinates for the MK52 magnetic heatbed
  89. static constexpr int probe_calib_bed_temp = BED_MAX_TARGET, // Bed temperature while calibrating probe
  90. bed_calib_probe_temp = BTC_PROBE_TEMP; // Probe temperature while calibrating bed
  91. static int16_t *sensor_z_offsets[TSI_COUNT],
  92. z_offsets_probe[cali_info_init[TSI_PROBE].measurements], // (µm)
  93. z_offsets_bed[cali_info_init[TSI_BED].measurements]; // (µm)
  94. #if ENABLED(USE_TEMP_EXT_COMPENSATION)
  95. static int16_t z_offsets_ext[cali_info_init[TSI_EXT].measurements]; // (µm)
  96. #endif
  97. static inline void reset_index() { calib_idx = 0; };
  98. static inline uint8_t get_index() { return calib_idx; }
  99. static void clear_offsets(const TempSensorID tsi);
  100. static inline void clear_all_offsets() {
  101. clear_offsets(TSI_BED);
  102. clear_offsets(TSI_PROBE);
  103. TERN_(USE_TEMP_EXT_COMPENSATION, clear_offsets(TSI_EXT));
  104. }
  105. static bool set_offset(const TempSensorID tsi, const uint8_t idx, const int16_t offset);
  106. static void print_offsets();
  107. static void prepare_new_calibration(const float &init_meas_z);
  108. static void push_back_new_measurement(const TempSensorID tsi, const float &meas_z);
  109. static bool finish_calibration(const TempSensorID tsi);
  110. static void compensate_measurement(const TempSensorID tsi, const float &temp, float &meas_z);
  111. private:
  112. static uint8_t calib_idx;
  113. /**
  114. * Base value. Temperature compensation values will be deltas
  115. * to this value, set at first probe.
  116. */
  117. static float init_measurement;
  118. static float get_offset_for_temperature(const TempSensorID tsi, const float &temp);
  119. /**
  120. * Fit a linear function in measured temperature offsets
  121. * to allow generating values of higher temperatures.
  122. */
  123. static bool linear_regression(const TempSensorID tsi, float &k, float &d);
  124. };
  125. extern ProbeTempComp temp_comp;