2019-04-06 23:04:34 +00:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2020-02-03 14:00:57 +00:00
|
|
|
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2019-04-06 23:04:34 +00:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
2019-06-28 04:57:50 +00:00
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
2019-04-06 23:04:34 +00: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
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "../inc/MarlinConfig.h"
|
|
|
|
|
|
|
|
#if ENABLED(BABYSTEPPING)
|
|
|
|
|
|
|
|
#include "babystep.h"
|
2020-01-03 01:01:38 +00:00
|
|
|
#include "../MarlinCore.h"
|
2019-04-06 23:04:34 +00:00
|
|
|
#include "../module/planner.h"
|
|
|
|
#include "../module/stepper.h"
|
|
|
|
|
|
|
|
#if ENABLED(BABYSTEP_ALWAYS_AVAILABLE)
|
|
|
|
#include "../gcode/gcode.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
Babystep babystep;
|
|
|
|
|
2019-09-16 20:01:46 +00:00
|
|
|
volatile int16_t Babystep::steps[BS_TODO_AXIS(Z_AXIS) + 1];
|
2019-09-28 21:58:48 +00:00
|
|
|
#if ENABLED(BABYSTEP_DISPLAY_TOTAL)
|
|
|
|
int16_t Babystep::axis_total[BS_TOTAL_AXIS(Z_AXIS) + 1];
|
2019-04-06 23:04:34 +00:00
|
|
|
#endif
|
2019-09-28 21:58:48 +00:00
|
|
|
int16_t Babystep::accum;
|
2019-04-06 23:04:34 +00:00
|
|
|
|
|
|
|
void Babystep::step_axis(const AxisEnum axis) {
|
2019-09-16 20:01:46 +00:00
|
|
|
const int16_t curTodo = steps[BS_TODO_AXIS(axis)]; // get rid of volatile for performance
|
2019-04-06 23:04:34 +00:00
|
|
|
if (curTodo) {
|
|
|
|
stepper.babystep((AxisEnum)axis, curTodo > 0);
|
2019-09-16 20:01:46 +00:00
|
|
|
if (curTodo > 0) steps[BS_TODO_AXIS(axis)]--; else steps[BS_TODO_AXIS(axis)]++;
|
2019-04-06 23:04:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Babystep::add_mm(const AxisEnum axis, const float &mm) {
|
|
|
|
add_steps(axis, mm * planner.settings.axis_steps_per_mm[axis]);
|
|
|
|
}
|
|
|
|
|
2019-04-10 23:34:38 +00:00
|
|
|
void Babystep::add_steps(const AxisEnum axis, const int16_t distance) {
|
2019-04-06 23:04:34 +00:00
|
|
|
|
|
|
|
#if ENABLED(BABYSTEP_WITHOUT_HOMING)
|
|
|
|
#define CAN_BABYSTEP(AXIS) true
|
|
|
|
#else
|
|
|
|
extern uint8_t axis_known_position;
|
|
|
|
#define CAN_BABYSTEP(AXIS) TEST(axis_known_position, AXIS)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!CAN_BABYSTEP(axis)) return;
|
|
|
|
|
2019-09-28 21:58:48 +00:00
|
|
|
accum += distance; // Count up babysteps for the UI
|
|
|
|
#if ENABLED(BABYSTEP_DISPLAY_TOTAL)
|
|
|
|
axis_total[BS_TOTAL_AXIS(axis)] += distance;
|
2019-04-06 23:04:34 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLED(BABYSTEP_ALWAYS_AVAILABLE)
|
2020-01-30 09:24:23 +00:00
|
|
|
#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)
|
2019-04-06 23:04:34 +00:00
|
|
|
#else
|
|
|
|
#define BSA_ENABLE(AXIS) NOOP
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if IS_CORE
|
|
|
|
#if ENABLED(BABYSTEP_XY)
|
|
|
|
switch (axis) {
|
|
|
|
case CORE_AXIS_1: // X on CoreXY and CoreXZ, Y on CoreYZ
|
|
|
|
BSA_ENABLE(CORE_AXIS_1);
|
|
|
|
BSA_ENABLE(CORE_AXIS_2);
|
2019-09-16 20:01:46 +00:00
|
|
|
steps[CORE_AXIS_1] += distance * 2;
|
|
|
|
steps[CORE_AXIS_2] += distance * 2;
|
2019-04-06 23:04:34 +00:00
|
|
|
break;
|
|
|
|
case CORE_AXIS_2: // Y on CoreXY, Z on CoreXZ and CoreYZ
|
|
|
|
BSA_ENABLE(CORE_AXIS_1);
|
|
|
|
BSA_ENABLE(CORE_AXIS_2);
|
2019-09-16 20:01:46 +00:00
|
|
|
steps[CORE_AXIS_1] += CORESIGN(distance * 2);
|
|
|
|
steps[CORE_AXIS_2] -= CORESIGN(distance * 2);
|
2019-04-06 23:04:34 +00:00
|
|
|
break;
|
|
|
|
case NORMAL_AXIS: // Z on CoreXY, Y on CoreXZ, X on CoreYZ
|
|
|
|
default:
|
|
|
|
BSA_ENABLE(NORMAL_AXIS);
|
2019-09-16 20:01:46 +00:00
|
|
|
steps[NORMAL_AXIS] += distance;
|
2019-04-06 23:04:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
#elif CORE_IS_XZ || CORE_IS_YZ
|
|
|
|
// Only Z stepping needs to be handled here
|
|
|
|
BSA_ENABLE(CORE_AXIS_1);
|
|
|
|
BSA_ENABLE(CORE_AXIS_2);
|
2019-09-16 20:01:46 +00:00
|
|
|
steps[CORE_AXIS_1] += CORESIGN(distance * 2);
|
|
|
|
steps[CORE_AXIS_2] -= CORESIGN(distance * 2);
|
2019-04-06 23:04:34 +00:00
|
|
|
#else
|
|
|
|
BSA_ENABLE(Z_AXIS);
|
2019-09-16 20:01:46 +00:00
|
|
|
steps[Z_AXIS] += distance;
|
2019-04-06 23:04:34 +00:00
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#if ENABLED(BABYSTEP_XY)
|
|
|
|
BSA_ENABLE(axis);
|
|
|
|
#else
|
|
|
|
BSA_ENABLE(Z_AXIS);
|
|
|
|
#endif
|
2019-09-16 20:01:46 +00:00
|
|
|
steps[BS_TODO_AXIS(axis)] += distance;
|
2019-04-06 23:04:34 +00:00
|
|
|
#endif
|
|
|
|
#if ENABLED(BABYSTEP_ALWAYS_AVAILABLE)
|
|
|
|
gcode.reset_stepper_timeout();
|
|
|
|
#endif
|
2020-02-16 03:42:28 +00:00
|
|
|
|
|
|
|
#if ENABLED(INTEGRATED_BABYSTEPPING)
|
|
|
|
if (has_steps()) stepper.initiateBabystepping();
|
|
|
|
#endif
|
2019-04-06 23:04:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // BABYSTEPPING
|