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 <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2018-07-12 22:15:45 -04:00
parent 7d897d84d7
commit 8faab46ed2
9 changed files with 37 additions and 17 deletions

View File

@ -4,7 +4,7 @@
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import math, logging
import probe, delta, mathutil
import probe, mathutil, kinematics.delta
class DeltaCalibrate:
def __init__(self, config):
@ -40,10 +40,11 @@ class DeltaCalibrate:
logging.info("Initial delta_calibrate parameters: %s", params)
adj_params = ('endstop_a', 'endstop_b', 'endstop_c', 'radius',
'angle_a', 'angle_b')
get_position_from_stable = kinematics.delta.get_position_from_stable
def delta_errorfunc(params):
total_error = 0.
for spos in positions:
x, y, z = delta.get_position_from_stable(spos, params)
x, y, z = get_position_from_stable(spos, params)
total_error += (z - z_offset)**2
return total_error
new_params = mathutil.coordinate_descent(
@ -51,8 +52,8 @@ class DeltaCalibrate:
logging.info("Calculated delta_calibrate parameters: %s", new_params)
for spos in positions:
logging.info("orig: %s new: %s",
delta.get_position_from_stable(spos, params),
delta.get_position_from_stable(spos, new_params))
get_position_from_stable(spos, params),
get_position_from_stable(spos, new_params))
self.gcode.respond_info(
"stepper_a: position_endstop: %.6f angle: %.6f\n"
"stepper_b: position_endstop: %.6f angle: %.6f\n"

View File

@ -4,7 +4,7 @@
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import os, re, logging, collections
import homing, extruder
import homing, kinematics.extruder
class error(Exception):
pass
@ -116,7 +116,7 @@ class GCodeParser:
if self.move_transform is None:
self.move_with_transform = self.toolhead.move
self.position_with_transform = self.toolhead.get_position
extruders = extruder.get_printer_extruders(self.printer)
extruders = kinematics.extruder.get_printer_extruders(self.printer)
if extruders:
self.extruder = extruders[0]
self.toolhead.set_extruder(self.extruder)
@ -396,7 +396,7 @@ class GCodeParser:
self.respond_info('Unknown command:"%s"' % (cmd,))
def cmd_Tn(self, params):
# Select Tool
extruders = extruder.get_printer_extruders(self.printer)
extruders = kinematics.extruder.get_printer_extruders(self.printer)
index = self.get_int('T', params, minval=0, maxval=len(extruders)-1)
e = extruders[index]
if self.extruder is e:

View File

@ -0,0 +1,5 @@
# Package definition for the kinematics directory
#
# Copyright (C) 2018 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.

View File

@ -168,3 +168,6 @@ class CartKinematics:
carriage = gcode.get_int('CARRIAGE', params, minval=0, maxval=1)
self._activate_carriage(carriage)
gcode.reset_last_position()
def load_kinematics(toolhead, config):
return CartKinematics(toolhead, config)

View File

@ -141,3 +141,6 @@ class CoreXYKinematics:
rail_y.step_itersolve(cmove)
if axes_d[2]:
rail_z.step_itersolve(cmove)
def load_kinematics(toolhead, config):
return CoreXYKinematics(toolhead, config)

View File

@ -198,3 +198,6 @@ def get_position_from_stable(spos, params):
sphere_coords = [(t[0], t[1], es + math.sqrt(a2 - radius2) - p)
for t, es, a2, p in zip(towers, endstops, arm2, spos)]
return mathutil.trilateration(sphere_coords, arm2)
def load_kinematics(toolhead, config):
return DeltaKinematics(toolhead, config)

View File

@ -7,7 +7,7 @@
import sys, os, optparse, logging, time, threading
import collections, ConfigParser, importlib
import util, reactor, queuelogger, msgproto
import gcode, pins, heater, mcu, toolhead, extruder
import gcode, pins, heater, mcu, toolhead
message_ready = "Printer is ready"
@ -216,7 +216,7 @@ class Printer:
m.add_printer_objects(config)
for section in fileconfig.sections():
self.try_load_module(config, section)
for m in [toolhead, extruder]:
for m in [toolhead]:
m.add_printer_objects(config)
# Validate that there are no undefined parameters in the config file
valid_sections = { s: 1 for s, o in self.all_config_options }

View File

@ -3,8 +3,8 @@
# Copyright (C) 2016-2018 Kevin O'Connor <kevin@koconnor.net>
#
# 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)