Fix Babystepping loop (again)

This commit is contained in:
Scott Lahteine 2020-02-24 05:29:13 -06:00
parent 8ba5ef8cae
commit 5e197df89a
8 changed files with 48 additions and 36 deletions

View file

@ -35,17 +35,17 @@
Babystep babystep;
volatile int16_t Babystep::steps[BS_TODO_AXIS(Z_AXIS) + 1];
volatile int16_t Babystep::steps[BS_AXIS_IND(Z_AXIS) + 1];
#if ENABLED(BABYSTEP_DISPLAY_TOTAL)
int16_t Babystep::axis_total[BS_TOTAL_AXIS(Z_AXIS) + 1];
#endif
int16_t Babystep::accum;
void Babystep::step_axis(const AxisEnum axis) {
const int16_t curTodo = steps[BS_TODO_AXIS(axis)]; // get rid of volatile for performance
const int16_t curTodo = steps[BS_AXIS_IND(axis)]; // get rid of volatile for performance
if (curTodo) {
stepper.do_babystep((AxisEnum)axis, curTodo > 0);
if (curTodo > 0) steps[BS_TODO_AXIS(axis)]--; else steps[BS_TODO_AXIS(axis)]++;
if (curTodo > 0) steps[BS_AXIS_IND(axis)]--; else steps[BS_AXIS_IND(axis)]++;
}
}
@ -112,7 +112,7 @@ void Babystep::add_steps(const AxisEnum axis, const int16_t distance) {
#else
BSA_ENABLE(Z_AXIS);
#endif
steps[BS_TODO_AXIS(axis)] += distance;
steps[BS_AXIS_IND(axis)] += distance;
#endif
#if ENABLED(BABYSTEP_ALWAYS_AVAILABLE)
gcode.reset_stepper_timeout();

View file

@ -32,9 +32,11 @@
#endif
#if IS_CORE || EITHER(BABYSTEP_XY, I2C_POSITION_ENCODERS)
#define BS_TODO_AXIS(A) A
#define BS_AXIS_IND(A) A
#define BS_AXIS(I) AxisEnum(I)
#else
#define BS_TODO_AXIS(A) 0
#define BS_AXIS_IND(A) 0
#define BS_AXIS(I) Z_AXIS
#endif
#if ENABLED(BABYSTEP_DISPLAY_TOTAL)
@ -47,7 +49,7 @@
class Babystep {
public:
static volatile int16_t steps[BS_TODO_AXIS(Z_AXIS) + 1];
static volatile int16_t steps[BS_AXIS_IND(Z_AXIS) + 1];
static int16_t accum; // Total babysteps in current edit
#if ENABLED(BABYSTEP_DISPLAY_TOTAL)
@ -65,7 +67,7 @@ public:
static void add_mm(const AxisEnum axis, const float &mm);
static inline bool has_steps() {
return steps[BS_TODO_AXIS(X_AXIS)] || steps[BS_TODO_AXIS(Y_AXIS)] || steps[BS_TODO_AXIS(Z_AXIS)];
return steps[BS_AXIS_IND(X_AXIS)] || steps[BS_AXIS_IND(Y_AXIS)] || steps[BS_AXIS_IND(Z_AXIS)];
}
//
@ -73,7 +75,7 @@ public:
// apply accumulated babysteps to the axes.
//
static inline void task() {
LOOP_LE_N(axis, BS_TODO_AXIS(Z_AXIS)) step_axis((AxisEnum)axis);
LOOP_LE_N(i, BS_AXIS_IND(Z_AXIS)) step_axis(BS_AXIS(i));
}
private:

View file

@ -131,7 +131,7 @@ void GcodeSuite::M290() {
#else
PSTR("Babystep Z")
#endif
, babystep.axis_total[BS_TODO_AXIS(Z_AXIS)]
, babystep.axis_total[BS_AXIS_IND(Z_AXIS)]
);
}
#endif

View file

@ -785,7 +785,7 @@ namespace ExtUI {
#if HAS_BED_PROBE
return probe.offset.z;
#elif ENABLED(BABYSTEP_DISPLAY_TOTAL)
return (planner.steps_to_mm[Z_AXIS] * babystep.axis_total[BS_TODO_AXIS(Z_AXIS)]);
return (planner.steps_to_mm[Z_AXIS] * babystep.axis_total[BS_AXIS_IND(Z_AXIS)]);
#else
return 0.0;
#endif

View file

@ -81,6 +81,8 @@
Stepper stepper; // Singleton
#define BABYSTEPPING_EXTRA_DIR_WAIT
#if HAS_MOTOR_CURRENT_PWM
bool Stepper::initialized; // = false
#endif
@ -1367,8 +1369,8 @@ void Stepper::isr() {
#endif
#if ENABLED(INTEGRATED_BABYSTEPPING)
const bool do_babystep = (nextBabystepISR == 0); // 0 = Do Babystepping (XY)Z pulses
if (do_babystep) nextBabystepISR = babystepping_isr();
const bool is_babystep = (nextBabystepISR == 0); // 0 = Do Babystepping (XY)Z pulses
if (is_babystep) nextBabystepISR = babystepping_isr();
#endif
// ^== Time critical. NOTHING besides pulse generation should be above here!!!
@ -1376,7 +1378,7 @@ void Stepper::isr() {
if (!nextMainISR) nextMainISR = block_phase_isr(); // Manage acc/deceleration, get next block
#if ENABLED(INTEGRATED_BABYSTEPPING)
if (do_babystep) // Avoid ANY stepping too soon after baby-stepping
if (is_babystep) // Avoid ANY stepping too soon after baby-stepping
NOLESS(nextMainISR, (BABYSTEP_TICKS) / 8); // FULL STOP for 125µs after a baby-step
if (nextBabystepISR != BABYSTEP_NEVER) // Avoid baby-stepping too close to axis Stepping
@ -2507,6 +2509,14 @@ void Stepper::report_positions() {
#endif
#endif
#if ENABLED(BABYSTEPPING_EXTRA_DIR_WAIT)
#define EXTRA_DIR_WAIT_BEFORE DIR_WAIT_BEFORE
#define EXTRA_DIR_WAIT_AFTER DIR_WAIT_AFTER
#else
#define EXTRA_DIR_WAIT_BEFORE()
#define EXTRA_DIR_WAIT_AFTER()
#endif
#if DISABLED(DELTA)
#define BABYSTEP_AXIS(AXIS, INV, DIR) do{ \
@ -2519,9 +2529,9 @@ void Stepper::report_positions() {
_APPLY_STEP(AXIS, !_INVERT_STEP_PIN(AXIS), true); \
_PULSE_WAIT(); \
_APPLY_STEP(AXIS, _INVERT_STEP_PIN(AXIS), true); \
DIR_WAIT_BEFORE(); \
EXTRA_DIR_WAIT_BEFORE(); \
_APPLY_DIR(AXIS, old_dir); \
DIR_WAIT_AFTER(); \
EXTRA_DIR_WAIT_AFTER(); \
}while(0)
#elif IS_CORE
@ -2539,9 +2549,9 @@ void Stepper::report_positions() {
_PULSE_WAIT(); \
_APPLY_STEP(A, _INVERT_STEP_PIN(A), true); \
_APPLY_STEP(B, _INVERT_STEP_PIN(B), true); \
DIR_WAIT_BEFORE(); \
EXTRA_DIR_WAIT_BEFORE(); \
_APPLY_DIR(A, old_dir.a); _APPLY_DIR(B, old_dir.b); \
DIR_WAIT_AFTER(); \
EXTRA_DIR_WAIT_AFTER(); \
}while(0)
#endif
@ -2620,13 +2630,13 @@ void Stepper::report_positions() {
Z_STEP_WRITE(INVERT_Z_STEP_PIN);
// Restore direction bits
DIR_WAIT_BEFORE();
EXTRA_DIR_WAIT_BEFORE();
X_DIR_WRITE(old_dir.x);
Y_DIR_WRITE(old_dir.y);
Z_DIR_WRITE(old_dir.z);
DIR_WAIT_AFTER();
EXTRA_DIR_WAIT_AFTER();
#endif