- How did you validate that the magnetic encoders are properly calibrated? If the encoders have jitter (due to magnet offset, due to precision limitations, or due to timing inaccuracies) it could skew the microstep results. I doubt this would be an issue (as angle sensor calibration is typically done at the full-step level). I am curious on the methodology you used though.
I did not alter the current logic of Klipper, only added something aside.
My answer is completely about my approach to playing with MSLUT, based on which I do believe it is mostly positionally accurate.
Physical stuff
I feared that I would face all possible issues with jitter, non-linearity, and poor resolution.
So, I did some stuff like picking the right-sized magnet, checking magnet fields visually with a magnetic field viewer, and making the right motor mount with a slot for viewing the distance and centering of the magnet/encoder, everything according to the datasheet and after run internal chip calibration to an account of non-linearity.
That was controlled by ANGLE_CALIBRATE
, so I have something like this:
// angle: stddev=15.322 (0.718 forward / 0.734 reverse) in 399936 queries
360 * 15 / (1 << 16) ~= 0.0823
360 / 200 / 16 = 0.1125
Here, I just assumed this is motor behavior and not sensor because of friction, inertia, and inequality.
I saw them when calibrating the motor with a laser (I already knew they existed).
Software stuff
I have control of the hysteresis register, so I played with it to get the idea of positional jitter.
It seems like even with minimal hysteresis (0.003 degrees) it just does not produce different results.
Moving tests, tricky cause of friction and inequality
Look how beautiful it is in the middle of the full step:
And how ugly it can be around zero:
But I assumed it will exist:
- I just collect N samples and use the average in tuning code.
- I do sweeping moves to overcome friction, like +2, -2, +1 (micro steps)
- I only measure everything in relation to the start of full steps
Maybe I’m lucky here.
Also, I have too much logging, so I’m able to see what happens during calibration and how repeatability/position accuracy looks at each run over the same 4 full steps.
BTW, I use raw samples without compensation, to detect chip resolution and allow misalignment of steps up to ± (360 / (encoder resolution).
Time jitter - it does not matter, because I measure the motor in static
like it is done in ANGLE_CALIBRATE
.
Cause I already have data on the accelerometer, micro-step level, full step level. I think I can mostly or less look at motan graphs and assume that forms of deviation are related to what I see beneath.
But I should notice, that this is one motor, one encoder, and one me, like we do not really know how it looks in different circumstances.
- Have you observed any patterns when going in a positive stepper direction vs a negative stepper direction?
Mostly no, from laser tests moving looks symmetrically bad
.
I did not test this specifically with the encoder.
I only observe that sometimes micro step data in relation to full steps looks reversed.
Like in a perfect world with perfect motors and electronics full steps are equal and microstep inequality is the same for all of them. But the actual situation looks more random, like the micro-step distance pattern can be in order for the first 2 steps and reversed for the other two, or even/odd. Sometimes sin prevails over cos, and sometimes vice versa.
My hypothesis here, aside from the physical inequality of coils and motor is sin/cos phase shift can account for that. I will only be able to validate it when I get my hands on TMC2240.
I mostly think from a practical perspective of what tools we have to work with, so there are 2 outcomes after phase shift compensation it will be better or not, even if not - fine.
From a high level of view they seem symmetrical (mirrored) fullsteps and microsteps in relation to the stepper phase (default mslut, 32 steps, interpolation enabled, pulley/belt is connected):
Graphs
G91
SET_VELOCITY_LIMIT ACCEL=2000
G0 Y50 F600
G0 Y-50 F600
Full steps look similar, microsteps at first full step have a higher jitter, and later on, they seem better.
- Have you considered altering the Klipper iterative solver to account for these step deviations (instead of altering the tmc driver configuration)? That is, change the motion planning so that each step is not a constant distance, in an effort to alter the stepper timing, in an effort to account for stepper microstep cogging. I suspect the Klipper step compression code may struggle to handle high speeds if step distance is not constant, but the test results may be enlightening (even if it is only possible to test at slow/mid speeds).
I think about it, often, cause it “should work”.
But I’m too stupid to do that right now (meh, this sounds silly).
It should be possible to pass phase data to cffi, keep it in sync, and modify stepcompress
data after itersolve, before actual compress.
Like on the paper, we have the motor phase already and can calculate it in real-time, we have an accelerometer to validate, and we have a “possible known pattern” where we want to slow down part of the phase and accelerate another part.
Eventually, I may try to make it work, but it looks complicated.