gcode_arcs: add max error support

Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
This commit is contained in:
Timofey Titovets 2025-07-21 02:09:50 +02:00
parent 20d9c84a9f
commit c17c243a9a
2 changed files with 11 additions and 1 deletions

View file

@ -1723,6 +1723,9 @@ Support for gcode arc (G2/G3) commands.
# finer arc, but also more work for your machine. Arcs smaller than
# the configured value will become straight lines. The default is
# 1mm.
#sagitta: 0.01
# Max path deviation between the actual arg segment and
# the approximated line. The default is 0.01mm
```
### [respond]

View file

@ -29,6 +29,7 @@ class ArcSupport:
def __init__(self, config):
self.printer = config.get_printer()
self.mm_per_arc_segment = config.getfloat('resolution', 1., above=0.0)
self.sagitta = config.getfloat('sagitta', 0.01, above=0.0)
self.gcode_move = self.printer.load_object(config, 'gcode_move')
self.gcode = self.printer.lookup_object('gcode')
@ -137,7 +138,13 @@ class ArcSupport:
mm_of_travel = math.hypot(flat_mm, linear_travel)
else:
mm_of_travel = math.fabs(flat_mm)
segments = max(1., math.floor(mm_of_travel / self.mm_per_arc_segment))
mm_per_segment = self.mm_per_arc_segment
if radius > self.sagitta:
r = radius
s = self.sagitta
l = 2 * math.sqrt(2 * r * s - s**2)
mm_per_segment = min(l, self.mm_per_arc_segment)
segments = max(1., math.floor(mm_of_travel / mm_per_segment))
# Generate coordinates
theta_per_segment = angular_travel / segments