stepper: Automatically detect and handle shared stepper enable lines
It's common for multiple steppers to use the same stepper enable line. Detect this and only create a single digital_out oid on the micro-controller. Also, prohibit any other pin from being used multiple times in the config file. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
265b9097d5
commit
df6528715e
|
@ -71,8 +71,6 @@ Hardware features
|
||||||
|
|
||||||
* Support for additional kinematics: scara, etc.
|
* Support for additional kinematics: scara, etc.
|
||||||
|
|
||||||
* Support shared motor enable GPIO lines.
|
|
||||||
|
|
||||||
* Support for bed-level probes.
|
* Support for bed-level probes.
|
||||||
|
|
||||||
* Possible support for touch panels attached to the micro-controller.
|
* Possible support for touch panels attached to the micro-controller.
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# Pin name to pin number definitions
|
# Pin name to pin number definitions
|
||||||
#
|
#
|
||||||
# Copyright (C) 2016,2017 Kevin O'Connor <kevin@koconnor.net>
|
# Copyright (C) 2016-2018 Kevin O'Connor <kevin@koconnor.net>
|
||||||
#
|
#
|
||||||
# This file may be distributed under the terms of the GNU GPLv3 license.
|
# This file may be distributed under the terms of the GNU GPLv3 license.
|
||||||
import re
|
import re
|
||||||
|
@ -180,7 +180,8 @@ class PrinterPins:
|
||||||
error = error
|
error = error
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.chips = {}
|
self.chips = {}
|
||||||
def lookup_pin(self, pin_type, pin_desc):
|
self.active_pins = {}
|
||||||
|
def lookup_pin(self, pin_type, pin_desc, share_type=None):
|
||||||
can_invert = pin_type in ['stepper', 'endstop', 'digital_out', 'pwm']
|
can_invert = pin_type in ['stepper', 'endstop', 'digital_out', 'pwm']
|
||||||
can_pullup = pin_type == 'endstop'
|
can_pullup = pin_type == 'endstop'
|
||||||
pullup = invert = 0
|
pullup = invert = 0
|
||||||
|
@ -196,8 +197,19 @@ class PrinterPins:
|
||||||
chip_name, pin = [s.strip() for s in pin_desc.split(':', 1)]
|
chip_name, pin = [s.strip() for s in pin_desc.split(':', 1)]
|
||||||
if chip_name not in self.chips:
|
if chip_name not in self.chips:
|
||||||
raise error("Unknown pin chip name '%s'" % (chip_name,))
|
raise error("Unknown pin chip name '%s'" % (chip_name,))
|
||||||
return {'chip': self.chips[chip_name], 'chip_name': chip_name,
|
share_name = "%s:%s" % (chip_name, pin)
|
||||||
'type': pin_type, 'pin': pin, 'invert': invert, 'pullup': pullup}
|
if share_name in self.active_pins:
|
||||||
|
pin_params = self.active_pins[share_name]
|
||||||
|
if share_type is None or share_type != pin_params['share_type']:
|
||||||
|
raise error("pin %s used multiple times in config" % (pin,))
|
||||||
|
if invert != pin_params['invert'] or pullup != pin_params['pullup']:
|
||||||
|
raise error("Shared pin %s must have same polarity" % (pin,))
|
||||||
|
return pin_params
|
||||||
|
pin_params = {'chip': self.chips[chip_name], 'chip_name': chip_name,
|
||||||
|
'type': pin_type, 'share_type': share_type,
|
||||||
|
'pin': pin, 'invert': invert, 'pullup': pullup}
|
||||||
|
self.active_pins[share_name] = pin_params
|
||||||
|
return pin_params
|
||||||
def setup_pin(self, pin_type, pin_desc):
|
def setup_pin(self, pin_type, pin_desc):
|
||||||
pin_params = self.lookup_pin(pin_type, pin_desc)
|
pin_params = self.lookup_pin(pin_type, pin_desc)
|
||||||
return pin_params['chip'].setup_pin(pin_params)
|
return pin_params['chip'].setup_pin(pin_params)
|
||||||
|
|
|
@ -1,11 +1,38 @@
|
||||||
# Printer stepper support
|
# Printer stepper support
|
||||||
#
|
#
|
||||||
# Copyright (C) 2016,2017 Kevin O'Connor <kevin@koconnor.net>
|
# Copyright (C) 2016-2018 Kevin O'Connor <kevin@koconnor.net>
|
||||||
#
|
#
|
||||||
# This file may be distributed under the terms of the GNU GPLv3 license.
|
# This file may be distributed under the terms of the GNU GPLv3 license.
|
||||||
import math, logging
|
import math, logging
|
||||||
import homing, pins
|
import homing, pins
|
||||||
|
|
||||||
|
# Tracking of shared stepper enable pins
|
||||||
|
class StepperEnablePin:
|
||||||
|
def __init__(self, mcu_enable, enable_count=0):
|
||||||
|
self.mcu_enable = mcu_enable
|
||||||
|
self.enable_count = enable_count
|
||||||
|
def set_enable(self, print_time, enable):
|
||||||
|
if enable:
|
||||||
|
if not self.enable_count:
|
||||||
|
self.mcu_enable.set_digital(print_time, 1)
|
||||||
|
self.enable_count += 1
|
||||||
|
else:
|
||||||
|
self.enable_count -= 1
|
||||||
|
if not self.enable_count:
|
||||||
|
self.mcu_enable.set_digital(print_time, 0)
|
||||||
|
|
||||||
|
def lookup_enable_pin(printer, pin):
|
||||||
|
if pin is None:
|
||||||
|
return StepperEnablePin(None, 9999)
|
||||||
|
pin_params = pins.get_printer_pins(printer).lookup_pin(
|
||||||
|
'digital_out', pin, 'stepper_enable')
|
||||||
|
enable = pin_params.get('class')
|
||||||
|
if enable is None:
|
||||||
|
mcu_enable = pin_params['chip'].setup_pin(pin_params)
|
||||||
|
mcu_enable.setup_max_duration(0.)
|
||||||
|
pin_params['class'] = enable = StepperEnablePin(mcu_enable)
|
||||||
|
return enable
|
||||||
|
|
||||||
# Code storing the definitions for a stepper motor
|
# Code storing the definitions for a stepper motor
|
||||||
class PrinterStepper:
|
class PrinterStepper:
|
||||||
def __init__(self, printer, config):
|
def __init__(self, printer, config):
|
||||||
|
@ -23,12 +50,7 @@ class PrinterStepper:
|
||||||
self.mcu_stepper.setup_step_distance(self.step_dist)
|
self.mcu_stepper.setup_step_distance(self.step_dist)
|
||||||
self.step_const = self.mcu_stepper.step_const
|
self.step_const = self.mcu_stepper.step_const
|
||||||
self.step_delta = self.mcu_stepper.step_delta
|
self.step_delta = self.mcu_stepper.step_delta
|
||||||
# Enable pin
|
self.enable = lookup_enable_pin(printer, config.get('enable_pin', None))
|
||||||
enable_pin = config.get('enable_pin', None)
|
|
||||||
self.mcu_enable = None
|
|
||||||
if enable_pin is not None:
|
|
||||||
self.mcu_enable = pins.setup_pin(printer, 'digital_out', enable_pin)
|
|
||||||
self.mcu_enable.setup_max_duration(0.)
|
|
||||||
def _dist_to_time(self, dist, start_velocity, accel):
|
def _dist_to_time(self, dist, start_velocity, accel):
|
||||||
# Calculate the time it takes to travel a distance with constant accel
|
# Calculate the time it takes to travel a distance with constant accel
|
||||||
time_offset = start_velocity / accel
|
time_offset = start_velocity / accel
|
||||||
|
@ -44,9 +66,8 @@ class PrinterStepper:
|
||||||
def set_position(self, pos):
|
def set_position(self, pos):
|
||||||
self.mcu_stepper.set_position(pos)
|
self.mcu_stepper.set_position(pos)
|
||||||
def motor_enable(self, print_time, enable=0):
|
def motor_enable(self, print_time, enable=0):
|
||||||
if (self.mcu_enable is not None
|
if self.need_motor_enable != (not enable):
|
||||||
and self.need_motor_enable != (not enable)):
|
self.enable.set_enable(print_time, enable)
|
||||||
self.mcu_enable.set_digital(print_time, enable)
|
|
||||||
self.need_motor_enable = not enable
|
self.need_motor_enable = not enable
|
||||||
|
|
||||||
# Support for stepper controlled linear axis with an endstop
|
# Support for stepper controlled linear axis with an endstop
|
||||||
|
|
Loading…
Reference in New Issue