Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance SET_VELOCITY_LIMIT #557

Merged
merged 3 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion docs/G-Codes.md
Original file line number Diff line number Diff line change
Expand Up @@ -1589,11 +1589,15 @@ The toolhead module is automatically loaded.

#### SET_VELOCITY_LIMIT
`SET_VELOCITY_LIMIT [VELOCITY=<value>] [ACCEL=<value>]
[MINIMUM_CRUISE_RATIO=<value>] [SQUARE_CORNER_VELOCITY=<value>]`: This
[MINIMUM_CRUISE_RATIO=<value>] [SQUARE_CORNER_VELOCITY=<value>]
[X_VELOCITY=<value>] [X_ACCEL=<value>] [Y_VELOCITY=<value>] [Y_ACCEL=<value>]
[Z_VELOCITY=<value>] [Z_ACCEL=<value>]`: 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
Expand Down
104 changes: 95 additions & 9 deletions klippy/toolhead.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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",
Expand All @@ -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)

Expand Down
Loading