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.

G0_G1.cpp 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. #include "../gcode.h"
  23. #include "../../module/motion.h"
  24. #include "../../MarlinCore.h"
  25. #if BOTH(FWRETRACT, FWRETRACT_AUTORETRACT)
  26. #include "../../feature/fwretract.h"
  27. #endif
  28. #include "../../sd/cardreader.h"
  29. #if ENABLED(NANODLP_Z_SYNC)
  30. #include "../../module/stepper.h"
  31. #endif
  32. extern xyze_pos_t destination;
  33. #if ENABLED(VARIABLE_G0_FEEDRATE)
  34. feedRate_t fast_move_feedrate = MMM_TO_MMS(G0_FEEDRATE);
  35. #endif
  36. /**
  37. * G0, G1: Coordinated movement of X Y Z E axes
  38. */
  39. void GcodeSuite::G0_G1(TERN_(HAS_FAST_MOVES, const bool fast_move/*=false*/)) {
  40. if (IsRunning()
  41. #if ENABLED(NO_MOTION_BEFORE_HOMING)
  42. && !homing_needed_error(
  43. NUM_AXIS_GANG(
  44. (parser.seen_test('X') ? _BV(X_AXIS) : 0),
  45. | (parser.seen_test('Y') ? _BV(Y_AXIS) : 0),
  46. | (parser.seen_test('Z') ? _BV(Z_AXIS) : 0),
  47. | (parser.seen_test(AXIS4_NAME) ? _BV(I_AXIS) : 0),
  48. | (parser.seen_test(AXIS5_NAME) ? _BV(J_AXIS) : 0),
  49. | (parser.seen_test(AXIS6_NAME) ? _BV(K_AXIS) : 0),
  50. | (parser.seen_test(AXIS7_NAME) ? _BV(U_AXIS) : 0),
  51. | (parser.seen_test(AXIS8_NAME) ? _BV(V_AXIS) : 0),
  52. | (parser.seen_test(AXIS9_NAME) ? _BV(W_AXIS) : 0))
  53. )
  54. #endif
  55. ) {
  56. TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_RUNNING));
  57. #ifdef G0_FEEDRATE
  58. feedRate_t old_feedrate;
  59. #if ENABLED(VARIABLE_G0_FEEDRATE)
  60. if (fast_move) {
  61. old_feedrate = feedrate_mm_s; // Back up the (old) motion mode feedrate
  62. feedrate_mm_s = fast_move_feedrate; // Get G0 feedrate from last usage
  63. }
  64. #endif
  65. #endif
  66. get_destination_from_command(); // Get X Y [Z[I[J[K]]]] [E] F (and set cutter power)
  67. #ifdef G0_FEEDRATE
  68. if (fast_move) {
  69. #if ENABLED(VARIABLE_G0_FEEDRATE)
  70. fast_move_feedrate = feedrate_mm_s; // Save feedrate for the next G0
  71. #else
  72. old_feedrate = feedrate_mm_s; // Back up the (new) motion mode feedrate
  73. feedrate_mm_s = MMM_TO_MMS(G0_FEEDRATE); // Get the fixed G0 feedrate
  74. #endif
  75. }
  76. #endif
  77. #if BOTH(FWRETRACT, FWRETRACT_AUTORETRACT)
  78. if (MIN_AUTORETRACT <= MAX_AUTORETRACT) {
  79. // When M209 Autoretract is enabled, convert E-only moves to firmware retract/recover moves
  80. if (fwretract.autoretract_enabled && parser.seen_test('E')
  81. && !parser.seen(NUM_AXIS_GANG("X", "Y", "Z", STR_I, STR_J, STR_K, STR_U, STR_V, STR_W))
  82. ) {
  83. const float echange = destination.e - current_position.e;
  84. // Is this a retract or recover move?
  85. if (WITHIN(ABS(echange), MIN_AUTORETRACT, MAX_AUTORETRACT) && fwretract.retracted[active_extruder] == (echange > 0.0)) {
  86. current_position.e = destination.e; // Hide a G1-based retract/recover from calculations
  87. sync_plan_position_e(); // AND from the planner
  88. return fwretract.retract(echange < 0.0); // Firmware-based retract/recover (double-retract ignored)
  89. }
  90. }
  91. }
  92. #endif // FWRETRACT
  93. #if IS_SCARA
  94. fast_move ? prepare_fast_move_to_destination() : prepare_line_to_destination();
  95. #else
  96. prepare_line_to_destination();
  97. #endif
  98. #ifdef G0_FEEDRATE
  99. // Restore the motion mode feedrate
  100. if (fast_move) feedrate_mm_s = old_feedrate;
  101. #endif
  102. #if ENABLED(NANODLP_Z_SYNC)
  103. #if ENABLED(NANODLP_ALL_AXIS)
  104. #define _MOVE_SYNC parser.seenval('X') || parser.seenval('Y') || parser.seenval('Z') // For any move wait and output sync message
  105. #else
  106. #define _MOVE_SYNC parser.seenval('Z') // Only for Z move
  107. #endif
  108. if (_MOVE_SYNC) {
  109. planner.synchronize();
  110. SERIAL_ECHOLNPGM(STR_Z_MOVE_COMP);
  111. }
  112. TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_IDLE));
  113. #else
  114. TERN_(FULL_REPORT_TO_HOST_FEATURE, report_current_grblstate_moving());
  115. #endif
  116. }
  117. }