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.

G38.cpp 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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(G38_PROBE_TARGET)
  24. #include "../gcode.h"
  25. #include "../../module/endstops.h"
  26. #include "../../module/motion.h"
  27. #include "../../module/stepper.h"
  28. #include "../../module/probe.h"
  29. inline void G38_single_probe(const uint8_t move_value) {
  30. endstops.enable(true);
  31. G38_move = move_value;
  32. prepare_line_to_destination();
  33. planner.synchronize();
  34. G38_move = 0;
  35. endstops.hit_on_purpose();
  36. set_current_from_steppers_for_axis(ALL_AXES);
  37. sync_plan_position();
  38. }
  39. inline bool G38_run_probe() {
  40. bool G38_pass_fail = false;
  41. #if MULTIPLE_PROBING > 1
  42. // Get direction of move and retract
  43. xyz_float_t retract_mm;
  44. LOOP_XYZ(i) {
  45. const float dist = destination[i] - current_position[i];
  46. retract_mm[i] = ABS(dist) < G38_MINIMUM_MOVE ? 0 : home_bump_mm((AxisEnum)i) * (dist > 0 ? -1 : 1);
  47. }
  48. #endif
  49. planner.synchronize(); // wait until the machine is idle
  50. // Move flag value
  51. #if ENABLED(G38_PROBE_AWAY)
  52. const uint8_t move_value = parser.subcode;
  53. #else
  54. constexpr uint8_t move_value = 1;
  55. #endif
  56. G38_did_trigger = false;
  57. // Move until destination reached or target hit
  58. G38_single_probe(move_value);
  59. if (G38_did_trigger) {
  60. G38_pass_fail = true;
  61. #if MULTIPLE_PROBING > 1
  62. // Move away by the retract distance
  63. destination = current_position + retract_mm;
  64. endstops.enable(false);
  65. prepare_line_to_destination();
  66. planner.synchronize();
  67. REMEMBER(fr, feedrate_mm_s, feedrate_mm_s * 0.25);
  68. // Bump the target more slowly
  69. destination -= retract_mm * 2;
  70. G38_single_probe(move_value);
  71. #endif
  72. }
  73. endstops.not_homing();
  74. return G38_pass_fail;
  75. }
  76. /**
  77. * G38 Probe Target
  78. *
  79. * G38.2 - Probe toward workpiece, stop on contact, signal error if failure
  80. * G38.3 - Probe toward workpiece, stop on contact
  81. *
  82. * With G38_PROBE_AWAY:
  83. *
  84. * G38.4 - Probe away from workpiece, stop on contact break, signal error if failure
  85. * G38.5 - Probe away from workpiece, stop on contact break
  86. */
  87. void GcodeSuite::G38(const int8_t subcode) {
  88. // Get X Y Z E F
  89. get_destination_from_command();
  90. remember_feedrate_scaling_off();
  91. const bool error_on_fail =
  92. #if ENABLED(G38_PROBE_AWAY)
  93. !TEST(subcode, 0)
  94. #else
  95. (subcode == 2)
  96. #endif
  97. ;
  98. // If any axis has enough movement, do the move
  99. LOOP_XYZ(i)
  100. if (ABS(destination[i] - current_position[i]) >= G38_MINIMUM_MOVE) {
  101. if (!parser.seenval('F')) feedrate_mm_s = homing_feedrate((AxisEnum)i);
  102. // If G38.2 fails throw an error
  103. if (!G38_run_probe() && error_on_fail) SERIAL_ERROR_MSG("Failed to reach target");
  104. break;
  105. }
  106. restore_feedrate_and_scaling();
  107. }
  108. #endif // G38_PROBE_TARGET