Account for coordinate space offsets #4402
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
A fundamental flaw has been found in the management of coordinates in various functions.
Background: Marlin has long had a
home_offset
array that changes the home position. It used to apply on the nextG28
but it was updated to take effect immediately onM206
. Thehome_offset
was later applied to the software endstops. More recently theposition_shift
array was added, which remembers any redefinition of thecurrent_position
(such as withG92
) and also applies it to the software endstops.The Basic Problem: When you specify coordinates for Marlin now, the current coordinate space must be taken into account. So, for example, when saving points for Mesh Bed Leveling, we need to subtract these offsets so that if we shift the coordinate space, we can still get the right mesh points.
The Planner Problem: When we send coordinates to the planner and stepper code regions, for cartesian machines we have always set them to the current "logical position" — the position that includes the coordinate space offsets. This is fine. The planner and stepper functions can return coordinates to us in the current coordinate space with no extra figuring required. However, on DELTA the planner and stepper positions are translated, so they must always use the "raw position" for their figuring. So we have to take care here.
The Bed Leveling Problem: As mentioned, Mesh Bed Leveling always stores the "raw position" so its mesh can still apply as the coordinate space shifts. The grid-based mesh used by DELTA and the planar grid leveling used by Automatic Bed Leveling are still stuck in a non-moving coordinate space, so after
G92
orM206
the leveling compensation is likely wrong. Furthermore, the arguments toG29
presume a non-moving coordinate space, and will produce bad results in a shifted coordinate space.The Solution: Basically, everywhere that coordinates are specified, we need to audit and ensure that the most appropriate coordinates are being stored. When performing bed leveling, it would be best to store the "raw position" values instead of the shifted coordinates. And when doing bed probing, it would be best to treat input coordinates as being in the current coordinate-space, and to make sure to include the coordinate-space offsets for the probe points.
This PR includes only some of that work so far, but will continue to accumulate commits patching these overlooked aspects of the system.