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
6 changed files with 39 additions and 27 deletions

View File

@ -49,7 +49,13 @@ GcodeSuite gcode;
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)
GcodeSuite::MarlinBusyState GcodeSuite::busy_state = NOT_BUSY;
@ -110,9 +116,7 @@ void GcodeSuite::get_destination_from_command() {
LOOP_XYZE(i) {
if ( (seen[i] = parser.seenval(axis_codes[i])) ) {
const float v = parser.value_axis_units((AxisEnum)i);
destination[i] = (axis_relative_modes[i] || relative_mode)
? current_position[i] + v
: (i == E_AXIS) ? v : LOGICAL_TO_NATIVE(v, i);
destination[i] = axis_is_relative(AxisEnum(i)) ? current_position[i] + v : (i == E_AXIS) ? v : LOGICAL_TO_NATIVE(v, i);
}
else
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
#endif
case 90: relative_mode = false; break; // G90: Relative Mode
case 91: relative_mode = true; break; // G91: Absolute Mode
case 90: set_relative_mode(false); break; // G90: Absolute Mode
case 91: set_relative_mode(true); break; // G91: Relative Mode
case 92: G92(); break; // G92: Set current axis position(s)

View File

@ -283,12 +283,31 @@
#include "../feature/I2CPositionEncoder.h"
#endif
enum AxisRelative : uint8_t { REL_X, REL_Y, REL_Z, REL_E, E_MODE_ABS, E_MODE_REL };
class GcodeSuite {
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)
/**

View File

@ -25,9 +25,9 @@
/**
* 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
*/
void GcodeSuite::M83() { axis_relative_modes[E_AXIS] = true; }
void GcodeSuite::M83() { set_e_relative(); }