Skip to content

Commit

Permalink
Implement fourth axis support.
Browse files Browse the repository at this point in the history
  • Loading branch information
smohekey committed Aug 5, 2024
1 parent 4180d81 commit 2d16400
Show file tree
Hide file tree
Showing 61 changed files with 1,891 additions and 4,295 deletions.
2 changes: 1 addition & 1 deletion Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,7 @@
#define X_ENABLE_ON 1
#define Y_ENABLE_ON 1
#define Z_ENABLE_ON 1
#define A_ENABLE_ON 1
#define A_ENABLE_ON 1

// Disable axis steppers immediately when they're not being stepped.
// WARNING: When motors turn off there is a chance of losing position accuracy!
Expand Down
12 changes: 8 additions & 4 deletions Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -663,9 +663,9 @@
// #define SENSORLESS_BACKOFF_MM { 40, 40, 40 } // (mm) Backoff from endstops before sensorless homing

#define HOMING_BUMP_MM \
{ 15, 15, 15 } // (mm) Backoff from endstops after first bump
{ 15, 15, 15, 15, 15, 15 } // (mm) Backoff from endstops after first bump
#define HOMING_BUMP_DIVISOR \
{ 10, 10, 5 } // Re-Bump Speed Divisor (Divides the Homing Feedrate)
{ 10, 10, 5, 10, 10, 10 } // Re-Bump Speed Divisor (Divides the Homing Feedrate)

// #define HOMING_BACKOFF_POST_MM { 5, 5, 2 } // (mm) Backoff from endstops after homing

Expand Down Expand Up @@ -857,7 +857,9 @@
#define INVERT_X_STEP_PIN true
#define INVERT_Y_STEP_PIN true
#define INVERT_Z_STEP_PIN true
#define INVERT_E_STEP_PIN true
#define INVERT_A_STEP_PIN true
#define INVERT_B_STEP_PIN true
#define INVERT_C_STEP_PIN true

