MarlinFirmware / Marlin

Marlin is an optimized firmware for RepRap 3D printers based on the Arduino platform. Many commercial 3D printers come with Marlin installed. Check with your vendor if you need source code for your specific machine.
https://marlinfw.org
GNU General Public License v3.0
15.94k stars 19.08k forks source link

Move cruise LASER_POWER_TRAP code to cruise block. #27031

Closed mh-dm closed 1 day ago

mh-dm commented 2 weeks ago

Move cruise LASER_POWER_TRAP code into stepper cruise block. Small cleanup that fixes some potential issues:

Only affects code using LASER_POWER_TRAP.

Lightly tested by hooking up a logic analyzer to the laser pwm pin. The ramp up/cruise/down look ok and quite similar as to before this change. Here's just an example of what I've looked at (snapshot of acceleration->cruise at 80% power): laser-before

This change comes as a result of discussions on #27013

tombrazier commented 1 week ago

I think the problems with MULTISTEPPING_LIMIT and laser also extend to the accel and decel ramp LASER_POWER_TRAP code blocks. In those blocks the laser power is increased by current_block->laser.trap_ramp_entry_incr or decreased by current_block->laser.trap_ramp_exit_decr for every call to block_phase_isr(). These values should be multiplied by steps_per_isr.

Another problem is that the laser power ramps are linear with respect to step count whereas the speed is proportional to the square root of the step count. This is because speed is increasing linearly with time but the earlier steps in the acceleration ramp take longer than the later steps and mutatis mutandis for deceleration.

descipher commented 1 week ago

Did a review pass on this one, I think it is Ok, Instead of having the laser trap calc'd based on it's own step tracking for nominal you are moving it to the assumed cruise (nominal) rate if else position. I do not see any negative impacts and there is one less compare to do. This is of course with the multi step adjustment :) +1 Tom!

mh-dm commented 1 week ago

I think the problems with MULTISTEPPING_LIMIT and laser also extend to the accel and decel ramp LASER_POWER_TRAP code blocks. In those blocks the laser power is increased by current_block->laser.trap_ramp_entry_incr or decreased by current_block->laser.trap_ramp_exit_decr for every call to block_phase_isr(). These values should be multiplied by steps_per_isr.

Pre-existing problem but a very good catch. I've forced an always on 4x multistepping with some local chages and got this capture: laser_multi_broken

I've implemented the suggested * steps_per_isr and there's no more sudden jump in laser power: laser_multi_after

Another problem is that the laser power ramps are linear with respect to step count whereas the speed is proportional to the square root of the step count. This is because speed is increasing linearly with time but the earlier steps in the acceleration ramp take longer than the later steps and mutatis mutandis for deceleration.

Good point. However, it's a more complex pre-existing issue so I'm not going to attempt a fix in this PR.

tombrazier commented 1 week ago

Good point. However, it's a more complex pre-existing issue so I'm not going to attempt a fix in this PR.

I support that. For reference, I think a solution that adds a multiple of interval would work. But to do it properly would need good testing by someone with a laser cutter. In the meantime, it would be good to get the PR merged.

sjasonsmith commented 1 week ago

@mh-dm / @tombrazier does this change stand on its own, or does it need to be consumed at the same time as the other planner changes in flight?

tombrazier commented 1 week ago

It stands on its own.

tombrazier commented 1 week ago

However it will conflict with the much discussed variable rename. But that's easy to resolve as this PR simply removes the one reference to accelerate_until.

mh-dm commented 2 days ago

If there are no more concerns, can this be merged to unblock #27013?

mh-dm commented 2 days ago

I mistakenly thought at least someone in this thread had bugfix merge privileges so looks like I need to call on @thinkyhead.