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 4.0KB

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