mirror of
https://github.com/Klipper3d/klipper.git
synced 2025-07-18 20:28:10 -06:00
delta_calibrate: Perform coordinate descent in a background process
Run the coordinate descent in a background process so that the main thread does not block. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
46355f903e
commit
368703fd78
2 changed files with 30 additions and 8 deletions
|
@ -3,7 +3,7 @@
|
|||
# Copyright (C) 2018 Kevin O'Connor <kevin@koconnor.net>
|
||||
#
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license.
|
||||
import math, logging
|
||||
import math, logging, multiprocessing
|
||||
|
||||
|
||||
######################################################################
|
||||
|
@ -45,6 +45,33 @@ def coordinate_descent(adj_params, params, error_func):
|
|||
logging.info("Coordinate descent best_err: %s rounds: %d", best_err, rounds)
|
||||
return params
|
||||
|
||||
# Helper to run the coordinate descent function in a background
|
||||
# process so that it does not block the main thread.
|
||||
def background_coordinate_descent(printer, adj_params, params, error_func):
|
||||
parent_conn, child_conn = multiprocessing.Pipe()
|
||||
def wrapper():
|
||||
res = coordinate_descent(adj_params, params, error_func)
|
||||
child_conn.send(res)
|
||||
child_conn.close()
|
||||
# Start a process to perform the calculation
|
||||
calc_proc = multiprocessing.Process(target=wrapper)
|
||||
calc_proc.daemon = True
|
||||
calc_proc.start()
|
||||
# Wait for the process to finish
|
||||
reactor = printer.get_reactor()
|
||||
gcode = printer.lookup_object("gcode")
|
||||
eventtime = last_report_time = reactor.monotonic()
|
||||
while calc_proc.is_alive():
|
||||
if eventtime > last_report_time + 5.:
|
||||
last_report_time = eventtime
|
||||
gcode.respond_info("Working on calibration...")
|
||||
eventtime = reactor.pause(eventtime + .1)
|
||||
# Return results
|
||||
res = parent_conn.recv()
|
||||
calc_proc.join()
|
||||
parent_conn.close()
|
||||
return res
|
||||
|
||||
|
||||
######################################################################
|
||||
# Trilateration
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue