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.

babystep.cpp 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2019 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(BABYSTEPPING)
  24. #include "babystep.h"
  25. #include "../MarlinCore.h"
  26. #include "../module/planner.h"
  27. #include "../module/stepper.h"
  28. #if ENABLED(BABYSTEP_ALWAYS_AVAILABLE)
  29. #include "../gcode/gcode.h"
  30. #endif
  31. Babystep babystep;
  32. volatile int16_t Babystep::steps[BS_TODO_AXIS(Z_AXIS) + 1];
  33. #if ENABLED(BABYSTEP_DISPLAY_TOTAL)
  34. int16_t Babystep::axis_total[BS_TOTAL_AXIS(Z_AXIS) + 1];
  35. #endif
  36. int16_t Babystep::accum;
  37. void Babystep::step_axis(const AxisEnum axis) {
  38. const int16_t curTodo = steps[BS_TODO_AXIS(axis)]; // get rid of volatile for performance
  39. if (curTodo) {
  40. stepper.babystep((AxisEnum)axis, curTodo > 0);
  41. if (curTodo > 0) steps[BS_TODO_AXIS(axis)]--; else steps[BS_TODO_AXIS(axis)]++;
  42. }
  43. }
  44. void Babystep::task() {
  45. #if EITHER(BABYSTEP_XY, I2C_POSITION_ENCODERS)
  46. LOOP_XYZ(axis) step_axis((AxisEnum)axis);
  47. #else
  48. step_axis(Z_AXIS);
  49. #endif
  50. }
  51. void Babystep::add_mm(const AxisEnum axis, const float &mm) {
  52. add_steps(axis, mm * planner.settings.axis_steps_per_mm[axis]);
  53. }
  54. void Babystep::add_steps(const AxisEnum axis, const int16_t distance) {
  55. #if ENABLED(BABYSTEP_WITHOUT_HOMING)
  56. #define CAN_BABYSTEP(AXIS) true
  57. #else
  58. extern uint8_t axis_known_position;
  59. #define CAN_BABYSTEP(AXIS) TEST(axis_known_position, AXIS)
  60. #endif
  61. if (!CAN_BABYSTEP(axis)) return;
  62. accum += distance; // Count up babysteps for the UI
  63. #if ENABLED(BABYSTEP_DISPLAY_TOTAL)
  64. axis_total[BS_TOTAL_AXIS(axis)] += distance;
  65. #endif
  66. #if ENABLED(BABYSTEP_ALWAYS_AVAILABLE)
  67. #define BSA_ENABLE(AXIS) do{ switch (AXIS) { case X_AXIS: enable_X(); break; case Y_AXIS: enable_Y(); break; case Z_AXIS: enable_Z(); break; default: break; } }while(0)
  68. #else
  69. #define BSA_ENABLE(AXIS) NOOP
  70. #endif
  71. #if IS_CORE
  72. #if ENABLED(BABYSTEP_XY)
  73. switch (axis) {
  74. case CORE_AXIS_1: // X on CoreXY and CoreXZ, Y on CoreYZ
  75. BSA_ENABLE(CORE_AXIS_1);
  76. BSA_ENABLE(CORE_AXIS_2);
  77. steps[CORE_AXIS_1] += distance * 2;
  78. steps[CORE_AXIS_2] += distance * 2;
  79. break;
  80. case CORE_AXIS_2: // Y on CoreXY, Z on CoreXZ and CoreYZ
  81. BSA_ENABLE(CORE_AXIS_1);
  82. BSA_ENABLE(CORE_AXIS_2);
  83. steps[CORE_AXIS_1] += CORESIGN(distance * 2);
  84. steps[CORE_AXIS_2] -= CORESIGN(distance * 2);
  85. break;
  86. case NORMAL_AXIS: // Z on CoreXY, Y on CoreXZ, X on CoreYZ
  87. default:
  88. BSA_ENABLE(NORMAL_AXIS);
  89. steps[NORMAL_AXIS] += distance;
  90. break;
  91. }
  92. #elif CORE_IS_XZ || CORE_IS_YZ
  93. // Only Z stepping needs to be handled here
  94. BSA_ENABLE(CORE_AXIS_1);
  95. BSA_ENABLE(CORE_AXIS_2);
  96. steps[CORE_AXIS_1] += CORESIGN(distance * 2);
  97. steps[CORE_AXIS_2] -= CORESIGN(distance * 2);
  98. #else
  99. BSA_ENABLE(Z_AXIS);
  100. steps[Z_AXIS] += distance;
  101. #endif
  102. #else
  103. #if ENABLED(BABYSTEP_XY)
  104. BSA_ENABLE(axis);
  105. #else
  106. BSA_ENABLE(Z_AXIS);
  107. #endif
  108. steps[BS_TODO_AXIS(axis)] += distance;
  109. #endif
  110. #if ENABLED(BABYSTEP_ALWAYS_AVAILABLE)
  111. gcode.reset_stepper_timeout();
  112. #endif
  113. }
  114. #endif // BABYSTEPPING