I was thinking of some sort of ‘output shaper’ to compensate for stepper motion irregularities lately. So I tried to collect some data to see how exactly the stepper motor motion behaves. Alas, I don’t have an angle sensor, so I worked purely with the accelerometer data. And I think I got some interesting data points.
I ran this simple test in spreadcycle mode (starting from X==0)
G4 P500
G0 X200 F4800
G4 P500
G0 X0 F4800
G4 P500
basically moving from X==0 to X==200 with a velocity of 80 mm/sec and then back. I used data_logger.py
to capture the statistics during this test.
In order to process the data, I’ve made a simple analyzer for motan
scripts to map adxl345 readings to tmc stepper phases (averaging the readings for the same phase). Since the scripts plots the data only by time, I just made the script repeat the values for the same phases at different times. I generated two charts with
scripts/motan/motan_graph.py -s 3.25 -d 2.4 test_x -g '[["trapq(toolhead,x_velocity)"], ["step_phase(tmc5160 stepper_x)"], ["average_by(adxl345(hotend,x),step_phase(tmc5160 stepper_x))"]]'
scripts/motan/motan_graph.py -s 6.3 -d 2.4 test_x -g '[["trapq(toolhead,x_velocity)"], ["step_phase(tmc5160 stepper_x)"], ["average_by(adxl345(hotend,x),step_phase(tmc5160 stepper_x))"]]'
Here are the charts (I enlarged two full phase periods) for forward move (top) and backward move (bottom). Note that I run the printer at 256 full microstepping without interpolation (hence the phase is in the range from 0 to 1023).
Here I noticed a few things. First, the data is non-periodic at full steps (256 microsteps) and at double-steps (512 steps), even though with double-step period, it is almost periodic with some small deviations. Though these deviations are repeatable across many different runs, so I think this is not an error of the measurements.
Second, backward and forward pass look almost identical modulo negation when acceleration is plotted with time as X axis (in the backward pass, the toolhead moves in the opposite direction, so acceleration naturally is inverted). However, I would normally expect the acceleration to demonstrate that symmetry when plotted with a stepper phase as X axis. Basically, I’d normally expect the “disturbing force” of a stepper to be the same at a certain stepper position, and that force to accelerate the toolhead when it moves in one direction, and decelerate it - when it moves in the opposite direction. Here we observe a different effect - as if poles of the stepper motor repel or attract the rotor regardless of which direction it moves.
If the latter effect is true, it means that a simple model to compensate for stepper motion inconsistencies like
X'(t) = S(X(t))
with S
function accounting for stepper motion non-linearities won’t work, because the effect is direction-dependent. One would need to use something like X'(t) = S(X(t), dX(t)/dt)
, which becomes quite more complicated to implement and tune.
Another thing is that the results depend on the velocity. That is, at different velocities I get quite different acceleration profiles (but also repeatable within the same velocity). The most plausible explanation to this effect is that, depending on the speed, you may hit different resonances of the frame, which may amplify the vibrations (up to a few times) at different frequencies, changing the acceleration profile substantially.
The raw data from my test is attached:
test_x.zip (429.7 KB)
One can also repeat a similar test on their printer using mainline Klipper, and use the linked analyzer to process the results.