2019-04-07 01:04:34 +02:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2020-02-03 15:00:57 +01:00
|
|
|
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2019-04-07 01:04:34 +02:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
2019-06-28 06:57:50 +02:00
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
2019-04-07 01:04:34 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2020-07-23 05:20:14 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2019-04-07 01:04:34 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "../inc/MarlinConfig.h"
|
|
|
|
|
|
|
|
#if ENABLED(BABYSTEPPING)
|
|
|
|
|
|
|
|
#include "babystep.h"
|
2020-01-03 02:01:38 +01:00
|
|
|
#include "../MarlinCore.h"
|
2020-08-27 23:05:53 +02:00
|
|
|
#include "../module/motion.h" // for axes_should_home()
|
|
|
|
#include "../module/planner.h" // for axis_steps_per_mm[]
|
2019-04-07 01:04:34 +02:00
|
|
|
#include "../module/stepper.h"
|
|
|
|
|
|
|
|
#if ENABLED(BABYSTEP_ALWAYS_AVAILABLE)
|
|
|
|
#include "../gcode/gcode.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
Babystep babystep;
|
|
|
|
|
2020-02-24 12:29:13 +01:00
|
|
|
volatile int16_t Babystep::steps[BS_AXIS_IND(Z_AXIS) + 1];
|
2019-09-28 23:58:48 +02:00
|
|
|
#if ENABLED(BABYSTEP_DISPLAY_TOTAL)
|
2020-02-24 13:11:31 +01:00
|
|
|
int16_t Babystep::axis_total[BS_TOTAL_IND(Z_AXIS) + 1];
|
2019-04-07 01:04:34 +02:00
|
|
|
#endif
|
2019-09-28 23:58:48 +02:00
|
|
|
int16_t Babystep::accum;
|
2019-04-07 01:04:34 +02:00
|
|
|
|
|
|
|
void Babystep::step_axis(const AxisEnum axis) {
|
2020-02-24 12:29:13 +01:00
|
|
|
const int16_t curTodo = steps[BS_AXIS_IND(axis)]; // get rid of volatile for performance
|
2019-04-07 01:04:34 +02:00
|
|
|
if (curTodo) {
|
2020-02-17 00:46:41 +01:00
|
|
|
stepper.do_babystep((AxisEnum)axis, curTodo > 0);
|
2020-02-24 12:29:13 +01:00
|
|
|
if (curTodo > 0) steps[BS_AXIS_IND(axis)]--; else steps[BS_AXIS_IND(axis)]++;
|
2019-04-07 01:04:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-02 00:59:57 +02:00
|
|
|
void Babystep::add_mm(const AxisEnum axis, const_float_t mm) {
|
2019-04-07 01:04:34 +02:00
|
|
|
add_steps(axis, mm * planner.settings.axis_steps_per_mm[axis]);
|
|
|
|
}
|
|
|
|
|
2019-04-11 01:34:38 +02:00
|
|
|
void Babystep::add_steps(const AxisEnum axis, const int16_t distance) {
|
2020-08-27 23:05:53 +02:00
|
|
|
if (DISABLED(BABYSTEP_WITHOUT_HOMING) && axes_should_home(_BV(axis))) return;
|
2019-04-07 01:04:34 +02:00
|
|
|
|
2019-09-28 23:58:48 +02:00
|
|
|
accum += distance; // Count up babysteps for the UI
|
2020-06-18 22:28:52 +02:00
|
|
|
steps[BS_AXIS_IND(axis)] += distance;
|
2020-04-22 23:35:03 +02:00
|
|
|
TERN_(BABYSTEP_DISPLAY_TOTAL, axis_total[BS_TOTAL_IND(axis)] += distance);
|
|
|
|
TERN_(BABYSTEP_ALWAYS_AVAILABLE, gcode.reset_stepper_timeout());
|
|
|
|
TERN_(INTEGRATED_BABYSTEPPING, if (has_steps()) stepper.initiateBabystepping());
|
2019-04-07 01:04:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // BABYSTEPPING
|