My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

bltouch.cpp 7.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. #include "../inc/MarlinConfig.h"
  23. #if ENABLED(BLTOUCH)
  24. #include "bltouch.h"
  25. BLTouch bltouch;
  26. bool BLTouch::last_written_mode; // Initialized by settings.load, 0 = Open Drain; 1 = 5V Drain
  27. #include "../module/servo.h"
  28. void stop();
  29. #define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE)
  30. #include "../core/debug_out.h"
  31. bool BLTouch::command(const BLTCommand cmd, const millis_t &ms) {
  32. if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPAIR("BLTouch Command :", cmd);
  33. MOVE_SERVO(Z_PROBE_SERVO_NR, cmd);
  34. safe_delay(_MAX(ms, (uint32_t)BLTOUCH_DELAY)); // BLTOUCH_DELAY is also the *minimum* delay
  35. return triggered();
  36. }
  37. // Init the class and device. Call from setup().
  38. void BLTouch::init(const bool set_voltage/*=false*/) {
  39. // Voltage Setting (if enabled). At every Marlin initialization:
  40. // BLTOUCH < V3.0 and clones: This will be ignored by the probe
  41. // BLTOUCH V3.0: SET_5V_MODE or SET_OD_MODE (if enabled).
  42. // OD_MODE is the default on power on, but setting it does not hurt
  43. // This mode will stay active until manual SET_OD_MODE or power cycle
  44. // BLTOUCH V3.1: SET_5V_MODE or SET_OD_MODE (if enabled).
  45. // At power on, the probe will default to the eeprom settings configured by the user
  46. _reset();
  47. _stow();
  48. #if ENABLED(BLTOUCH_FORCE_MODE_SET)
  49. constexpr bool should_set = true;
  50. #else
  51. if (DEBUGGING(LEVELING)) {
  52. DEBUG_ECHOLNPAIR("last_written_mode - ", (int)last_written_mode);
  53. DEBUG_ECHOLNPGM("config mode - "
  54. #if ENABLED(BLTOUCH_SET_5V_MODE)
  55. "BLTOUCH_SET_5V_MODE"
  56. #else
  57. "OD"
  58. #endif
  59. );
  60. }
  61. const bool should_set = last_written_mode != (false
  62. #if ENABLED(BLTOUCH_SET_5V_MODE)
  63. || true
  64. #endif
  65. );
  66. #endif
  67. if (should_set && set_voltage)
  68. mode_conv_proc((false
  69. #if ENABLED(BLTOUCH_SET_5V_MODE)
  70. || true
  71. #endif
  72. ));
  73. }
  74. void BLTouch::clear() {
  75. _reset(); // RESET or RESET_SW will clear an alarm condition but...
  76. // ...it will not clear a triggered condition in SW mode when the pin is currently up
  77. // ANTClabs <-- CODE ERROR
  78. _stow(); // STOW will pull up the pin and clear any triggered condition unless it fails, don't care
  79. _deploy(); // DEPLOY to test the probe. Could fail, don't care
  80. _stow(); // STOW to be ready for meaningful work. Could fail, don't care
  81. }
  82. bool BLTouch::triggered() {
  83. return (
  84. #if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
  85. READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING
  86. #else
  87. READ(Z_MIN_PROBE_PIN) != Z_MIN_PROBE_ENDSTOP_INVERTING
  88. #endif
  89. );
  90. }
  91. bool BLTouch::deploy_proc() {
  92. // Do a DEPLOY
  93. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("BLTouch DEPLOY requested");
  94. // Attempt to DEPLOY, wait for DEPLOY_DELAY or ALARM
  95. if (_deploy_query_alarm()) {
  96. // The deploy might have failed or the probe is already triggered (nozzle too low?)
  97. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("BLTouch ALARM or TRIGGER after DEPLOY, recovering");
  98. clear(); // Get the probe into start condition
  99. // Last attempt to DEPLOY
  100. if (_deploy_query_alarm()) {
  101. // The deploy might have failed or the probe is actually triggered (nozzle too low?) again
  102. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("BLTouch Recovery Failed");
  103. SERIAL_ERROR_MSG(STR_STOP_BLTOUCH); // Tell the user something is wrong, needs action
  104. stop(); // but it's not too bad, no need to kill, allow restart
  105. return true; // Tell our caller we goofed in case he cares to know
  106. }
  107. }
  108. // One of the recommended ANTClabs ways to probe, using SW MODE
  109. #if ENABLED(BLTOUCH_FORCE_SW_MODE)
  110. _set_SW_mode();
  111. #endif
  112. // Now the probe is ready to issue a 10ms pulse when the pin goes up.
  113. // The trigger STOW (see motion.cpp for example) will pull up the probes pin as soon as the pulse
  114. // is registered.
  115. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("bltouch.deploy_proc() end");
  116. return false; // report success to caller
  117. }
  118. bool BLTouch::stow_proc() {
  119. // Do a STOW
  120. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("BLTouch STOW requested");
  121. // A STOW will clear a triggered condition in the probe (10ms pulse).
  122. // At the moment that we come in here, we might (pulse) or will (SW mode) see the trigger on the pin.
  123. // So even though we know a STOW will be ignored if an ALARM condition is active, we will STOW.
  124. // Note: If the probe is deployed AND in an ALARM condition, this STOW will not pull up the pin
  125. // and the ALARM condition will still be there. --> ANTClabs should change this behavior maybe
  126. // Attempt to STOW, wait for STOW_DELAY or ALARM
  127. if (_stow_query_alarm()) {
  128. // The stow might have failed
  129. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("BLTouch ALARM or TRIGGER after STOW, recovering");
  130. _reset(); // This RESET will then also pull up the pin. If it doesn't
  131. // work and the pin is still down, there will no longer be
  132. // an ALARM condition though.
  133. // But one more STOW will catch that
  134. // Last attempt to STOW
  135. if (_stow_query_alarm()) { // so if there is now STILL an ALARM condition:
  136. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("BLTouch Recovery Failed");
  137. SERIAL_ERROR_MSG(STR_STOP_BLTOUCH); // Tell the user something is wrong, needs action
  138. stop(); // but it's not too bad, no need to kill, allow restart
  139. return true; // Tell our caller we goofed in case he cares to know
  140. }
  141. }
  142. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("bltouch.stow_proc() end");
  143. return false; // report success to caller
  144. }
  145. bool BLTouch::status_proc() {
  146. /**
  147. * Return a TRUE for "YES, it is DEPLOYED"
  148. * This function will ensure switch state is reset after execution
  149. */
  150. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("BLTouch STATUS requested");
  151. _set_SW_mode(); // Incidentally, _set_SW_mode() will also RESET any active alarm
  152. const bool tr = triggered(); // If triggered in SW mode, the pin is up, it is STOWED
  153. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("BLTouch is ", (int)tr);
  154. if (tr) _stow(); else _deploy(); // Turn off SW mode, reset any trigger, honor pin state
  155. return !tr;
  156. }
  157. void BLTouch::mode_conv_proc(const bool M5V) {
  158. /**
  159. * BLTOUCH pre V3.0 and clones: No reaction at all to this sequence apart from a DEPLOY -> STOW
  160. * BLTOUCH V3.0: This will set the mode (twice) and sadly, a STOW is needed at the end, because of the deploy
  161. * BLTOUCH V3.1: This will set the mode and store it in the eeprom. The STOW is not needed but does not hurt
  162. */
  163. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("BLTouch Set Mode - ", (int)M5V);
  164. _deploy();
  165. if (M5V) _set_5V_mode(); else _set_OD_mode();
  166. _mode_store();
  167. if (M5V) _set_5V_mode(); else _set_OD_mode();
  168. _stow();
  169. last_written_mode = M5V;
  170. }
  171. #endif // BLTOUCH