My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

babystep.cpp 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 <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::add_mm(const AxisEnum axis, const float &mm) {
  45. add_steps(axis, mm * planner.settings.axis_steps_per_mm[axis]);
  46. }
  47. void Babystep::add_steps(const AxisEnum axis, const int16_t distance) {
  48. #if ENABLED(BABYSTEP_WITHOUT_HOMING)
  49. #define CAN_BABYSTEP(AXIS) true
  50. #else
  51. extern uint8_t axis_known_position;
  52. #define CAN_BABYSTEP(AXIS) TEST(axis_known_position, AXIS)
  53. #endif
  54. if (!CAN_BABYSTEP(axis)) return;
  55. accum += distance; // Count up babysteps for the UI
  56. #if ENABLED(BABYSTEP_DISPLAY_TOTAL)
  57. axis_total[BS_TOTAL_AXIS(axis)] += distance;
  58. #endif
  59. #if ENABLED(BABYSTEP_ALWAYS_AVAILABLE)
  60. #define BSA_ENABLE(AXIS) do{ switch (AXIS) { case X_AXIS: ENABLE_AXIS_X(); break; case Y_AXIS: ENABLE_AXIS_Y(); break; case Z_AXIS: ENABLE_AXIS_Z(); break; default: break; } }while(0)
  61. #else
  62. #define BSA_ENABLE(AXIS) NOOP
  63. #endif
  64. #if IS_CORE
  65. #if ENABLED(BABYSTEP_XY)
  66. switch (axis) {
  67. case CORE_AXIS_1: // X on CoreXY and CoreXZ, Y on CoreYZ
  68. BSA_ENABLE(CORE_AXIS_1);
  69. BSA_ENABLE(CORE_AXIS_2);
  70. steps[CORE_AXIS_1] += distance * 2;
  71. steps[CORE_AXIS_2] += distance * 2;
  72. break;
  73. case CORE_AXIS_2: // Y on CoreXY, Z on CoreXZ and CoreYZ
  74. BSA_ENABLE(CORE_AXIS_1);
  75. BSA_ENABLE(CORE_AXIS_2);
  76. steps[CORE_AXIS_1] += CORESIGN(distance * 2);
  77. steps[CORE_AXIS_2] -= CORESIGN(distance * 2);
  78. break;
  79. case NORMAL_AXIS: // Z on CoreXY, Y on CoreXZ, X on CoreYZ
  80. default:
  81. BSA_ENABLE(NORMAL_AXIS);
  82. steps[NORMAL_AXIS] += distance;
  83. break;
  84. }
  85. #elif CORE_IS_XZ || CORE_IS_YZ
  86. // Only Z stepping needs to be handled here
  87. BSA_ENABLE(CORE_AXIS_1);
  88. BSA_ENABLE(CORE_AXIS_2);
  89. steps[CORE_AXIS_1] += CORESIGN(distance * 2);
  90. steps[CORE_AXIS_2] -= CORESIGN(distance * 2);
  91. #else
  92. BSA_ENABLE(Z_AXIS);
  93. steps[Z_AXIS] += distance;
  94. #endif
  95. #else
  96. #if ENABLED(BABYSTEP_XY)
  97. BSA_ENABLE(axis);
  98. #else
  99. BSA_ENABLE(Z_AXIS);
  100. #endif
  101. steps[BS_TODO_AXIS(axis)] += distance;
  102. #endif
  103. #if ENABLED(BABYSTEP_ALWAYS_AVAILABLE)
  104. gcode.reset_stepper_timeout();
  105. #endif
  106. #if ENABLED(INTEGRATED_BABYSTEPPING)
  107. if (has_steps()) stepper.initiateBabystepping();
  108. #endif
  109. }
  110. #endif // BABYSTEPPING