🚸 Better M350, M114 with more axes (#23986)

Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
This commit is contained in:
DerAndere 2022-04-04 04:43:42 +02:00 committed by Scott Lahteine
parent f18b0f6f4b
commit a03516a9f4
7 changed files with 103 additions and 84 deletions

View file

@ -27,6 +27,13 @@
#include "../gcode.h" #include "../gcode.h"
#include "../../module/stepper.h" #include "../../module/stepper.h"
#if LINEAR_AXES == XYZ && EXTRUDERS >= 1
#define HAS_M350_B_PARAM 1 // "5th axis" (after E0) for an original XYZEB setup.
#if AXIS_COLLISION('B')
#error "M350 parameter 'B' collision with axis name."
#endif
#endif
/** /**
* M350: Set axis microstepping modes. S sets mode for all drivers. * M350: Set axis microstepping modes. S sets mode for all drivers.
* *
@ -35,27 +42,30 @@
void GcodeSuite::M350() { void GcodeSuite::M350() {
if (parser.seen('S')) LOOP_DISTINCT_AXES(i) stepper.microstep_mode(i, parser.value_byte()); if (parser.seen('S')) LOOP_DISTINCT_AXES(i) stepper.microstep_mode(i, parser.value_byte());
LOOP_LOGICAL_AXES(i) if (parser.seenval(AXIS_CHAR(i))) stepper.microstep_mode(i, parser.value_byte()); LOOP_LOGICAL_AXES(i) if (parser.seenval(AXIS_CHAR(i))) stepper.microstep_mode(i, parser.value_byte());
if (parser.seenval('B')) stepper.microstep_mode(E_AXIS + 1, parser.value_byte()); TERN_(HAS_M350_B_PARAM, if (parser.seenval('B')) stepper.microstep_mode(E_AXIS + 1, parser.value_byte()));
stepper.microstep_readings(); 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 . . . E [B]
* S# determines MS1, MS2 or MS3, X# sets the pin high/low. * S# determines MS1, MS2 or MS3, X# sets the pin high/low.
*
* Parameter 'B' sets "5th axis" (after E0) only for an original XYZEB setup.
*/ */
void GcodeSuite::M351() { void GcodeSuite::M351() {
const int8_t bval = TERN(HAS_M350_B_PARAM, parser.byteval('B', -1), -1); UNUSED(bval);
if (parser.seenval('S')) switch (parser.value_byte()) { if (parser.seenval('S')) switch (parser.value_byte()) {
case 1: case 1:
LOOP_LOGICAL_AXES(i) if (parser.seenval(AXIS_CHAR(i))) stepper.microstep_ms(i, parser.value_byte(), -1, -1); LOOP_LOGICAL_AXES(i) if (parser.seenval(AXIS_CHAR(i))) stepper.microstep_ms(i, parser.value_byte(), -1, -1);
if (parser.seenval('B')) stepper.microstep_ms(4, parser.value_byte(), -1, -1); TERN_(HAS_M350_B_PARAM, if (bval >= 0) stepper.microstep_ms(E_AXIS + 1, bval != 0, -1, -1));
break; break;
case 2: case 2:
LOOP_LOGICAL_AXES(i) if (parser.seenval(AXIS_CHAR(i))) stepper.microstep_ms(i, -1, parser.value_byte(), -1); LOOP_LOGICAL_AXES(i) if (parser.seenval(AXIS_CHAR(i))) stepper.microstep_ms(i, -1, parser.value_byte(), -1);
if (parser.seenval('B')) stepper.microstep_ms(4, -1, parser.value_byte(), -1); TERN_(HAS_M350_B_PARAM, if (bval >= 0) stepper.microstep_ms(E_AXIS + 1, -1, bval != 0, -1));
break; break;
case 3: case 3:
LOOP_LOGICAL_AXES(i) if (parser.seenval(AXIS_CHAR(i))) stepper.microstep_ms(i, -1, -1, parser.value_byte()); LOOP_LOGICAL_AXES(i) if (parser.seenval(AXIS_CHAR(i))) stepper.microstep_ms(i, -1, -1, parser.value_byte());
if (parser.seenval('B')) stepper.microstep_ms(4, -1, -1, parser.value_byte()); TERN_(HAS_M350_B_PARAM, if (bval >= 0) stepper.microstep_ms(E_AXIS + 1, -1, -1, bval != 0));
break; break;
} }
stepper.microstep_readings(); stepper.microstep_readings();

View file

@ -25,7 +25,7 @@
#if HAS_L64XX #if HAS_L64XX
#if AXIS_COLLISION('I') #if AXIS_COLLISION('I')
#error "M906 parameter collision with axis name." #error "M906 parameter 'I' collision with axis name."
#endif #endif
#include "../../gcode.h" #include "../../gcode.h"

View file

@ -52,7 +52,7 @@ void GcodeSuite::M907() {
return M907_report(); return M907_report();
if (parser.seenval('S')) LOOP_L_N(i, MOTOR_CURRENT_COUNT) stepper.set_digipot_current(i, parser.value_int()); if (parser.seenval('S')) LOOP_L_N(i, MOTOR_CURRENT_COUNT) stepper.set_digipot_current(i, parser.value_int());
LOOP_LOGICAL_AXES(i) if (parser.seenval(IAXIS_CHAR(i))) stepper.set_digipot_current(i, parser.value_int()); // X Y Z (I J K) E (map to drivers according to DIGIPOT_CHANNELS. Default with NUM_AXES 3: map X Y Z E to X Y Z E0) LOOP_LOGICAL_AXES(i) if (parser.seenval(IAXIS_CHAR(i))) stepper.set_digipot_current(i, parser.value_int()); // X Y Z (I J K) E (map to drivers according to DIGIPOT_CHANNELS. Default with LINEAR_AXES 3: map X Y Z E to X Y Z E0)
// Additional extruders use B,C. // Additional extruders use B,C.
// TODO: Change these parameters because 'E' is used and D should be reserved for debugging. B<index>? // TODO: Change these parameters because 'E' is used and D should be reserved for debugging. B<index>?
#if E_STEPPERS >= 2 #if E_STEPPERS >= 2
@ -104,11 +104,11 @@ void GcodeSuite::M907() {
#if HAS_MOTOR_CURRENT_I2C #if HAS_MOTOR_CURRENT_I2C
// this one uses actual amps in floating point // this one uses actual amps in floating point
if (parser.seenval('S')) LOOP_L_N(q, DIGIPOT_I2C_NUM_CHANNELS) digipot_i2c.set_current(q, parser.value_float()); if (parser.seenval('S')) LOOP_L_N(q, DIGIPOT_I2C_NUM_CHANNELS) digipot_i2c.set_current(q, parser.value_float());
LOOP_LOGICAL_AXES(i) if (parser.seenval(IAXIS_CHAR(i))) digipot_i2c.set_current(i, parser.value_float()); // X Y Z (I J K) E (map to drivers according to pots adresses. Default with NUM_AXES 3 X Y Z E: map to X Y Z E0) LOOP_LOGICAL_AXES(i) if (parser.seenval(IAXIS_CHAR(i))) digipot_i2c.set_current(i, parser.value_float()); // X Y Z (I J K) E (map to drivers according to pots adresses. Default with LINEAR_AXES 3 X Y Z E: map to X Y Z E0)
// Additional extruders use B,C,D. // Additional extruders use B,C,D.
// TODO: Change these parameters because 'E' is used and because 'D' should be reserved for debugging. B<index>? // TODO: Change these parameters because 'E' is used and because 'D' should be reserved for debugging. B<index>?
#if E_STEPPERS >= 2 #if E_STEPPERS >= 2
for (uint8_t i = E_AXIS + 1; i < _MAX(DIGIPOT_I2C_NUM_CHANNELS, (NUM_AXES + 3)); i++) for (uint8_t i = E_AXIS + 1; i < _MAX(DIGIPOT_I2C_NUM_CHANNELS, (LINEAR_AXES + 3)); i++)
if (parser.seenval('B' + i - (E_AXIS + 1))) digipot_i2c.set_current(i, parser.value_float()); if (parser.seenval('B' + i - (E_AXIS + 1))) digipot_i2c.set_current(i, parser.value_float());
#endif #endif
#endif #endif
@ -118,7 +118,7 @@ void GcodeSuite::M907() {
const float dac_percent = parser.value_float(); const float dac_percent = parser.value_float();
LOOP_LOGICAL_AXES(i) stepper_dac.set_current_percent(i, dac_percent); LOOP_LOGICAL_AXES(i) stepper_dac.set_current_percent(i, dac_percent);
} }
LOOP_LOGICAL_AXES(i) if (parser.seenval(IAXIS_CHAR(i))) stepper_dac.set_current_percent(i, parser.value_float()); // X Y Z (I J K) E (map to drivers according to DAC_STEPPER_ORDER. Default with NUM_AXES 3: X Y Z E map to X Y Z E0) LOOP_LOGICAL_AXES(i) if (parser.seenval(IAXIS_CHAR(i))) stepper_dac.set_current_percent(i, parser.value_float()); // X Y Z (I J K) E (map to drivers according to DAC_STEPPER_ORDER. Default with LINEAR_AXES 3: X Y Z E map to X Y Z E0)
#endif #endif
} }
@ -139,7 +139,7 @@ void GcodeSuite::M907() {
SERIAL_ECHO(stepper.motor_current_setting[q]); SERIAL_ECHO(stepper.motor_current_setting[q]);
} }
#if E_STEPPERS >= 2 #if E_STEPPERS >= 2
SERIAL_ECHOPGM_P(PSTR(" B"), stepper.motor_current_setting[E_AXIS + 1] // B (maps to E1 with NUM_AXES 3 according to DIGIPOT_CHANNELS) SERIAL_ECHOPGM_P(PSTR(" B"), stepper.motor_current_setting[E_AXIS + 1] // B (maps to E1 with LINEAR_AXES 3 according to DIGIPOT_CHANNELS)
#if E_STEPPERS >= 3 #if E_STEPPERS >= 3
, PSTR(" C"), stepper.motor_current_setting[E_AXIS + 2] // C (mapping to E2 must be defined by DIGIPOT_CHANNELS) , PSTR(" C"), stepper.motor_current_setting[E_AXIS + 2] // C (mapping to E2 must be defined by DIGIPOT_CHANNELS)
#endif #endif

View file

@ -25,7 +25,7 @@
#if HAS_STEALTHCHOP #if HAS_STEALTHCHOP
#if AXIS_COLLISION('I') #if AXIS_COLLISION('I')
#error "M569 parameter collision with axis name." #error "M569 parameter 'I' collision with axis name."
#endif #endif
#include "../../gcode.h" #include "../../gcode.h"

View file

@ -25,7 +25,7 @@
#if HAS_TRINAMIC_CONFIG #if HAS_TRINAMIC_CONFIG
#if AXIS_COLLISION('I') #if AXIS_COLLISION('I')
#error "M919 parameter collision with axis name." #error "M919 parameter 'I' collision with axis name."
#endif #endif
#include "../../gcode.h" #include "../../gcode.h"

View file

@ -25,7 +25,7 @@
#if ENABLED(BEZIER_CURVE_SUPPORT) #if ENABLED(BEZIER_CURVE_SUPPORT)
#if AXIS_COLLISION('I') || AXIS_COLLISION('J') #if AXIS_COLLISION('I') || AXIS_COLLISION('J')
#error "G5 parameter collision with axis name." #error "G5 parameter 'I' or 'J' collision with axis name."
#endif #endif
#include "../../module/motion.h" #include "../../module/motion.h"

View file

@ -3485,7 +3485,7 @@ void Stepper::report_positions() {
void Stepper::microstep_ms(const uint8_t driver, const int8_t ms1, const int8_t ms2, const int8_t ms3) { void Stepper::microstep_ms(const uint8_t driver, const int8_t ms1, const int8_t ms2, const int8_t ms3) {
if (ms1 >= 0) switch (driver) { if (ms1 >= 0) switch (driver) {
#if HAS_X_MS_PINS || HAS_X2_MS_PINS #if HAS_X_MS_PINS || HAS_X2_MS_PINS
case 0: case X_AXIS:
#if HAS_X_MS_PINS #if HAS_X_MS_PINS
WRITE(X_MS1_PIN, ms1); WRITE(X_MS1_PIN, ms1);
#endif #endif
@ -3495,7 +3495,7 @@ void Stepper::report_positions() {
break; break;
#endif #endif
#if HAS_Y_MS_PINS || HAS_Y2_MS_PINS #if HAS_Y_MS_PINS || HAS_Y2_MS_PINS
case 1: case Y_AXIS:
#if HAS_Y_MS_PINS #if HAS_Y_MS_PINS
WRITE(Y_MS1_PIN, ms1); WRITE(Y_MS1_PIN, ms1);
#endif #endif
@ -3505,7 +3505,7 @@ void Stepper::report_positions() {
break; break;
#endif #endif
#if HAS_SOME_Z_MS_PINS #if HAS_SOME_Z_MS_PINS
case 2: case Z_AXIS:
#if HAS_Z_MS_PINS #if HAS_Z_MS_PINS
WRITE(Z_MS1_PIN, ms1); WRITE(Z_MS1_PIN, ms1);
#endif #endif
@ -3520,43 +3520,43 @@ void Stepper::report_positions() {
#endif #endif
break; break;
#endif #endif
#if HAS_E0_MS_PINS
case 3: WRITE(E0_MS1_PIN, ms1); break;
#endif
#if HAS_E1_MS_PINS
case 4: WRITE(E1_MS1_PIN, ms1); break;
#endif
#if HAS_E2_MS_PINS
case 5: WRITE(E2_MS1_PIN, ms1); break;
#endif
#if HAS_E3_MS_PINS
case 6: WRITE(E3_MS1_PIN, ms1); break;
#endif
#if HAS_E4_MS_PINS
case 7: WRITE(E4_MS1_PIN, ms1); break;
#endif
#if HAS_E5_MS_PINS
case 8: WRITE(E5_MS1_PIN, ms1); break;
#endif
#if HAS_E6_MS_PINS
case 9: WRITE(E6_MS1_PIN, ms1); break;
#endif
#if HAS_E7_MS_PINS
case 10: WRITE(E7_MS1_PIN, ms1); break;
#endif
#if HAS_I_MS_PINS #if HAS_I_MS_PINS
case 11: WRITE(I_MS1_PIN, ms1); break case I_AXIS: WRITE(I_MS1_PIN, ms1); break
#endif #endif
#if HAS_J_MS_PINS #if HAS_J_MS_PINS
case 12: WRITE(J_MS1_PIN, ms1); break case J_AXIS: WRITE(J_MS1_PIN, ms1); break
#endif #endif
#if HAS_K_MS_PINS #if HAS_K_MS_PINS
case 13: WRITE(K_MS1_PIN, ms1); break case K_AXIS: WRITE(K_MS1_PIN, ms1); break
#endif
#if HAS_E0_MS_PINS
case E_AXIS: WRITE(E0_MS1_PIN, ms1); break;
#endif
#if HAS_E1_MS_PINS
case (E_AXIS + 1): WRITE(E1_MS1_PIN, ms1); break;
#endif
#if HAS_E2_MS_PINS
case (E_AXIS + 2): WRITE(E2_MS1_PIN, ms1); break;
#endif
#if HAS_E3_MS_PINS
case (E_AXIS + 3): WRITE(E3_MS1_PIN, ms1); break;
#endif
#if HAS_E4_MS_PINS
case (E_AXIS + 4): WRITE(E4_MS1_PIN, ms1); break;
#endif
#if HAS_E5_MS_PINS
case (E_AXIS + 5): WRITE(E5_MS1_PIN, ms1); break;
#endif
#if HAS_E6_MS_PINS
case (E_AXIS + 6): WRITE(E6_MS1_PIN, ms1); break;
#endif
#if HAS_E7_MS_PINS
case (E_AXIS + 7): WRITE(E7_MS1_PIN, ms1); break;
#endif #endif
} }
if (ms2 >= 0) switch (driver) { if (ms2 >= 0) switch (driver) {
#if HAS_X_MS_PINS || HAS_X2_MS_PINS #if HAS_X_MS_PINS || HAS_X2_MS_PINS
case 0: case X_AXIS:
#if HAS_X_MS_PINS #if HAS_X_MS_PINS
WRITE(X_MS2_PIN, ms2); WRITE(X_MS2_PIN, ms2);
#endif #endif
@ -3566,7 +3566,7 @@ void Stepper::report_positions() {
break; break;
#endif #endif
#if HAS_Y_MS_PINS || HAS_Y2_MS_PINS #if HAS_Y_MS_PINS || HAS_Y2_MS_PINS
case 1: case Y_AXIS:
#if HAS_Y_MS_PINS #if HAS_Y_MS_PINS
WRITE(Y_MS2_PIN, ms2); WRITE(Y_MS2_PIN, ms2);
#endif #endif
@ -3576,7 +3576,7 @@ void Stepper::report_positions() {
break; break;
#endif #endif
#if HAS_SOME_Z_MS_PINS #if HAS_SOME_Z_MS_PINS
case 2: case Z_AXIS:
#if HAS_Z_MS_PINS #if HAS_Z_MS_PINS
WRITE(Z_MS2_PIN, ms2); WRITE(Z_MS2_PIN, ms2);
#endif #endif
@ -3591,43 +3591,43 @@ void Stepper::report_positions() {
#endif #endif
break; break;
#endif #endif
#if HAS_E0_MS_PINS
case 3: WRITE(E0_MS2_PIN, ms2); break;
#endif
#if HAS_E1_MS_PINS
case 4: WRITE(E1_MS2_PIN, ms2); break;
#endif
#if HAS_E2_MS_PINS
case 5: WRITE(E2_MS2_PIN, ms2); break;
#endif
#if HAS_E3_MS_PINS
case 6: WRITE(E3_MS2_PIN, ms2); break;
#endif
#if HAS_E4_MS_PINS
case 7: WRITE(E4_MS2_PIN, ms2); break;
#endif
#if HAS_E5_MS_PINS
case 8: WRITE(E5_MS2_PIN, ms2); break;
#endif
#if HAS_E6_MS_PINS
case 9: WRITE(E6_MS2_PIN, ms2); break;
#endif
#if HAS_E7_MS_PINS
case 10: WRITE(E7_MS2_PIN, ms2); break;
#endif
#if HAS_I_MS_PINS #if HAS_I_MS_PINS
case 11: WRITE(I_MS2_PIN, ms2); break case I_AXIS: WRITE(I_MS2_PIN, ms2); break
#endif #endif
#if HAS_J_MS_PINS #if HAS_J_MS_PINS
case 12: WRITE(J_MS2_PIN, ms2); break case J_AXIS: WRITE(J_MS2_PIN, ms2); break
#endif #endif
#if HAS_K_MS_PINS #if HAS_K_MS_PINS
case 13: WRITE(K_MS2_PIN, ms2); break case K_AXIS: WRITE(K_MS2_PIN, ms2); break
#endif
#if HAS_E0_MS_PINS
case E_AXIS: WRITE(E0_MS2_PIN, ms2); break;
#endif
#if HAS_E1_MS_PINS
case (E_AXIS + 1): WRITE(E1_MS2_PIN, ms2); break;
#endif
#if HAS_E2_MS_PINS
case (E_AXIS + 2): WRITE(E2_MS2_PIN, ms2); break;
#endif
#if HAS_E3_MS_PINS
case (E_AXIS + 3): WRITE(E3_MS2_PIN, ms2); break;
#endif
#if HAS_E4_MS_PINS
case (E_AXIS + 4): WRITE(E4_MS2_PIN, ms2); break;
#endif
#if HAS_E5_MS_PINS
case (E_AXIS + 5): WRITE(E5_MS2_PIN, ms2); break;
#endif
#if HAS_E6_MS_PINS
case (E_AXIS + 6): WRITE(E6_MS2_PIN, ms2); break;
#endif
#if HAS_E7_MS_PINS
case (E_AXIS + 7): WRITE(E7_MS2_PIN, ms2); break;
#endif #endif
} }
if (ms3 >= 0) switch (driver) { if (ms3 >= 0) switch (driver) {
#if HAS_X_MS_PINS || HAS_X2_MS_PINS #if HAS_X_MS_PINS || HAS_X2_MS_PINS
case 0: case X_AXIS:
#if HAS_X_MS_PINS && PIN_EXISTS(X_MS3) #if HAS_X_MS_PINS && PIN_EXISTS(X_MS3)
WRITE(X_MS3_PIN, ms3); WRITE(X_MS3_PIN, ms3);
#endif #endif
@ -3637,7 +3637,7 @@ void Stepper::report_positions() {
break; break;
#endif #endif
#if HAS_Y_MS_PINS || HAS_Y2_MS_PINS #if HAS_Y_MS_PINS || HAS_Y2_MS_PINS
case 1: case Y_AXIS:
#if HAS_Y_MS_PINS && PIN_EXISTS(Y_MS3) #if HAS_Y_MS_PINS && PIN_EXISTS(Y_MS3)
WRITE(Y_MS3_PIN, ms3); WRITE(Y_MS3_PIN, ms3);
#endif #endif
@ -3647,7 +3647,7 @@ void Stepper::report_positions() {
break; break;
#endif #endif
#if HAS_SOME_Z_MS_PINS #if HAS_SOME_Z_MS_PINS
case 2: case Z_AXIS:
#if HAS_Z_MS_PINS && PIN_EXISTS(Z_MS3) #if HAS_Z_MS_PINS && PIN_EXISTS(Z_MS3)
WRITE(Z_MS3_PIN, ms3); WRITE(Z_MS3_PIN, ms3);
#endif #endif
@ -3662,29 +3662,38 @@ void Stepper::report_positions() {
#endif #endif
break; break;
#endif #endif
#if HAS_I_MS_PINS
case I_AXIS: WRITE(I_MS3_PIN, ms3); break
#endif
#if HAS_J_MS_PINS
case J_AXIS: WRITE(J_MS3_PIN, ms3); break
#endif
#if HAS_K_MS_PINS
case K_AXIS: WRITE(K_MS3_PIN, ms3); break
#endif
#if HAS_E0_MS_PINS && PIN_EXISTS(E0_MS3) #if HAS_E0_MS_PINS && PIN_EXISTS(E0_MS3)
case 3: WRITE(E0_MS3_PIN, ms3); break; case E_AXIS: WRITE(E0_MS3_PIN, ms3); break;
#endif #endif
#if HAS_E1_MS_PINS && PIN_EXISTS(E1_MS3) #if HAS_E1_MS_PINS && PIN_EXISTS(E1_MS3)
case 4: WRITE(E1_MS3_PIN, ms3); break; case (E_AXIS + 1): WRITE(E1_MS3_PIN, ms3); break;
#endif #endif
#if HAS_E2_MS_PINS && PIN_EXISTS(E2_MS3) #if HAS_E2_MS_PINS && PIN_EXISTS(E2_MS3)
case 5: WRITE(E2_MS3_PIN, ms3); break; case (E_AXIS + 2): WRITE(E2_MS3_PIN, ms3); break;
#endif #endif
#if HAS_E3_MS_PINS && PIN_EXISTS(E3_MS3) #if HAS_E3_MS_PINS && PIN_EXISTS(E3_MS3)
case 6: WRITE(E3_MS3_PIN, ms3); break; case (E_AXIS + 3): WRITE(E3_MS3_PIN, ms3); break;
#endif #endif
#if HAS_E4_MS_PINS && PIN_EXISTS(E4_MS3) #if HAS_E4_MS_PINS && PIN_EXISTS(E4_MS3)
case 7: WRITE(E4_MS3_PIN, ms3); break; case (E_AXIS + 4): WRITE(E4_MS3_PIN, ms3); break;
#endif #endif
#if HAS_E5_MS_PINS && PIN_EXISTS(E5_MS3) #if HAS_E5_MS_PINS && PIN_EXISTS(E5_MS3)
case 8: WRITE(E5_MS3_PIN, ms3); break; case (E_AXIS + 5): WRITE(E5_MS3_PIN, ms3); break;
#endif #endif
#if HAS_E6_MS_PINS && PIN_EXISTS(E6_MS3) #if HAS_E6_MS_PINS && PIN_EXISTS(E6_MS3)
case 9: WRITE(E6_MS3_PIN, ms3); break; case (E_AXIS + 6): WRITE(E6_MS3_PIN, ms3); break;
#endif #endif
#if HAS_E7_MS_PINS && PIN_EXISTS(E7_MS3) #if HAS_E7_MS_PINS && PIN_EXISTS(E7_MS3)
case 10: WRITE(E7_MS3_PIN, ms3); break; case (E_AXIS + 7): WRITE(E7_MS3_PIN, ms3); break;
#endif #endif
} }
} }