♻️ More updates for multi-axis

This commit is contained in:
Scott Lahteine 2022-05-26 18:31:05 -05:00
parent 1d4f928342
commit 1f322b565f
8 changed files with 46 additions and 51 deletions

View file

@ -181,7 +181,6 @@ enum AxisEnum : uint8_t {
};
typedef IF<(NUM_AXIS_ENUMS > 8), uint16_t, uint8_t>::type axis_bits_t;
typedef IF<(NUM_AXES > 8), uint16_t, uint8_t>::type linear_axis_bits_t;
//
// Loop over axes

View file

@ -23,6 +23,7 @@
#include "../gcode.h"
#include "../../MarlinCore.h" // for stepper_inactive_time, disable_e_steppers
#include "../../lcd/marlinui.h"
#include "../../module/motion.h" // for e_axis_mask
#include "../../module/stepper.h"
#if ENABLED(AUTO_BED_LEVELING_UBL)
@ -43,7 +44,7 @@ inline stepper_flags_t selected_axis_bits() {
selected.bits = _BV(INDEX_OF_AXIS(E_AXIS, e));
}
else
selected.bits = selected.e_bits();
selected.bits = e_axis_mask;
}
#endif
selected.bits |= NUM_AXIS_GANG(

View file

@ -45,9 +45,10 @@
* X, Y, Z : Specify axes to move during cleaning. Default: ALL.
*/
void GcodeSuite::G12() {
// Don't allow nozzle cleaning without homing first
if (homing_needed_error(linear_bits & ~TERN0(NOZZLE_CLEAN_NO_Z, Z_AXIS) & ~TERN0(NOZZLE_CLEAN_NO_Y, Y_AXIS)))
return;
constexpr main_axes_bits_t clean_axis_mask = main_axes_mask & ~TERN0(NOZZLE_CLEAN_NO_Z, Z_AXIS) & ~TERN0(NOZZLE_CLEAN_NO_Y, Y_AXIS);
if (homing_needed_error(clean_axis_mask)) return;
#ifdef WIPE_SEQUENCE_COMMANDS
if (!parser.seen_any()) {

View file

@ -80,9 +80,9 @@ FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const
dwin_string.set();
if (blink)
dwin_string.add(value);
else if (!TEST(axis_homed, axis))
else if (!TEST(axes_homed, axis))
while (const char c = *value++) dwin_string.add(c <= '.' ? c : '?');
else if (NONE(HOME_AFTER_DEACTIVATE, DISABLE_REDUCED_ACCURACY_WARNING) && !TEST(axis_trusted, axis))
else if (NONE(HOME_AFTER_DEACTIVATE, DISABLE_REDUCED_ACCURACY_WARNING) && !TEST(axes_trusted, axis))
dwin_string.add(TERN1(DWIN_MARLINUI_PORTRAIT, axis == Z_AXIS) ? PSTR(" ") : PSTR(" "));
else
dwin_string.add(value);
@ -105,11 +105,11 @@ FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const
if (blink)
dwin_string.add(value);
else {
if (!TEST(axis_homed, axis))
if (!TEST(axes_homed, axis))
while (const char c = *value++) dwin_string.add(c <= '.' ? c : '?');
else {
#if NONE(HOME_AFTER_DEACTIVATE, DISABLE_REDUCED_ACCURACY_WARNING)
if (!TEST(axis_trusted, axis))
if (!TEST(axes_trusted, axis))
dwin_string.add(TERN1(DWIN_MARLINUI_PORTRAIT, axis == Z_AXIS) ? PSTR(" ") : PSTR(" "));
else
#endif

View file

@ -1382,10 +1382,10 @@ void prepare_line_to_destination() {
#if HAS_ENDSTOPS
linear_axis_bits_t axis_homed, axis_trusted; // = 0
main_axes_bits_t axes_homed, axes_trusted; // = 0
linear_axis_bits_t axes_should_home(linear_axis_bits_t axis_bits/*=linear_bits*/) {
auto set_should = [](linear_axis_bits_t &b, AxisEnum a) {
main_axes_bits_t axes_should_home(main_axes_bits_t axis_bits/*=main_axes_mask*/) {
auto set_should = [](main_axes_bits_t &b, AxisEnum a) {
if (TEST(b, a) && TERN(HOME_AFTER_DEACTIVATE, axis_is_trusted, axis_was_homed)(a))
CBI(b, a);
};
@ -1398,23 +1398,12 @@ void prepare_line_to_destination() {
return axis_bits;
}
bool homing_needed_error(linear_axis_bits_t axis_bits/*=linear_bits*/) {
bool homing_needed_error(main_axes_bits_t axis_bits/*=main_axes_mask*/) {
if ((axis_bits = axes_should_home(axis_bits))) {
PGM_P home_first = GET_TEXT(MSG_HOME_FIRST);
char msg[30];
sprintf_P(msg, home_first,
NUM_AXIS_LIST(
TEST(axis_bits, X_AXIS) ? STR_A : "",
TEST(axis_bits, Y_AXIS) ? STR_B : "",
TEST(axis_bits, Z_AXIS) ? STR_C : "",
TEST(axis_bits, I_AXIS) ? STR_I : "",
TEST(axis_bits, J_AXIS) ? STR_J : "",
TEST(axis_bits, K_AXIS) ? STR_K : "",
TEST(axis_bits, U_AXIS) ? STR_U : "",
TEST(axis_bits, V_AXIS) ? STR_V : "",
TEST(axis_bits, W_AXIS) ? STR_W : ""
)
);
#define _AXIS_CHAR(N) TEST(axis_bits, _AXIS(N)) ? STR_##N : ""
sprintf_P(msg, home_first, MAPLIST(_AXIS_CHAR, MAIN_AXIS_NAMES));
SERIAL_ECHO_START();
SERIAL_ECHOLN(msg);
ui.set_status(msg);

View file

@ -407,38 +407,41 @@ void restore_feedrate_and_scaling();
/**
* Homing and Trusted Axes
*/
typedef IF<(NUM_AXES > 8), uint16_t, uint8_t>::type linear_axis_bits_t;
constexpr linear_axis_bits_t linear_bits = _BV(NUM_AXES) - 1;
typedef IF<(NUM_AXES > 8), uint16_t, uint8_t>::type main_axes_bits_t;
constexpr main_axes_bits_t main_axes_mask = _BV(NUM_AXES) - 1;
typedef IF<(NUM_AXES + EXTRUDERS > 8), uint16_t, uint8_t>::type e_axis_bits_t;
constexpr e_axis_bits_t e_axis_mask = (_BV(EXTRUDERS) - 1) << NUM_AXES;
void set_axis_is_at_home(const AxisEnum axis);
#if HAS_ENDSTOPS
/**
* axis_homed
* axes_homed
* Flags that each linear axis was homed.
* XYZ on cartesian, ABC on delta, ABZ on SCARA.
*
* axis_trusted
* axes_trusted
* Flags that the position is trusted in each linear axis. Set when homed.
* Cleared whenever a stepper powers off, potentially losing its position.
*/
extern linear_axis_bits_t axis_homed, axis_trusted;
extern main_axes_bits_t axes_homed, axes_trusted;
void homeaxis(const AxisEnum axis);
void set_axis_never_homed(const AxisEnum axis);
linear_axis_bits_t axes_should_home(linear_axis_bits_t axis_bits=linear_bits);
bool homing_needed_error(linear_axis_bits_t axis_bits=linear_bits);
inline void set_axis_unhomed(const AxisEnum axis) { CBI(axis_homed, axis); }
inline void set_axis_untrusted(const AxisEnum axis) { CBI(axis_trusted, axis); }
inline void set_all_unhomed() { axis_homed = axis_trusted = 0; }
inline void set_axis_homed(const AxisEnum axis) { SBI(axis_homed, axis); }
inline void set_axis_trusted(const AxisEnum axis) { SBI(axis_trusted, axis); }
inline void set_all_homed() { axis_homed = axis_trusted = linear_bits; }
main_axes_bits_t axes_should_home(main_axes_bits_t axes_mask=main_axes_mask);
bool homing_needed_error(main_axes_bits_t axes_mask=main_axes_mask);
inline void set_axis_unhomed(const AxisEnum axis) { CBI(axes_homed, axis); }
inline void set_axis_untrusted(const AxisEnum axis) { CBI(axes_trusted, axis); }
inline void set_all_unhomed() { axes_homed = axes_trusted = 0; }
inline void set_axis_homed(const AxisEnum axis) { SBI(axes_homed, axis); }
inline void set_axis_trusted(const AxisEnum axis) { SBI(axes_trusted, axis); }
inline void set_all_homed() { axes_homed = axes_trusted = main_axes_mask; }
#else
constexpr linear_axis_bits_t axis_homed = linear_bits, axis_trusted = linear_bits; // Zero-endstop machines are always homed and trusted
constexpr main_axes_bits_t axes_homed = main_axes_mask, axes_trusted = main_axes_mask; // Zero-endstop machines are always homed and trusted
inline void homeaxis(const AxisEnum axis) {}
inline void set_axis_never_homed(const AxisEnum) {}
inline linear_axis_bits_t axes_should_home(linear_axis_bits_t=linear_bits) { return 0; }
inline bool homing_needed_error(linear_axis_bits_t=linear_bits) { return false; }
inline main_axes_bits_t axes_should_home(main_axes_bits_t=main_axes_mask) { return 0; }
inline bool homing_needed_error(main_axes_bits_t=main_axes_mask) { return false; }
inline void set_axis_unhomed(const AxisEnum axis) {}
inline void set_axis_untrusted(const AxisEnum axis) {}
inline void set_all_unhomed() {}
@ -447,13 +450,13 @@ void set_axis_is_at_home(const AxisEnum axis);
inline void set_all_homed() {}
#endif
inline bool axis_was_homed(const AxisEnum axis) { return TEST(axis_homed, axis); }
inline bool axis_is_trusted(const AxisEnum axis) { return TEST(axis_trusted, axis); }
inline bool axis_was_homed(const AxisEnum axis) { return TEST(axes_homed, axis); }
inline bool axis_is_trusted(const AxisEnum axis) { return TEST(axes_trusted, axis); }
inline bool axis_should_home(const AxisEnum axis) { return (axes_should_home() & _BV(axis)) != 0; }
inline bool no_axes_homed() { return !axis_homed; }
inline bool all_axes_homed() { return linear_bits == (axis_homed & linear_bits); }
inline bool no_axes_homed() { return !axes_homed; }
inline bool all_axes_homed() { return main_axes_mask == (axes_homed & main_axes_mask); }
inline bool homing_needed() { return !all_axes_homed(); }
inline bool all_axes_trusted() { return linear_bits == (axis_trusted & linear_bits); }
inline bool all_axes_trusted() { return main_axes_mask == (axes_trusted & main_axes_mask); }
void home_if_needed(const bool keeplev=false);

View file

@ -274,14 +274,14 @@ xyz_pos_t Probe::offset; // Initialized by settings.load()
#if ENABLED(PROBING_STEPPERS_OFF) && DISABLED(DELTA)
static uint8_t old_trusted;
if (dopause) {
old_trusted = axis_trusted;
old_trusted = axes_trusted;
stepper.disable_axis(X_AXIS);
stepper.disable_axis(Y_AXIS);
}
else {
if (TEST(old_trusted, X_AXIS)) stepper.enable_axis(X_AXIS);
if (TEST(old_trusted, Y_AXIS)) stepper.enable_axis(Y_AXIS);
axis_trusted = old_trusted;
axes_trusted = old_trusted;
}
#endif
if (dopause) safe_delay(_MAX(DELAY_BEFORE_PROBING, 25));

View file

@ -246,7 +246,11 @@
#define MIN_STEP_ISR_FREQUENCY (MAX_STEP_ISR_FREQUENCY_1X / 2)
#define ENABLE_COUNT (NUM_AXES + E_STEPPERS)
typedef IF<(ENABLE_COUNT > 8), uint16_t, uint8_t>::type ena_mask_t;
#if ENABLE_COUNT > 16
typedef uint32_t ena_mask_t;
#else
typedef IF<(ENABLE_COUNT > 8), uint16_t, uint8_t>::type ena_mask_t;
#endif
// Axis flags type, for enabled state or other simple state
typedef struct {
@ -259,8 +263,6 @@ typedef struct {
#endif
};
};
constexpr ena_mask_t linear_bits() { return _BV(NUM_AXES) - 1; }
constexpr ena_mask_t e_bits() { return (_BV(EXTRUDERS) - 1) << NUM_AXES; }
} stepper_flags_t;
// All the stepper enable pins