stepper: No need to pass printer reference to kinematic/stepper constructors
The config reference already stores a reference to the printer object. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
76e2b041b4
commit
d0590ccb0e
|
@ -9,10 +9,10 @@ import stepper, homing, chelper
|
|||
StepList = (0, 1, 2)
|
||||
|
||||
class CartKinematics:
|
||||
def __init__(self, toolhead, printer, config):
|
||||
self.printer = printer
|
||||
def __init__(self, toolhead, config):
|
||||
self.printer = config.get_printer()
|
||||
self.steppers = [stepper.LookupMultiHomingStepper(
|
||||
printer, config.getsection('stepper_' + n))
|
||||
config.getsection('stepper_' + n))
|
||||
for n in ['x', 'y', 'z']]
|
||||
max_velocity, max_accel = toolhead.get_max_velocity()
|
||||
self.max_z_velocity = config.getfloat(
|
||||
|
@ -40,12 +40,12 @@ class CartKinematics:
|
|||
dc_config = config.getsection('dual_carriage')
|
||||
dc_axis = dc_config.getchoice('axis', {'x': 'x', 'y': 'y'})
|
||||
self.dual_carriage_axis = {'x': 0, 'y': 1}[dc_axis]
|
||||
dc_stepper = stepper.LookupMultiHomingStepper(printer, dc_config)
|
||||
dc_stepper = stepper.LookupMultiHomingStepper(dc_config)
|
||||
dc_stepper.setup_cartesian_itersolve(dc_axis)
|
||||
dc_stepper.set_max_jerk(max_halt_velocity, max_accel)
|
||||
self.dual_carriage_steppers = [
|
||||
self.steppers[self.dual_carriage_axis], dc_stepper]
|
||||
printer.lookup_object('gcode').register_command(
|
||||
self.printer.lookup_object('gcode').register_command(
|
||||
'SET_DUAL_CARRIAGE', self.cmd_SET_DUAL_CARRIAGE,
|
||||
desc=self.cmd_SET_DUAL_CARRIAGE_help)
|
||||
def get_steppers(self, flags=""):
|
||||
|
|
|
@ -9,14 +9,11 @@ import stepper, homing, chelper
|
|||
StepList = (0, 1, 2)
|
||||
|
||||
class CoreXYKinematics:
|
||||
def __init__(self, toolhead, printer, config):
|
||||
def __init__(self, toolhead, config):
|
||||
self.steppers = [
|
||||
stepper.PrinterHomingStepper(
|
||||
printer, config.getsection('stepper_x')),
|
||||
stepper.PrinterHomingStepper(
|
||||
printer, config.getsection('stepper_y')),
|
||||
stepper.LookupMultiHomingStepper(
|
||||
printer, config.getsection('stepper_z'))]
|
||||
stepper.PrinterHomingStepper(config.getsection('stepper_x')),
|
||||
stepper.PrinterHomingStepper(config.getsection('stepper_y')),
|
||||
stepper.LookupMultiHomingStepper(config.getsection('stepper_z'))]
|
||||
self.steppers[0].mcu_endstop.add_stepper(self.steppers[1].mcu_stepper)
|
||||
self.steppers[1].mcu_endstop.add_stepper(self.steppers[0].mcu_stepper)
|
||||
max_velocity, max_accel = toolhead.get_max_velocity()
|
||||
|
|
|
@ -12,16 +12,16 @@ StepList = (0, 1, 2)
|
|||
SLOW_RATIO = 3.
|
||||
|
||||
class DeltaKinematics:
|
||||
def __init__(self, toolhead, printer, config):
|
||||
def __init__(self, toolhead, config):
|
||||
stepper_configs = [config.getsection('stepper_' + n)
|
||||
for n in ['a', 'b', 'c']]
|
||||
stepper_a = stepper.PrinterHomingStepper(
|
||||
printer, stepper_configs[0], need_position_minmax = False)
|
||||
stepper_configs[0], need_position_minmax = False)
|
||||
stepper_b = stepper.PrinterHomingStepper(
|
||||
printer, stepper_configs[1], need_position_minmax = False,
|
||||
stepper_configs[1], need_position_minmax = False,
|
||||
default_position_endstop=stepper_a.position_endstop)
|
||||
stepper_c = stepper.PrinterHomingStepper(
|
||||
printer, stepper_configs[2], need_position_minmax = False,
|
||||
stepper_configs[2], need_position_minmax = False,
|
||||
default_position_endstop=stepper_a.position_endstop)
|
||||
self.steppers = [stepper_a, stepper_b, stepper_c]
|
||||
self.need_motor_enable = self.need_home = True
|
||||
|
|
|
@ -9,16 +9,16 @@ import stepper, homing, chelper
|
|||
EXTRUDE_DIFF_IGNORE = 1.02
|
||||
|
||||
class PrinterExtruder:
|
||||
def __init__(self, printer, config):
|
||||
self.printer = printer
|
||||
def __init__(self, config):
|
||||
self.printer = config.get_printer()
|
||||
self.name = config.get_name()
|
||||
shared_heater = config.get('shared_heater', None)
|
||||
pheater = printer.lookup_object('heater')
|
||||
pheater = self.printer.lookup_object('heater')
|
||||
if shared_heater is None:
|
||||
self.heater = pheater.setup_heater(config)
|
||||
else:
|
||||
self.heater = pheater.lookup_heater(shared_heater)
|
||||
self.stepper = stepper.PrinterStepper(printer, config)
|
||||
self.stepper = stepper.PrinterStepper(config)
|
||||
self.nozzle_diameter = config.getfloat('nozzle_diameter', above=0.)
|
||||
filament_diameter = config.getfloat(
|
||||
'filament_diameter', minval=self.nozzle_diameter)
|
||||
|
@ -28,7 +28,7 @@ class PrinterExtruder:
|
|||
, above=0.)
|
||||
self.max_extrude_ratio = max_cross_section / self.filament_area
|
||||
logging.info("Extruder max_extrude_ratio=%.6f", self.max_extrude_ratio)
|
||||
toolhead = printer.lookup_object('toolhead')
|
||||
toolhead = self.printer.lookup_object('toolhead')
|
||||
max_velocity, max_accel = toolhead.get_max_velocity()
|
||||
self.max_e_velocity = config.getfloat(
|
||||
'max_extrude_only_velocity', max_velocity * self.max_extrude_ratio
|
||||
|
@ -236,12 +236,11 @@ def add_printer_objects(printer, config):
|
|||
section = 'extruder%d' % (i,)
|
||||
if not config.has_section(section):
|
||||
if not i and config.has_section('extruder'):
|
||||
printer.add_object('extruder0', PrinterExtruder(
|
||||
printer, config.getsection('extruder')))
|
||||
pe = PrinterExtruder(config.getsection('extruder'))
|
||||
printer.add_object('extruder0', pe)
|
||||
continue
|
||||
break
|
||||
printer.add_object(section, PrinterExtruder(
|
||||
printer, config.getsection(section)))
|
||||
printer.add_object(section, PrinterExtruder(config.getsection(section)))
|
||||
|
||||
def get_printer_extruders(printer):
|
||||
out = []
|
||||
|
|
|
@ -34,8 +34,8 @@ def lookup_enable_pin(ppins, pin):
|
|||
|
||||
# Code storing the definitions for a stepper motor
|
||||
class PrinterStepper:
|
||||
def __init__(self, printer, config):
|
||||
self.printer = printer
|
||||
def __init__(self, config):
|
||||
printer = config.get_printer()
|
||||
self.name = config.get_name()
|
||||
if self.name.startswith('stepper_'):
|
||||
self.name = self.name[8:]
|
||||
|
@ -74,11 +74,11 @@ class PrinterStepper:
|
|||
|
||||
# Support for stepper controlled linear axis with an endstop
|
||||
class PrinterHomingStepper(PrinterStepper):
|
||||
def __init__(self, printer, config, need_position_minmax=True,
|
||||
def __init__(self, config, need_position_minmax=True,
|
||||
default_position_endstop=None):
|
||||
PrinterStepper.__init__(self, printer, config)
|
||||
PrinterStepper.__init__(self, config)
|
||||
# Endstop and its position
|
||||
ppins = printer.lookup_object('pins')
|
||||
ppins = config.get_printer().lookup_object('pins')
|
||||
self.mcu_endstop = ppins.setup_pin('endstop', config.get('endstop_pin'))
|
||||
self.mcu_endstop.add_stepper(self.mcu_stepper)
|
||||
if default_position_endstop is None:
|
||||
|
@ -179,8 +179,8 @@ class PrinterHomingStepper(PrinterStepper):
|
|||
|
||||
# Wrapper for dual stepper motor support
|
||||
class PrinterMultiStepper(PrinterHomingStepper):
|
||||
def __init__(self, printer, config):
|
||||
PrinterHomingStepper.__init__(self, printer, config)
|
||||
def __init__(self, config):
|
||||
PrinterHomingStepper.__init__(self, config)
|
||||
self.endstops = PrinterHomingStepper.get_endstops(self)
|
||||
self.extras = []
|
||||
self.all_step_itersolve = [self.step_itersolve]
|
||||
|
@ -188,12 +188,12 @@ class PrinterMultiStepper(PrinterHomingStepper):
|
|||
if not config.has_section(config.get_name() + str(i)):
|
||||
break
|
||||
extraconfig = config.getsection(config.get_name() + str(i))
|
||||
extra = PrinterStepper(printer, extraconfig)
|
||||
extra = PrinterStepper(extraconfig)
|
||||
self.extras.append(extra)
|
||||
self.all_step_itersolve.append(extra.step_itersolve)
|
||||
extraendstop = extraconfig.get('endstop_pin', None)
|
||||
if extraendstop is not None:
|
||||
ppins = printer.lookup_object('pins')
|
||||
ppins = config.get_printer().lookup_object('pins')
|
||||
mcu_endstop = ppins.setup_pin('endstop', extraendstop)
|
||||
mcu_endstop.add_stepper(extra.mcu_stepper)
|
||||
self.endstops.append((mcu_endstop, extra.name))
|
||||
|
@ -225,7 +225,7 @@ class PrinterMultiStepper(PrinterHomingStepper):
|
|||
def get_endstops(self):
|
||||
return self.endstops
|
||||
|
||||
def LookupMultiHomingStepper(printer, config):
|
||||
def LookupMultiHomingStepper(config):
|
||||
if not config.has_section(config.get_name() + '1'):
|
||||
return PrinterHomingStepper(printer, config)
|
||||
return PrinterMultiStepper(printer, config)
|
||||
return PrinterHomingStepper(config)
|
||||
return PrinterMultiStepper(config)
|
||||
|
|
|
@ -186,10 +186,10 @@ STALL_TIME = 0.100
|
|||
|
||||
# Main code to track events (and their timing) on the printer toolhead
|
||||
class ToolHead:
|
||||
def __init__(self, printer, config):
|
||||
self.printer = printer
|
||||
self.reactor = printer.get_reactor()
|
||||
self.all_mcus = printer.lookup_module_objects('mcu')
|
||||
def __init__(self, config):
|
||||
self.printer = config.get_printer()
|
||||
self.reactor = self.printer.get_reactor()
|
||||
self.all_mcus = self.printer.lookup_module_objects('mcu')
|
||||
self.mcu = self.all_mcus[0]
|
||||
self.max_velocity = config.getfloat('max_velocity', above=0.)
|
||||
self.max_accel = config.getfloat('max_accel', above=0.)
|
||||
|
@ -232,10 +232,9 @@ class ToolHead:
|
|||
kintypes = {'cartesian': cartesian.CartKinematics,
|
||||
'corexy': corexy.CoreXYKinematics,
|
||||
'delta': delta.DeltaKinematics}
|
||||
self.kin = config.getchoice('kinematics', kintypes)(
|
||||
self, printer, config)
|
||||
self.kin = config.getchoice('kinematics', kintypes)(self, config)
|
||||
# SET_VELOCITY_LIMIT command
|
||||
gcode = printer.lookup_object('gcode')
|
||||
gcode = self.printer.lookup_object('gcode')
|
||||
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)
|
||||
|
@ -443,4 +442,4 @@ class ToolHead:
|
|||
self.max_accel = min(accel, self.config_max_accel)
|
||||
|
||||
def add_printer_objects(printer, config):
|
||||
printer.add_object('toolhead', ToolHead(printer, config))
|
||||
printer.add_object('toolhead', ToolHead(config))
|
||||
|
|
Loading…
Reference in New Issue