Skip to content

MihaNormalen/Baclash_fix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

7 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Backlash Compensation Scripts for FluidNC

A suite of Python scripts designed to automatically calculate and apply compensation for mechanical backlash (slop/deadband) in motion control systems, specifically tailored for G-code used with FluidNC or similar controllers. This tool ensures greater precision by eliminating movement inconsistencies caused by gear train or screw wear.


โœจ Features

  • Precise Compensation: Calculates and inserts necessary motion offsets (G0 moves) to physically engage the drivetrain and eliminate mechanical play.
  • Targeted Axes: Supports independent compensation for X and Y axes.
  • Safety Integration: Inserts compensation moves with a defined safe feedrate (F200 default) and includes safety checks to prevent negative coordinates (Soft Limit Alarms).
  • Threshold Filtering: Ignores very small movements (below $0.05$ mm default) to filter out noise and avoid unnecessary compensation moves.
  • Variable Backlash Support: The advanced script (variable_backlash.py) allows for dynamic backlash compensation that changes linearly across the X-axis.

๐Ÿ› ๏ธ Prerequisites

To run this script, you need:

  • Python 3.x
  • No external libraries are required (uses standard re and argparse).

๐Ÿš€ Installation and Setup

  1. Clone the repository to your local machine:

    git clone [https://github.com/MihaNormalen/Baclash_fix.git](https://github.com/MihaNormalen/Baclash_fix.git)
    cd Baclash_fix
  2. Ensure the backlash_fix.py script is executable (optional, but good practice):

    chmod +x backlash_fix.py

๐Ÿ“ Usage: Fixed Backlash Compensation (backlash_fix.py)

The script backlash_fix.py applies a single, constant backlash value for each axis.

Command Line Syntax (Fixed Mode)

python backlash_fix.py <INPUT_FILE> [OUTPUT_FILE] [--bx <VALUE>] [--by <VALUE>]
python backlash_fix.py raw_cut.gcode fixed_cut.gcode --bx 0.10 --by 0.05

Argument,Description,Default
input,Path to the source G-code file.,N/A
output,"Path for the corrected output G-code file. If omitted, defaults to fixed_<input_file>.",fixed_...
--bx,Backlash magnitude for the X-axis (in mm).,0.5
--by,Backlash magnitude for the Y-axis (in mm).,1.6

โšก Advanced Usage: Variable Backlash Compensation (advanced/variable_backlash.py)
The script advanced/variable_backlash.py accounts for backlash magnitude changing linearly across the X-axis travel (e.g., due to wear or non-uniform leadscrew alignment).

Command Line Syntax (Variable Mode)
python advanced/variable_backlash.py <INPUT_FILE> <OUTPUT_FILE> --max_x <MAX> --bx_start <X0> --bx_end <XMAX> --by_start <Y0> --by_end <YMAX>
python advanced/variable_backlash.py raw_cut.gcode fixed_variable.gcode --max_x 300.0 --bx_start 0.05 --bx_end 0.15 --by_start 0.20 --by_end 0.10

Argument,Description,Default
input,Path to the source G-code file.,N/A
output,Path for the corrected output G-code file.,N/A
--max_x,"Maximum physical travel of the X-axis (in mm), used for interpolation.",150.0
--bx_start,Backlash magnitude for X-axis at X=0 (in mm).,0.5
--bx_end,Backlash magnitude for X-axis at X=max_x (in mm).,0.5
--by_start,Backlash magnitude for Y-axis at X=0 (in mm).,3.2
--by_end,Backlash magnitude for Y-axis at X=max_x (in mm).,1.6

About

Backlash compensation tool for precise mechanical control

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages