evil-mad / EggBot

Software for The Original EggBot
GNU General Public License v3.0
288 stars 140 forks source link

Modify LT command to allow <rate> values to go through zero (i.e. change sign) #185

Closed EmbeddedMan closed 1 year ago

EmbeddedMan commented 2 years ago

As of v2.8.1 of the EBB firmware, the LT command is not happy (and will produce undefined behavior) if the parameters are picked such that the value (i.e. the time between steps) changes sign during a single move. The desired behavior is for the motor to smoothly change direction at this point in the move.

EmbeddedMan commented 1 year ago

The result of the work for this issue is a release v2.9.0 of EBB Firmware.

During the implementation of the changes to allow LT and LM to decelerate through zero speed and reverse direction, a concern was raised about the additional instructions being added and if those added instructions would slow the entire EBB firmware down.

In the process of trying to answer that question, several different attempts were made at different implementations of the changes. It quickly became a larger task - one of optimizing the motion ISR in the EBB firmware for speed. During that process, other changes were made to enhance code readability (now that the ISR was optimized for speed, readability suffered so many comments were added).

In the end, a simple set of motion commands were used on all 19 optimization steps along the way, profiling the performance of the ISR using a logic analyzer in a way that could measure the differences of each code change. A further discussion of this profiling process is explained below.

The end result was v2.9.0 of the EBB firmware which is faster in almost every way than previous releases even with the addition of the changes required to implement the LM/LT zero speed switch. This ISR refactor also sets up the codebase to handle several future changes which will require additional math and checks to happen in the ISR. The performance benchmarking system can also be used to measure the impact of those future additions to the ISR.

EmbeddedMan commented 1 year ago

The initial goal of this issue was to add code to the firmware so that if an LT command contained parameters such that the speed in an axis was decelerating (i.e. a negative Accel1 or Accel2 value), and the move continued past the point where the effective Rate1 or Rate2 went negative, then the behavior would invert the direction of that axis at the point where the rate went negative and the sign of the acceleration would be made positive at that point. The end result is a smooth deceleration of an axis to the point where the motor stops, and then it begins accelerating in the other direction (a the same acceleration rate that it was decelerating before). This of course happens independently on each axis.

As it turns out, the exact same changes necessary to make this happen for the LT command work for the LM command as well, so that was updated as well.

EmbeddedMan commented 1 year ago

Pull Request #200 has resolved this feature request. Documentation on the new math, the new commands, etc. will be included in the next major release of the EBB Firmware.