2016-07-07 15:52:44 -04:00
|
|
|
# Code for coordinating events on the printer toolhead
|
|
|
|
|
#
|
2025-04-12 15:54:39 -04:00
|
|
|
# Copyright (C) 2016-2025 Kevin O'Connor <kevin@koconnor.net>
|
2016-07-07 15:52:44 -04:00
|
|
|
#
|
|
|
|
|
# This file may be distributed under the terms of the GNU GPLv3 license.
|
2018-07-12 22:15:45 -04:00
|
|
|
import math, logging, importlib
|
2021-01-08 12:07:45 -05:00
|
|
|
import mcu, chelper, kinematics.extruder
|
2016-07-12 12:04:06 -04:00
|
|
|
|
2016-07-07 15:52:44 -04:00
|
|
|
# Common suffixes: _d is distance (in mm), _v is velocity (in
|
2017-01-14 13:35:27 -05:00
|
|
|
# mm/second), _v2 is velocity squared (mm^2/s^2), _t is time (in
|
|
|
|
|
# seconds), _r is ratio (scalar between 0.0 and 1.0)
|
2016-07-07 15:52:44 -04:00
|
|
|
|
2016-07-07 16:01:58 -04:00
|
|
|
# Class to track each move request
|
2016-07-07 15:52:44 -04:00
|
|
|
class Move:
|
2017-01-14 12:41:49 -05:00
|
|
|
def __init__(self, toolhead, start_pos, end_pos, speed):
|
2016-07-07 15:52:44 -04:00
|
|
|
self.toolhead = toolhead
|
2016-10-25 19:11:05 -04:00
|
|
|
self.start_pos = tuple(start_pos)
|
|
|
|
|
self.end_pos = tuple(end_pos)
|
2017-01-14 12:41:49 -05:00
|
|
|
self.accel = toolhead.max_accel
|
2022-10-10 01:07:04 +02:00
|
|
|
self.junction_deviation = toolhead.junction_deviation
|
2020-01-02 19:32:10 -05:00
|
|
|
self.timing_callbacks = []
|
2019-01-04 12:42:55 -05:00
|
|
|
velocity = min(speed, toolhead.max_velocity)
|
2017-01-31 11:04:49 -05:00
|
|
|
self.is_kinematic_move = True
|
2025-03-21 22:14:13 -04:00
|
|
|
self.axes_d = axes_d = [ep - sp for sp, ep in zip(start_pos, end_pos)]
|
2017-01-31 11:04:49 -05:00
|
|
|
self.move_d = move_d = math.sqrt(sum([d*d for d in axes_d[:3]]))
|
2018-09-11 13:23:20 -04:00
|
|
|
if move_d < .000000001:
|
2017-01-31 11:04:49 -05:00
|
|
|
# Extrude only move
|
2025-03-21 22:14:13 -04:00
|
|
|
self.end_pos = ((start_pos[0], start_pos[1], start_pos[2])
|
|
|
|
|
+ self.end_pos[3:])
|
2018-09-11 13:23:20 -04:00
|
|
|
axes_d[0] = axes_d[1] = axes_d[2] = 0.
|
2025-03-21 22:14:13 -04:00
|
|
|
self.move_d = move_d = max([abs(ad) for ad in axes_d[3:]])
|
2019-11-06 08:41:50 -05:00
|
|
|
inv_move_d = 0.
|
|
|
|
|
if move_d:
|
|
|
|
|
inv_move_d = 1. / move_d
|
2019-01-04 12:42:55 -05:00
|
|
|
self.accel = 99999999.9
|
|
|
|
|
velocity = speed
|
2017-01-31 11:04:49 -05:00
|
|
|
self.is_kinematic_move = False
|
2019-11-06 08:41:50 -05:00
|
|
|
else:
|
|
|
|
|
inv_move_d = 1. / move_d
|
|
|
|
|
self.axes_r = [d * inv_move_d for d in axes_d]
|
2019-01-04 12:42:55 -05:00
|
|
|
self.min_move_t = move_d / velocity
|
2017-01-14 13:35:27 -05:00
|
|
|
# Junction speeds are tracked in velocity squared. The
|
|
|
|
|
# delta_v2 is the maximum amount of this squared-velocity that
|
|
|
|
|
# can change in this move.
|
|
|
|
|
self.max_start_v2 = 0.
|
2019-01-04 12:42:55 -05:00
|
|
|
self.max_cruise_v2 = velocity**2
|
2017-01-14 13:35:27 -05:00
|
|
|
self.delta_v2 = 2.0 * move_d * self.accel
|
2024-12-06 11:54:26 +09:00
|
|
|
self.next_junction_v2 = 999999999.9
|
2025-09-26 01:22:57 -04:00
|
|
|
# Setup for minimum_cruise_ratio checks
|
|
|
|
|
self.max_mcr_start_v2 = 0.
|
|
|
|
|
self.mcr_delta_v2 = 2.0 * move_d * toolhead.mcr_pseudo_accel
|
2016-09-30 14:47:45 -04:00
|
|
|
def limit_speed(self, speed, accel):
|
2017-02-11 12:29:19 -05:00
|
|
|
speed2 = speed**2
|
|
|
|
|
if speed2 < self.max_cruise_v2:
|
|
|
|
|
self.max_cruise_v2 = speed2
|
|
|
|
|
self.min_move_t = self.move_d / speed
|
2017-01-31 11:04:49 -05:00
|
|
|
self.accel = min(self.accel, accel)
|
|
|
|
|
self.delta_v2 = 2.0 * self.move_d * self.accel
|
2025-09-26 01:22:57 -04:00
|
|
|
self.mcr_delta_v2 = min(self.mcr_delta_v2, self.delta_v2)
|
2024-12-06 11:54:26 +09:00
|
|
|
def limit_next_junction_speed(self, speed):
|
|
|
|
|
self.next_junction_v2 = min(self.next_junction_v2, speed**2)
|
2020-09-03 16:22:54 -04:00
|
|
|
def move_error(self, msg="Move out of range"):
|
2020-09-04 11:41:57 -04:00
|
|
|
ep = self.end_pos
|
|
|
|
|
m = "%s: %.3f %.3f %.3f [%.3f]" % (msg, ep[0], ep[1], ep[2], ep[3])
|
|
|
|
|
return self.toolhead.printer.command_error(m)
|
2016-07-07 15:52:44 -04:00
|
|
|
def calc_junction(self, prev_move):
|
2017-09-03 14:10:21 -04:00
|
|
|
if not self.is_kinematic_move or not prev_move.is_kinematic_move:
|
2016-09-30 14:47:45 -04:00
|
|
|
return
|
2025-03-21 22:14:13 -04:00
|
|
|
# Allow extra axes to calculate maximum junction
|
|
|
|
|
ea_v2 = [ea.calc_junction(prev_move, self, e_index+3)
|
|
|
|
|
for e_index, ea in enumerate(self.toolhead.extra_axes)]
|
|
|
|
|
max_start_v2 = min([self.max_cruise_v2,
|
|
|
|
|
prev_move.max_cruise_v2, prev_move.next_junction_v2,
|
|
|
|
|
prev_move.max_start_v2 + prev_move.delta_v2]
|
|
|
|
|
+ ea_v2)
|
2019-02-27 13:11:12 -05:00
|
|
|
# Find max velocity using "approximated centripetal velocity"
|
2019-11-06 08:41:50 -05:00
|
|
|
axes_r = self.axes_r
|
|
|
|
|
prev_axes_r = prev_move.axes_r
|
|
|
|
|
junction_cos_theta = -(axes_r[0] * prev_axes_r[0]
|
|
|
|
|
+ axes_r[1] * prev_axes_r[1]
|
|
|
|
|
+ axes_r[2] * prev_axes_r[2])
|
2024-11-27 22:34:17 -05:00
|
|
|
sin_theta_d2 = math.sqrt(max(0.5*(1.0-junction_cos_theta), 0.))
|
|
|
|
|
cos_theta_d2 = math.sqrt(max(0.5*(1.0+junction_cos_theta), 0.))
|
|
|
|
|
one_minus_sin_theta_d2 = 1. - sin_theta_d2
|
|
|
|
|
if one_minus_sin_theta_d2 > 0. and cos_theta_d2 > 0.:
|
|
|
|
|
R_jd = sin_theta_d2 / one_minus_sin_theta_d2
|
|
|
|
|
move_jd_v2 = R_jd * self.junction_deviation * self.accel
|
|
|
|
|
pmove_jd_v2 = R_jd * prev_move.junction_deviation * prev_move.accel
|
|
|
|
|
# Approximated circle must contact moves no further than mid-move
|
|
|
|
|
# centripetal_v2 = .5 * self.move_d * self.accel * tan_theta_d2
|
|
|
|
|
quarter_tan_theta_d2 = .25 * sin_theta_d2 / cos_theta_d2
|
|
|
|
|
move_centripetal_v2 = self.delta_v2 * quarter_tan_theta_d2
|
|
|
|
|
pmove_centripetal_v2 = prev_move.delta_v2 * quarter_tan_theta_d2
|
|
|
|
|
max_start_v2 = min(max_start_v2, move_jd_v2, pmove_jd_v2,
|
|
|
|
|
move_centripetal_v2, pmove_centripetal_v2)
|
2020-02-28 22:27:23 -05:00
|
|
|
# Apply limits
|
2024-11-27 22:34:17 -05:00
|
|
|
self.max_start_v2 = max_start_v2
|
2025-09-26 01:22:57 -04:00
|
|
|
self.max_mcr_start_v2 = min(
|
|
|
|
|
max_start_v2, prev_move.max_mcr_start_v2 + prev_move.mcr_delta_v2)
|
2017-01-27 22:06:54 -05:00
|
|
|
def set_junction(self, start_v2, cruise_v2, end_v2):
|
2016-07-11 13:21:27 -04:00
|
|
|
# Determine accel, cruise, and decel portions of the move distance
|
2019-11-06 08:23:16 -05:00
|
|
|
half_inv_accel = .5 / self.accel
|
|
|
|
|
accel_d = (cruise_v2 - start_v2) * half_inv_accel
|
|
|
|
|
decel_d = (cruise_v2 - end_v2) * half_inv_accel
|
|
|
|
|
cruise_d = self.move_d - accel_d - decel_d
|
2016-07-07 16:01:58 -04:00
|
|
|
# Determine move velocities
|
2017-01-14 13:35:27 -05:00
|
|
|
self.start_v = start_v = math.sqrt(start_v2)
|
|
|
|
|
self.cruise_v = cruise_v = math.sqrt(cruise_v2)
|
|
|
|
|
self.end_v = end_v = math.sqrt(end_v2)
|
2016-07-11 13:21:27 -04:00
|
|
|
# Determine time spent in each portion of move (time is the
|
|
|
|
|
# distance divided by average velocity)
|
2019-11-06 08:23:16 -05:00
|
|
|
self.accel_t = accel_d / ((start_v + cruise_v) * 0.5)
|
|
|
|
|
self.cruise_t = cruise_d / cruise_v
|
|
|
|
|
self.decel_t = decel_d / ((end_v + cruise_v) * 0.5)
|
2016-07-07 15:52:44 -04:00
|
|
|
|
2017-02-11 12:29:19 -05:00
|
|
|
LOOKAHEAD_FLUSH_TIME = 0.250
|
|
|
|
|
|
2016-07-07 16:01:58 -04:00
|
|
|
# Class to track a list of pending move requests and to facilitate
|
|
|
|
|
# "look-ahead" across moves to reduce acceleration between moves.
|
2024-01-18 12:16:47 -05:00
|
|
|
class LookAheadQueue:
|
2025-04-12 15:54:39 -04:00
|
|
|
def __init__(self):
|
2016-07-07 16:01:58 -04:00
|
|
|
self.queue = []
|
2017-02-11 12:29:19 -05:00
|
|
|
self.junction_flush = LOOKAHEAD_FLUSH_TIME
|
2016-09-19 13:18:55 -04:00
|
|
|
def reset(self):
|
|
|
|
|
del self.queue[:]
|
2017-02-11 12:29:19 -05:00
|
|
|
self.junction_flush = LOOKAHEAD_FLUSH_TIME
|
2017-02-11 14:43:36 -05:00
|
|
|
def set_flush_time(self, flush_time):
|
|
|
|
|
self.junction_flush = flush_time
|
2020-01-02 19:32:10 -05:00
|
|
|
def get_last(self):
|
|
|
|
|
if self.queue:
|
|
|
|
|
return self.queue[-1]
|
|
|
|
|
return None
|
2016-07-07 16:01:58 -04:00
|
|
|
def flush(self, lazy=False):
|
2017-02-11 12:29:19 -05:00
|
|
|
self.junction_flush = LOOKAHEAD_FLUSH_TIME
|
2017-01-27 22:06:54 -05:00
|
|
|
update_flush_count = lazy
|
|
|
|
|
queue = self.queue
|
|
|
|
|
flush_count = len(queue)
|
2016-07-11 13:21:27 -04:00
|
|
|
# Traverse queue from last to first move and determine maximum
|
|
|
|
|
# junction speed assuming the robot comes to a complete stop
|
|
|
|
|
# after the last move.
|
2025-09-25 14:32:05 -04:00
|
|
|
junction_info = [None] * flush_count
|
2025-09-26 01:22:57 -04:00
|
|
|
next_start_v2 = next_mcr_start_v2 = peak_cruise_v2 = 0.
|
2025-09-25 14:32:05 -04:00
|
|
|
pending_cv2_assign = 0
|
2019-11-02 21:08:07 -04:00
|
|
|
for i in range(flush_count-1, -1, -1):
|
2017-01-27 22:06:54 -05:00
|
|
|
move = queue[i]
|
2025-09-26 01:22:57 -04:00
|
|
|
reachable_start_v2 = next_start_v2 + move.delta_v2
|
2017-01-14 13:35:27 -05:00
|
|
|
start_v2 = min(move.max_start_v2, reachable_start_v2)
|
2025-09-25 14:32:05 -04:00
|
|
|
cruise_v2 = None
|
|
|
|
|
pending_cv2_assign += 1
|
2025-09-26 01:22:57 -04:00
|
|
|
reach_mcr_start_v2 = next_mcr_start_v2 + move.mcr_delta_v2
|
|
|
|
|
mcr_start_v2 = min(move.max_mcr_start_v2, reach_mcr_start_v2)
|
|
|
|
|
if mcr_start_v2 < reach_mcr_start_v2:
|
2017-01-31 15:29:16 -05:00
|
|
|
# It's possible for this move to accelerate
|
2025-09-26 01:22:57 -04:00
|
|
|
if (mcr_start_v2 + move.mcr_delta_v2 > next_mcr_start_v2
|
2025-09-25 14:32:05 -04:00
|
|
|
or pending_cv2_assign > 1):
|
|
|
|
|
# This move can both accel and decel, or this is a
|
|
|
|
|
# full accel move followed by a full decel move
|
2017-01-31 15:29:16 -05:00
|
|
|
if update_flush_count and peak_cruise_v2:
|
2025-09-26 11:43:19 -04:00
|
|
|
flush_count = i + pending_cv2_assign
|
2017-01-31 15:29:16 -05:00
|
|
|
update_flush_count = False
|
2025-09-25 14:32:05 -04:00
|
|
|
peak_cruise_v2 = (mcr_start_v2 + reach_mcr_start_v2) * .5
|
|
|
|
|
cruise_v2 = min((start_v2 + reachable_start_v2) * .5
|
|
|
|
|
, move.max_cruise_v2, peak_cruise_v2)
|
|
|
|
|
pending_cv2_assign = 0
|
|
|
|
|
junction_info[i] = (move, start_v2, cruise_v2, next_start_v2)
|
2025-09-26 01:22:57 -04:00
|
|
|
next_start_v2 = start_v2
|
|
|
|
|
next_mcr_start_v2 = mcr_start_v2
|
2019-11-02 21:08:07 -04:00
|
|
|
if update_flush_count or not flush_count:
|
2025-04-12 15:54:39 -04:00
|
|
|
return []
|
2025-09-25 14:32:05 -04:00
|
|
|
# Traverse queue in forward direction to propagate cruise_v2
|
|
|
|
|
prev_cruise_v2 = 0.
|
|
|
|
|
for i in range(flush_count):
|
|
|
|
|
move, start_v2, cruise_v2, next_start_v2 = junction_info[i]
|
|
|
|
|
if cruise_v2 is None:
|
|
|
|
|
# This move can't accelerate - propagate cruise_v2 from previous
|
|
|
|
|
cruise_v2 = min(prev_cruise_v2, start_v2)
|
|
|
|
|
move.set_junction(min(start_v2, cruise_v2), cruise_v2
|
|
|
|
|
, min(next_start_v2, cruise_v2))
|
|
|
|
|
prev_cruise_v2 = cruise_v2
|
2016-07-11 13:21:27 -04:00
|
|
|
# Remove processed moves from the queue
|
2025-04-12 15:54:39 -04:00
|
|
|
res = queue[:flush_count]
|
2019-11-02 21:08:07 -04:00
|
|
|
del queue[:flush_count]
|
2025-04-12 15:54:39 -04:00
|
|
|
return res
|
2016-07-07 16:01:58 -04:00
|
|
|
def add_move(self, move):
|
|
|
|
|
self.queue.append(move)
|
|
|
|
|
if len(self.queue) == 1:
|
|
|
|
|
return
|
2016-07-07 16:08:00 -04:00
|
|
|
move.calc_junction(self.queue[-2])
|
2017-02-11 12:29:19 -05:00
|
|
|
self.junction_flush -= move.min_move_t
|
2025-04-12 15:54:39 -04:00
|
|
|
# Check if enough moves have been queued to reach the target flush time.
|
|
|
|
|
return self.junction_flush <= 0.
|
2016-07-07 16:01:58 -04:00
|
|
|
|
2023-11-26 19:01:24 -05:00
|
|
|
BUFFER_TIME_HIGH = 2.0
|
|
|
|
|
BUFFER_TIME_START = 0.250
|
2016-07-07 15:52:44 -04:00
|
|
|
|
2016-07-07 16:01:58 -04:00
|
|
|
# Main code to track events (and their timing) on the printer toolhead
|
2016-07-07 15:52:44 -04:00
|
|
|
class ToolHead:
|
2018-06-21 13:47:39 -04:00
|
|
|
def __init__(self, config):
|
|
|
|
|
self.printer = config.get_printer()
|
|
|
|
|
self.reactor = self.printer.get_reactor()
|
2025-08-12 20:07:08 -04:00
|
|
|
self.mcu = self.printer.lookup_object('mcu')
|
2025-04-12 15:54:39 -04:00
|
|
|
self.lookahead = LookAheadQueue()
|
2024-01-18 12:16:47 -05:00
|
|
|
self.lookahead.set_flush_time(BUFFER_TIME_HIGH)
|
2018-07-08 14:08:21 -04:00
|
|
|
self.commanded_pos = [0., 0., 0., 0.]
|
|
|
|
|
# Velocity and acceleration control
|
2017-09-03 15:17:02 -04:00
|
|
|
self.max_velocity = config.getfloat('max_velocity', above=0.)
|
2017-04-11 11:37:09 -04:00
|
|
|
self.max_accel = config.getfloat('max_accel', above=0.)
|
2024-03-21 22:00:32 -04:00
|
|
|
self.min_cruise_ratio = config.getfloat('minimum_cruise_ratio',
|
2025-08-04 12:02:35 -04:00
|
|
|
0.5, below=1., minval=0.)
|
2018-07-08 14:08:21 -04:00
|
|
|
self.square_corner_velocity = config.getfloat(
|
|
|
|
|
'square_corner_velocity', 5., minval=0.)
|
2025-09-26 01:22:57 -04:00
|
|
|
self.junction_deviation = self.mcr_pseudo_accel = 0.
|
2018-07-08 14:08:21 -04:00
|
|
|
self._calc_junction_deviation()
|
2023-11-26 19:05:36 -05:00
|
|
|
# Input stall detection
|
|
|
|
|
self.check_stall_time = 0.
|
|
|
|
|
self.print_stall = 0
|
|
|
|
|
# Input pause tracking
|
|
|
|
|
self.can_pause = True
|
|
|
|
|
if self.mcu.is_fileoutput():
|
|
|
|
|
self.can_pause = False
|
|
|
|
|
self.need_check_pause = -1.
|
2016-07-07 15:52:44 -04:00
|
|
|
# Print time tracking
|
|
|
|
|
self.print_time = 0.
|
2023-11-28 11:27:25 -05:00
|
|
|
self.special_queuing_state = "NeedPrime"
|
2023-11-27 18:02:47 -05:00
|
|
|
self.priming_timer = None
|
2025-08-04 22:41:15 -04:00
|
|
|
# Setup for generating moves
|
2025-08-04 21:57:45 -04:00
|
|
|
self.motion_queuing = self.printer.load_object(config, 'motion_queuing')
|
2025-09-02 13:45:29 -04:00
|
|
|
self.motion_queuing.register_flush_callback(self._handle_step_flush,
|
|
|
|
|
can_add_trapq=True)
|
2025-08-04 22:41:15 -04:00
|
|
|
self.trapq = self.motion_queuing.allocate_trapq()
|
|
|
|
|
self.trapq_append = self.motion_queuing.lookup_trapq_append()
|
2017-09-03 15:17:02 -04:00
|
|
|
# Create kinematics class
|
2021-01-08 12:07:45 -05:00
|
|
|
gcode = self.printer.lookup_object('gcode')
|
|
|
|
|
self.Coord = gcode.Coord
|
2025-03-21 22:14:13 -04:00
|
|
|
extruder = kinematics.extruder.DummyExtruder(self.printer)
|
|
|
|
|
self.extra_axes = [extruder]
|
2018-07-12 22:15:45 -04:00
|
|
|
kin_name = config.get('kinematics')
|
|
|
|
|
try:
|
|
|
|
|
mod = importlib.import_module('kinematics.' + kin_name)
|
|
|
|
|
self.kin = mod.load_kinematics(self, config)
|
2018-08-30 10:14:32 -04:00
|
|
|
except config.error as e:
|
|
|
|
|
raise
|
|
|
|
|
except self.printer.lookup_object('pins').error as e:
|
|
|
|
|
raise
|
2018-07-12 22:15:45 -04:00
|
|
|
except:
|
|
|
|
|
msg = "Error loading kinematics '%s'" % (kin_name,)
|
|
|
|
|
logging.exception(msg)
|
|
|
|
|
raise config.error(msg)
|
2025-08-04 13:45:59 -04:00
|
|
|
# Register handlers
|
2023-11-26 19:05:36 -05:00
|
|
|
self.printer.register_event_handler("klippy:shutdown",
|
|
|
|
|
self._handle_shutdown)
|
2025-08-12 20:07:08 -04:00
|
|
|
# Print time tracking
|
2025-08-12 12:23:27 -04:00
|
|
|
def _advance_move_time(self, next_print_time):
|
|
|
|
|
self.print_time = max(self.print_time, next_print_time)
|
2018-10-15 18:24:15 -04:00
|
|
|
def _calc_print_time(self):
|
2018-10-18 12:04:50 -04:00
|
|
|
curtime = self.reactor.monotonic()
|
|
|
|
|
est_print_time = self.mcu.estimated_print_time(curtime)
|
2025-08-12 20:07:08 -04:00
|
|
|
kin_time = self.motion_queuing.calc_step_gen_restart(est_print_time)
|
2023-11-26 19:01:24 -05:00
|
|
|
min_print_time = max(est_print_time + BUFFER_TIME_START, kin_time)
|
2019-09-17 22:53:17 -04:00
|
|
|
if min_print_time > self.print_time:
|
2020-08-15 11:23:50 -04:00
|
|
|
self.print_time = min_print_time
|
2018-10-18 12:04:50 -04:00
|
|
|
self.printer.send_event("toolhead:sync_print_time",
|
|
|
|
|
curtime, est_print_time, self.print_time)
|
2025-04-12 15:54:39 -04:00
|
|
|
def _process_lookahead(self, lazy=False):
|
|
|
|
|
moves = self.lookahead.flush(lazy=lazy)
|
|
|
|
|
if not moves:
|
|
|
|
|
return
|
2019-10-29 18:58:45 -04:00
|
|
|
# Resync print_time if necessary
|
|
|
|
|
if self.special_queuing_state:
|
2025-04-12 16:48:36 -04:00
|
|
|
# Transition from "NeedPrime"/"Priming" state to main state
|
|
|
|
|
self.special_queuing_state = ""
|
|
|
|
|
self.need_check_pause = -1.
|
2019-10-29 18:58:45 -04:00
|
|
|
self._calc_print_time()
|
|
|
|
|
# Queue moves into trapezoid motion queue (trapq)
|
|
|
|
|
next_move_time = self.print_time
|
|
|
|
|
for move in moves:
|
|
|
|
|
if move.is_kinematic_move:
|
|
|
|
|
self.trapq_append(
|
|
|
|
|
self.trapq, next_move_time,
|
|
|
|
|
move.accel_t, move.cruise_t, move.decel_t,
|
|
|
|
|
move.start_pos[0], move.start_pos[1], move.start_pos[2],
|
2019-11-06 08:41:50 -05:00
|
|
|
move.axes_r[0], move.axes_r[1], move.axes_r[2],
|
2019-10-29 18:58:45 -04:00
|
|
|
move.start_v, move.cruise_v, move.accel)
|
2025-03-21 22:14:13 -04:00
|
|
|
for e_index, ea in enumerate(self.extra_axes):
|
|
|
|
|
if move.axes_d[e_index + 3]:
|
|
|
|
|
ea.process_move(next_move_time, move, e_index + 3)
|
2019-11-05 15:42:19 -05:00
|
|
|
next_move_time = (next_move_time + move.accel_t
|
|
|
|
|
+ move.cruise_t + move.decel_t)
|
2020-01-02 19:32:10 -05:00
|
|
|
for cb in move.timing_callbacks:
|
|
|
|
|
cb(next_move_time)
|
2019-10-29 18:58:45 -04:00
|
|
|
# Generate steps for moves
|
2023-11-27 19:54:39 -05:00
|
|
|
self._advance_move_time(next_move_time)
|
2025-09-02 13:45:29 -04:00
|
|
|
self.motion_queuing.note_mcu_movequeue_activity(next_move_time)
|
2025-09-06 22:22:12 -04:00
|
|
|
def _flush_lookahead(self, is_runout=False):
|
2025-08-13 14:07:03 -04:00
|
|
|
# Transit from "NeedPrime"/"Priming"/main state to "NeedPrime"
|
2025-09-06 22:22:12 -04:00
|
|
|
prev_print_time = self.print_time
|
2025-04-12 15:54:39 -04:00
|
|
|
self._process_lookahead()
|
2023-11-28 11:27:25 -05:00
|
|
|
self.special_queuing_state = "NeedPrime"
|
2023-11-26 19:05:36 -05:00
|
|
|
self.need_check_pause = -1.
|
2024-01-18 12:16:47 -05:00
|
|
|
self.lookahead.set_flush_time(BUFFER_TIME_HIGH)
|
2023-11-26 19:05:36 -05:00
|
|
|
self.check_stall_time = 0.
|
2025-09-06 22:22:12 -04:00
|
|
|
if is_runout and prev_print_time != self.print_time:
|
|
|
|
|
self.check_stall_time = self.print_time
|
2023-11-28 11:27:25 -05:00
|
|
|
def flush_step_generation(self):
|
|
|
|
|
self._flush_lookahead()
|
2025-09-02 13:23:02 -04:00
|
|
|
self.motion_queuing.flush_all_steps()
|
2017-02-11 14:43:36 -05:00
|
|
|
def get_last_move_time(self):
|
2019-06-25 20:32:33 -04:00
|
|
|
if self.special_queuing_state:
|
2023-11-28 11:27:25 -05:00
|
|
|
self._flush_lookahead()
|
2018-10-15 18:24:15 -04:00
|
|
|
self._calc_print_time()
|
2023-11-28 11:27:25 -05:00
|
|
|
else:
|
2025-04-12 15:54:39 -04:00
|
|
|
self._process_lookahead()
|
2018-10-15 18:24:15 -04:00
|
|
|
return self.print_time
|
2023-11-26 19:05:36 -05:00
|
|
|
def _check_pause(self):
|
2017-02-06 14:07:55 -05:00
|
|
|
eventtime = self.reactor.monotonic()
|
2023-11-27 18:02:47 -05:00
|
|
|
est_print_time = self.mcu.estimated_print_time(eventtime)
|
|
|
|
|
buffer_time = self.print_time - est_print_time
|
2019-06-25 20:32:33 -04:00
|
|
|
if self.special_queuing_state:
|
2023-11-26 19:05:36 -05:00
|
|
|
if self.check_stall_time:
|
2023-11-28 11:27:25 -05:00
|
|
|
# Was in "NeedPrime" state and got there from idle input
|
2023-11-26 19:05:36 -05:00
|
|
|
if est_print_time < self.check_stall_time:
|
2018-01-12 16:24:47 -05:00
|
|
|
self.print_stall += 1
|
2023-11-26 19:05:36 -05:00
|
|
|
self.check_stall_time = 0.
|
2023-11-28 11:27:25 -05:00
|
|
|
# Transition from "NeedPrime"/"Priming" state to "Priming" state
|
2019-06-25 20:32:33 -04:00
|
|
|
self.special_queuing_state = "Priming"
|
2023-11-26 19:05:36 -05:00
|
|
|
self.need_check_pause = -1.
|
2023-11-27 18:02:47 -05:00
|
|
|
if self.priming_timer is None:
|
|
|
|
|
self.priming_timer = self.reactor.register_timer(
|
|
|
|
|
self._priming_handler)
|
2025-09-02 13:45:29 -04:00
|
|
|
wtime = eventtime + max(0.100, buffer_time - BUFFER_TIME_HIGH)
|
2023-11-27 18:02:47 -05:00
|
|
|
self.reactor.update_timer(self.priming_timer, wtime)
|
2023-11-26 19:05:36 -05:00
|
|
|
# Check if there are lots of queued moves and pause if so
|
2016-12-09 09:41:46 -05:00
|
|
|
while 1:
|
2023-11-26 19:05:36 -05:00
|
|
|
pause_time = buffer_time - BUFFER_TIME_HIGH
|
|
|
|
|
if pause_time <= 0.:
|
2016-12-09 09:41:46 -05:00
|
|
|
break
|
2019-11-07 18:06:46 -05:00
|
|
|
if not self.can_pause:
|
2023-11-26 19:05:36 -05:00
|
|
|
self.need_check_pause = self.reactor.NEVER
|
2016-12-09 09:41:46 -05:00
|
|
|
return
|
2023-11-26 19:05:36 -05:00
|
|
|
eventtime = self.reactor.pause(eventtime + min(1., pause_time))
|
2023-11-27 18:02:47 -05:00
|
|
|
est_print_time = self.mcu.estimated_print_time(eventtime)
|
|
|
|
|
buffer_time = self.print_time - est_print_time
|
2019-06-25 20:32:33 -04:00
|
|
|
if not self.special_queuing_state:
|
2023-11-26 19:05:36 -05:00
|
|
|
# In main state - defer pause checking until needed
|
|
|
|
|
self.need_check_pause = est_print_time + BUFFER_TIME_HIGH + 0.100
|
2023-11-27 18:02:47 -05:00
|
|
|
def _priming_handler(self, eventtime):
|
|
|
|
|
self.reactor.unregister_timer(self.priming_timer)
|
|
|
|
|
self.priming_timer = None
|
|
|
|
|
try:
|
|
|
|
|
if self.special_queuing_state == "Priming":
|
2025-09-06 22:22:12 -04:00
|
|
|
self._flush_lookahead(is_runout=True)
|
2023-11-27 18:02:47 -05:00
|
|
|
except:
|
|
|
|
|
logging.exception("Exception in priming_handler")
|
|
|
|
|
self.printer.invoke_shutdown("Exception in priming_handler")
|
|
|
|
|
return self.reactor.NEVER
|
2025-09-02 13:45:29 -04:00
|
|
|
def _handle_step_flush(self, flush_time, step_gen_time):
|
2025-08-12 14:27:21 -04:00
|
|
|
if self.special_queuing_state:
|
2025-09-02 13:45:29 -04:00
|
|
|
return
|
2025-08-12 14:27:21 -04:00
|
|
|
# In "main" state - flush lookahead if buffer runs low
|
2025-09-02 13:45:29 -04:00
|
|
|
kin_flush_delay = self.motion_queuing.get_kin_flush_delay()
|
2025-09-15 19:20:00 -04:00
|
|
|
if step_gen_time >= self.print_time - kin_flush_delay - 0.001:
|
2025-09-02 13:45:29 -04:00
|
|
|
self._flush_lookahead(is_runout=True)
|
2016-07-07 15:52:44 -04:00
|
|
|
# Movement commands
|
|
|
|
|
def get_position(self):
|
|
|
|
|
return list(self.commanded_pos)
|
2025-01-10 11:27:30 -05:00
|
|
|
def set_position(self, newpos, homing_axes=""):
|
2019-11-13 23:34:21 -05:00
|
|
|
self.flush_step_generation()
|
2021-07-23 12:46:14 -04:00
|
|
|
ffi_main, ffi_lib = chelper.get_ffi()
|
|
|
|
|
ffi_lib.trapq_set_position(self.trapq, self.print_time,
|
|
|
|
|
newpos[0], newpos[1], newpos[2])
|
2025-03-21 22:12:30 -04:00
|
|
|
self.commanded_pos[:3] = newpos[:3]
|
2018-01-16 18:58:41 -05:00
|
|
|
self.kin.set_position(newpos, homing_axes)
|
2020-08-16 22:02:23 -04:00
|
|
|
self.printer.send_event("toolhead:set_position")
|
2024-12-06 11:54:26 +09:00
|
|
|
def limit_next_junction_speed(self, speed):
|
|
|
|
|
last_move = self.lookahead.get_last()
|
|
|
|
|
if last_move is not None:
|
|
|
|
|
last_move.limit_next_junction_speed(speed)
|
2016-11-30 22:34:38 -05:00
|
|
|
def move(self, newpos, speed):
|
2017-01-14 12:41:49 -05:00
|
|
|
move = Move(self, self.commanded_pos, newpos, speed)
|
2016-10-25 19:11:05 -04:00
|
|
|
if not move.move_d:
|
|
|
|
|
return
|
2016-12-28 11:48:40 -05:00
|
|
|
if move.is_kinematic_move:
|
|
|
|
|
self.kin.check_move(move)
|
2025-03-21 22:14:13 -04:00
|
|
|
for e_index, ea in enumerate(self.extra_axes):
|
|
|
|
|
if move.axes_d[e_index + 3]:
|
|
|
|
|
ea.check_move(move, e_index + 3)
|
2018-09-11 13:45:33 -04:00
|
|
|
self.commanded_pos[:] = move.end_pos
|
2025-04-12 15:54:39 -04:00
|
|
|
want_flush = self.lookahead.add_move(move)
|
|
|
|
|
if want_flush:
|
|
|
|
|
self._process_lookahead(lazy=True)
|
2023-11-26 19:05:36 -05:00
|
|
|
if self.print_time > self.need_check_pause:
|
|
|
|
|
self._check_pause()
|
2020-08-16 22:43:03 -04:00
|
|
|
def manual_move(self, coord, speed):
|
|
|
|
|
curpos = list(self.commanded_pos)
|
|
|
|
|
for i in range(len(coord)):
|
|
|
|
|
if coord[i] is not None:
|
|
|
|
|
curpos[i] = coord[i]
|
|
|
|
|
self.move(curpos, speed)
|
|
|
|
|
self.printer.send_event("toolhead:manual_move")
|
2019-06-27 13:17:03 -04:00
|
|
|
def dwell(self, delay):
|
2025-09-29 11:31:31 -04:00
|
|
|
self._flush_lookahead()
|
2019-10-29 18:58:45 -04:00
|
|
|
next_print_time = self.get_last_move_time() + max(0., delay)
|
2023-11-27 19:54:39 -05:00
|
|
|
self._advance_move_time(next_print_time)
|
2023-11-26 19:05:36 -05:00
|
|
|
self._check_pause()
|
2016-12-28 21:24:12 -05:00
|
|
|
def wait_moves(self):
|
2017-02-11 14:43:36 -05:00
|
|
|
self._flush_lookahead()
|
2017-02-06 13:31:34 -05:00
|
|
|
eventtime = self.reactor.monotonic()
|
2019-06-25 20:32:33 -04:00
|
|
|
while (not self.special_queuing_state
|
2017-09-12 12:24:44 -04:00
|
|
|
or self.print_time >= self.mcu.estimated_print_time(eventtime)):
|
2019-11-07 18:06:46 -05:00
|
|
|
if not self.can_pause:
|
|
|
|
|
break
|
2016-12-28 21:24:12 -05:00
|
|
|
eventtime = self.reactor.pause(eventtime + 0.100)
|
2019-11-13 11:02:26 -05:00
|
|
|
def set_extruder(self, extruder, extrude_pos):
|
2025-03-21 22:14:13 -04:00
|
|
|
# XXX - should use add_extra_axis
|
|
|
|
|
self.extra_axes[0] = extruder
|
2017-04-29 14:56:39 -04:00
|
|
|
self.commanded_pos[3] = extrude_pos
|
2018-05-20 12:52:19 -04:00
|
|
|
def get_extruder(self):
|
2025-03-21 22:14:13 -04:00
|
|
|
return self.extra_axes[0]
|
|
|
|
|
def add_extra_axis(self, ea, axis_pos):
|
|
|
|
|
self._flush_lookahead()
|
|
|
|
|
self.extra_axes.append(ea)
|
|
|
|
|
self.commanded_pos.append(axis_pos)
|
|
|
|
|
self.printer.send_event("toolhead:update_extra_axes")
|
|
|
|
|
def remove_extra_axis(self, ea):
|
|
|
|
|
self._flush_lookahead()
|
|
|
|
|
if ea not in self.extra_axes:
|
|
|
|
|
return
|
|
|
|
|
ea_index = self.extra_axes.index(ea) + 3
|
|
|
|
|
self.commanded_pos.pop(ea_index)
|
|
|
|
|
self.extra_axes.pop(ea_index - 3)
|
|
|
|
|
self.printer.send_event("toolhead:update_extra_axes")
|
|
|
|
|
def get_extra_axes(self):
|
|
|
|
|
return [None, None, None] + self.extra_axes
|
2019-10-29 18:58:45 -04:00
|
|
|
# Homing "drip move" handling
|
2025-04-12 16:48:36 -04:00
|
|
|
def _drip_load_trapq(self, submit_move):
|
|
|
|
|
# Queue move into trapezoid motion queue (trapq)
|
|
|
|
|
if submit_move.move_d:
|
|
|
|
|
self.commanded_pos[:] = submit_move.end_pos
|
|
|
|
|
self.lookahead.add_move(submit_move)
|
|
|
|
|
moves = self.lookahead.flush()
|
|
|
|
|
self._calc_print_time()
|
2025-08-13 14:07:03 -04:00
|
|
|
start_time = end_time = self.print_time
|
2025-04-12 16:48:36 -04:00
|
|
|
for move in moves:
|
|
|
|
|
self.trapq_append(
|
2025-08-13 14:07:03 -04:00
|
|
|
self.trapq, end_time,
|
2025-04-12 16:48:36 -04:00
|
|
|
move.accel_t, move.cruise_t, move.decel_t,
|
|
|
|
|
move.start_pos[0], move.start_pos[1], move.start_pos[2],
|
|
|
|
|
move.axes_r[0], move.axes_r[1], move.axes_r[2],
|
|
|
|
|
move.start_v, move.cruise_v, move.accel)
|
2025-08-13 14:07:03 -04:00
|
|
|
end_time = end_time + move.accel_t + move.cruise_t + move.decel_t
|
2025-04-12 16:48:36 -04:00
|
|
|
self.lookahead.reset()
|
2025-08-13 14:07:03 -04:00
|
|
|
return start_time, end_time
|
2025-04-12 16:48:36 -04:00
|
|
|
def drip_move(self, newpos, speed, drip_completion):
|
|
|
|
|
# Create and verify move is valid
|
|
|
|
|
newpos = newpos[:3] + self.commanded_pos[3:]
|
|
|
|
|
move = Move(self, self.commanded_pos, newpos, speed)
|
|
|
|
|
if move.move_d:
|
|
|
|
|
self.kin.check_move(move)
|
|
|
|
|
# Make sure stepper movement doesn't start before nominal start time
|
2023-11-29 01:04:28 -05:00
|
|
|
kin_flush_delay = self.motion_queuing.get_kin_flush_delay()
|
|
|
|
|
self.dwell(kin_flush_delay)
|
2025-04-12 16:48:36 -04:00
|
|
|
# Transmit move in "drip" mode
|
|
|
|
|
self._process_lookahead()
|
2025-08-13 14:07:03 -04:00
|
|
|
start_time, end_time = self._drip_load_trapq(move)
|
2025-08-12 20:07:08 -04:00
|
|
|
self.motion_queuing.drip_update_time(start_time, end_time,
|
|
|
|
|
drip_completion)
|
2025-04-12 16:48:36 -04:00
|
|
|
# Move finished; cleanup any remnants on trapq
|
2025-08-04 22:41:15 -04:00
|
|
|
self.motion_queuing.wipe_trapq(self.trapq)
|
2017-02-06 14:07:55 -05:00
|
|
|
# Misc commands
|
2018-02-05 13:52:05 -05:00
|
|
|
def stats(self, eventtime):
|
2023-12-30 12:35:42 -05:00
|
|
|
est_print_time = self.mcu.estimated_print_time(eventtime)
|
|
|
|
|
buffer_time = self.print_time - est_print_time
|
2019-06-25 20:32:33 -04:00
|
|
|
is_active = buffer_time > -60. or not self.special_queuing_state
|
2018-02-05 13:52:05 -05:00
|
|
|
return is_active, "print_time=%.3f buffer_time=%.3f print_stall=%d" % (
|
|
|
|
|
self.print_time, max(buffer_time, 0.), self.print_stall)
|
2018-10-18 12:04:50 -04:00
|
|
|
def check_busy(self, eventtime):
|
|
|
|
|
est_print_time = self.mcu.estimated_print_time(eventtime)
|
2024-01-18 12:16:47 -05:00
|
|
|
lookahead_empty = not self.lookahead.queue
|
2018-10-18 12:04:50 -04:00
|
|
|
return self.print_time, est_print_time, lookahead_empty
|
2018-02-20 20:50:06 -05:00
|
|
|
def get_status(self, eventtime):
|
2018-07-12 19:07:54 -04:00
|
|
|
print_time = self.print_time
|
|
|
|
|
estimated_print_time = self.mcu.estimated_print_time(eventtime)
|
2025-03-21 22:14:13 -04:00
|
|
|
extruder = self.extra_axes[0]
|
2019-11-24 19:16:21 -05:00
|
|
|
res = dict(self.kin.get_status(eventtime))
|
2020-08-15 11:23:50 -04:00
|
|
|
res.update({ 'print_time': print_time,
|
2021-04-09 20:44:27 -04:00
|
|
|
'stalls': self.print_stall,
|
2019-11-24 19:16:21 -05:00
|
|
|
'estimated_print_time': estimated_print_time,
|
2025-03-21 22:14:13 -04:00
|
|
|
'extruder': extruder.get_name(),
|
|
|
|
|
'position': self.Coord(*self.commanded_pos[:4]),
|
2020-08-01 11:21:41 -04:00
|
|
|
'max_velocity': self.max_velocity,
|
|
|
|
|
'max_accel': self.max_accel,
|
2023-12-03 18:50:44 -05:00
|
|
|
'minimum_cruise_ratio': self.min_cruise_ratio,
|
2020-08-01 11:21:41 -04:00
|
|
|
'square_corner_velocity': self.square_corner_velocity})
|
2019-11-24 19:16:21 -05:00
|
|
|
return res
|
2019-01-08 09:15:40 -05:00
|
|
|
def _handle_shutdown(self):
|
2019-11-07 18:06:46 -05:00
|
|
|
self.can_pause = False
|
2024-01-18 12:16:47 -05:00
|
|
|
self.lookahead.reset()
|
2017-12-06 09:59:00 -05:00
|
|
|
def get_kinematics(self):
|
|
|
|
|
return self.kin
|
2019-10-27 18:50:53 -04:00
|
|
|
def get_trapq(self):
|
|
|
|
|
return self.trapq
|
2020-01-02 19:32:10 -05:00
|
|
|
def register_lookahead_callback(self, callback):
|
2024-01-18 12:16:47 -05:00
|
|
|
last_move = self.lookahead.get_last()
|
2020-01-02 19:32:10 -05:00
|
|
|
if last_move is None:
|
|
|
|
|
callback(self.get_last_move_time())
|
|
|
|
|
return
|
|
|
|
|
last_move.timing_callbacks.append(callback)
|
2017-09-03 15:17:02 -04:00
|
|
|
def get_max_velocity(self):
|
|
|
|
|
return self.max_velocity, self.max_accel
|
2018-07-08 14:08:21 -04:00
|
|
|
def _calc_junction_deviation(self):
|
|
|
|
|
scv2 = self.square_corner_velocity**2
|
|
|
|
|
self.junction_deviation = scv2 * (math.sqrt(2.) - 1.) / self.max_accel
|
2025-09-26 01:22:57 -04:00
|
|
|
self.mcr_pseudo_accel = self.max_accel * (1. - self.min_cruise_ratio)
|
2025-08-04 13:45:59 -04:00
|
|
|
def set_max_velocities(self, max_velocity, max_accel,
|
|
|
|
|
square_corner_velocity, min_cruise_ratio):
|
|
|
|
|
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 min_cruise_ratio is not None:
|
|
|
|
|
self.min_cruise_ratio = min_cruise_ratio
|
|
|
|
|
self._calc_junction_deviation()
|
|
|
|
|
return (self.max_velocity, self.max_accel,
|
|
|
|
|
self.square_corner_velocity, self.min_cruise_ratio)
|
|
|
|
|
|
|
|
|
|
# Support common G-Code commands relative to the toolhead
|
|
|
|
|
class ToolHeadCommandHelper:
|
|
|
|
|
def __init__(self, config):
|
|
|
|
|
self.printer = config.get_printer()
|
|
|
|
|
self.toolhead = self.printer.lookup_object("toolhead")
|
|
|
|
|
# Register commands
|
|
|
|
|
gcode = self.printer.lookup_object('gcode')
|
|
|
|
|
gcode.register_command('G4', self.cmd_G4)
|
|
|
|
|
gcode.register_command('M400', self.cmd_M400)
|
|
|
|
|
gcode.register_command('SET_VELOCITY_LIMIT',
|
|
|
|
|
self.cmd_SET_VELOCITY_LIMIT,
|
|
|
|
|
desc=self.cmd_SET_VELOCITY_LIMIT_help)
|
|
|
|
|
gcode.register_command('M204', self.cmd_M204)
|
2020-08-16 14:40:04 -04:00
|
|
|
def cmd_G4(self, gcmd):
|
|
|
|
|
# Dwell
|
|
|
|
|
delay = gcmd.get_float('P', 0., minval=0.) / 1000.
|
2025-08-04 13:45:59 -04:00
|
|
|
self.toolhead.dwell(delay)
|
2020-08-16 14:40:04 -04:00
|
|
|
def cmd_M400(self, gcmd):
|
|
|
|
|
# Wait for current moves to finish
|
2025-08-04 13:45:59 -04:00
|
|
|
self.toolhead.wait_moves()
|
2018-04-20 22:13:29 -04:00
|
|
|
cmd_SET_VELOCITY_LIMIT_help = "Set printer velocity limits"
|
2020-04-24 19:54:24 -04:00
|
|
|
def cmd_SET_VELOCITY_LIMIT(self, gcmd):
|
2021-08-31 19:37:48 +02:00
|
|
|
max_velocity = gcmd.get_float('VELOCITY', None, above=0.)
|
|
|
|
|
max_accel = gcmd.get_float('ACCEL', None, above=0.)
|
2020-04-24 19:54:24 -04:00
|
|
|
square_corner_velocity = gcmd.get_float(
|
2021-08-31 19:37:48 +02:00
|
|
|
'SQUARE_CORNER_VELOCITY', None, minval=0.)
|
2023-12-03 18:50:44 -05:00
|
|
|
min_cruise_ratio = gcmd.get_float(
|
|
|
|
|
'MINIMUM_CRUISE_RATIO', None, minval=0., below=1.)
|
2025-08-04 13:45:59 -04:00
|
|
|
mv, ma, scv, mcr = self.toolhead.set_max_velocities(
|
|
|
|
|
max_velocity, max_accel, square_corner_velocity, min_cruise_ratio)
|
2018-04-20 22:13:29 -04:00
|
|
|
msg = ("max_velocity: %.6f\n"
|
|
|
|
|
"max_accel: %.6f\n"
|
2023-12-03 18:50:44 -05:00
|
|
|
"minimum_cruise_ratio: %.6f\n"
|
2025-09-01 21:20:00 -04:00
|
|
|
"square_corner_velocity: %.6f" % (mv, ma, mcr, scv))
|
2018-04-20 22:13:29 -04:00
|
|
|
self.printer.set_rollover_info("toolhead", "toolhead: %s" % (msg,))
|
2023-12-03 18:50:44 -05:00
|
|
|
if (max_velocity is None and max_accel is None
|
|
|
|
|
and square_corner_velocity is None and min_cruise_ratio is None):
|
2021-08-31 19:37:48 +02:00
|
|
|
gcmd.respond_info(msg, log=False)
|
2020-04-24 19:54:24 -04:00
|
|
|
def cmd_M204(self, gcmd):
|
|
|
|
|
# Use S for accel
|
|
|
|
|
accel = gcmd.get_float('S', None, above=0.)
|
|
|
|
|
if accel is None:
|
2018-09-02 12:22:43 -04:00
|
|
|
# Use minimum of P and T for accel
|
2020-04-24 19:54:24 -04:00
|
|
|
p = gcmd.get_float('P', None, above=0.)
|
|
|
|
|
t = gcmd.get_float('T', None, above=0.)
|
|
|
|
|
if p is None or t is None:
|
|
|
|
|
gcmd.respond_info('Invalid M204 command "%s"'
|
|
|
|
|
% (gcmd.get_commandline(),))
|
|
|
|
|
return
|
|
|
|
|
accel = min(p, t)
|
2025-08-04 13:45:59 -04:00
|
|
|
self.toolhead.set_max_velocities(None, accel, None, None)
|
2017-04-29 13:57:02 -04:00
|
|
|
|
2018-07-12 22:26:32 -04:00
|
|
|
def add_printer_objects(config):
|
2025-08-04 13:21:55 -04:00
|
|
|
printer = config.get_printer()
|
|
|
|
|
printer.add_object('toolhead', ToolHead(config))
|
2025-08-04 13:45:59 -04:00
|
|
|
ToolHeadCommandHelper(config)
|
|
|
|
|
# Load default extruder objects
|
2018-07-12 22:15:45 -04:00
|
|
|
kinematics.extruder.add_printer_objects(config)
|
2025-08-04 13:21:55 -04:00
|
|
|
# Load some default modules
|
|
|
|
|
modules = ["gcode_move", "homing", "idle_timeout", "statistics",
|
|
|
|
|
"manual_probe", "tuning_tower", "garbage_collection"]
|
|
|
|
|
for module_name in modules:
|
|
|
|
|
printer.load_object(config, module_name)
|