Skip to content

Commit

Permalink
✏️ Followup to Six Linear Axes (#22056)
Browse files Browse the repository at this point in the history
  • Loading branch information
DerAndere1 authored Jun 6, 2021
1 parent ce5dece commit ba4fa49
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 80 deletions.
4 changes: 2 additions & 2 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@
* the position of the toolhead relative to the workspace.
*/

//#define SENSORLESS_BACKOFF_MM { 2, 2 } // (mm) Backoff from endstops before sensorless homing
//#define SENSORLESS_BACKOFF_MM { 2, 2, 0 } // (mm) Backoff from endstops before sensorless homing

#define HOMING_BUMP_MM { 5, 5, 2 } // (mm) Backoff from endstops after first bump
#define HOMING_BUMP_DIVISOR { 2, 2, 4 } // Re-Bump Speed Divisor (Divides the Homing Feedrate)
Expand Down Expand Up @@ -2253,7 +2253,7 @@
* Extra G-code to run while executing tool-change commands. Can be used to use an additional
* stepper motor (I axis, see option LINEAR_AXES in Configuration.h) to drive the tool-changer.
*/
//#define EVENT_GCODE_TOOLCHANGE_T0 "G28 A\nG1 I0" // Extra G-code to run while executing tool-change command T0
//#define EVENT_GCODE_TOOLCHANGE_T0 "G28 A\nG1 A0" // Extra G-code to run while executing tool-change command T0
//#define EVENT_GCODE_TOOLCHANGE_T1 "G1 A10" // Extra G-code to run while executing tool-change command T1

/**
Expand Down
12 changes: 6 additions & 6 deletions Marlin/src/core/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@
#define _XMIN_ 100
#define _YMIN_ 200
#define _ZMIN_ 300
#define _IMIN_ 400
#define _JMIN_ 500
#define _KMIN_ 600
#define _IMIN_ 500
#define _JMIN_ 600
#define _KMIN_ 700
#define _XMAX_ 101
#define _YMAX_ 201
#define _ZMAX_ 301
#define _IMAX_ 401
#define _JMAX_ 501
#define _KMAX_ 601
#define _IMAX_ 501
#define _JMAX_ 601
#define _KMAX_ 701
#define _XDIAG_ 102
#define _YDIAG_ 202
#define _ZDIAG_ 302
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -570,8 +570,8 @@
#error "NEOPIXEL_BKGD_LED_INDEX is now NEOPIXEL_BKGD_INDEX_FIRST."
#endif

constexpr float sbm[] = AXIS_RELATIVE_MODES;
static_assert(COUNT(sbm) == LOGICAL_AXES, "AXIS_RELATIVE_MODES must contain " _LOGICAL_AXES_STR "elements.");
constexpr float arm[] = AXIS_RELATIVE_MODES;
static_assert(COUNT(arm) == LOGICAL_AXES, "AXIS_RELATIVE_MODES must contain " _LOGICAL_AXES_STR "elements.");

/**
* Probe temp compensation requirements
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/module/endstops.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class Endstops {
typedef struct {
union {
bool any;
struct { bool x:1, y:1, z:1; };
struct { bool LINEAR_AXIS_LIST(x:1, y:1, z:1, i:1, j:1, k:1); };
};
} tmc_spi_homing_t;
static tmc_spi_homing_t tmc_spi_homing;
Expand Down
79 changes: 57 additions & 22 deletions Marlin/src/module/motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,27 +588,27 @@ void do_blocking_move_to_x(const_float_t rx, const_feedRate_t fr_mm_s/*=0.0*/) {
}
#endif

#if LINEAR_AXES == 4
#if LINEAR_AXES >= 4
void do_blocking_move_to_i(const_float_t ri, const_feedRate_t fr_mm_s/*=0.0*/) {
do_blocking_move_to_xyz_i(current_position, ri, fr_mm_s);
}
void do_blocking_move_to_xyz_i(const xyze_pos_t &raw, const_float_t i, const_feedRate_t fr_mm_s/*=0.0f*/) {
do_blocking_move_to(raw.x, raw.y, raw.z, i, fr_mm_s);
do_blocking_move_to(
LINEAR_AXIS_LIST(raw.x, raw.y, raw.z, i, raw.j, raw.k),
fr_mm_s
);
}
#endif

#if LINEAR_AXES >= 5
void do_blocking_move_to_i(const_float_t ri, const_feedRate_t fr_mm_s/*=0.0*/) {
do_blocking_move_to_xyz_i(current_position, ri, fr_mm_s);
}
void do_blocking_move_to_xyz_i(const xyze_pos_t &raw, const_float_t i, const_feedRate_t fr_mm_s/*=0.0f*/) {
do_blocking_move_to(raw.x, raw.y, raw.z, i, raw.j, fr_mm_s);
}
void do_blocking_move_to_j(const_float_t rj, const_feedRate_t fr_mm_s/*=0.0*/) {
do_blocking_move_to_xyzi_j(current_position, rj, fr_mm_s);
}
void do_blocking_move_to_xyzi_j(const xyze_pos_t &raw, const_float_t j, const_feedRate_t fr_mm_s/*=0.0f*/) {
do_blocking_move_to(raw.x, raw.y, raw.z, raw.i, j, fr_mm_s);
do_blocking_move_to(
LINEAR_AXIS_LIST(raw.x, raw.y, raw.z, raw.i, j, raw.k),
fr_mm_s
);
}
#endif

Expand All @@ -617,7 +617,10 @@ void do_blocking_move_to_x(const_float_t rx, const_feedRate_t fr_mm_s/*=0.0*/) {
do_blocking_move_to_xyzij_k(current_position, rk, fr_mm_s);
}
void do_blocking_move_to_xyzij_k(const xyze_pos_t &raw, const_float_t k, const_feedRate_t fr_mm_s/*=0.0f*/) {
do_blocking_move_to(raw.x, raw.y, raw.z, raw.i, raw.j, k, fr_mm_s);
do_blocking_move_to(
LINEAR_AXIS_LIST(raw.x, raw.y, raw.z, raw.i, raw.j, k),
fr_mm_s
);
}
#endif

