Fix incorrect XY scaling when axis_steps_per_mm is not 100.#5062
Open
fosterish wants to merge 1 commit intoprusa3d:masterfrom
Open
Fix incorrect XY scaling when axis_steps_per_mm is not 100.#5062fosterish wants to merge 1 commit intoprusa3d:masterfrom
axis_steps_per_mm is not 100.#5062fosterish wants to merge 1 commit intoprusa3d:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
Issuing
M92(for instance, to compensate for 1.5mm pitch belt pulleys on the CORE One) produces incorrect results. The nature of the error depends on where in the gcode the command is issued in relation to aG28command.Inverted scaling
If
M92is issued beforeG28, the resulting scale factor will be inverted (values lower than 100 produce a larger print, and values higher than 100 produce a smaller print).Cause
This happens because
G28callsMarlinSettings::reset_motion, which resets the planner'saxis_steps_per_mm(and notmm_per_stepet al.), which never gets restored during the call toMotion_Parameters::loadat the end of the command. So then we're using the default 100 steps per mm to generate step counts inPlanner::buffer_segment, but then consume them with a scaledmm_per_mstepinPlanner::_populate_block.Solution
I've unified
motion_parameters_tandplanner_settings_t. Maybe this causes issues elsewhere, but the two were so similar I didn't understand why they were separate. At the very least, this causesaxis_steps_per_mmto get saved and loaded with the rest of the motion parameters. I also callPlanner::refresh_positioninganytime we change that value.Ignored scaling
If
M92is issued afterG28, there is no effect on the scale of the print.Cause
A print move gets converted into motor movements through a convoluted chain of conversions: mm -> ministeps -> mm -> duration@speed -> rotation speed. The final step of this chain relies on
AxisMotorParams::mm_to_rev, which gets calculated only once, at startup, and not anytimeaxis_steps_per_mmchanges.Solution
I've created
phase_stepping::update_axis_motor_params, which I call from insidePlanner::refresh_positioning. It does the same thing as the initialization, but pulls its values from the planner and not the defaults.Note: I would never claim to be familiar with concurrent programming in C++, so someone who actually knows what they're doing should look at this. I noticed that
axis_motor_paramsis getting read thousands of times per second by the step ISR, so I figured we'd be dabbling in some light UB if we didn't at least disable interrupts before modifying it.Background
I have a Prusa CORE One, and have recently swapped the stock belts and pulleys for 1.5mm pitch belts and pulleys, as many people are experimenting with, to combat VFAs. Because the pitch diameter of the new pulleys is slightly smaller than that of the stock pulleys, one needs to configure the machine's steps per mm to compensate.
The common solution found in the forums and in videos is to issue
M92 X98.44 Y98.44at the start of your gcode, which does indeed have an enlarging effect on the print. However, this solution has problems:With this PR, I hope to get the ball rolling on a fix. I've tested it on my own CORE One, and it works very well. With this fix, one can correctly issue the appropriate
M92command, and get properly sized prints using 1.5mm pitch belts and pulleys without leaving your printer in a weird state:M92 X101.5873 Y101.5873I believe this solves #4619, #4675, and the first part of #4946, though I haven't tested it on any printer other than the CORE One.