Cleanup of planner code
- Use named axis indexes, `X_AXIS` etc. - Replace `block.steps_A` with block.steps[A]` - Replace `A_segment_time` with `segment_time[A]` - Add `A_AXIS`, `B_AXIS` for `COREXY` axes - Conditional compile based on `EXTRUDERS` - Add BLOCK_MOD macro for planner block indexes - Apply coding standards to `planner.h` and `planner.cpp` - Small optimizations of planner code - Update `stepper.cpp` for new `block` struct - Replace `memcpy` with loops, let the compiler unroll them - Make `movesplanned` into an inline function
This commit is contained in:
@ -370,7 +370,7 @@ ISR(TIMER1_COMPA_vect) {
|
||||
step_events_completed = 0;
|
||||
|
||||
#ifdef Z_LATE_ENABLE
|
||||
if (current_block->steps_z > 0) {
|
||||
if (current_block->steps[Z_AXIS] > 0) {
|
||||
enable_z();
|
||||
OCR1A = 2000; //1ms wait
|
||||
return;
|
||||
@ -411,7 +411,7 @@ ISR(TIMER1_COMPA_vect) {
|
||||
|
||||
#define UPDATE_ENDSTOP(axis,AXIS,minmax,MINMAX) \
|
||||
bool axis ##_## minmax ##_endstop = (READ(AXIS ##_## MINMAX ##_PIN) != AXIS ##_## MINMAX ##_ENDSTOP_INVERTING); \
|
||||
if (axis ##_## minmax ##_endstop && old_## axis ##_## minmax ##_endstop && (current_block->steps_## axis > 0)) { \
|
||||
if (axis ##_## minmax ##_endstop && old_## axis ##_## minmax ##_endstop && (current_block->steps[AXIS ##_AXIS] > 0)) { \
|
||||
endstops_trigsteps[AXIS ##_AXIS] = count_position[AXIS ##_AXIS]; \
|
||||
endstop_## axis ##_hit = true; \
|
||||
step_events_completed = current_block->step_event_count; \
|
||||
@ -420,54 +420,54 @@ ISR(TIMER1_COMPA_vect) {
|
||||
|
||||
// Check X and Y endstops
|
||||
if (check_endstops) {
|
||||
#ifndef COREXY
|
||||
if (TEST(out_bits, X_AXIS)) // stepping along -X axis (regular cartesians bot)
|
||||
#else
|
||||
#ifdef COREXY
|
||||
// Head direction in -X axis for CoreXY bots.
|
||||
// If DeltaX == -DeltaY, the movement is only in Y axis
|
||||
if (current_block->steps_x != current_block->steps_y || (TEST(out_bits, X_AXIS) == TEST(out_bits, Y_AXIS)))
|
||||
if (TEST(out_bits, X_HEAD))
|
||||
#endif
|
||||
{ // -direction
|
||||
#ifdef DUAL_X_CARRIAGE
|
||||
// with 2 x-carriages, endstops are only checked in the homing direction for the active extruder
|
||||
if ((current_block->active_extruder == 0 && X_HOME_DIR == -1) || (current_block->active_extruder != 0 && X2_HOME_DIR == -1))
|
||||
#endif
|
||||
{
|
||||
#if defined(X_MIN_PIN) && X_MIN_PIN >= 0
|
||||
UPDATE_ENDSTOP(x, X, min, MIN);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else { // +direction
|
||||
#ifdef DUAL_X_CARRIAGE
|
||||
// with 2 x-carriages, endstops are only checked in the homing direction for the active extruder
|
||||
if ((current_block->active_extruder == 0 && X_HOME_DIR == 1) || (current_block->active_extruder != 0 && X2_HOME_DIR == 1))
|
||||
#endif
|
||||
{
|
||||
#if defined(X_MAX_PIN) && X_MAX_PIN >= 0
|
||||
UPDATE_ENDSTOP(x, X, max, MAX);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#ifndef COREXY
|
||||
if (TEST(out_bits, Y_AXIS)) // -direction
|
||||
if (current_block->steps[A_AXIS] != current_block->steps[B_AXIS] || (TEST(out_bits, A_AXIS) == TEST(out_bits, B_AXIS)))
|
||||
if (TEST(out_bits, X_HEAD))
|
||||
#else
|
||||
if (TEST(out_bits, X_AXIS)) // stepping along -X axis (regular cartesians bot)
|
||||
#endif
|
||||
{ // -direction
|
||||
#ifdef DUAL_X_CARRIAGE
|
||||
// with 2 x-carriages, endstops are only checked in the homing direction for the active extruder
|
||||
if ((current_block->active_extruder == 0 && X_HOME_DIR == -1) || (current_block->active_extruder != 0 && X2_HOME_DIR == -1))
|
||||
#endif
|
||||
{
|
||||
#if defined(X_MIN_PIN) && X_MIN_PIN >= 0
|
||||
UPDATE_ENDSTOP(x, X, min, MIN);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else { // +direction
|
||||
#ifdef DUAL_X_CARRIAGE
|
||||
// with 2 x-carriages, endstops are only checked in the homing direction for the active extruder
|
||||
if ((current_block->active_extruder == 0 && X_HOME_DIR == 1) || (current_block->active_extruder != 0 && X2_HOME_DIR == 1))
|
||||
#endif
|
||||
{
|
||||
#if defined(X_MAX_PIN) && X_MAX_PIN >= 0
|
||||
UPDATE_ENDSTOP(x, X, max, MAX);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#ifdef COREXY
|
||||
// Head direction in -Y axis for CoreXY bots.
|
||||
// If DeltaX == DeltaY, the movement is only in X axis
|
||||
if (current_block->steps_x != current_block->steps_y || (TEST(out_bits, X_AXIS) != TEST(out_bits, Y_AXIS)))
|
||||
if (TEST(out_bits, Y_HEAD))
|
||||
if (current_block->steps[A_AXIS] != current_block->steps[B_AXIS] || (TEST(out_bits, A_AXIS) != TEST(out_bits, B_AXIS)))
|
||||
if (TEST(out_bits, Y_HEAD))
|
||||
#else
|
||||
if (TEST(out_bits, Y_AXIS)) // -direction
|
||||
#endif
|
||||
{ // -direction
|
||||
#if defined(Y_MIN_PIN) && Y_MIN_PIN >= 0
|
||||
UPDATE_ENDSTOP(y, Y, min, MIN);
|
||||
#endif
|
||||
}
|
||||
else { // +direction
|
||||
#if defined(Y_MAX_PIN) && Y_MAX_PIN >= 0
|
||||
UPDATE_ENDSTOP(y, Y, max, MAX);
|
||||
#endif
|
||||
}
|
||||
{ // -direction
|
||||
#if defined(Y_MIN_PIN) && Y_MIN_PIN >= 0
|
||||
UPDATE_ENDSTOP(y, Y, min, MIN);
|
||||
#endif
|
||||
}
|
||||
else { // +direction
|
||||
#if defined(Y_MAX_PIN) && Y_MAX_PIN >= 0
|
||||
UPDATE_ENDSTOP(y, Y, max, MAX);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (TEST(out_bits, Z_AXIS)) { // -direction
|
||||
@ -515,7 +515,7 @@ ISR(TIMER1_COMPA_vect) {
|
||||
#endif
|
||||
|
||||
#ifdef ADVANCE
|
||||
counter_e += current_block->steps_e;
|
||||
counter_e += current_block->steps[E_AXIS];
|
||||
if (counter_e > 0) {
|
||||
counter_e -= current_block->step_event_count;
|
||||
e_steps[current_block->active_extruder] += TEST(out_bits, E_AXIS) ? -1 : 1;
|
||||
@ -529,15 +529,14 @@ ISR(TIMER1_COMPA_vect) {
|
||||
* instead of doing each in turn. The extra tests add enough
|
||||
* lag to allow it work with without needing NOPs
|
||||
*/
|
||||
counter_x += current_block->steps_x;
|
||||
if (counter_x > 0) X_STEP_WRITE(HIGH);
|
||||
counter_y += current_block->steps_y;
|
||||
if (counter_y > 0) Y_STEP_WRITE(HIGH);
|
||||
counter_z += current_block->steps_z;
|
||||
if (counter_z > 0) Z_STEP_WRITE(HIGH);
|
||||
#define STEP_ADD(axis, AXIS) \
|
||||
counter_## axis += current_block->steps[AXIS ##_AXIS]; \
|
||||
if (counter_## axis > 0) { AXIS ##_STEP_WRITE(HIGH); }
|
||||
STEP_ADD(x,X);
|
||||
STEP_ADD(y,Y);
|
||||
STEP_ADD(z,Z);
|
||||
#ifndef ADVANCE
|
||||
counter_e += current_block->steps_e;
|
||||
if (counter_e > 0) E_STEP_WRITE(HIGH);
|
||||
STEP_ADD(e,E);
|
||||
#endif
|
||||
|
||||
#define STEP_IF_COUNTER(axis, AXIS) \
|
||||
@ -557,7 +556,7 @@ ISR(TIMER1_COMPA_vect) {
|
||||
#else // !CONFIG_STEPPERS_TOSHIBA
|
||||
|
||||
#define APPLY_MOVEMENT(axis, AXIS) \
|
||||
counter_## axis += current_block->steps_## axis; \
|
||||
counter_## axis += current_block->steps[AXIS ##_AXIS]; \
|
||||
if (counter_## axis > 0) { \
|
||||
AXIS ##_APPLY_STEP(!INVERT_## AXIS ##_STEP_PIN,0); \
|
||||
counter_## axis -= current_block->step_event_count; \
|
||||
|
Reference in New Issue
Block a user