Skip to content
coldelectrons edited this page Nov 14, 2023 · 3 revisions

Welcome to the klipper laser-ppi fork wiki.

Others have or are attempting to make PWM tools usable with Klipper in a CNC or laser machine.

However, there is a mode of laser and tools usage that Klipper already almost supports: PPI mode.

How it works

My fork currently abuses the code for steppers to do PPI modes.

Simply put, for a given move:

laser_pulses = ( move_distance / unit_scale ) * ( max_pulses_per_unit * power_level )

Unit scale defaults to 25.4mm. power_level is the current gcode S parameter value.

Like extruder moves, laser moves may require slowing the XYZ motion.

laser_min_move_t = laser_pulses * (step_pulse_duration + step_pulse_min_off_duration)

If that minimum time is greater than the move.min_move_t, then we calculate a new velocity and call move.limit_speed()

Incorporated changes

  • Adds an S parameter to Gcode, for laser power
  • Differentiates between G0 and G1, for non-firing and firing moves, respectively
    • I also added a change to extras/gcode_arcs.py so it would not bypass the chain of handlers so I can laser cute little circles if I want
  • Added a kinematics/laser_ppi.py, which adds a kinematic PPI-mode tool
  • Added that tool to toolhead.py
  • Added some basic variables into toolhead.Move for a laser
  • Added a console command and a firmware method to change the step_pulse_ticks of a stepper during run-time.
  • Added a basic config/example-laser.cfg

Pros

  • It works with minimal changes to the existing code.
  • Output is proportionally ramped to movement, no extra burning at the end of moves.

Cons

  • Many, many ways to throw an error, because I am abusing the stepper code.
    • Having too high a PPI
    • Not enough time between pulses
    • Having pulses too long
    • Kinematics slow down XYZ motion too much
  • The normal extras/gcode-arcs.py G2/G3 doesn't follow the same interpreter path as G1, in spite of generating G1 moves. Without my current hack, arcs would not cut.
  • The laser pseudo-axis always moves up. This might result in a bug after a few hours, when the 32-bit mcu stepper position overflows.

TODO

  • figure out the issue of minimum time between pulses, how to calculate it, how to enforce it
  • barring a way to calculate limits, code a way to change all settings with commands, so a simple gcode benchmark program can explicitly show those limits
  • starting a cut with an arc doesn't start the laser
  • move all G[0123]/M[34589] hooks out to a extras/gcode-laser.py, to be enabled separately
Clone this wiki locally