polar kinemcatics: adds velocity scaling

Print near the origin lead in to fast motor movements, therefore the
movement needs to be scaled down. The start of the scaling is done via
a critical radius variable from the config

Signed-off-by: Nils Hensch nils.hensch@gmx.de
This commit is contained in:
Neelix 2026-01-23 18:54:42 +01:00 committed by GitHub
parent 48f0b3cad6
commit 60a344bdcb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -6,6 +6,25 @@
import logging, math
import stepper
def distance_line_to_point(p1, p2):
ab_x = p2[0]-p1[0]
ab_y = p2[1]-p1[1]
ap_x = -p1[0]
ap_y = -p1[1]
ab_ap_dot_product = ab_x * ap_x + ab_y * ap_y
ab_length = math.sqrt(ab_x ** 2 + ab_y ** 2)
# Check if the projected point lies on the bounded line segment
if ab_ap_dot_product <= -0.1:
dist = math.sqrt(ap_x ** 2 + ap_y ** 2)
elif ab_ap_dot_product >= ab_length ** 2:
dist = math.sqrt(p2[0] ** 2 + p2[1] ** 2)
else:
dist = abs(ab_x * ap_y - ab_y * ap_x) / ab_length
return dist
class PolarKinematics:
def __init__(self, toolhead, config):
# Setup axis steppers
@ -22,11 +41,13 @@ class PolarKinematics:
for s in self.get_steppers():
s.set_trapq(toolhead.get_trapq())
# Setup boundary checks
max_velocity, max_accel = toolhead.get_max_velocity()
self.max_velocity, self.max_accel = toolhead.get_max_velocity()
self.max_z_velocity = config.getfloat(
'max_z_velocity', max_velocity, above=0., maxval=max_velocity)
'max_z_velocity', self.max_velocity, above=0., maxval=self.max_velocity)
self.max_z_accel = config.getfloat(
'max_z_accel', max_accel, above=0., maxval=max_accel)
'max_z_accel', self.max_accel, above=0., maxval=self.max_accel)
self.critical_radius = config.getfloat(
'critical_radius', above=0., default=0)
self.limit_z = (1.0, -1.0)
self.limit_xy2 = -1.
max_xy = self.rails[0].get_range()[1]
@ -101,6 +122,15 @@ class PolarKinematics:
z_ratio = move.move_d / abs(move.axes_d[2])
move.limit_speed(self.max_z_velocity * z_ratio,
self.max_z_accel * z_ratio)
# Slow down near center
if move.axes_d[0] or move.axes_d[1]:
if self.critical_radius != 0:
min_dist = distance_line_to_point(move.start_pos[0:2], move.end_pos[0:2])
if min_dist <= self.critical_radius:
if min_dist != 0:
scale_radius = min_dist/self.critical_radius
move.limit_speed(self.max_velocity * scale_radius, self.max_accel * scale_radius)
def get_status(self, eventtime):
xy_home = "xy" if self.limit_xy2 >= 0. else ""
z_home = "z" if self.limit_z[0] <= self.limit_z[1] else ""
@ -111,4 +141,4 @@ class PolarKinematics:
}
def load_kinematics(toolhead, config):
return PolarKinematics(toolhead, config)
return PolarKinematics(toolhead, config)