aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/extras/gcode_arcs.py
diff options
context:
space:
mode:
Diffstat (limited to 'klippy/extras/gcode_arcs.py')
-rw-r--r--klippy/extras/gcode_arcs.py79
1 files changed, 47 insertions, 32 deletions
diff --git a/klippy/extras/gcode_arcs.py b/klippy/extras/gcode_arcs.py
index 3917dac3..2e13e3af 100644
--- a/klippy/extras/gcode_arcs.py
+++ b/klippy/extras/gcode_arcs.py
@@ -28,10 +28,10 @@ class ArcSupport:
def __init__(self, config):
self.printer = config.get_printer()
- self.mm_per_arc_segment = config.getfloat('resolution', 1., above=0.0)
+ self.mm_per_arc_segment = config.getfloat("resolution", 1.0, above=0.0)
- self.gcode_move = self.printer.load_object(config, 'gcode_move')
- self.gcode = self.printer.lookup_object('gcode')
+ self.gcode_move = self.printer.load_object(config, "gcode_move")
+ self.gcode = self.printer.lookup_object("gcode")
self.gcode.register_command("G2", self.cmd_G2)
self.gcode.register_command("G3", self.cmd_G3)
@@ -59,30 +59,32 @@ class ArcSupport:
def _cmd_inner(self, gcmd, clockwise):
gcodestatus = self.gcode_move.get_status()
- if not gcodestatus['absolute_coordinates']:
+ if not gcodestatus["absolute_coordinates"]:
raise gcmd.error("G2/G3 does not support relative move mode")
- currentPos = gcodestatus['gcode_position']
- absolut_extrude = gcodestatus['absolute_extrude']
+ currentPos = gcodestatus["gcode_position"]
+ absolut_extrude = gcodestatus["absolute_extrude"]
# Parse parameters
- asTarget = [gcmd.get_float("X", currentPos[0]),
- gcmd.get_float("Y", currentPos[1]),
- gcmd.get_float("Z", currentPos[2])]
+ asTarget = [
+ gcmd.get_float("X", currentPos[0]),
+ gcmd.get_float("Y", currentPos[1]),
+ gcmd.get_float("Z", currentPos[2]),
+ ]
if gcmd.get_float("R", None) is not None:
raise gcmd.error("G2/G3 does not support R moves")
# determine the plane coordinates and the helical axis
- I = gcmd.get_float('I', 0.)
- J = gcmd.get_float('J', 0.)
+ I = gcmd.get_float("I", 0.0)
+ J = gcmd.get_float("J", 0.0)
asPlanar = (I, J)
axes = (X_AXIS, Y_AXIS, Z_AXIS)
if self.plane == ARC_PLANE_X_Z:
- K = gcmd.get_float('K', 0.)
+ K = gcmd.get_float("K", 0.0)
asPlanar = (I, K)
axes = (X_AXIS, Z_AXIS, Y_AXIS)
elif self.plane == ARC_PLANE_Y_Z:
- K = gcmd.get_float('K', 0.)
+ K = gcmd.get_float("K", 0.0)
asPlanar = (J, K)
axes = (Y_AXIS, Z_AXIS, X_AXIS)
@@ -90,8 +92,9 @@ class ArcSupport:
raise gcmd.error("G2/G3 requires IJ, IK or JK parameters")
# Build linear coordinates to move
- self.planArc(currentPos, asTarget, asPlanar, clockwise,
- gcmd, absolut_extrude, *axes)
+ self.planArc(
+ currentPos, asTarget, asPlanar, clockwise, gcmd, absolut_extrude, *axes
+ )
# function planArc() originates from marlin plan_arc()
# https://github.com/MarlinFirmware/Marlin
@@ -101,9 +104,18 @@ class ArcSupport:
# Arcs smaller then this value, will be a Line only
#
# alpha and beta axes are the current plane, helical axis is linear travel
- def planArc(self, currentPos, targetPos, offset, clockwise,
- gcmd, absolut_extrude,
- alpha_axis, beta_axis, helical_axis):
+ def planArc(
+ self,
+ currentPos,
+ targetPos,
+ offset,
+ clockwise,
+ gcmd,
+ absolut_extrude,
+ alpha_axis,
+ beta_axis,
+ helical_axis,
+ ):
# todo: sometimes produces full circles
# Radius vector from center to current location
@@ -115,19 +127,22 @@ class ArcSupport:
center_Q = currentPos[beta_axis] - r_Q
rt_Alpha = targetPos[alpha_axis] - center_P
rt_Beta = targetPos[beta_axis] - center_Q
- angular_travel = math.atan2(r_P * rt_Beta - r_Q * rt_Alpha,
- r_P * rt_Alpha + r_Q * rt_Beta)
- if angular_travel < 0.:
- angular_travel += 2. * math.pi
+ angular_travel = math.atan2(
+ r_P * rt_Beta - r_Q * rt_Alpha, r_P * rt_Alpha + r_Q * rt_Beta
+ )
+ if angular_travel < 0.0:
+ angular_travel += 2.0 * math.pi
if clockwise:
- angular_travel -= 2. * math.pi
+ angular_travel -= 2.0 * math.pi
- if (angular_travel == 0.
+ if (
+ angular_travel == 0.0
and currentPos[alpha_axis] == targetPos[alpha_axis]
- and currentPos[beta_axis] == targetPos[beta_axis]):
+ and currentPos[beta_axis] == targetPos[beta_axis]
+ ):
# Make a circle if the angular rotation is 0 and the
# target is current position
- angular_travel = 2. * math.pi
+ angular_travel = 2.0 * math.pi
# Determine number of segments
linear_travel = targetPos[helical_axis] - currentPos[helical_axis]
@@ -137,7 +152,7 @@ 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))
+ segments = max(1.0, math.floor(mm_of_travel / self.mm_per_arc_segment))
# Generate coordinates
theta_per_segment = angular_travel / segments
@@ -146,7 +161,7 @@ class ArcSupport:
asE = gcmd.get_float("E", None)
asF = gcmd.get_float("F", None)
- e_per_move = e_base = 0.
+ e_per_move = e_base = 0.0
if asE is not None:
if absolut_extrude:
e_base = currentPos[3]
@@ -165,19 +180,19 @@ class ArcSupport:
c[beta_axis] = center_Q + r_Q
c[helical_axis] = currentPos[helical_axis] + dist_Helical
-
if i == segments:
c = targetPos
# Convert coords into G1 commands
- g1_params = {'X': c[0], 'Y': c[1], 'Z': c[2]}
+ g1_params = {"X": c[0], "Y": c[1], "Z": c[2]}
if e_per_move:
- g1_params['E'] = e_base + e_per_move
+ g1_params["E"] = e_base + e_per_move
if absolut_extrude:
e_base += e_per_move
if asF is not None:
- g1_params['F'] = asF
+ g1_params["F"] = asF
g1_gcmd = self.gcode.create_gcode_command("G1", "G1", g1_params)
self.gcode_move.cmd_G1(g1_gcmd)
+
def load_config(config):
return ArcSupport(config)