manual_stepper: Support LIMIT_VELOCITY and LIMIT_ACCEL when using gcode axis

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2025-04-30 19:59:14 -04:00
parent ee0bc3d697
commit 6c1d5d912a
2 changed files with 17 additions and 2 deletions

View File

@ -969,6 +969,7 @@ stepper move uses SYNC=0 then future G-Code movement commands may run
in parallel with the stepper movement.
`MANUAL_STEPPER STEPPER=config_name GCODE_AXIS=[A-Z]
[LIMIT_VELOCITY=<velocity>] [LIMIT_ACCEL=<accel>]
[INSTANTANEOUS_CORNER_VELOCITY=<velocity>]`: If the `GCODE_AXIS`
parameter is specified then it configures the stepper motor as an
extra axis on `G1` move commands. For example, if one were to issue a
@ -979,6 +980,9 @@ xyz movements. If the motor is associated with a `GCODE_AXIS` then
one may no longer issue movements using the above `MANUAL_STEPPER`
command - one may unregister the stepper with a `MANUAL_STEPPER
... GCODE_AXIS=` command to resume manual control of the motor. The
`LIMIT_VELOCITY` and `LIMIT_ACCEL` parameters allow one to reduce the
speed of `G1` moves if those moves would result in a velocity or
acceleration above the specified limits. The
`INSTANTANEOUS_CORNER_VELOCITY` specifies the maximum instantaneous
velocity change (in mm/s) of the motor during the junction of two
moves (the default is 1mm/s).

View File

@ -34,6 +34,7 @@ class ManualStepper:
# Registered with toolhead as an axtra axis
self.axis_gcode_id = None
self.instant_corner_v = 0.
self.gaxis_limit_velocity = self.gaxis_limit_accel = 0.
# Register commands
stepper_name = config.get_name().split()[1]
gcode = self.printer.lookup_object('gcode')
@ -130,6 +131,8 @@ class ManualStepper:
gcode_axis = gcmd.get('GCODE_AXIS').upper()
instant_corner_v = gcmd.get_float('INSTANTANEOUS_CORNER_VELOCITY', 1.,
minval=0.)
limit_velocity = gcmd.get_float('LIMIT_VELOCITY', 999999.9, above=0.)
limit_accel = gcmd.get_float('LIMIT_ACCEL', 999999.9, above=0.)
if self.axis_gcode_id is not None:
if gcode_axis:
raise gcmd.error("Must unregister axis first")
@ -149,6 +152,8 @@ class ManualStepper:
raise gcmd.error("Axis '%s' already registered" % (gcode_axis,))
self.axis_gcode_id = gcode_axis
self.instant_corner_v = instant_corner_v
self.gaxis_limit_velocity = limit_velocity
self.gaxis_limit_accel = limit_accel
toolhead.add_extra_axis(self, self.get_position()[0])
toolhead.register_step_generator(self.rail.generate_steps)
def process_move(self, print_time, move, ea_index):
@ -163,12 +168,18 @@ class ManualStepper:
1., 0., 0.,
start_v, cruise_v, accel)
def check_move(self, move, ea_index):
# Check move is in bounds
movepos = move.end_pos[ea_index]
if ((self.pos_min is not None and movepos < self.pos_min)
or (self.pos_max is not None and movepos > self.pos_max)):
raise move.move_error()
# XXX - support max accel/velocity
# XXX - support non-kinematic max accel/velocity
# Check if need to limit maximum velocity and acceleration
axis_ratio = move.move_d / abs(move.axes_d[ea_index])
limit_velocity = self.gaxis_limit_velocity * axis_ratio
limit_accel = self.gaxis_limit_accel * axis_ratio
if not move.is_kinematic_move and self.accel:
limit_accel = min(limit_accel, self.accel * axis_ratio)
move.limit_speed(limit_velocity, limit_accel)
def calc_junction(self, prev_move, move, ea_index):
diff_r = move.axes_r[ea_index] - prev_move.axes_r[ea_index]
if diff_r: