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.

G34.cpp 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 "../../inc/MarlinConfigPre.h"
  23. #if ENABLED(MECHANICAL_GANTRY_CALIBRATION)
  24. #include "../gcode.h"
  25. #include "../../module/motion.h"
  26. #include "../../module/stepper.h"
  27. #include "../../module/endstops.h"
  28. #if HAS_LEVELING
  29. #include "../../feature/bedlevel/bedlevel.h"
  30. #endif
  31. #define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE)
  32. #include "../../core/debug_out.h"
  33. void GcodeSuite::G34() {
  34. // Home before the alignment procedure
  35. if (!all_axes_known()) home_all_axes();
  36. SET_SOFT_ENDSTOP_LOOSE(true);
  37. TEMPORARY_BED_LEVELING_STATE(false);
  38. TemporaryGlobalEndstopsState unlock_z(false);
  39. #ifdef GANTRY_CALIBRATION_COMMANDS_PRE
  40. gcode.process_subcommands_now_P(PSTR(GANTRY_CALIBRATION_COMMANDS_PRE));
  41. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Sub Commands Processed");
  42. #endif
  43. #ifdef GANTRY_CALIBRATION_SAFE_POSITION
  44. // Move XY to safe position
  45. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Parking XY");
  46. const xy_pos_t safe_pos = GANTRY_CALIBRATION_SAFE_POSITION;
  47. do_blocking_move_to(safe_pos, MMM_TO_MMS(GANTRY_CALIBRATION_XY_PARK_FEEDRATE));
  48. #endif
  49. const float move_distance = parser.intval('Z', GANTRY_CALIBRATION_EXTRA_HEIGHT),
  50. zbase = ENABLED(GANTRY_CALIBRATION_TO_MIN) ? Z_MIN_POS : Z_MAX_POS,
  51. zpounce = zbase - move_distance, zgrind = zbase + move_distance;
  52. // Move Z to pounce position
  53. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Setting Z Pounce");
  54. do_blocking_move_to_z(zpounce, MMM_TO_MMS(HOMING_FEEDRATE_Z));
  55. // Store current motor settings, then apply reduced value
  56. #define _REDUCE_CURRENT ANY(HAS_MOTOR_CURRENT_SPI, HAS_MOTOR_CURRENT_PWM, HAS_MOTOR_CURRENT_DAC, HAS_MOTOR_CURRENT_I2C, HAS_TRINAMIC_CONFIG)
  57. #if _REDUCE_CURRENT
  58. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Reducing Current");
  59. #endif
  60. #if HAS_MOTOR_CURRENT_SPI
  61. const uint16_t target_current = parser.intval('S', GANTRY_CALIBRATION_CURRENT);
  62. const uint32_t previous_current = stepper.motor_current_setting[Z_AXIS];
  63. stepper.set_digipot_current(Z_AXIS, target_current);
  64. #elif HAS_MOTOR_CURRENT_PWM
  65. const uint16_t target_current = parser.intval('S', GANTRY_CALIBRATION_CURRENT);
  66. const uint32_t previous_current = stepper.motor_current_setting[Z_AXIS];
  67. stepper.set_digipot_current(1, target_current);
  68. #elif HAS_MOTOR_CURRENT_DAC
  69. const float target_current = parser.floatval('S', GANTRY_CALIBRATION_CURRENT);
  70. const float previous_current = dac_amps(Z_AXIS, target_current);
  71. stepper_dac.set_current_value(Z_AXIS, target_current);
  72. #elif ENABLED(HAS_MOTOR_CURRENT_I2C)
  73. const uint16_t target_current = parser.intval('S', GANTRY_CALIBRATION_CURRENT);
  74. previous_current = dac_amps(Z_AXIS);
  75. digipot_i2c.set_current(Z_AXIS, target_current)
  76. #elif HAS_TRINAMIC_CONFIG
  77. const uint16_t target_current = parser.intval('S', GANTRY_CALIBRATION_CURRENT);
  78. static uint16_t previous_current_arr[NUM_Z_STEPPER_DRIVERS];
  79. #if AXIS_IS_TMC(Z)
  80. previous_current_arr[0] = stepperZ.getMilliamps();
  81. stepperZ.rms_current(target_current);
  82. #endif
  83. #if AXIS_IS_TMC(Z2)
  84. previous_current_arr[1] = stepperZ2.getMilliamps();
  85. stepperZ2.rms_current(target_current);
  86. #endif
  87. #if AXIS_IS_TMC(Z3)
  88. previous_current_arr[2] = stepperZ3.getMilliamps();
  89. stepperZ3.rms_current(target_current);
  90. #endif
  91. #if AXIS_IS_TMC(Z4)
  92. previous_current_arr[3] = stepperZ4.getMilliamps();
  93. stepperZ4.rms_current(target_current);
  94. #endif
  95. #endif
  96. // Do Final Z move to adjust
  97. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Final Z Move");
  98. do_blocking_move_to_z(zgrind, MMM_TO_MMS(GANTRY_CALIBRATION_FEEDRATE));
  99. // Back off end plate, back to normal motion range
  100. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Z Backoff");
  101. do_blocking_move_to_z(zpounce, MMM_TO_MMS(GANTRY_CALIBRATION_FEEDRATE));
  102. #if _REDUCE_CURRENT
  103. // Reset current to original values
  104. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Restore Current");
  105. #endif
  106. #if HAS_MOTOR_CURRENT_SPI
  107. stepper.set_digipot_current(Z_AXIS, previous_current);
  108. #elif HAS_MOTOR_CURRENT_PWM
  109. stepper.set_digipot_current(1, previous_current);
  110. #elif HAS_MOTOR_CURRENT_DAC
  111. stepper_dac.set_current_value(Z_AXIS, previous_current);
  112. #elif ENABLED(HAS_MOTOR_CURRENT_I2C)
  113. digipot_i2c.set_current(Z_AXIS, previous_current)
  114. #elif HAS_TRINAMIC_CONFIG
  115. #if AXIS_IS_TMC(Z)
  116. stepperZ.rms_current(previous_current_arr[0]);
  117. #endif
  118. #if AXIS_IS_TMC(Z2)
  119. stepperZ2.rms_current(previous_current_arr[1]);
  120. #endif
  121. #if AXIS_IS_TMC(Z3)
  122. stepperZ3.rms_current(previous_current_arr[2]);
  123. #endif
  124. #if AXIS_IS_TMC(Z4)
  125. stepperZ4.rms_current(previous_current_arr[3]);
  126. #endif
  127. #endif
  128. #ifdef GANTRY_CALIBRATION_COMMANDS_POST
  129. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Running Post Commands");
  130. gcode.process_subcommands_now_P(PSTR(GANTRY_CALIBRATION_COMMANDS_POST));
  131. #endif
  132. SET_SOFT_ENDSTOP_LOOSE(false);
  133. }
  134. #endif // MECHANICAL_GANTRY_CALIBRATION