/**
* Idle Stepper Shutdown
Expand All @@ -868,7 +870,9 @@
#define DISABLE_INACTIVE_X false
#define DISABLE_INACTIVE_Y false
#define DISABLE_INACTIVE_Z false // Set 'false' if the nozzle could fall onto your printed part!
#define DISABLE_INACTIVE_E false
#define DISABLE_INACTIVE_A false
#define DISABLE_INACTIVE_B false
#define DISABLE_INACTIVE_C false

// If the Nozzle or Bed falls when the Z stepper is disabled, set its resting position here.
// #define Z_AFTER_DEACTIVATE Z_HOME_POS
Expand Down
23 changes: 23 additions & 0 deletions src/marlin/HAL/SAMD51/endstop_interrupts.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@
#else
#define MATCH_Z4_MIN_EILINE(P) false
#endif
#if HAS_A_MAX
#define MATCH_A_MAX_EILINE(P) MATCH_EILINE(P, A_MAX_PIN)
#else
#define MATCH_A_MAX_EILINE(P) false
#endif
#if HAS_A_MIN
#define MATCH_A_MIN_EILINE(P) MATCH_EILINE(P, A_MIN_PIN)
#else
#define MATCH_A_MIN_EILINE(P) false
#endif
#if HAS_Z_MIN_PROBE_PIN
#define MATCH_Z_MIN_PROBE_EILINE(P) MATCH_EILINE(P, Z_MIN_PROBE_PIN)
#else
Expand All @@ -120,6 +130,7 @@
&& !MATCH_Z2_MAX_EILINE(P) && !MATCH_Z2_MIN_EILINE(P) \
&& !MATCH_Z3_MAX_EILINE(P) && !MATCH_Z3_MIN_EILINE(P) \
&& !MATCH_Z4_MAX_EILINE(P) && !MATCH_Z4_MIN_EILINE(P) \
&& !MATCH_A_MAX_EILINE(P) && !MATCH_A_MIN_EILINE(P) \
&& !MATCH_Z_MIN_PROBE_EILINE(P))

// One ISR for all EXT-Interrupts
Expand Down Expand Up @@ -210,6 +221,18 @@ void setup_endstop_interrupts() {
#error "Z4_MIN_PIN has no EXTINT line available."
#endif
_ATTACH(Z4_MIN_PIN);
#endif
#if HAS_A_MAX
#if !AVAILABLE_EILINE(A_MAX_PIN)
#error "A_MAX_PIN has no EXTINT line available."
#endif
_ATTACH(A_MAX_PIN);
#endif
#if HAS_A_MIN
#if !AVAILABLE_EILINE(A_MIN_PIN)
#error "A_MIN_PIN has no EXTINT line available."
#endif
_ATTACH(A_MIN_PIN);
#endif
#if HAS_Z_MIN_PROBE_PIN
#if !AVAILABLE_EILINE(Z_MIN_PROBE_PIN)
Expand Down
47 changes: 15 additions & 32 deletions src/marlin/MarlinCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ PGMSTR(SP_E_STR, " E");
PGMSTR(SP_X_LBL, " X:");
PGMSTR(SP_Y_LBL, " Y:");
PGMSTR(SP_Z_LBL, " Z:");
PGMSTR(SP_E_LBL, " E:");
PGMSTR(SP_A_LBL, " A:");
PGMSTR(SP_B_LBL, " B:");
PGMSTR(SP_C_LBL, " C:");

MarlinState marlin_state = MF_INITIALIZING;

Expand Down Expand Up @@ -344,47 +346,28 @@ void protected_pin_err() {
void quickstop_stepper() {
planner.quick_stop();
planner.synchronize();
set_current_from_steppers_for_axis(ALL_AXES);
set_current_from_steppers_for_axis(AxisValue::All);
sync_plan_position();
}

void enable_e_steppers() {
#define _ENA_E(N) ENABLE_AXIS_E##N();
REPEAT(E_STEPPERS, _ENA_E)
}

void enable_all_steppers() {
TERN_(AUTO_POWER_CONTROL, powerManager.power_on());
ENABLE_AXIS_X();
ENABLE_AXIS_Y();
ENABLE_AXIS_Z();
enable_e_steppers();

TERN_(EXTENSIBLE_UI, ExtUI::onSteppersEnabled());
}

void disable_e_steppers() {
#define _DIS_E(N) DISABLE_AXIS_E##N();
REPEAT(E_STEPPERS, _DIS_E)
}
ENABLE_AXIS_A();
ENABLE_AXIS_B();
ENABLE_AXIS_C();

void disable_e_stepper(const uint8_t e) {
#define _CASE_DIS_E(N) \
case N: \
DISABLE_AXIS_E##N(); \
break;
switch (e) {
REPEAT(EXTRUDERS, _CASE_DIS_E)
}
safe_delay(200);
}

void disable_all_steppers() {
DISABLE_AXIS_X();
DISABLE_AXIS_Y();
DISABLE_AXIS_Z();
disable_e_steppers();

TERN_(EXTENSIBLE_UI, ExtUI::onSteppersDisabled());
DISABLE_AXIS_A();
DISABLE_AXIS_B();
DISABLE_AXIS_C();
}

#if ENABLED(G29_RETRY_AND_RECOVER)
Expand Down Expand Up @@ -544,8 +527,6 @@ inline void manage_inactivity(const bool ignore_stepper_queue = false) {
DISABLE_AXIS_Y();
if (ENABLED(DISABLE_INACTIVE_Z))
DISABLE_AXIS_Z();
if (ENABLED(DISABLE_INACTIVE_E))
disable_e_steppers();

TERN_(AUTO_BED_LEVELING_UBL, ubl.steppers_were_disabled());
}
Expand Down Expand Up @@ -891,8 +872,10 @@ void minkill(const bool steppers_off /*=false*/) {

TERN_(HAS_CUTTER, cutter.enabled(false)); // Reiterate cutter shutdown

// Power off all steppers (for M112) or just the E steppers
steppers_off ? disable_all_steppers() : disable_e_steppers();
// Power off all steppers (for M112)
if (steppers_off) {
disable_all_steppers();
}

TERN_(PSU_CONTROL, PSU_OFF());

Expand Down
5 changes: 1 addition & 4 deletions src/marlin/MarlinCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ extern bool G38_did_trigger; // Flag from the ISR to indicate the endstop change
/**
* The axis order in all axis related arrays is X, Y, Z, E
*/
void enable_e_steppers();
void enable_all_steppers();
void disable_e_stepper(const uint8_t e);
void disable_e_steppers();
void disable_all_steppers();

void kill(PGM_P const lcd_error = nullptr, PGM_P const lcd_component = nullptr, const bool steppers_off = false);
Expand Down Expand Up @@ -142,4 +139,4 @@ void event_probe_failure();
extern const char NUL_STR[], M112_KILL_STR[], G28_STR[], M21_STR[], M23_STR[], M24_STR[],
SP_A_STR[], SP_B_STR[], SP_C_STR[],
SP_P_STR[], SP_T_STR[], SP_X_STR[], SP_Y_STR[], SP_Z_STR[], SP_E_STR[],
X_LBL[], Y_LBL[], Z_LBL[], E_LBL[], SP_X_LBL[], SP_Y_LBL[], SP_Z_LBL[], SP_E_LBL[];
X_LBL[], Y_LBL[], Z_LBL[], E_LBL[], SP_X_LBL[], SP_Y_LBL[], SP_Z_LBL[], SP_A_LBL[], SP_B_LBL[], SP_C_LBL[];
24 changes: 10 additions & 14 deletions src/marlin/core/drivers.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,17 @@
#define AXIS_DRIVER_TYPE_Z3(T) (NUM_Z_STEPPER_DRIVERS >= 3 && _AXIS_DRIVER_TYPE(Z3,T))
#define AXIS_DRIVER_TYPE_Z4(T) (NUM_Z_STEPPER_DRIVERS >= 4 && _AXIS_DRIVER_TYPE(Z4,T))

#define AXIS_DRIVER_TYPE_E(N,T) (E_STEPPERS > N && _AXIS_DRIVER_TYPE(E##N,T))
#define AXIS_DRIVER_TYPE_E0(T) AXIS_DRIVER_TYPE_E(0,T)
#define AXIS_DRIVER_TYPE_E1(T) AXIS_DRIVER_TYPE_E(1,T)
#define AXIS_DRIVER_TYPE_E2(T) AXIS_DRIVER_TYPE_E(2,T)
#define AXIS_DRIVER_TYPE_E3(T) AXIS_DRIVER_TYPE_E(3,T)
#define AXIS_DRIVER_TYPE_E4(T) AXIS_DRIVER_TYPE_E(4,T)
#define AXIS_DRIVER_TYPE_E5(T) AXIS_DRIVER_TYPE_E(5,T)
#define AXIS_DRIVER_TYPE_E6(T) AXIS_DRIVER_TYPE_E(6,T)
#define AXIS_DRIVER_TYPE_E7(T) AXIS_DRIVER_TYPE_E(7,T)
#define AXIS_DRIVER_TYPE_A(T) _AXIS_DRIVER_TYPE(A,T)
#define AXIS_DRIVER_TYPE_B(T) _AXIS_DRIVER_TYPE(B,T)
#define AXIS_DRIVER_TYPE_C(T) _AXIS_DRIVER_TYPE(C,T)

#define AXIS_DRIVER_TYPE(A,T) AXIS_DRIVER_TYPE_##A(T)

#define _OR_ADTE(N,T) || AXIS_DRIVER_TYPE_E(N,T)
#define HAS_E_DRIVER(T) (0 RREPEAT2(E_STEPPERS, _OR_ADTE, T))

#define HAS_DRIVER(T) ( AXIS_DRIVER_TYPE_X(T) || AXIS_DRIVER_TYPE_Y(T) || AXIS_DRIVER_TYPE_Z(T) \
|| AXIS_DRIVER_TYPE_X2(T) || AXIS_DRIVER_TYPE_Y2(T) || AXIS_DRIVER_TYPE_Z2(T) \
|| AXIS_DRIVER_TYPE_Z3(T) || AXIS_DRIVER_TYPE_Z4(T) || HAS_E_DRIVER(T) )
|| AXIS_DRIVER_TYPE_Z3(T) || AXIS_DRIVER_TYPE_Z4(T) || AXIS_DRIVER_TYPE_A(T) \
|| AXIS_DRIVER_TYPE_B(T) || AXIS_DRIVER_TYPE_C(T) )

