mirror of
https://github.com/Klipper3d/klipper.git
synced 2025-10-26 07:46:11 +01:00
motion_queuing: Move remaining steppersync logic from mcu module
Move the last parts of the steppersync logic into the motion_queuing module. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
@@ -65,7 +65,8 @@ class PrinterMotionQueuing:
|
||||
ffi_lib.stepcompress_free)
|
||||
self.stepcompress.append((mcu, sc))
|
||||
return sc
|
||||
def allocate_steppersync(self, mcu, serialqueue, move_count):
|
||||
def setup_mcu_movequeue(self, mcu, serialqueue, move_count):
|
||||
# Setup steppersync object for the mcu's main movequeue
|
||||
stepqueues = []
|
||||
for sc_mcu, sc in self.stepcompress:
|
||||
if sc_mcu is mcu:
|
||||
@@ -76,7 +77,8 @@ class PrinterMotionQueuing:
|
||||
move_count),
|
||||
ffi_lib.steppersync_free)
|
||||
self.steppersyncs.append((mcu, ss))
|
||||
return ss
|
||||
mcu_freq = float(mcu.seconds_to_clock(1.))
|
||||
ffi_lib.steppersync_set_time(ss, 0., mcu_freq)
|
||||
def register_flush_callback(self, callback):
|
||||
self.flush_callbacks.append(callback)
|
||||
def unregister_flush_callback(self, callback):
|
||||
@@ -118,9 +120,12 @@ class PrinterMotionQueuing:
|
||||
ffi_main, ffi_lib = chelper.get_ffi()
|
||||
return ffi_lib.trapq_append
|
||||
def stats(self, eventtime):
|
||||
# Hack to globally invoke mcu check_active()
|
||||
for m in self.all_mcus:
|
||||
m.check_active(self.last_step_gen_time, eventtime)
|
||||
# Globally calibrate mcu clocks (and step generation clocks)
|
||||
sync_time = self.last_step_gen_time
|
||||
ffi_main, ffi_lib = chelper.get_ffi()
|
||||
for mcu, ss in self.steppersyncs:
|
||||
offset, freq = mcu.calibrate_clock(sync_time, eventtime)
|
||||
ffi_lib.steppersync_set_time(ss, offset, freq)
|
||||
# Calculate history expiration
|
||||
est_print_time = self.mcu.estimated_print_time(eventtime)
|
||||
self.clear_history_time = est_print_time - MOVE_HISTORY_EXPIRE
|
||||
|
||||
@@ -604,11 +604,9 @@ class MCU:
|
||||
self._init_cmds = []
|
||||
self._mcu_freq = 0.
|
||||
# Move command queuing
|
||||
ffi_main, self._ffi_lib = chelper.get_ffi()
|
||||
self._max_stepper_error = config.getfloat('max_stepper_error', 0.000025,
|
||||
minval=0.)
|
||||
self._reserved_move_slots = 0
|
||||
self._steppersync = None
|
||||
# Stats
|
||||
self._get_status_info = {}
|
||||
self._stats_sumsq_base = 0.
|
||||
@@ -773,10 +771,8 @@ class MCU:
|
||||
raise error("Too few moves available on MCU '%s'" % (self._name,))
|
||||
ss_move_count = move_count - self._reserved_move_slots
|
||||
motion_queuing = self._printer.lookup_object('motion_queuing')
|
||||
self._steppersync = motion_queuing.allocate_steppersync(
|
||||
motion_queuing.setup_mcu_movequeue(
|
||||
self, self._serial.get_serialqueue(), ss_move_count)
|
||||
self._ffi_lib.steppersync_set_time(self._steppersync,
|
||||
0., self._mcu_freq)
|
||||
# Log config information
|
||||
move_msg = "Configured MCU '%s' (%d moves)" % (self._name, move_count)
|
||||
logging.info(move_msg)
|
||||
@@ -919,7 +915,6 @@ class MCU:
|
||||
# Restarts
|
||||
def _disconnect(self):
|
||||
self._serial.disconnect()
|
||||
self._steppersync = None
|
||||
def _shutdown(self, force=False):
|
||||
if (self._emergency_stop_cmd is None
|
||||
or (self._is_shutdown and not force)):
|
||||
@@ -974,11 +969,7 @@ class MCU:
|
||||
# Move queue tracking
|
||||
def request_move_queue_slot(self):
|
||||
self._reserved_move_slots += 1
|
||||
def check_active(self, print_time, eventtime):
|
||||
if self._steppersync is None:
|
||||
return
|
||||
offset, freq = self._clocksync.calibrate_clock(print_time, eventtime)
|
||||
self._ffi_lib.steppersync_set_time(self._steppersync, offset, freq)
|
||||
def _check_timeout(self, eventtime):
|
||||
if (self._clocksync.is_active() or self.is_fileoutput()
|
||||
or self._is_timeout):
|
||||
return
|
||||
@@ -987,6 +978,10 @@ class MCU:
|
||||
self._name, eventtime)
|
||||
self._printer.invoke_shutdown("Lost communication with MCU '%s'" % (
|
||||
self._name,))
|
||||
def calibrate_clock(self, print_time, eventtime):
|
||||
offset, freq = self._clocksync.calibrate_clock(print_time, eventtime)
|
||||
self._check_timeout(eventtime)
|
||||
return offset, freq
|
||||
# Misc external commands
|
||||
def is_fileoutput(self):
|
||||
return self._printer.get_start_args().get('debugoutput') is not None
|
||||
|
||||
Reference in New Issue
Block a user