Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve M350 and M114 with NUM_AXES > 3 #23986

Merged
merged 15 commits into from
Apr 4, 2022
3 changes: 3 additions & 0 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -2866,6 +2866,7 @@
#define U_RSENSE 0.11
#define U_CHAIN_POS -1
//#define U_INTERPOLATE true
//#define U_HOLD_MULTIPLIER 0.5
#endif

#if AXIS_IS_TMC(V)
Expand All @@ -2875,6 +2876,7 @@
#define V_RSENSE 0.11
#define V_CHAIN_POS -1
//#define V_INTERPOLATE true
//#define V_HOLD_MULTIPLIER 0.5
#endif

#if AXIS_IS_TMC(W)
Expand All @@ -2884,6 +2886,7 @@
#define W_RSENSE 0.11
#define W_CHAIN_POS -1
//#define W_INTERPOLATE true
//#define W_HOLD_MULTIPLIER 0.5
#endif

#if AXIS_IS_TMC(E0)
Expand Down
3 changes: 3 additions & 0 deletions Marlin/src/core/serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ extern const char NUL_STR[], SP_P_STR[], SP_T_STR[],
X_STR[], Y_STR[], Z_STR[], I_STR[], J_STR[], K_STR[], U_STR[], V_STR[], W_STR[], E_STR[],
X_LBL[], Y_LBL[], Z_LBL[], I_LBL[], J_LBL[], K_LBL[], U_LBL[], V_LBL[], W_LBL[], E_LBL[];

const char* const SP_AXIS_LBL[] PROGMEM = LOGICAL_AXIS_ARRAY(SP_E_LBL, SP_X_LBL, SP_Y_LBL, SP_Z_LBL, SP_I_LBL, SP_J_LBL, SP_K_LBL, SP_U_LBL, SP_V_LBL, SP_W_LBL);
const char* const SP_AXIS_STR[] PROGMEM = LOGICAL_AXIS_ARRAY(SP_E_STR, SP_X_STR, SP_Y_STR, SP_Z_STR, SP_I_STR, SP_J_STR, SP_K_STR, SP_U_STR, SP_V_STR, SP_W_STR);

