ftmotion-extrusion-simulator: FTMotion: Debugging 3D Printer Physics in the Browser

How a strict TypeScript port of Marlin's C++ motion algorithms turns the slow, wasteful process of tuning hardware into an instant visual sandbox.

7 min read • View on GitHub • More from dbuezas

A 3D printer hotend extruding glowing mathematical symbols and vector lines onto a print bed, illustrating the translation of physical hardware into digital mathematics.
The FTMotion Simulator bridges the gap between physical hardware adjustments and complex mathematical modeling.
Key Takeaways

The Calibration Cube Problem

The hardest part of developing firmware for hardware is the feedback loop. To test a new motion algorithm in a 3D printer, developers traditionally write C++ code, compile it, flash it to a microcontroller, and print a physical calibration cube. They then inspect the plastic for bulging corners or skipped layers to see if their math was correct. It is a slow, opaque process where the physical hardware acts as a black box.

A magnifying glass held over a deformed 3D printed cube, where the lens reveals the underlying sharp vector math and control points.
Hardware debugging often requires translating physical defects back into abstract mathematical errors.

The FTMotion Simulator breaks this cycle entirely. It provides an environment where developers can see exactly how a change in acceleration or jerk settings will affect the final extrusion path before a single stepper motor ever turns.

A Mathematical Mirror in TypeScript

This tool is not a rough approximation. It is a direct translation of Marlin's complex C++ motion generation into strict TypeScript. The core of the simulator relies on a one-to-one port of the Poly6TrajectoryGenerator. By moving this logic to the browser, the developer leverages the HTML5 Canvas API to render high-performance visualizations of the resulting arrays.

The FTMotion calculation pipeline translates raw UI parameters into a rendered physical extrusion path.

This architecture bypasses heavy frontend frameworks. It uses a lightweight development stack to ensure that the visualization runs fast enough to provide instant feedback as users drag sliders for acceleration and velocity.

The End of the Trapezoid

Legacy 3D printer firmware relies heavily on trapezoidal motion profiles. These profiles suffer from infinite jerk spikes when transitioning between constant velocity and acceleration. FTMotion introduces Sextic (6th-order) polynomials to explicitly solve this mechanical issue.

Sextic polynomial acceleration curves provide a continuous, smooth transition compared to the sharp spikes of legacy trapezoidal motion.

By using a normalized time variable, the FTMotion algorithm ensures that acceleration transitions smoothly. The simulator allows users to visually scrub through these curves, verifying that the math produces a continuous flow without mechanical shock.

Simulating the Melt Zone

The simulator goes beyond mere travel motion. It tackles the physics of extrusion by simulating Linear Advance. The code calculates three distinct traces: the planned path, the path modified by the advance algorithm, and the effective real-world result.

A cross-section of a 3D printer nozzle containing a heavy industrial spring being compressed by a piston, with a mechanical dial gauge attached to the side.
Treating the nozzle as a first-order lag system allows the simulator to visually predict the elasticity of molten plastic.

By treating the nozzle and molten plastic as a first-order lag system, the tool can visually predict physical pressure lag. This mathematical compensation is crucial for achieving clean, sharp corners on a physical print.

I've tested your`FT_MOTION` code in the last Marlin bugfix, great work, nice improvement in sound.

narno2202, Contributor · Marlin Pull Request #28058

The Firmware Convergence

The changes visualized in this simulator represent a significant shift for Marlin. By aligning its unit definitions and pressure management systems with modern alternatives, FTMotion brings robust, predictable motion control back to the core firmware.

FeatureLegacy MarlinFTMotion SimulatorKlipper
Motion PlanningTrapezoidalSextic PolynomialKinematic
Extrusion AdvanceAbstract K-factorTime-based physical constantsTime-based physical constants
Debugging MethodPrint-and-MeasureVisual Browser SimulationPrint-and-Measure

As these features are adopted by the community, the need for blind hardware tuning diminishes. The ability to see and adjust motion physics in a browser shifts the burden of proof from the physical print bed to the digital canvas.