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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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/MarlinConfig.h"
  23. #if ENABLED(BABYSTEPPING)
  24. #include "babystep.h"
  25. #include "../MarlinCore.h"
  26. #include "../module/motion.h" // for axes_should_home()
  27. #include "../module/planner.h" // for axis_steps_per_mm[]
  28. #include "../module/stepper.h"
  29. #if ENABLED(BABYSTEP_ALWAYS_AVAILABLE)
  30. #include "../gcode/gcode.h"
  31. #endif
  32. Babystep babystep;
  33. volatile int16_t Babystep::steps[BS_AXIS_IND(Z_AXIS) + 1];
  34. #if ENABLED(BABYSTEP_DISPLAY_TOTAL)
  35. int16_t Babystep::axis_total[BS_TOTAL_IND(Z_AXIS) + 1];
  36. #endif
  37. int16_t Babystep::accum;
  38. void Babystep::step_axis(const AxisEnum axis) {
  39. const int16_t curTodo = steps[BS_AXIS_IND(axis)]; // get rid of volatile for performance
  40. if (curTodo) {
  41. stepper.do_babystep((AxisEnum)axis, curTodo > 0);
  42. if (curTodo > 0) steps[BS_AXIS_IND(axis)]--; else steps[BS_AXIS_IND(axis)]++;
  43. }
  44. }
  45. void Babystep::add_mm(const AxisEnum axis, const float &mm) {
  46. add_steps(axis, mm * planner.settings.axis_steps_per_mm[axis]);
  47. }
  48. void Babystep::add_steps(const AxisEnum axis, const int16_t distance) {
  49. if (DISABLED(BABYSTEP_WITHOUT_HOMING) && axes_should_home(_BV(axis))) return;
  50. accum += distance; // Count up babysteps for the UI
  51. steps[BS_AXIS_IND(axis)] += distance;
  52. TERN_(BABYSTEP_DISPLAY_TOTAL, axis_total[BS_TOTAL_IND(axis)] += distance);
  53. TERN_(BABYSTEP_ALWAYS_AVAILABLE, gcode.reset_stepper_timeout());
  54. TERN_(INTEGRATED_BABYSTEPPING, if (has_steps()) stepper.initiateBabystepping());
  55. }
  56. #endif // BABYSTEPPING