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.6KB

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