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.h 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. #pragma once
  23. #include "../inc/MarlinConfigPre.h"
  24. #if ENABLED(INTEGRATED_BABYSTEPPING)
  25. #define BABYSTEPS_PER_SEC 1000UL
  26. #define BABYSTEP_TICKS ((STEPPER_TIMER_RATE) / (BABYSTEPS_PER_SEC))
  27. #else
  28. #define BABYSTEPS_PER_SEC 976UL
  29. #define BABYSTEP_TICKS ((TEMP_TIMER_RATE) / (BABYSTEPS_PER_SEC))
  30. #endif
  31. #if IS_CORE || EITHER(BABYSTEP_XY, I2C_POSITION_ENCODERS)
  32. #define BS_TODO_AXIS(A) A
  33. #else
  34. #define BS_TODO_AXIS(A) 0
  35. #endif
  36. #if ENABLED(BABYSTEP_DISPLAY_TOTAL)
  37. #if ENABLED(BABYSTEP_XY)
  38. #define BS_TOTAL_AXIS(A) A
  39. #else
  40. #define BS_TOTAL_AXIS(A) 0
  41. #endif
  42. #endif
  43. class Babystep {
  44. public:
  45. static volatile int16_t steps[BS_TODO_AXIS(Z_AXIS) + 1];
  46. static int16_t accum; // Total babysteps in current edit
  47. #if ENABLED(BABYSTEP_DISPLAY_TOTAL)
  48. static int16_t axis_total[BS_TOTAL_AXIS(Z_AXIS) + 1]; // Total babysteps since G28
  49. static inline void reset_total(const AxisEnum axis) {
  50. if (true
  51. #if ENABLED(BABYSTEP_XY)
  52. && axis == Z_AXIS
  53. #endif
  54. ) axis_total[BS_TOTAL_AXIS(axis)] = 0;
  55. }
  56. #endif
  57. static void add_steps(const AxisEnum axis, const int16_t distance);
  58. static void add_mm(const AxisEnum axis, const float &mm);
  59. static inline bool has_steps() {
  60. return steps[BS_TODO_AXIS(X_AXIS)] || steps[BS_TODO_AXIS(Y_AXIS)] || steps[BS_TODO_AXIS(Z_AXIS)];
  61. }
  62. //
  63. // Called by the Temperature or Stepper ISR to
  64. // apply accumulated babysteps to the axes.
  65. //
  66. static inline void task() {
  67. LOOP_LE_N(axis, BS_TODO_AXIS(Z_AXIS)) step_axis((AxisEnum)axis);
  68. }
  69. private:
  70. static void step_axis(const AxisEnum axis);
  71. };
  72. extern Babystep babystep;