Skip to content

Commit

Permalink
Enhance SET_VELOCITY_LIMIT (#557)
Browse files Browse the repository at this point in the history
* Update toolhead.py

* updated docs

* fixed formatting
  • Loading branch information
Zeanon authored Jan 30, 2025
1 parent af3e731 commit 35bca85
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 10 deletions.
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

0 comments on commit 35bca85

Please sign in to comment.