Fix G90, G91, M82, M83 rel/abs modes (#15218)

This commit is contained in:
Scott Lahteine 2019-09-11 01:29:33 -05:00 committed by GitHub
parent 41a3fbceac
commit 6091e6300a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 39 additions and 27 deletions

View File

@ -215,9 +215,8 @@ void PrintJobRecovery::save(const bool force/*=false*/, const bool save_queue/*=
info.retract_hop = fwretract.current_hop; info.retract_hop = fwretract.current_hop;
#endif #endif
// Relative mode // Relative axis modes
info.relative_mode = relative_mode; info.axis_relative = gcode.axis_relative;
info.relative_modes_e = gcode.axis_relative_modes[E_AXIS];
// Elapsed print job time // Elapsed print job time
info.print_job_elapsed = print_job_timer.duration(); info.print_job_elapsed = print_job_timer.duration();
@ -392,9 +391,8 @@ void PrintJobRecovery::resume() {
sprintf_P(cmd, PSTR("G92.9 E%s"), dtostrf(info.current_position[E_AXIS], 1, 3, str_1)); sprintf_P(cmd, PSTR("G92.9 E%s"), dtostrf(info.current_position[E_AXIS], 1, 3, str_1));
gcode.process_subcommands_now(cmd); gcode.process_subcommands_now(cmd);
// Relative mode // Relative axis modes
relative_mode = info.relative_mode; gcode.axis_relative = info.axis_relative;
gcode.axis_relative_modes[E_AXIS] = info.relative_modes_e;
#if HAS_HOME_OFFSET || HAS_POSITION_SHIFT #if HAS_HOME_OFFSET || HAS_POSITION_SHIFT
LOOP_XYZ(i) { LOOP_XYZ(i) {

View File

@ -89,8 +89,8 @@ typedef struct {
#endif #endif
#endif #endif
// Relative mode // Relative axis modes
bool relative_mode, relative_modes_e; uint8_t axis_relative;
// SD Filename and position // SD Filename and position
char sd_filename[MAXPATHNAMELENGTH]; char sd_filename[MAXPATHNAMELENGTH];

View File

@ -698,8 +698,6 @@ void MMU2::filament_runout() {
} }
LCD_MESSAGEPGM(MSG_MMU2_EJECTING_FILAMENT); LCD_MESSAGEPGM(MSG_MMU2_EJECTING_FILAMENT);
const bool saved_e_relative_mode = gcode.axis_relative_modes[E_AXIS];
gcode.axis_relative_modes[E_AXIS] = true;
enable_E0(); enable_E0();
current_position[E_AXIS] -= MMU2_FILAMENTCHANGE_EJECT_FEED; current_position[E_AXIS] -= MMU2_FILAMENTCHANGE_EJECT_FEED;
@ -735,8 +733,6 @@ void MMU2::filament_runout() {
BUZZ(200, 404); BUZZ(200, 404);
gcode.axis_relative_modes[E_AXIS] = saved_e_relative_mode;
disable_E0(); disable_E0();
return true; return true;
@ -784,9 +780,6 @@ void MMU2::filament_runout() {
planner.synchronize(); planner.synchronize();
enable_E0(); enable_E0();
const bool saved_e_relative_mode = gcode.axis_relative_modes[E_AXIS];
gcode.axis_relative_modes[E_AXIS] = true;
const E_Step* step = sequence; const E_Step* step = sequence;
for (uint8_t i = 0; i < steps; i++) { for (uint8_t i = 0; i < steps; i++) {
@ -804,8 +797,6 @@ void MMU2::filament_runout() {
step++; step++;
} }
gcode.axis_relative_modes[E_AXIS] = saved_e_relative_mode;
disable_E0(); disable_E0();
} }

View File

@ -49,7 +49,13 @@ GcodeSuite gcode;
millis_t GcodeSuite::previous_move_ms; millis_t GcodeSuite::previous_move_ms;
bool GcodeSuite::axis_relative_modes[] = AXIS_RELATIVE_MODES; static constexpr bool ar_init[XYZE] = AXIS_RELATIVE_MODES;
uint8_t GcodeSuite::axis_relative = (
(ar_init[X_AXIS] ? _BV(REL_X) : 0)
| (ar_init[Y_AXIS] ? _BV(REL_Y) : 0)
| (ar_init[Z_AXIS] ? _BV(REL_Z) : 0)
| (ar_init[E_AXIS] ? _BV(REL_E) : 0)
);
#if ENABLED(HOST_KEEPALIVE_FEATURE) #if ENABLED(HOST_KEEPALIVE_FEATURE)
GcodeSuite::MarlinBusyState GcodeSuite::busy_state = NOT_BUSY; GcodeSuite::MarlinBusyState GcodeSuite::busy_state = NOT_BUSY;
@ -110,9 +116,7 @@ void GcodeSuite::get_destination_from_command() {
LOOP_XYZE(i) { LOOP_XYZE(i) {
if ( (seen[i] = parser.seenval(axis_codes[i])) ) { if ( (seen[i] = parser.seenval(axis_codes[i])) ) {
const float v = parser.value_axis_units((AxisEnum)i); const float v = parser.value_axis_units((AxisEnum)i);
destination[i] = (axis_relative_modes[i] || relative_mode) destination[i] = axis_is_relative(AxisEnum(i)) ? current_position[i] + v : (i == E_AXIS) ? v : LOGICAL_TO_NATIVE(v, i);
? current_position[i] + v
: (i == E_AXIS) ? v : LOGICAL_TO_NATIVE(v, i);
} }
else else
destination[i] = current_position[i]; destination[i] = current_position[i];
@ -295,8 +299,8 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
case 80: G80(); break; // G80: Reset the current motion mode case 80: G80(); break; // G80: Reset the current motion mode
#endif #endif
case 90: relative_mode = false; break; // G90: Relative Mode case 90: set_relative_mode(false); break; // G90: Absolute Mode
case 91: relative_mode = true; break; // G91: Absolute Mode case 91: set_relative_mode(true); break; // G91: Relative Mode
case 92: G92(); break; // G92: Set current axis position(s) case 92: G92(); break; // G92: Set current axis position(s)

View File

@ -283,12 +283,31 @@
#include "../feature/I2CPositionEncoder.h" #include "../feature/I2CPositionEncoder.h"
#endif #endif
enum AxisRelative : uint8_t { REL_X, REL_Y, REL_Z, REL_E, E_MODE_ABS, E_MODE_REL };
class GcodeSuite { class GcodeSuite {
public: public:
GcodeSuite() {} static uint8_t axis_relative;
static bool axis_relative_modes[]; static inline bool axis_is_relative(const AxisEnum a) {
if (a == E_AXIS) {
if (TEST(axis_relative, E_MODE_REL)) return true;
if (TEST(axis_relative, E_MODE_ABS)) return false;
}
return TEST(axis_relative, a);
}
static inline void set_relative_mode(const bool rel) {
axis_relative = rel ? _BV(REL_X) | _BV(REL_Y) | _BV(REL_Z) | _BV(REL_E) : 0;
}
static inline void set_e_relative() {
CBI(axis_relative, E_MODE_ABS);
SBI(axis_relative, E_MODE_REL);
}
static inline void set_e_absolute() {
CBI(axis_relative, E_MODE_REL);
SBI(axis_relative, E_MODE_ABS);
}
#if ENABLED(CNC_WORKSPACE_PLANES) #if ENABLED(CNC_WORKSPACE_PLANES)
/** /**

View File

@ -25,9 +25,9 @@
/** /**
* M82: Set E codes absolute (default) * M82: Set E codes absolute (default)
*/ */
void GcodeSuite::M82() { axis_relative_modes[E_AXIS] = false; } void GcodeSuite::M82() { set_e_absolute(); }
/** /**
* M83: Set E codes relative while in Absolute Coordinates (G90) mode * M83: Set E codes relative while in Absolute Coordinates (G90) mode
*/ */
void GcodeSuite::M83() { axis_relative_modes[E_AXIS] = true; } void GcodeSuite::M83() { set_e_relative(); }