//
// Debugging flags for use by M111
//
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/core/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void safe_delay(millis_t ms) {
#if ABL_PLANAR
SERIAL_ECHOPGM("ABL Adjustment");
LOOP_NUM_AXES(a) {
SERIAL_CHAR(' ', AXIS_CHAR(a));
SERIAL_ECHOPGM_P(SP_AXIS_STR[a]);
serial_offset(planner.get_axis_position_mm(AxisEnum(a)) - current_position[a]);
}
#else
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/core/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ constexpr uint8_t ui8_to_percent(const uint8_t i) { return (int(i) * 100 + 127)

// Axis names for G-code parsing, reports, etc.
const xyze_char_t axis_codes LOGICAL_AXIS_ARRAY('E', 'X', 'Y', 'Z', AXIS4_NAME, AXIS5_NAME, AXIS6_NAME, AXIS7_NAME, AXIS8_NAME, AXIS9_NAME);
#if NUM_AXES <= XYZ
#if NUM_AXES <= XYZ && !HAS_EXTRUDERS
#define AXIS_CHAR(A) ((char)('X' + A))
#define IAXIS_CHAR AXIS_CHAR
#else
Expand Down
9 changes: 3 additions & 6 deletions Marlin/src/gcode/calibrate/M425.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void GcodeSuite::M425() {
LOOP_NUM_AXES(a) {
if (axis_can_calibrate(a) && parser.seen(AXIS_CHAR(a))) {
planner.synchronize();
backlash.set_distance_mm(AxisEnum(a), parser.has_value() ? parser.value_axis_units(AxisEnum(a)) : backlash.get_measurement(AxisEnum(a)));
backlash.set_distance_mm((AxisEnum)a, parser.has_value() ? parser.value_axis_units((AxisEnum)a) : backlash.get_measurement((AxisEnum)a));
noArgs = false;
}
}
Expand All @@ -92,9 +92,7 @@ void GcodeSuite::M425() {
SERIAL_ECHOLNPGM(" Correction Amount/Fade-out: F", backlash.get_correction(), " (F1.0 = full, F0.0 = none)");
SERIAL_ECHOPGM(" Backlash Distance (mm): ");
LOOP_NUM_AXES(a) if (axis_can_calibrate(a)) {
SERIAL_CHAR(' ', AXIS_CHAR(a));
SERIAL_ECHO(backlash.get_distance_mm(AxisEnum(a)));
SERIAL_EOL();
SERIAL_ECHOLNPGM_P(SP_AXIS_STR[a], backlash.get_distance_mm((AxisEnum)a));
}

#ifdef BACKLASH_SMOOTHING_MM
Expand All @@ -105,8 +103,7 @@ void GcodeSuite::M425() {
SERIAL_ECHOPGM(" Average measured backlash (mm):");
if (backlash.has_any_measurement()) {
LOOP_NUM_AXES(a) if (axis_can_calibrate(a) && backlash.has_measurement(AxisEnum(a))) {
SERIAL_CHAR(' ', AXIS_CHAR(a));
SERIAL_ECHO(backlash.get_measurement(AxisEnum(a)));
SERIAL_ECHOPGM_P(SP_AXIS_STR[a], backlash.get_measurement((AxisEnum)a));
}
}
else
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/gcode/config/M200-M205.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void GcodeSuite::M201() {
#endif

LOOP_LOGICAL_AXES(i) {
if (parser.seenval(axis_codes[i])) {
if (parser.seenval(AXIS_CHAR(i))) {
const uint8_t a = TERN(HAS_EXTRUDERS, (i == E_AXIS ? uint8_t(E_AXIS_N(target_extruder)) : i), i);
planner.set_max_acceleration(a, parser.value_axis_units((AxisEnum)a));
}
Expand All @@ -144,7 +144,7 @@ void GcodeSuite::M201_report(const bool forReplay/*=true*/) {
SP_K_STR, K_AXIS_UNIT(planner.settings.max_acceleration_mm_per_s2[K_AXIS]),
SP_U_STR, U_AXIS_UNIT(planner.settings.max_acceleration_mm_per_s2[U_AXIS]),
SP_V_STR, V_AXIS_UNIT(planner.settings.max_acceleration_mm_per_s2[V_AXIS]),
SP_W_STR, W_AXIS_UNIT(planner.settings.max_acceleration_mm_per_s2[W_AXIS]),
SP_W_STR, W_AXIS_UNIT(planner.settings.max_acceleration_mm_per_s2[W_AXIS])
)
#if HAS_EXTRUDERS && DISABLED(DISTINCT_E_FACTORS)
, SP_E_STR, VOLUMETRIC_UNIT(planner.settings.max_acceleration_mm_per_s2[E_AXIS])
Expand Down Expand Up @@ -174,7 +174,7 @@ void GcodeSuite::M203() {
if (target_extruder < 0) return;

LOOP_LOGICAL_AXES(i)
if (parser.seenval(axis_codes[i])) {
if (parser.seenval(AXIS_CHAR(i))) {
const uint8_t a = TERN(HAS_EXTRUDERS, (i == E_AXIS ? uint8_t(E_AXIS_N(target_extruder)) : i), i);
planner.set_max_feedrate(a, parser.value_axis_units((AxisEnum)a));
}
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/config/M92.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void GcodeSuite::M92() {
return M92_report(true, target_extruder);

LOOP_LOGICAL_AXES(i) {
if (parser.seenval(axis_codes[i])) {
if (parser.seenval(AXIS_CHAR(i))) {
if (TERN1(HAS_EXTRUDERS, i != E_AXIS))
planner.settings.axis_steps_per_mm[i] = parser.value_per_axis_units((AxisEnum)i);
else {
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/gcode/control/M17_M18_M84.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void do_enable(const axis_flags_t to_enable) {

if ((also_enabled &= ~(shall_enable | was_enabled))) {
SERIAL_CHAR('(');
LOOP_NUM_AXES(a) if (TEST(also_enabled, a)) SERIAL_CHAR(axis_codes[a], ' ');
LOOP_NUM_AXES(a) if (TEST(also_enabled, a)) SERIAL_CHAR(AXIS_CHAR(a), ' ');
#if HAS_EXTRUDERS
#define _EN_ALSO(N) if (TEST(also_enabled, INDEX_OF_AXIS(E_AXIS, N))) SERIAL_CHAR('E', '0' + N, ' ');
REPEAT(EXTRUDERS, _EN_ALSO)
Expand Down Expand Up @@ -184,7 +184,7 @@ void try_to_disable(const axis_flags_t to_disable) {

auto overlap_warning = [](const ena_mask_t axis_bits) {
SERIAL_ECHOPGM(" not disabled. Shared with");
LOOP_NUM_AXES(a) if (TEST(axis_bits, a)) SERIAL_CHAR(' ', axis_codes[a]);
LOOP_NUM_AXES(a) if (TEST(axis_bits, a)) SERIAL_ECHOPGM_P(SP_AXIS_STR[a]);
#if HAS_EXTRUDERS
#define _EN_STILLON(N) if (TEST(axis_bits, INDEX_OF_AXIS(E_AXIS, N))) SERIAL_CHAR(' ', 'E', '0' + N);
REPEAT(EXTRUDERS, _EN_STILLON)
Expand Down
20 changes: 10 additions & 10 deletions Marlin/src/gcode/control/M350_M351.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,29 @@
* Warning: Steps-per-unit remains unchanged.
*/
void GcodeSuite::M350() {
if (parser.seen('S')) LOOP_LE_N(i, 4) stepper.microstep_mode(i, parser.value_byte());
LOOP_LOGICAL_AXES(i) if (parser.seen(axis_codes[i])) stepper.microstep_mode(i, parser.value_byte());
if (parser.seen('B')) stepper.microstep_mode(4, parser.value_byte());
if (parser.seen('S')) LOOP_DISTINCT_AXES(i) stepper.microstep_mode(i, parser.value_byte());
LOOP_LOGICAL_AXES(i) if (parser.seen(IAXIS_CHAR(i))) stepper.microstep_mode(i, parser.value_byte());
TERN_(HAS_EXTRUDERS, if (parser.seen('B')) stepper.microstep_mode(E_AXIS + 1, parser.value_byte()));
stepper.microstep_readings();
}

/**
* M351: Toggle MS1 MS2 pins directly with axis codes X Y Z E B
* M351: Toggle MS1 MS2 pins directly with axis codes X Y Z I J K U V W E B
* S# determines MS1, MS2 or MS3, X# sets the pin high/low.
*/
void GcodeSuite::M351() {
if (parser.seenval('S')) switch (parser.value_byte()) {
case 1:
LOOP_LOGICAL_AXES(i) if (parser.seenval(axis_codes[i])) stepper.microstep_ms(i, parser.value_byte(), -1, -1);
if (parser.seenval('B')) stepper.microstep_ms(4, parser.value_byte(), -1, -1);
LOOP_LOGICAL_AXES(i) if (parser.seenval(IAXIS_CHAR(i))) stepper.microstep_ms(i, parser.value_byte(), -1, -1);
TERN_(HAS_EXTRUDERS, if (parser.seenval('B')) stepper.microstep_ms(E_AXIS + 1, parser.value_byte(), -1, -1));
break;
case 2:
LOOP_LOGICAL_AXES(i) if (parser.seenval(axis_codes[i])) stepper.microstep_ms(i, -1, parser.value_byte(), -1);
if (parser.seenval('B')) stepper.microstep_ms(4, -1, parser.value_byte(), -1);
LOOP_LOGICAL_AXES(i) if (parser.seenval(IAXIS_CHAR(i))) stepper.microstep_ms(i, -1, parser.value_byte(), -1);
TERN_(HAS_EXTRUDERS, if (parser.seenval('B')) stepper.microstep_ms(E_AXIS + 1, -1, parser.value_byte(), -1));
break;
case 3:
LOOP_LOGICAL_AXES(i) if (parser.seenval(axis_codes[i])) stepper.microstep_ms(i, -1, -1, parser.value_byte());
if (parser.seenval('B')) stepper.microstep_ms(4, -1, -1, parser.value_byte());
LOOP_LOGICAL_AXES(i) if (parser.seenval(IAXIS_CHAR(i))) stepper.microstep_ms(i, -1, -1, parser.value_byte());
TERN_(HAS_EXTRUDERS, if (parser.seenval('B')) stepper.microstep_ms(E_AXIS + 1, -1, -1, parser.value_byte()));
break;
}
stepper.microstep_readings();
Expand Down
49 changes: 44 additions & 5 deletions Marlin/src/gcode/feature/L6470/M906.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@

#if HAS_L64XX

#if AXIS_COLLISION('I')
#error "M906 parameter collision with axis name."
#endif

#include "../../gcode.h"
#include "../../../libs/L64XX/L64XX_Marlin.h"
#include "../../../module/stepper/indirection.h"
Expand Down Expand Up @@ -211,7 +207,7 @@ void L64XX_report_current(L64XX &motor, const L64XX_axis_t axis) {
* 1 - monitor only X2, Y2, Z2
* 2 - monitor only Z3
* 3 - monitor only Z4
* Xxxx, Yxxx, Zxxx, Exxx - axis to change (optional)
* Xxxx, Yxxx, Zxxx, Axxx, Bxxx, Cxxx, Uxxx, Vxxx, Wxxx, Exxx - axis to change (optional)
* L6474 - current in mA (4A max)
* All others - 0-255
*
Expand Down Expand Up @@ -285,6 +281,31 @@ void GcodeSuite::M906() {
break;
#endif

#if AXIS_IS_L64XX(I)
case I_AXIS:
L6470_SET_KVAL_HOLD(I);
#endif
#if AXIS_IS_L64XX(J)
case J_AXIS:
L6470_SET_KVAL_HOLD(J);
#endif
#if AXIS_IS_L64XX(K)
case K_AXIS:
L6470_SET_KVAL_HOLD(K);
#endif
#if AXIS_IS_L64XX(U)
case U_AXIS:
L6470_SET_KVAL_HOLD(U);
#endif
#if AXIS_IS_L64XX(V)
case V_AXIS:
L6470_SET_KVAL_HOLD(V);
#endif
#if AXIS_IS_L64XX(W)
case W_AXIS:
L6470_SET_KVAL_HOLD(W);
#endif

#if AXIS_IS_L64XX(E0) || AXIS_IS_L64XX(E1) || AXIS_IS_L64XX(E2) || AXIS_IS_L64XX(E3) || AXIS_IS_L64XX(E4) || AXIS_IS_L64XX(E5) || AXIS_IS_L64XX(E6) || AXIS_IS_L64XX(E7)
case E_AXIS: {
const int8_t eindex = get_target_e_stepper_from_command(-2);
Expand Down Expand Up @@ -346,6 +367,24 @@ void GcodeSuite::M906() {
#if AXIS_IS_L64XX(Z4)
L64XX_REPORT_CURRENT(Z4);
#endif
#if AXIS_IS_L64XX(I)
L64XX_REPORT_CURRENT(I);
#endif
#if AXIS_IS_L64XX(J)
L64XX_REPORT_CURRENT(J);
#endif
#if AXIS_IS_L64XX(K)
L64XX_REPORT_CURRENT(K);
#endif
#if AXIS_IS_L64XX(U)
L64XX_REPORT_CURRENT(U);
#endif
#if AXIS_IS_L64XX(V)
L64XX_REPORT_CURRENT(V);
#endif
#if AXIS_IS_L64XX(W)
L64XX_REPORT_CURRENT(W);
#endif
#if AXIS_IS_L64XX(E0)
L64XX_REPORT_CURRENT(E0);
#endif
Expand Down
6 changes: 1 addition & 5 deletions Marlin/src/gcode/feature/trinamic/M569.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@

#if HAS_STEALTHCHOP

#if AXIS_COLLISION('I')
#error "M569 parameter collision with axis name."
#endif

thinkyhead marked this conversation as resolved.
Show resolved Hide resolved
#include "../../gcode.h"
#include "../../../feature/tmc_util.h"
#include "../../../module/stepper/indirection.h"
Expand All @@ -53,7 +49,7 @@ static void set_stealth_status(const bool enable, const int8_t eindex) {
constexpr int8_t index = -1;
#endif

LOOP_LOGICAL_AXES(i) if (parser.seen(axis_codes[i])) {
LOOP_LOGICAL_AXES(i) if (parser.seen(AXIS_CHAR(i))) {
switch (i) {
case X_AXIS:
TERN_(X_HAS_STEALTHCHOP, if (index < 0 || index == 0) TMC_SET_STEALTH(X));
Expand Down
4 changes: 0 additions & 4 deletions Marlin/src/gcode/feature/trinamic/M919.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@

#if HAS_TRINAMIC_CONFIG

#if AXIS_COLLISION('I')
#error "M919 parameter collision with axis name."
#endif

#include "../../gcode.h"
#include "../../../feature/tmc_util.h"
#include "../../../module/stepper/indirection.h"
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/gcode/geometry/G92.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void GcodeSuite::G92() {
#if ENABLED(POWER_LOSS_RECOVERY)
case 9: // G92.9 - Set Current Position directly (like Marlin 1.0)
LOOP_LOGICAL_AXES(i) {
if (parser.seenval(axis_codes[i])) {
if (parser.seenval(AXIS_CHAR(i))) {
if (TERN1(HAS_EXTRUDERS, i != E_AXIS))
sync_XYZE = true;
else {
Expand All @@ -88,7 +88,7 @@ void GcodeSuite::G92() {

case 0:
LOOP_LOGICAL_AXES(i) {
if (parser.seenval(axis_codes[i])) {
if (parser.seenval(AXIS_CHAR(i))) {
const float l = parser.value_axis_units((AxisEnum)i), // Given axis coordinate value, converted to millimeters
v = TERN0(HAS_EXTRUDERS, i == E_AXIS) ? l : LOGICAL_TO_NATIVE(l, i), // Axis position in NATIVE space (applying the existing offset)
d = v - current_position[i]; // How much is the current axis position altered by?
Expand Down
12 changes: 4 additions & 8 deletions Marlin/src/gcode/host/M114.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
#include "../../core/debug_out.h"
#endif

void report_all_axis_pos(const xyze_pos_t &pos, const uint8_t n=XYZE, const uint8_t precision=3) {
void report_all_axis_pos(const xyze_pos_t &pos, const uint8_t n=LOGICAL_AXES, const uint8_t precision=3) {
char str[12];
LOOP_L_N(a, n) {
SERIAL_CHAR(' ', axis_codes[a], ':');
SERIAL_ECHOPGM_P(SP_AXIS_LBL[a]);
if (pos[a] >= 0) SERIAL_CHAR(' ');
SERIAL_ECHO(dtostrf(pos[a], 1, precision, str));
}
Expand All @@ -47,10 +47,7 @@

void report_linear_axis_pos(const xyz_pos_t &pos, const uint8_t precision=3) {
char str[12];
LOOP_NUM_AXES(a) {
SERIAL_CHAR(' ', AXIS_CHAR(a), ':');
SERIAL_ECHO(dtostrf(pos[a], 1, precision, str));
}
LOOP_NUM_AXES(a) SERIAL_ECHOPGM_P(SP_AXIS_LBL[a], dtostrf(pos[a], 1, precision, str));
SERIAL_EOL();
}

Expand Down Expand Up @@ -172,8 +169,7 @@

SERIAL_ECHOPGM("Stepper:");
LOOP_LOGICAL_AXES(i) {
SERIAL_CHAR(' ', axis_codes[i], ':');
SERIAL_ECHO(stepper.position((AxisEnum)i));
SERIAL_ECHOPGM_P(SP_AXIS_LBL[i], stepper.position((AxisEnum)i));
}
SERIAL_EOL();

Expand Down
4 changes: 0 additions & 4 deletions Marlin/src/gcode/motion/G5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@

#if ENABLED(BEZIER_CURVE_SUPPORT)

#if AXIS_COLLISION('I') || AXIS_COLLISION('J')
#error "G5 parameter collision with axis name."
#endif

#include "../../module/motion.h"
#include "../../module/planner_bezier.h"

Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/libs/L64XX/L64XX_Marlin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ uint8_t L64XX_Marlin::get_user_input(uint8_t &driver_count, L64XX_axis_t axis_in
found_displacement = true;
displacement = _displacement;
uint8_t axis_offset = parser.byteval('J');
axis_mon[0][0] = axis_codes[i]; // Axis first character, one of XYZE
axis_mon[0][0] = AXIS_CHAR(i); // Axis first character, one of XYZE
const bool single_or_e = axis_offset >= 2 || axis_mon[0][0] == 'E',
one_or_more = !single_or_e && axis_offset == 0;
uint8_t driver_count_local = 0; // Can't use "driver_count" directly as a subscript because it's passed by reference
Expand Down Expand Up @@ -667,7 +667,7 @@ uint8_t L64XX_Marlin::get_user_input(uint8_t &driver_count, L64XX_axis_t axis_in
static constexpr float default_max_feedrate[] = DEFAULT_MAX_FEEDRATE;
const uint8_t num_feedrates = COUNT(default_max_feedrate);
for (j = 0; j < num_feedrates; j++) {
if (axis_codes[j] == axis_mon[0][0]) {
if (AXIS_CHAR(j) == axis_mon[0][0]) {
final_feedrate = default_max_feedrate[j];
break;
}
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/libs/L64XX/L64XX_Marlin.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#define HAS_L64XX_EXTRUDER (AXIS_IS_L64XX(E0) || AXIS_IS_L64XX(E1) || AXIS_IS_L64XX(E2) || AXIS_IS_L64XX(E3) || AXIS_IS_L64XX(E4) || AXIS_IS_L64XX(E5) || AXIS_IS_L64XX(E6) || AXIS_IS_L64XX(E7))

#define _EN_ITEM(N) , E##N
enum L64XX_axis_t : uint8_t { NUM_AXIS_LIST(X, Y, Z, I, J, K), X2, Y2, Z2, Z3, Z4 REPEAT(E_STEPPERS, _EN_ITEM), MAX_L64XX };
enum L64XX_axis_t : uint8_t { NUM_AXIS_LIST(X, Y, Z, I, J, K, U, V, W), X2, Y2, Z2, Z3, Z4 REPEAT(E_STEPPERS, _EN_ITEM), MAX_L64XX };
#undef _EN_ITEM

class L64XX_Marlin : public L64XXHelper {
Expand Down
Loading