From 8faab46ed2fc05495e63bbca8fe3dfa6828f7db3 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Thu, 12 Jul 2018 22:15:45 -0400 Subject: toolhead: Move kinematic modules to new kinematics/ directory Move extruder.py, cartesian.py, corexy.py, and delta.py to a new kinematics/ sub-directory. This is intended to make adding new kinematics a little easier. Signed-off-by: Kevin O'Connor --- klippy/toolhead.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'klippy/toolhead.py') diff --git a/klippy/toolhead.py b/klippy/toolhead.py index 6b0058d3..d9b26ef8 100644 --- a/klippy/toolhead.py +++ b/klippy/toolhead.py @@ -3,8 +3,8 @@ # Copyright (C) 2016-2018 Kevin O'Connor # # This file may be distributed under the terms of the GNU GPLv3 license. -import math, logging -import mcu, homing, cartesian, corexy, delta, extruder +import math, logging, importlib +import mcu, homing, kinematics.extruder # Common suffixes: _d is distance (in mm), _v is velocity (in # mm/second), _v2 is velocity squared (mm^2/s^2), _t is time (in @@ -227,12 +227,16 @@ class ToolHead: self.motor_off_timer = self.reactor.register_timer( self._motor_off_handler, self.reactor.NOW) # Create kinematics class - self.extruder = extruder.DummyExtruder() + self.extruder = kinematics.extruder.DummyExtruder() self.move_queue.set_extruder(self.extruder) - kintypes = {'cartesian': cartesian.CartKinematics, - 'corexy': corexy.CoreXYKinematics, - 'delta': delta.DeltaKinematics} - self.kin = config.getchoice('kinematics', kintypes)(self, config) + kin_name = config.get('kinematics') + try: + mod = importlib.import_module('kinematics.' + kin_name) + self.kin = mod.load_kinematics(self, config) + except: + msg = "Error loading kinematics '%s'" % (kin_name,) + logging.exception(msg) + raise config.error(msg) # SET_VELOCITY_LIMIT command gcode = self.printer.lookup_object('gcode') gcode.register_command('SET_VELOCITY_LIMIT', self.cmd_SET_VELOCITY_LIMIT, @@ -353,7 +357,7 @@ class ToolHead: self.dwell(STALL_TIME) last_move_time = self.get_last_move_time() self.kin.motor_off(last_move_time) - for ext in extruder.get_printer_extruders(self.printer): + for ext in kinematics.extruder.get_printer_extruders(self.printer): ext.motor_off(last_move_time) self.dwell(STALL_TIME) self.need_motor_off = False @@ -444,3 +448,4 @@ class ToolHead: def add_printer_objects(config): config.get_printer().add_object('toolhead', ToolHead(config)) + kinematics.extruder.add_printer_objects(config) -- cgit v1.2.3-70-g09d2