User:Zhang.benj/sandbox

Klipper is an open source combination of software and firmware designed for FDM (fused deposition modeling) 3D printers using a microcontroller and a Raspberry Pi or other Linux computer. Klipper reads and executes common G-code instructions used by slicer software, either streamed through serial or read directly by the Klipper host, as well as some extended human-readable commands specific to Klipper. Unlike in conventional printer firmware, a microcontroller running Klipper does not receive any G-code; that task is handled by a host computer.

Klipper was initially released on GitHub in 2016 under a GPLv3 license with only basic cartesian printer support. Development has continued to add many advanced features since then, with the latest stable release published in September 2021. Klipper's continued development is funded by sponsors and donations.

History
Klipper's first release, v0.2.0, was published by Kevin O'Connor on May 25th, 2016, with basic support for cartesian printers and control through OctoPrint.

Klipper latest release, v0.10.0, was published on September 29th, 2021, bringing support for new mechanical systems, changes to configuration, additional software features, support for communication over CAN bus, support for the RP2040 microcontroller, and bug fixes.

On July 19th, 2022, it was announced that BIGTREETECH, a 3D printer mainboard manufacturer, had become a sponsor of the Klipper project.

In addition to the stable releases listed on Klipper's website, users may install Klipper using the latest source code from GitHub.

Architecture
In conventional 3D printer firmware, like Marlin, the microcontroller processes G-code directly, either reading the instructions from an SD card or receiving them from a host software like OctoPrint. As G-code instructions are written with respect to initial and final spatial positions, the microcontroller must perform the planning calculations, as well as handle the changing of acceleration settings and other computational parameters. Due to the need to handle all processing on the microcontroller, some more advanced features may need to be disabled for Marlin to fit on older 8-bit microprocessors.

In contrast, Klipper uses software running on an external general-purpose computer to perform computational and planning tasks, and only uses the microcontroller for timing control. Specifically, the host software reads the G-code, interprets and plans the instructions, and then instructs the microcontroller firmware to control the stepper motors and PWM outputs, like heaters and fans. Due to the limited functionality required of the microcontroller, Klipper can fit in a very small amount of storage, as small as 16KB, while Marlin requires at least 50KB of flash program memory. Communication between the microcontroller and host software occurs over a hardware serial connection, either directly connected over an integrated serial port or using a USB connection. This communication may also be implemented using a CAN bus. Over this communication link, the Klipper software service sends a limited set of commands, such as intermittently setting the state of microcontroller outputs, or scheduling multiple stepper pulses.

Klipper's host software is largely written in Python, while the compiled firmware installed on the microcontroller is written in C.

Like conventional 3D printer firmwares, Klipper supports directly controlling the printer with an attached LCD menu and encoder input knob. Additionally, Klipper creates a psuedoterminal (by default at /tmp/printer) through which the Klipper host software can accept G-code commands from other host softwares, like OctoPrint. Klipper also provides an API through which other softwares may directly control Klipper.

Supported kinematic configurations
Initally, Klipper was only released for support for cartesian printers, where movement in each axis was proportional to the rotation of a single motor. Over time, support for more complex configurations of motors and belts has been added. Of note are support for CoreXY and its variant CoreXZ, where two motors fixed in space move an object in a planar motion, as well as delta robots, which use a complex set of linkages, either sliding on rails or directly rotated, to pivot the printer nozzle in 3D space. Klipper also supports cable winch kinematics.

Temperature control
As FDM 3D printers need to heat plastic at a consistent temperature, it is necessary for printer firmware to measure and control the heater. Klipper supports controlling resistive heaters using PID algorithms, where the heater power is set continuously using PWM based on the temperature change over time, as well as "watermark" control, where the heater is left fully powered until a threshold is crossed, at which point the power is cut until the temperature drops too low. . Klipper can automatically calculate coefficients for PID control by repeatedly heating and cooling a heater device while measuring the temperature, after which Klipper can calculate and save appropriate settings for the heating algorithm.

For temperature measurement, Klipper supports sensors which can be read directly using the microcontroller's ADC, such as thermistors and some RTDs, as well as temperature measurement devices which communicate over SPI.

Input shaping
In 2020, Klipper introduced support for input shaping, an open-loop control technique that can reduce the effects of resonances. As 3D printers often implement linear motion using polymer timing belts, the elasticity of the belts can result in residual motion at the ends of moves. By outputting a signal which cancels the oscillations, Klipper can reduce the effect of oscillations, though sometimes at the cost of smoothing out sharp corners. In addition to iteratively testing different frequencies to use with input shaping, Klipper supports using an accelerometer to measure the resonant frequencies of different moves and directly determine optimal input shaper settings.

Development
The firmware is developed openly on GitHub, with many forks available for use. The original fork of Klipper is mainly developed by Kevin O'Connor, but accepts contributions from the public, subject to a review process. The development of Klipper is supported by direct donations to the developers, as well as support from BIGTREETECH, a printer mainboard manufacturer. All forks of Klipper are published under the GNU General Public License version 3.