Expand Down Expand Up @@ -822,7 +825,7 @@ void restore_feedrate_and_scaling() {
#endif
}
#endif
#if LINEAR_AXES >= 4 // TODO (DerAndere): Find out why this was missing / removed
#if LINEAR_AXES >= 4
if (axis_was_homed(I_AXIS)) {
#if !HAS_SOFTWARE_ENDSTOPS || ENABLED(MIN_SOFTWARE_ENDSTOP_I)
NOLESS(target.i, soft_endstop.min.i);
Expand Down Expand Up @@ -1295,7 +1298,7 @@ void prepare_line_to_destination() {

bool homing_needed_error(linear_axis_bits_t axis_bits/*=linear_bits*/) {
if ((axis_bits = axes_should_home(axis_bits))) {
PGM_P home_first = GET_TEXT(MSG_HOME_FIRST); // TODO: (DerAndere) Set this up for extra axes
PGM_P home_first = GET_TEXT(MSG_HOME_FIRST);
char msg[strlen_P(home_first)+1];
sprintf_P(msg, home_first,
LINEAR_AXIS_LIST(
Expand Down Expand Up @@ -1390,8 +1393,21 @@ void prepare_line_to_destination() {
#if ENABLED(SPI_ENDSTOPS)
switch (axis) {
case X_AXIS: if (ENABLED(X_SPI_SENSORLESS)) endstops.tmc_spi_homing.x = true; break;
case Y_AXIS: if (ENABLED(Y_SPI_SENSORLESS)) endstops.tmc_spi_homing.y = true; break;
case Z_AXIS: if (ENABLED(Z_SPI_SENSORLESS)) endstops.tmc_spi_homing.z = true; break;
#if HAS_Y_AXIS
case Y_AXIS: if (ENABLED(Y_SPI_SENSORLESS)) endstops.tmc_spi_homing.y = true; break;
#endif
#if HAS_Z_AXIS
case Z_AXIS: if (ENABLED(Z_SPI_SENSORLESS)) endstops.tmc_spi_homing.z = true; break;
#endif
#if LINEAR_AXES >= 4
case I_AXIS: if (ENABLED(I_SPI_SENSORLESS)) endstops.tmc_spi_homing.i = true; break;
#endif
#if LINEAR_AXES >= 5
case J_AXIS: if (ENABLED(J_SPI_SENSORLESS)) endstops.tmc_spi_homing.j = true; break;
#endif
#if LINEAR_AXES >= 6
case K_AXIS: if (ENABLED(K_SPI_SENSORLESS)) endstops.tmc_spi_homing.k = true; break;
#endif
default: break;
}
#endif
Expand Down Expand Up @@ -1454,11 +1470,21 @@ void prepare_line_to_destination() {
#if ENABLED(SPI_ENDSTOPS)
switch (axis) {
case X_AXIS: if (ENABLED(X_SPI_SENSORLESS)) endstops.tmc_spi_homing.x = false; break;
case Y_AXIS: if (ENABLED(Y_SPI_SENSORLESS)) endstops.tmc_spi_homing.y = false; break;
case Z_AXIS: if (ENABLED(Z_SPI_SENSORLESS)) endstops.tmc_spi_homing.z = false; break;
case I_AXIS: if (ENABLED(I_SPI_SENSORLESS)) endstops.tmc_spi_homing.i = false; break;
case J_AXIS: if (ENABLED(J_SPI_SENSORLESS)) endstops.tmc_spi_homing.j = false; break;
case K_AXIS: if (ENABLED(K_SPI_SENSORLESS)) endstops.tmc_spi_homing.k = false; break;
#if HAS_Y_AXIS
case Y_AXIS: if (ENABLED(Y_SPI_SENSORLESS)) endstops.tmc_spi_homing.y = false; break;
#endif
#if HAS_Z_AXIS
case Z_AXIS: if (ENABLED(Z_SPI_SENSORLESS)) endstops.tmc_spi_homing.z = false; break;
#endif
#if LINEAR_AXES >= 4
case I_AXIS: if (ENABLED(I_SPI_SENSORLESS)) endstops.tmc_spi_homing.i = false; break;
#endif
#if LINEAR_AXES >= 5
case J_AXIS: if (ENABLED(J_SPI_SENSORLESS)) endstops.tmc_spi_homing.j = false; break;
#endif
#if LINEAR_AXES >= 6
case K_AXIS: if (ENABLED(K_SPI_SENSORLESS)) endstops.tmc_spi_homing.k = false; break;
#endif
default: break;
}
#endif
Expand Down Expand Up @@ -1734,11 +1760,11 @@ void prepare_line_to_destination() {
#endif

//
// Back away to prevent an early X/Y sensorless trigger
// Back away to prevent an early sensorless trigger
//
#if DISABLED(DELTA) && defined(SENSORLESS_BACKOFF_MM)
const xy_float_t backoff = SENSORLESS_BACKOFF_MM;
if ((TERN0(X_SENSORLESS, axis == X_AXIS) || TERN0(Y_SENSORLESS, axis == Y_AXIS)) && backoff[axis]) {
const xyz_float_t backoff = SENSORLESS_BACKOFF_MM;
if ((TERN0(X_SENSORLESS, axis == X_AXIS) || TERN0(Y_SENSORLESS, axis == Y_AXIS) || TERN0(Z_SENSORLESS, axis == Z_AXIS) || TERN0(I_SENSORLESS, axis == I_AXIS) || TERN0(J_SENSORLESS, axis == J_AXIS) || TERN0(K_SENSORLESS, axis == K_AXIS)) && backoff[axis]) {
const float backoff_length = -ABS(backoff[axis]) * axis_home_dir;
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Sensorless backoff: ", backoff_length, "mm");
do_homing_move(axis, backoff_length, homing_feedrate(axis));
Expand Down Expand Up @@ -1777,6 +1803,15 @@ void prepare_line_to_destination() {
case X_AXIS: es = X_ENDSTOP; break;
case Y_AXIS: es = Y_ENDSTOP; break;
case Z_AXIS: es = Z_ENDSTOP; break;
#if LINEAR_AXES >= 4
case I_AXIS: es = I_ENDSTOP; break;
#endif
#if LINEAR_AXES >= 5
case J_AXIS: es = J_ENDSTOP; break;
#endif
#if LINEAR_AXES >= 6
case K_AXIS: es = K_ENDSTOP; break;
#endif
}
if (TEST(endstops.state(), es)) {
SERIAL_ECHO_MSG("Bad ", AS_CHAR(AXIS_CHAR(axis)), " Endstop?");
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/module/motion.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ inline float home_bump_mm(const AxisEnum axis) {
TERN_(MAX_SOFTWARE_ENDSTOP_Z, amax = max.z);
break;
#endif
#if LINEAR_AXES >= 4 // TODO (DerAndere): Test for LINEAR_AXES >= 4
#if LINEAR_AXES >= 4
case I_AXIS:
TERN_(MIN_SOFTWARE_ENDSTOP_I, amin = min.i);
TERN_(MIN_SOFTWARE_ENDSTOP_I, amax = max.i);
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/module/planner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1451,7 +1451,7 @@ void Planner::check_axes_activity() {
float high = 0.0;
for (uint8_t b = block_buffer_tail; b != block_buffer_head; b = next_block_index(b)) {
block_t *block = &block_buffer[b];
if (LINEAR_AXIS_GANG(block->steps.x, || block->steps.y, || block->steps.z, block->steps.i, || block->steps.j, || block->steps.k)) {
if (LINEAR_AXIS_GANG(block->steps.x, || block->steps.y, || block->steps.z, || block->steps.i, || block->steps.j, || block->steps.k)) {
const float se = (float)block->steps.e / block->step_event_count * SQRT(block->nominal_speed_sqr); // mm/sec;
NOLESS(high, se);
}
Expand Down Expand Up @@ -2852,7 +2852,7 @@ bool Planner::buffer_segment(const abce_pos_t &abce
int32_t(LROUND(abce.a * settings.axis_steps_per_mm[A_AXIS])),
int32_t(LROUND(abce.b * settings.axis_steps_per_mm[B_AXIS])),
int32_t(LROUND(abce.c * settings.axis_steps_per_mm[C_AXIS])),
int32_t(LROUND(abce.i * settings.axis_steps_per_mm[I_AXIS])), // FIXME (DerAndere): Multiplication by 4.0 is a work-around for issue with wrong internal steps per mm
int32_t(LROUND(abce.i * settings.axis_steps_per_mm[I_AXIS])),
int32_t(LROUND(abce.j * settings.axis_steps_per_mm[J_AXIS])),
int32_t(LROUND(abce.k * settings.axis_steps_per_mm[K_AXIS]))
)
Expand Down Expand Up @@ -2893,7 +2893,7 @@ bool Planner::buffer_segment(const abce_pos_t &abce
#endif
#if LINEAR_AXES >= 4
SERIAL_ECHOPAIR_P(SP_I_LBL, abce.i);
SERIAL_ECHOPAIR(" (", position.i, "->", target.i); // FIXME (DerAndere): Introduce work-around for issue with wrong internal steps per mm and feedrate for I_AXIS
SERIAL_ECHOPAIR(" (", position.i, "->", target.i);
SERIAL_CHAR(')');
#endif
#if LINEAR_AXES >= 5
Expand Down
30 changes: 15 additions & 15 deletions Marlin/src/module/stepper/trinamic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -766,11 +766,7 @@ enum StealthIndex : uint8_t {
pwmconf.pwm_ofs = 36;
st.PWMCONF(pwmconf.sr);

#if ENABLED(HYBRID_THRESHOLD)
st.set_pwm_thrs(hyb_thrs);
#else
UNUSED(hyb_thrs);
#endif
TERN(HYBRID_THRESHOLD, st.set_pwm_thrs(hyb_thrs), UNUSED(hyb_thrs));
st.GSTAT(); // Clear GSTAT
}
#endif // TMC5160
Expand Down Expand Up @@ -971,11 +967,12 @@ void reset_trinamic_drivers() {
// Using a fixed-length character array for the port name allows this to be constexpr compatible.
struct SanityHwSerialDetails { const char port[20]; uint32_t address; };
#define TMC_HW_DETAIL_ARGS(A) TERN(A##_HAS_HW_SERIAL, STRINGIFY(A##_HARDWARE_SERIAL), ""), TERN0(A##_HAS_HW_SERIAL, A##_SLAVE_ADDRESS)
#define TMC_HW_DETAIL(A) {TMC_HW_DETAIL_ARGS(A)}
#define TMC_HW_DETAIL(A) { TMC_HW_DETAIL_ARGS(A) }
constexpr SanityHwSerialDetails sanity_tmc_hw_details[] = {
TMC_HW_DETAIL(X), TMC_HW_DETAIL(X2),
TMC_HW_DETAIL(Y), TMC_HW_DETAIL(Y2),
TMC_HW_DETAIL(Z), TMC_HW_DETAIL(Z2), TMC_HW_DETAIL(Z3), TMC_HW_DETAIL(Z4),
TMC_HW_DETAIL(I), TMC_HW_DETAIL(J), TMC_HW_DETAIL(K),
TMC_HW_DETAIL(E0), TMC_HW_DETAIL(E1), TMC_HW_DETAIL(E2), TMC_HW_DETAIL(E3), TMC_HW_DETAIL(E4), TMC_HW_DETAIL(E5), TMC_HW_DETAIL(E6), TMC_HW_DETAIL(E7)
};

Expand All @@ -995,10 +992,11 @@ void reset_trinamic_drivers() {

#define TMC_HWSERIAL_CONFLICT_MSG(A) STRINGIFY(A) "_SLAVE_ADDRESS conflicts with another driver using the same " STRINGIFY(A) "_HARDWARE_SERIAL"
#define SA_NO_TMC_HW_C(A) static_assert(1 >= count_tmc_hw_serial_matches(TMC_HW_DETAIL_ARGS(A), 0, COUNT(sanity_tmc_hw_details)), TMC_HWSERIAL_CONFLICT_MSG(A));
SA_NO_TMC_HW_C(X);SA_NO_TMC_HW_C(X2);
SA_NO_TMC_HW_C(Y);SA_NO_TMC_HW_C(Y2);
SA_NO_TMC_HW_C(Z);SA_NO_TMC_HW_C(Z2);SA_NO_TMC_HW_C(Z3);SA_NO_TMC_HW_C(Z4);
SA_NO_TMC_HW_C(E0);SA_NO_TMC_HW_C(E1);SA_NO_TMC_HW_C(E2);SA_NO_TMC_HW_C(E3);SA_NO_TMC_HW_C(E4);SA_NO_TMC_HW_C(E5);SA_NO_TMC_HW_C(E6);SA_NO_TMC_HW_C(E7);
SA_NO_TMC_HW_C(X); SA_NO_TMC_HW_C(X2);
SA_NO_TMC_HW_C(Y); SA_NO_TMC_HW_C(Y2);
SA_NO_TMC_HW_C(Z); SA_NO_TMC_HW_C(Z2); SA_NO_TMC_HW_C(Z3); SA_NO_TMC_HW_C(Z4);
SA_NO_TMC_HW_C(I); SA_NO_TMC_HW_C(J); SA_NO_TMC_HW_C(K);
SA_NO_TMC_HW_C(E0); SA_NO_TMC_HW_C(E1); SA_NO_TMC_HW_C(E2); SA_NO_TMC_HW_C(E3); SA_NO_TMC_HW_C(E4); SA_NO_TMC_HW_C(E5); SA_NO_TMC_HW_C(E6); SA_NO_TMC_HW_C(E7);
#endif

#if ANY_AXIS_HAS(SW_SERIAL)
Expand All @@ -1009,7 +1007,8 @@ void reset_trinamic_drivers() {
TMC_SW_DETAIL(X), TMC_SW_DETAIL(X2),
TMC_SW_DETAIL(Y), TMC_SW_DETAIL(Y2),
TMC_SW_DETAIL(Z), TMC_SW_DETAIL(Z2), TMC_SW_DETAIL(Z3), TMC_SW_DETAIL(Z4),
TMC_SW_DETAIL(E0), TMC_SW_DETAIL(E1), TMC_SW_DETAIL(E2), TMC_SW_DETAIL(E3), TMC_SW_DETAIL(E4), TMC_SW_DETAIL(E5), TMC_SW_DETAIL(E6), TMC_SW_DETAIL(E7)
TMC_SW_DETAIL(I), TMC_SW_DETAIL(J), TMC_SW_DETAIL(K),
TMC_SW_DETAIL(E0), TMC_SW_DETAIL(E1), TMC_SW_DETAIL(E2), TMC_SW_DETAIL(E3), TMC_SW_DETAIL(E4), TMC_SW_DETAIL(E5), TMC_SW_DETAIL(E6), TMC_SW_DETAIL(E7)
};

constexpr bool sc_sw_done(size_t start, size_t end) { return start == end; }
Expand All @@ -1023,10 +1022,11 @@ void reset_trinamic_drivers() {

#define TMC_SWSERIAL_CONFLICT_MSG(A) STRINGIFY(A) "_SLAVE_ADDRESS conflicts with another driver using the same " STRINGIFY(A) "_SERIAL_RX_PIN or " STRINGIFY(A) "_SERIAL_TX_PIN"
#define SA_NO_TMC_SW_C(A) static_assert(1 >= count_tmc_sw_serial_matches(TMC_SW_DETAIL_ARGS(A), 0, COUNT(sanity_tmc_sw_details)), TMC_SWSERIAL_CONFLICT_MSG(A));
SA_NO_TMC_SW_C(X);SA_NO_TMC_SW_C(X2);
SA_NO_TMC_SW_C(Y);SA_NO_TMC_SW_C(Y2);
SA_NO_TMC_SW_C(Z);SA_NO_TMC_SW_C(Z2);SA_NO_TMC_SW_C(Z3);SA_NO_TMC_SW_C(Z4);
SA_NO_TMC_SW_C(E0);SA_NO_TMC_SW_C(E1);SA_NO_TMC_SW_C(E2);SA_NO_TMC_SW_C(E3);SA_NO_TMC_SW_C(E4);SA_NO_TMC_SW_C(E5);SA_NO_TMC_SW_C(E6);SA_NO_TMC_SW_C(E7);
SA_NO_TMC_SW_C(X); SA_NO_TMC_SW_C(X2);
SA_NO_TMC_SW_C(Y); SA_NO_TMC_SW_C(Y2);
SA_NO_TMC_SW_C(Z); SA_NO_TMC_SW_C(Z2); SA_NO_TMC_SW_C(Z3); SA_NO_TMC_SW_C(Z4);
SA_NO_TMC_SW_C(I); SA_NO_TMC_SW_C(J); SA_NO_TMC_SW_C(K);
SA_NO_TMC_SW_C(E0); SA_NO_TMC_SW_C(E1); SA_NO_TMC_SW_C(E2); SA_NO_TMC_SW_C(E3); SA_NO_TMC_SW_C(E4); SA_NO_TMC_SW_C(E5); SA_NO_TMC_SW_C(E6); SA_NO_TMC_SW_C(E7);
#endif

#endif // HAS_TRINAMIC_CONFIG
Loading

0 comments on commit ba4fa49

Please sign in to comment.