From 35bca85a233347eefaf611e5c214da3e33cb1e9b Mon Sep 17 00:00:00 2001 From: Zeanon Date: Thu, 30 Jan 2025 04:11:30 +0100 Subject: [PATCH] Enhance SET_VELOCITY_LIMIT (#557) * Update toolhead.py * updated docs * fixed formatting --- docs/G-Codes.md | 6 ++- klippy/toolhead.py | 104 +++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 100 insertions(+), 10 deletions(-) diff --git a/docs/G-Codes.md b/docs/G-Codes.md index 55b165824..b26f55420 100644 --- a/docs/G-Codes.md +++ b/docs/G-Codes.md @@ -1589,11 +1589,15 @@ The toolhead module is automatically loaded. #### SET_VELOCITY_LIMIT `SET_VELOCITY_LIMIT [VELOCITY=] [ACCEL=] -[MINIMUM_CRUISE_RATIO=] [SQUARE_CORNER_VELOCITY=]`: This +[MINIMUM_CRUISE_RATIO=] [SQUARE_CORNER_VELOCITY=] +[X_VELOCITY=] [X_ACCEL=] [Y_VELOCITY=] [Y_ACCEL=] +[Z_VELOCITY=] [Z_ACCEL=]`: This command can alter the velocity limits that were specified in the printer config file. See the [printer config section](Config_Reference.md#printer) for a description of each parameter. +X_VELOCITY, X_ACCEL, Y_VELOCITY, Y_ACCEL, Z_VELOCITY and Z_ACCEL are only +available if the kinematic supports it. ### RESET_VELOCITY_LIMIT `RESET_VELOCITY_LIMIT`: This command resets the velocity limits to the values diff --git a/klippy/toolhead.py b/klippy/toolhead.py index 59df059ef..9e15a1df5 100644 --- a/klippy/toolhead.py +++ b/klippy/toolhead.py @@ -343,6 +343,19 @@ def __init__(self, config): "dual_carriage not compatible with '%s' kinematics system" % (kin_name,) ) + if hasattr(self.kin, "max_x_velocity"): + self.orig_cfg["max_x_velocity"] = self.kin.max_x_velocity + if hasattr(self.kin, "max_x_accel"): + self.orig_cfg["max_x_accel"] = self.kin.max_x_accel + if hasattr(self.kin, "max_y_velocity"): + self.orig_cfg["max_y_velocity"] = self.kin.max_y_velocity + if hasattr(self.kin, "max_y_accel"): + self.orig_cfg["max_y_accel"] = self.kin.max_y_accel + if hasattr(self.kin, "max_z_velocity"): + self.orig_cfg["max_z_velocity"] = self.kin.max_z_velocity + if hasattr(self.kin, "max_z_accel"): + self.orig_cfg["max_z_accel"] = self.kin.max_z_accel + # Register commands gcode.register_command("G4", self.cmd_G4) gcode.register_command("M400", self.cmd_M400) @@ -812,12 +825,54 @@ def cmd_SET_VELOCITY_LIMIT(self, gcmd): self.square_corner_velocity = square_corner_velocity if min_cruise_ratio is not None: self.min_cruise_ratio = min_cruise_ratio - self._calc_junction_deviation() - msg = ( + msg = [ "max_velocity: %.6f" % self.max_velocity, "max_accel: %.6f" % self.max_accel, - "minimum_cruise_ratio: %.6f" % self.min_cruise_ratio, - "square_corner_velocity: %.6f" % self.square_corner_velocity, + ] + if hasattr(self.kin, "max_x_velocity"): + max_x_velocity = gcmd.get_float("X_VELOCITY", None) + if max_x_velocity is not None: + self.kin.max_x_velocity = max_x_velocity + msg.append("max_x_velocity: %.6f" % self.kin.max_x_velocity) + + if hasattr(self.kin, "max_x_accel"): + max_x_accel = gcmd.get_float("X_ACCEL", None) + if max_x_accel is not None: + self.kin.max_x_accel = max_x_accel + msg.append("max_x_accel: %.6f" % self.kin.max_x_accel) + + if hasattr(self.kin, "max_y_velocity"): + max_y_velocity = gcmd.get_float("Y_VELOCITY", None) + if max_y_velocity is not None: + self.kin.max_y_velocity = max_y_velocity + msg.append("max_y_velocity: %.6f" % self.kin.max_y_velocity) + + if hasattr(self.kin, "max_y_accel"): + max_y_accel = gcmd.get_float("Y_ACCEL", None) + if max_y_accel is not None: + self.kin.max_y_accel = max_y_accel + msg.append( + "max_y_accel: %.6f" % self.kin.max_y_accel, + ) + + if hasattr(self.kin, "max_z_velocity"): + max_z_velocity = gcmd.get_float("Z_VELOCITY", None, above=0.0) + if max_z_velocity is not None: + self.kin.max_z_velocity = max_z_velocity + msg.append("max_z_velocity: %.6f" % self.kin.max_z_velocity) + + if hasattr(self.kin, "max_z_accel"): + max_z_accel = gcmd.get_float("Z_ACCEL", None, above=0.0) + if max_z_accel is not None: + self.kin.max_z_accel = max_z_accel + msg.append("max_z_accel: %.6f" % self.kin.max_z_accel) + + self._calc_junction_deviation() + msg.extend( + ( + "minimum_cruise_ratio: %.6f" % self.min_cruise_ratio, + "square_corner_velocity: %.6f" % self.square_corner_velocity, + ) ) self.printer.set_rollover_info( "toolhead", @@ -837,14 +892,45 @@ def cmd_SET_VELOCITY_LIMIT(self, gcmd): def cmd_RESET_VELOCITY_LIMIT(self, gcmd): self.max_velocity = self.orig_cfg["max_velocity"] self.max_accel = self.orig_cfg["max_accel"] + msg = [ + "max_velocity: %.6f" % self.max_velocity, + "max_accel: %.6f" % self.max_accel, + ] + + if hasattr(self.kin, "max_x_velocity"): + self.kin.max_x_velocity = self.orig_cfg["max_x_velocity"] + msg.append("max_x_velocity: %.6f" % self.kin.max_x_velocity) + + if hasattr(self.kin, "max_x_accel"): + self.kin.max_x_accel = self.orig_cfg["max_x_accel"] + msg.append("max_x_accel: %.6f" % self.kin.max_x_accel) + + if hasattr(self.kin, "max_y_velocity"): + self.kin.max_y_velocity = self.orig_cfg["max_y_velocity"] + msg.append("max_y_velocity: %.6f" % self.kin.max_y_velocity) + + if hasattr(self.kin, "max_y_accel"): + self.kin.max_y_accel = self.orig_cfg["max_y_accel"] + msg.append( + "max_y_accel: %.6f" % self.kin.max_y_accel, + ) + + if hasattr(self.kin, "max_z_velocity"): + self.kin.max_z_velocity = self.orig_cfg["max_z_velocity"] + msg.append("max_z_velocity: %.6f" % self.kin.max_z_velocity) + + if hasattr(self.kin, "max_z_accel"): + self.kin.max_z_accel = self.orig_cfg["max_z_accel"] + msg.append("max_z_accel: %.6f" % self.kin.max_z_accel) + self.square_corner_velocity = self.orig_cfg["square_corner_velocity"] self.min_cruise_ratio = self.orig_cfg["min_cruise_ratio"] self._calc_junction_deviation() - msg = ( - "max_velocity: %.6f" % self.max_velocity, - "max_accel: %.6f" % self.max_accel, - "minimum_cruise_ratio: %.6f" % self.min_cruise_ratio, - "square_corner_velocity: %.6f" % self.square_corner_velocity, + msg.extend( + ( + "minimum_cruise_ratio: %.6f" % self.min_cruise_ratio, + "square_corner_velocity: %.6f" % self.square_corner_velocity, + ) ) gcmd.respond_info("\n".join(msg), log=False)