//
// Trinamic Stepper Drivers
Expand Down Expand Up @@ -117,6 +110,7 @@
#define HAS_TMC220x 1
#endif

/*
#define AXIS_IS_TMC(A) ( AXIS_DRIVER_TYPE(A,TMC2130) || AXIS_DRIVER_TYPE(A,TMC2160) \
|| AXIS_DRIVER_TYPE(A,TMC2208) || AXIS_DRIVER_TYPE(A,TMC2209) \
|| AXIS_DRIVER_TYPE(A,TMC2660) \
Expand All @@ -142,7 +136,7 @@
#define AXIS_HAS_STEALTHCHOP(A) ( AXIS_DRIVER_TYPE(A,TMC2130) || AXIS_DRIVER_TYPE(A,TMC2160) \
|| AXIS_DRIVER_TYPE(A,TMC2208) || AXIS_DRIVER_TYPE(A,TMC2209) \
|| AXIS_DRIVER_TYPE(A,TMC5130) || AXIS_DRIVER_TYPE(A,TMC5160) )
#define AXIS_HAS_SG_RESULT(A) ( AXIS_DRIVER_TYPE(A,TMC2130) || AXIS_DRIVER_TYPE(A,TMC2160) \
|| AXIS_DRIVER_TYPE(A,TMC2208) || AXIS_DRIVER_TYPE(A,TMC2209) \
|| AXIS_DRIVER_TYPE(A,TMC2660) )
Expand All @@ -158,7 +152,8 @@
#define ANY_AXIS_HAS(T) ( AXIS_HAS_##T(X) || AXIS_HAS_##T(Y) || AXIS_HAS_##T(Z) \
|| AXIS_HAS_##T(X2) || AXIS_HAS_##T(Y2) || AXIS_HAS_##T(Z2) \
|| AXIS_HAS_##T(Z3) || AXIS_HAS_##T(Z4) || E_AXIS_HAS(T) )
|| AXIS_HAS_##T(Z3) || AXIS_HAS_##T(Z4) || AXIS_HAS_##T(A) \
|| AXIS_HAS_##T(B) || AXIS_HAS_##T(C) )
#if ANY_AXIS_HAS(STEALTHCHOP)
#define HAS_STEALTHCHOP 1
Expand All @@ -178,6 +173,7 @@
#if ANY_AXIS_HAS(SPI)
#define HAS_TMC_SPI 1
#endif
*/

//
// TMC26XX Stepper Drivers
Expand Down
2 changes: 2 additions & 0 deletions src/marlin/core/language.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@
#define STR_Z3_MAX "z3_max"
#define STR_Z4_MIN "z4_min"
#define STR_Z4_MAX "z4_max"
#define STR_A_MAX "a_max"
#define STR_A_MIN "a_min"
#define STR_Z_PROBE "z_probe"
#define STR_ESTOP "estop"
#define STR_WORK_PROBE "work_probe"
Expand Down
2 changes: 1 addition & 1 deletion src/marlin/core/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#define XYZ 3
#define XY 2

#define _AXIS(A) (A##_AXIS)
#define _AXIS(A) (Axis::A())

#define _XMIN_ 100
#define _YMIN_ 200
Expand Down
10 changes: 7 additions & 3 deletions src/marlin/core/serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
#pragma once

#include <Eigen/Core>
#include <swordfish/math.h>

#include "../inc/MarlinConfig.h"

Expand Down Expand Up @@ -908,8 +908,12 @@ inline void print_xyz(const xyz_pos_t& xyz, PGM_P const prefix = nullptr, PGM_P
print_xyz(xyz.x, xyz.y, xyz.z, prefix, suffix);
}

inline void print_xyz(const Eigen::Vector3f& xyz, PGM_P const prefix = nullptr, PGM_P const suffix = nullptr) {
print_xyz(xyz(0), xyz(1), xyz(2), prefix, suffix);
inline void print_xyz(const swordfish::math::Vector3f32& xyz, PGM_P const prefix = nullptr, PGM_P const suffix = nullptr) {
print_xyz(xyz.x(), xyz.y(), xyz.z(), prefix, suffix);
}

inline void print_xyz(const swordfish::math::Vector6f32& xyz, PGM_P const prefix = nullptr, PGM_P const suffix = nullptr) {
print_xyz(xyz.x(), xyz.y(), xyz.z(), prefix, suffix);
}

#define SERIAL_POS(SUFFIX, VAR) \
Expand Down
14 changes: 2 additions & 12 deletions src/marlin/core/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ typedef const __FlashStringHelper* progmem_str;
// - A_AXIS, B_AXIS, and C_AXIS should be used for Steppers, corresponding to XYZ on Cartesians
// - X_HEAD, Y_HEAD, and Z_HEAD should be used for Steppers on Core kinematics
//
enum AxisEnum : uint8_t {
/*enum AxisEnum : uint8_t {
X_AXIS = 0,
A_AXIS = 0,
Y_AXIS = 1,
Expand All @@ -59,17 +59,7 @@ enum AxisEnum : uint8_t {
E7_AXIS,
ALL_AXES = 0xFE,
NO_AXIS = 0xFF
};

//
// Loop over XYZE axes
//
#define LOOP_XYZ(VAR) LOOP_S_LE_N(VAR, X_AXIS, Z_AXIS)
#define LOOP_XYZE(VAR) LOOP_S_LE_N(VAR, X_AXIS, E_AXIS)
#define LOOP_XYZE_N(VAR) LOOP_S_L_N(VAR, X_AXIS, XYZE_N)
#define LOOP_ABC(VAR) LOOP_S_LE_N(VAR, A_AXIS, C_AXIS)
#define LOOP_ABCE(VAR) LOOP_S_LE_N(VAR, A_AXIS, E_AXIS)
#define LOOP_ABCE_N(VAR) LOOP_S_L_N(VAR, A_AXIS, XYZE_N)
};*/

//
// Conditional type assignment magic. For example...
Expand Down
Loading

0 comments on commit 2d16400

Please sign in to comment.