mirror of
https://github.com/Klipper3d/klipper.git
synced 2025-07-17 11:47:56 -06:00
toolhead: Replace max_accel_to_decel with minimum_cruise_ratio
The user facing max_accel_to_decel setting is complicated and confusing. Replace it with a new minimum_cruise_ratio parameter. Internally this user-facing parameter will calculate the existing low-level "accel_to_decel" mechanism. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
18de421c4a
commit
0105aa330f
10 changed files with 85 additions and 50 deletions
|
@ -217,12 +217,19 @@ class ToolHead:
|
|||
# Velocity and acceleration control
|
||||
self.max_velocity = config.getfloat('max_velocity', above=0.)
|
||||
self.max_accel = config.getfloat('max_accel', above=0.)
|
||||
self.requested_accel_to_decel = config.getfloat(
|
||||
'max_accel_to_decel', self.max_accel * 0.5, above=0.)
|
||||
self.max_accel_to_decel = self.requested_accel_to_decel
|
||||
self.min_cruise_ratio = config.getfloat('minimum_cruise_ratio', None,
|
||||
below=1., minval=0.)
|
||||
if self.min_cruise_ratio is None:
|
||||
self.min_cruise_ratio = 0.5
|
||||
req_accel_to_decel = config.getfloat('max_accel_to_decel', None,
|
||||
above=0.)
|
||||
if req_accel_to_decel is not None:
|
||||
config.deprecate('max_accel_to_decel')
|
||||
self.min_cruise_ratio = 1. - min(1., (req_accel_to_decel
|
||||
/ self.max_accel))
|
||||
self.square_corner_velocity = config.getfloat(
|
||||
'square_corner_velocity', 5., minval=0.)
|
||||
self.junction_deviation = 0.
|
||||
self.junction_deviation = self.max_accel_to_decel = 0.
|
||||
self._calc_junction_deviation()
|
||||
# Input stall detection
|
||||
self.check_stall_time = 0.
|
||||
|
@ -561,7 +568,7 @@ class ToolHead:
|
|||
'position': self.Coord(*self.commanded_pos),
|
||||
'max_velocity': self.max_velocity,
|
||||
'max_accel': self.max_accel,
|
||||
'max_accel_to_decel': self.requested_accel_to_decel,
|
||||
'minimum_cruise_ratio': self.min_cruise_ratio,
|
||||
'square_corner_velocity': self.square_corner_velocity})
|
||||
return res
|
||||
def _handle_shutdown(self):
|
||||
|
@ -600,8 +607,7 @@ class ToolHead:
|
|||
def _calc_junction_deviation(self):
|
||||
scv2 = self.square_corner_velocity**2
|
||||
self.junction_deviation = scv2 * (math.sqrt(2.) - 1.) / self.max_accel
|
||||
self.max_accel_to_decel = min(self.requested_accel_to_decel,
|
||||
self.max_accel)
|
||||
self.max_accel_to_decel = self.max_accel * (1. - self.min_cruise_ratio)
|
||||
def cmd_G4(self, gcmd):
|
||||
# Dwell
|
||||
delay = gcmd.get_float('P', 0., minval=0.) / 1000.
|
||||
|
@ -615,29 +621,34 @@ class ToolHead:
|
|||
max_accel = gcmd.get_float('ACCEL', None, above=0.)
|
||||
square_corner_velocity = gcmd.get_float(
|
||||
'SQUARE_CORNER_VELOCITY', None, minval=0.)
|
||||
requested_accel_to_decel = gcmd.get_float(
|
||||
'ACCEL_TO_DECEL', None, above=0.)
|
||||
min_cruise_ratio = gcmd.get_float(
|
||||
'MINIMUM_CRUISE_RATIO', None, minval=0., below=1.)
|
||||
if min_cruise_ratio is None:
|
||||
req_accel_to_decel = gcmd.get_float('ACCEL_TO_DECEL',
|
||||
None, above=0.)
|
||||
if req_accel_to_decel is not None and max_accel is not None:
|
||||
min_cruise_ratio = 1. - min(1., req_accel_to_decel / max_accel)
|
||||
elif req_accel_to_decel is not None and max_accel is None:
|
||||
min_cruise_ratio = 1. - min(1., (req_accel_to_decel
|
||||
/ self.max_accel))
|
||||
if max_velocity is not None:
|
||||
self.max_velocity = max_velocity
|
||||
if max_accel is not None:
|
||||
self.max_accel = max_accel
|
||||
if square_corner_velocity is not None:
|
||||
self.square_corner_velocity = square_corner_velocity
|
||||
if requested_accel_to_decel is not None:
|
||||
self.requested_accel_to_decel = requested_accel_to_decel
|
||||
if min_cruise_ratio is not None:
|
||||
self.min_cruise_ratio = min_cruise_ratio
|
||||
self._calc_junction_deviation()
|
||||
msg = ("max_velocity: %.6f\n"
|
||||
"max_accel: %.6f\n"
|
||||
"max_accel_to_decel: %.6f\n"
|
||||
"minimum_cruise_ratio: %.6f\n"
|
||||
"square_corner_velocity: %.6f" % (
|
||||
self.max_velocity, self.max_accel,
|
||||
self.requested_accel_to_decel,
|
||||
self.square_corner_velocity))
|
||||
self.min_cruise_ratio, self.square_corner_velocity))
|
||||
self.printer.set_rollover_info("toolhead", "toolhead: %s" % (msg,))
|
||||
if (max_velocity is None and
|
||||
max_accel is None and
|
||||
square_corner_velocity is None and
|
||||
requested_accel_to_decel is None):
|
||||
if (max_velocity is None and max_accel is None
|
||||
and square_corner_velocity is None and min_cruise_ratio is None):
|
||||
gcmd.respond_info(msg, log=False)
|
||||
def cmd_M204(self, gcmd):
|
||||
# Use S for accel
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue