Skip to content

Commit

Permalink
🚸 Revert M206 Home Offset behavior (#25996)
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead authored Jul 21, 2023
1 parent a0e3dea commit 9135e3f
Show file tree
Hide file tree
Showing 21 changed files with 70 additions and 130 deletions.
13 changes: 8 additions & 5 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -3835,14 +3835,17 @@
//#define REPETIER_GCODE_M360 // Add commands originally from Repetier FW

/**
* Enable this option for a leaner build of Marlin that removes all
* workspace offsets, simplifying coordinate transformations, leveling, etc.
*
* - M206 and M428 are disabled.
* - G92 will revert to its behavior from Marlin 1.0.
* Enable this option for a leaner build of Marlin that removes
* workspace offsets to slightly optimize performance.
* G92 will revert to its behavior from Marlin 1.0.
*/
//#define NO_WORKSPACE_OFFSETS

/**
* Disable M206 and M428 if you don't need home offsets.
*/
//#define NO_HOME_OFFSETS

/**
* CNC G-code options
* Support CNC-style G-code dialects used by laser cutters, drawing machine cams, etc.
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/MarlinCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1337,7 +1337,7 @@ void setup() {
SETUP_RUN(touchBt.init());
#endif

TERN_(HAS_M206_COMMAND, current_position += home_offset); // Init current position based on home_offset
TERN_(HAS_HOME_OFFSET, current_position += home_offset); // Init current position based on home_offset

sync_plan_position(); // Vital to init stepper/planner equivalent for current_position

Expand Down
13 changes: 5 additions & 8 deletions Marlin/src/feature/powerloss.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=POW

TERN_(GCODE_REPEAT_MARKERS, info.stored_repeat = repeat);
TERN_(HAS_HOME_OFFSET, info.home_offset = home_offset);
TERN_(HAS_POSITION_SHIFT, info.position_shift = position_shift);
TERN_(HAS_WORKSPACE_OFFSET, info.workspace_offset = workspace_offset);
E_TERN_(info.active_extruder = active_extruder);

#if DISABLED(NO_VOLUMETRICS)
Expand Down Expand Up @@ -552,10 +552,7 @@ void PrintJobRecovery::resume() {

TERN_(GCODE_REPEAT_MARKERS, repeat = info.stored_repeat);
TERN_(HAS_HOME_OFFSET, home_offset = info.home_offset);
TERN_(HAS_POSITION_SHIFT, position_shift = info.position_shift);
#if HAS_HOME_OFFSET || HAS_POSITION_SHIFT
LOOP_NUM_AXES(i) update_workspace_offset((AxisEnum)i);
#endif
TERN_(HAS_WORKSPACE_OFFSET, workspace_offset = info.workspace_offset);

// Relative axis modes
gcode.axis_relative = info.axis_relative;
Expand Down Expand Up @@ -600,11 +597,11 @@ void PrintJobRecovery::resume() {
DEBUG_EOL();
#endif

#if HAS_POSITION_SHIFT
DEBUG_ECHOPGM("position_shift: ");
#if HAS_WORKSPACE_OFFSET
DEBUG_ECHOPGM("workspace_offset: ");
LOOP_NUM_AXES(i) {
if (i) DEBUG_CHAR(',');
DEBUG_ECHO(info.position_shift[i]);
DEBUG_ECHO(info.workspace_offset[i]);
}
DEBUG_EOL();
#endif
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/feature/powerloss.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ typedef struct {
#if HAS_HOME_OFFSET
xyz_pos_t home_offset;
#endif
#if HAS_POSITION_SHIFT
xyz_pos_t position_shift;
#if HAS_WORKSPACE_OFFSET
xyz_pos_t workspace_offset;
#endif
#if HAS_MULTI_EXTRUDER
uint8_t active_extruder;
Expand Down
9 changes: 1 addition & 8 deletions Marlin/src/gcode/calibrate/G28.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,7 @@
* (Z is already at the right height)
*/
constexpr xy_float_t safe_homing_xy = { Z_SAFE_HOMING_X_POINT, Z_SAFE_HOMING_Y_POINT };
#if HAS_HOME_OFFSET && DISABLED(Z_SAFE_HOMING_POINT_ABSOLUTE)
xy_float_t okay_homing_xy = safe_homing_xy;
okay_homing_xy -= home_offset;
#else
constexpr xy_float_t okay_homing_xy = safe_homing_xy;
#endif

destination.set(okay_homing_xy, current_position.z);
destination.set(safe_homing_xy, current_position.z);

TERN_(HOMING_Z_WITH_PROBE, destination -= probe.offset_xy);

Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/gcode/gcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
case 204: M204(); break; // M204: Set acceleration
case 205: M205(); break; // M205: Set advanced settings

#if HAS_M206_COMMAND
#if HAS_HOME_OFFSET
case 206: M206(); break; // M206: Set home offsets
#endif

Expand Down Expand Up @@ -881,7 +881,7 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
case 425: M425(); break; // M425: Tune backlash compensation
#endif

#if HAS_M206_COMMAND
#if HAS_HOME_OFFSET
case 428: M428(); break; // M428: Apply current_position to home_offset
#endif

Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/gcode/gcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ class GcodeSuite {
static void M205();
static void M205_report(const bool forReplay=true);

#if HAS_M206_COMMAND
#if HAS_HOME_OFFSET
static void M206();
static void M206_report(const bool forReplay=true);
#endif
Expand Down Expand Up @@ -1043,7 +1043,7 @@ class GcodeSuite {
static void M425_report(const bool forReplay=true);
#endif

#if HAS_M206_COMMAND
#if HAS_HOME_OFFSET
static void M428();
#endif

Expand Down
7 changes: 1 addition & 6 deletions Marlin/src/gcode/geometry/G53-G59.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,7 @@ bool GcodeSuite::select_coordinate_system(const int8_t _new) {
xyz_float_t new_offset{0};
if (WITHIN(_new, 0, MAX_COORDINATE_SYSTEMS - 1))
new_offset = coordinate_system[_new];
LOOP_NUM_AXES(i) {
if (position_shift[i] != new_offset[i]) {
position_shift[i] = new_offset[i];
update_workspace_offset((AxisEnum)i);
}
}
workspace_offset = new_offset;
return true;
}

Expand Down
12 changes: 4 additions & 8 deletions Marlin/src/gcode/geometry/G92.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@ void GcodeSuite::G92() {

#if ENABLED(CNC_COORDINATE_SYSTEMS) && !IS_SCARA
case 1: // G92.1 - Zero the Workspace Offset
LOOP_NUM_AXES(i) if (position_shift[i]) {
position_shift[i] = 0;
update_workspace_offset((AxisEnum)i);
}
workspace_offset.reset();
break;
#endif

Expand All @@ -92,10 +89,9 @@ void GcodeSuite::G92() {
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?
if (!NEAR_ZERO(d)) {
#if HAS_POSITION_SHIFT && NONE(IS_SCARA, POLARGRAPH) // When using workspaces...
#if HAS_WORKSPACE_OFFSET && NONE(IS_SCARA, POLARGRAPH) // When using workspaces...
if (TERN1(HAS_EXTRUDERS, i != E_AXIS)) {
position_shift[i] += d; // ...most axes offset the workspace...
update_workspace_offset((AxisEnum)i);
workspace_offset[i] += d; // ...most axes offset the workspace...
}
else {
#if HAS_EXTRUDERS
Expand All @@ -120,7 +116,7 @@ void GcodeSuite::G92() {
#if ENABLED(CNC_COORDINATE_SYSTEMS)
// Apply Workspace Offset to the active coordinate system
if (WITHIN(active_coordinate_system, 0, MAX_COORDINATE_SYSTEMS - 1))
coordinate_system[active_coordinate_system] = position_shift;
coordinate_system[active_coordinate_system] = workspace_offset;
#endif

if (sync_XYZE) sync_plan_position();
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/gcode/geometry/M206_M428.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include "../../inc/MarlinConfig.h"

#if HAS_M206_COMMAND
#if HAS_HOME_OFFSET

#include "../gcode.h"
#include "../../module/motion.h"
Expand Down Expand Up @@ -101,4 +101,4 @@ void GcodeSuite::M428() {
OKAY_BUZZ();
}

#endif // HAS_M206_COMMAND
#endif // HAS_HOME_OFFSET
4 changes: 2 additions & 2 deletions Marlin/src/gcode/probe/M951.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void mpe_settings_init() {
mpe_settings.parking_xpos[0] = pex[0]; // M951 L
mpe_settings.parking_xpos[1] = pex[1]; // M951 R
mpe_settings.grab_distance = PARKING_EXTRUDER_GRAB_DISTANCE; // M951 I
TERN_(HAS_HOME_OFFSET, set_home_offset(X_AXIS, mpe_settings.grab_distance * -1));
TERN_(HAS_HOME_OFFSET, set_home_offset(X_AXIS, -mpe_settings.grab_distance));
mpe_settings.slow_feedrate = MMM_TO_MMS(MPE_SLOW_SPEED); // M951 J
mpe_settings.fast_feedrate = MMM_TO_MMS(MPE_FAST_SPEED); // M951 H
mpe_settings.travel_distance = MPE_TRAVEL_DISTANCE; // M951 D
Expand All @@ -59,7 +59,7 @@ void GcodeSuite::M951() {
if (parser.seenval('R')) mpe_settings.parking_xpos[1] = parser.value_linear_units();
if (parser.seenval('I')) {
mpe_settings.grab_distance = parser.value_linear_units();
TERN_(HAS_HOME_OFFSET, set_home_offset(X_AXIS, mpe_settings.grab_distance * -1));
TERN_(HAS_HOME_OFFSET, set_home_offset(X_AXIS, -mpe_settings.grab_distance));
}
if (parser.seenval('J')) mpe_settings.slow_feedrate = MMM_TO_MMS(parser.value_linear_units());
if (parser.seenval('H')) mpe_settings.fast_feedrate = MMM_TO_MMS(parser.value_linear_units());
Expand Down
1 change: 1 addition & 0 deletions Marlin/src/inc/Conditionals_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
#if !HAS_X_AXIS
//#define LCD_SHOW_E_TOTAL
#define NO_WORKSPACE_OFFSETS
#define NO_HOME_OFFSETS
#undef AUTOTEMP
#undef CALIBRATION_MEASURE_LEFT
#undef CALIBRATION_MEASURE_RIGHT
Expand Down
12 changes: 6 additions & 6 deletions Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -3140,15 +3140,15 @@
#undef MOTOR_CURRENT
#endif

// Updated G92 behavior shifts the workspace
// G92 shifts the workspace
#if DISABLED(NO_WORKSPACE_OFFSETS)
#define HAS_POSITION_SHIFT 1
#define HAS_WORKSPACE_OFFSET 1
#endif
#if DISABLED(NO_HOME_OFFSETS)
#if IS_CARTESIAN
#define HAS_HOME_OFFSET 1 // The home offset also shifts the coordinate space
#define HAS_WORKSPACE_OFFSET 1 // Cumulative offset to workspace to save some calculation
#define HAS_M206_COMMAND 1 // M206 sets the home offset for Cartesian machines
#define HAS_HOME_OFFSET 1 // M206 affects the Native Machine Space on G28
#elif IS_SCARA
#define HAS_SCARA_OFFSET 1 // The SCARA home offset applies only on G28
#define HAS_SCARA_OFFSET 1 // The SCARA home offset applies only on G28
#endif
#endif

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/menu/menu_advanced.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ void menu_advanced_settings() {
}
#endif

#if HAS_M206_COMMAND
#if HAS_HOME_OFFSET
// M428 - Set Home Offsets
ACTION_ITEM(MSG_SET_HOME_OFFSETS, []{ queue.inject(F("M428")); ui.return_to_status(); });
#endif
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/module/delta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void recalc_delta_settings() {
*
* Suggested optimizations include:
*
* - Disable the home_offset (M206) and/or position_shift (G92)
* - Disable the home_offset (M206) and/or workspace_offset (G92)
* features to remove up to 12 float additions.
*/

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/module/delta.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void recalc_delta_settings();
*
* Suggested optimizations include:
*
* - Disable the home_offset (M206) and/or position_shift (G92)
* - Disable the home_offset (M206) and/or workspace_offset (G92)
* features to remove up to 12 float additions.
*
* - Use a fast-inverse-sqrt function and add the reciprocal.
Expand Down
28 changes: 6 additions & 22 deletions Marlin/src/module/motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,12 @@ xyz_pos_t cartes;
* The workspace can be offset by some commands, or
* these offsets may be omitted to save on computation.
*/
#if HAS_POSITION_SHIFT
// The distance that XYZ has been offset by G92. Reset by G28.
xyz_pos_t position_shift{0};
#endif
#if HAS_HOME_OFFSET
// This offset is added to the configured home position.
// Set by M206, M428, or menu item. Saved to EEPROM.
xyz_pos_t home_offset{0};
#endif
#if HAS_HOME_OFFSET && HAS_POSITION_SHIFT
#if HAS_WORKSPACE_OFFSET
// The above two are combined to save on computes
xyz_pos_t workspace_offset{0};
#endif
Expand Down Expand Up @@ -2468,7 +2464,7 @@ void set_axis_is_at_home(const AxisEnum axis) {

#if ENABLED(DUAL_X_CARRIAGE)
if (axis == X_AXIS && (active_extruder == 1 || dual_x_carriage_mode == DXC_DUPLICATION_MODE)) {
current_position.x = x_home_pos(active_extruder);
current_position.x = SUM_TERN(HAS_HOME_OFFSET, x_home_pos(active_extruder), home_offset.x);
return;
}
#endif
Expand All @@ -2478,7 +2474,7 @@ void set_axis_is_at_home(const AxisEnum axis) {
#elif ENABLED(DELTA)
current_position[axis] = (axis == Z_AXIS) ? DIFF_TERN(HAS_BED_PROBE, delta_height, probe.offset.z) : base_home_pos(axis);
#else
current_position[axis] = base_home_pos(axis);
current_position[axis] = SUM_TERN(HAS_HOME_OFFSET, base_home_pos(axis), home_offset[axis]);
#endif

/**
Expand All @@ -2499,10 +2495,7 @@ void set_axis_is_at_home(const AxisEnum axis) {

TERN_(BABYSTEP_DISPLAY_TOTAL, babystep.reset_total(axis));

#if HAS_POSITION_SHIFT
position_shift[axis] = 0;
update_workspace_offset(axis);
#endif
TERN_(HAS_WORKSPACE_OFFSET, workspace_offset[axis] = 0);

if (DEBUGGING(LEVELING)) {
#if HAS_HOME_OFFSET
Expand All @@ -2513,20 +2506,11 @@ void set_axis_is_at_home(const AxisEnum axis) {
}
}

#if HAS_WORKSPACE_OFFSET
void update_workspace_offset(const AxisEnum axis) {
workspace_offset[axis] = home_offset[axis] + position_shift[axis];
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Axis ", AS_CHAR(AXIS_CHAR(axis)), " home_offset = ", home_offset[axis], " position_shift = ", position_shift[axis]);
}
#endif

#if HAS_M206_COMMAND
#if HAS_HOME_OFFSET
/**
* Change the home offset for an axis.
* Also refreshes the workspace offset.
* Set the home offset for an axis.
*/
void set_home_offset(const AxisEnum axis, const_float_t v) {
home_offset[axis] = v;
update_workspace_offset(axis);
}
#endif
Loading

1 comment on commit 9135e3f

@ThomasToka
Copy link
Contributor

@ThomasToka ThomasToka commented on 9135e3f Jul 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i found a little issue. maybe you can track this:

i set in configuration.h

  // Travel limits (mm) after homing, corresponding to endstop positions.
  #define X_MIN_POS -2
  #define Y_MIN_POS -2

when i boot up the machine i get:

Send: M206
Recv:   M206 X0.00 Y0.00 Z0.00

so x_min_pos and y_min_pos are not shown in M206 output. resetting M502 does not help. always 0.

when i then sent a offset:

Send: M206 X-2 Y-2
Recv: X:-2.00 Y:-2.00 Z:0.00 E:0.00 Count X:-159 Y:-159 Z:0

it is taken:

Send: M206
Recv:   M206 X-2.00 Y-2.00 Z0.00

but when i then home with G28 X Y

i get

Send: M114
Recv: X:-4.00 Y:-4.00 Z:6.90 E:0.00 Count X:-318 Y:-318 Z:2760

while M206 shows the correct value:

Send: M206
Recv:   M206 X-2.00 Y-2.00 Z0.00

summary:

  • default from config not taken into m206 startup value
  • set values add up to position in m114

Please sign in to comment.