Improved stepcompress implementation

I have done some experiments with step compression. This is a new attempt, inspired by Dmitry’s code here, my previous work on step compression, and the MARS algorithm. The code is at: GitHub - KevinOConnor/klipper-dev at work-stepcompress-20220831

This new code reduces the “micro velocity bursts” between queue_step commands with only host code changes. The mcu code and message protocol is unchanged; it is not necessary to reflash the mcu.

The code internally ties upcoming queue_step “interval” parameters to past step intervals - thus effectively forcing velocity to remain continuous between each move segment. The code implements the same absolute step scheduling constraints as the current code. It uses “least squares” to find add1,count1 sequences such that the following add2,count2 sequence has the maximal step “total count”.

This branch is probably only of interest to developers or those experimenting with the low-level kinematics. I’ve run a bunch of unit tests, but have only lightly tested it on real hardware.

I wanted to share some of my results - maybe it will inspire other ideas or implementations.

-Kevin

I ran a test on my Voron Zero using the various step compression algorithms. Below are some snippets from the test.

Original Klipper algorithm:

Code from my work-stepcompress-20220831 branch (e31be989):

Code from Dmitry’s stepcompress branch (83f7bd50):

Some high-level thoughts:

  • My work-stepcompress-20220831 branch does have smoother velocity compared to the baseline code. It is not as smooth as Dmitry’s code.
  • None of the branches seem to improve the jitter picked up by the accelerometer and angle sensors on this machine. It seems that my Voron Zero has an increase in mechanical jitter when moving around 60-80mm/s that is not related to step compression.

Cheers,
-Kevin

1 Like

This is interesting, I’ll take a look at your code, Kevin. Just for my curiosity, with which microstepping did you perform your test on Voron Zero?

I used settings like the following for both x and y (this is a corexy printer):

[stepper_x]
step_pin: PB3
dir_pin: PB4
enable_pin: !PD2
microsteps: 128
rotation_distance: 40
endstop_pin: PC0
position_endstop: 120
position_max: 120
homing_speed: 20   #Max 100

[tmc2209 stepper_x]
uart_pin: PC11
tx_pin: PC10
uart_address: 3
run_current: 0.800
interpolate: False
driver_TOFF: 4
driver_TBL: 0
driver_HSTRT: 0
driver_HEND: 0
stealthchop_threshold: 999999

The test is with diagonal moves. (The graph shows the accelerometer of the “x” direction, even though the move is diagonal.)

-Kevin

A post was split to a new topic: Error in stepcompress