mirror of
https://github.com/sinseman44/PyCNC.git
synced 2026-07-27 10:26:55 +00:00
add dynamic configuration and begin configuration of double H bridge driver l293d
This commit is contained in:
@@ -53,22 +53,35 @@ BED_PID = {"P": 0.226740848076,
|
|||||||
# Pins configuration.
|
# Pins configuration.
|
||||||
|
|
||||||
# Enable pin for all steppers, low level is enabled.
|
# Enable pin for all steppers, low level is enabled.
|
||||||
|
ENABLE_STEPPER_ENABLE_PIN = False
|
||||||
STEPPERS_ENABLE_PIN = 26
|
STEPPERS_ENABLE_PIN = 26
|
||||||
STEPPER_STEP_PIN_X = 21
|
STEPPER_STEP_PIN_X = 21
|
||||||
STEPPER_STEP_PIN_Y = 16
|
STEPPER_STEP_PIN_Y = 16
|
||||||
STEPPER_STEP_PIN_Z = 12
|
STEPPER_STEP_PIN_Z = 12
|
||||||
STEPPER_STEP_PIN_E = 8
|
STEPPER_STEP_PIN_E = 8
|
||||||
|
ENABLE_L293D = True
|
||||||
|
if ENABLE_L293D:
|
||||||
|
STEPPER_STEP_PINS_X = [4,17,27,22]
|
||||||
|
STEPPER_STEP_PINS_Y = []
|
||||||
|
ENABLE_FULL_STEP = False
|
||||||
|
ENABLE_HALF_STEP = True
|
||||||
|
|
||||||
STEPPER_DIR_PIN_X = 20
|
STEPPER_DIR_PIN_X = 20
|
||||||
STEPPER_DIR_PIN_Y = 19
|
STEPPER_DIR_PIN_Y = 19
|
||||||
STEPPER_DIR_PIN_Z = 13
|
STEPPER_DIR_PIN_Z = 13
|
||||||
STEPPER_DIR_PIN_E = 7
|
STEPPER_DIR_PIN_E = 7
|
||||||
|
|
||||||
|
ENABLE_SPINDLE = False
|
||||||
SPINDLE_PWM_PIN = 4
|
SPINDLE_PWM_PIN = 4
|
||||||
|
ENABLE_FAN = False
|
||||||
FAN_PIN = 27
|
FAN_PIN = 27
|
||||||
|
ENABLE_EXTRUDER_HEATER = False
|
||||||
EXTRUDER_HEATER_PIN = 18
|
EXTRUDER_HEATER_PIN = 18
|
||||||
|
ENABLE_BED_HEATER = False
|
||||||
BED_HEATER_PIN = 22
|
BED_HEATER_PIN = 22
|
||||||
|
if ENABLE_EXTRUDER_HEATER:
|
||||||
EXTRUDER_TEMPERATURE_SENSOR_CHANNEL = 2
|
EXTRUDER_TEMPERATURE_SENSOR_CHANNEL = 2
|
||||||
|
if ENABLE_BED_HEATER:
|
||||||
BED_TEMPERATURE_SENSOR_CHANNEL = 1
|
BED_TEMPERATURE_SENSOR_CHANNEL = 1
|
||||||
|
|
||||||
ENDSTOP_PIN_X = 23
|
ENDSTOP_PIN_X = 23
|
||||||
|
|||||||
+7
-7
@@ -107,19 +107,19 @@ except ImportError:
|
|||||||
# check if all methods that is needed is implemented
|
# check if all methods that is needed is implemented
|
||||||
if 'init' not in locals():
|
if 'init' not in locals():
|
||||||
raise NotImplementedError("hal.init() not implemented")
|
raise NotImplementedError("hal.init() not implemented")
|
||||||
if 'spindle_control' not in locals():
|
if ENABLE_SPINDLE and 'spindle_control' not in locals():
|
||||||
raise NotImplementedError("hal.spindle_control() not implemented")
|
raise NotImplementedError("hal.spindle_control() not implemented")
|
||||||
if 'fan_control' not in locals():
|
if ENABLE_FAN and 'fan_control' not in locals():
|
||||||
raise NotImplementedError("hal.fan_control() not implemented")
|
raise NotImplementedError("hal.fan_control() not implemented")
|
||||||
if 'extruder_heater_control' not in locals():
|
if ENABLE_EXTRUDER_HEATER and 'extruder_heater_control' not in locals():
|
||||||
raise NotImplementedError("hal.extruder_heater_control() not implemented")
|
raise NotImplementedError("hal.extruder_heater_control() not implemented")
|
||||||
if 'bed_heater_control' not in locals():
|
if ENABLE_BED_HEATER and 'bed_heater_control' not in locals():
|
||||||
raise NotImplementedError("hal.bed_heater_control() not implemented")
|
raise NotImplementedError("hal.bed_heater_control() not implemented")
|
||||||
if 'get_extruder_temperature' not in locals():
|
if ENABLE_EXTRUDER_HEATER and 'get_extruder_temperature' not in locals():
|
||||||
raise NotImplementedError("hal.get_extruder_temperature() not implemented")
|
raise NotImplementedError("hal.get_extruder_temperature() not implemented")
|
||||||
if 'get_bed_temperature' not in locals():
|
if ENABLE_BED_HEATER and 'get_bed_temperature' not in locals():
|
||||||
raise NotImplementedError("hal.get_bed_temperature() not implemented")
|
raise NotImplementedError("hal.get_bed_temperature() not implemented")
|
||||||
if 'disable_steppers' not in locals():
|
if ENABLE_STEPPER_ENABLE_PIN and 'disable_steppers' not in locals():
|
||||||
raise NotImplementedError("hal.disable_steppers() not implemented")
|
raise NotImplementedError("hal.disable_steppers() not implemented")
|
||||||
if 'calibrate' not in locals():
|
if 'calibrate' not in locals():
|
||||||
raise NotImplementedError("hal.calibrate() not implemented")
|
raise NotImplementedError("hal.calibrate() not implemented")
|
||||||
|
|||||||
@@ -21,7 +21,15 @@ STEP_PIN_MASK_E = 1 << STEPPER_STEP_PIN_E
|
|||||||
def init():
|
def init():
|
||||||
""" Initialize GPIO pins and machine itself.
|
""" Initialize GPIO pins and machine itself.
|
||||||
"""
|
"""
|
||||||
|
if ENABLE_L293D and STEPPER_STEP_PINS_X:
|
||||||
|
for pin in STEPPER_STEP_PINS_X:
|
||||||
|
gpio.init(pin, rpgpio.GPIO.MODE_OUTPUT)
|
||||||
|
else:
|
||||||
gpio.init(STEPPER_STEP_PIN_X, rpgpio.GPIO.MODE_OUTPUT)
|
gpio.init(STEPPER_STEP_PIN_X, rpgpio.GPIO.MODE_OUTPUT)
|
||||||
|
if ENABLE_L293D and STEPPER_STEP_PINS_Y:
|
||||||
|
for pin in STEPPER_STEP_PINS_Y:
|
||||||
|
gpio.init(pin, rpgpio.GPIO.MODE_OUTPUT)
|
||||||
|
else:
|
||||||
gpio.init(STEPPER_STEP_PIN_Y, rpgpio.GPIO.MODE_OUTPUT)
|
gpio.init(STEPPER_STEP_PIN_Y, rpgpio.GPIO.MODE_OUTPUT)
|
||||||
gpio.init(STEPPER_STEP_PIN_Z, rpgpio.GPIO.MODE_OUTPUT)
|
gpio.init(STEPPER_STEP_PIN_Z, rpgpio.GPIO.MODE_OUTPUT)
|
||||||
gpio.init(STEPPER_STEP_PIN_E, rpgpio.GPIO.MODE_OUTPUT)
|
gpio.init(STEPPER_STEP_PIN_E, rpgpio.GPIO.MODE_OUTPUT)
|
||||||
@@ -32,15 +40,20 @@ def init():
|
|||||||
gpio.init(ENDSTOP_PIN_X, rpgpio.GPIO.MODE_INPUT_PULLUP)
|
gpio.init(ENDSTOP_PIN_X, rpgpio.GPIO.MODE_INPUT_PULLUP)
|
||||||
gpio.init(ENDSTOP_PIN_Y, rpgpio.GPIO.MODE_INPUT_PULLUP)
|
gpio.init(ENDSTOP_PIN_Y, rpgpio.GPIO.MODE_INPUT_PULLUP)
|
||||||
gpio.init(ENDSTOP_PIN_Z, rpgpio.GPIO.MODE_INPUT_PULLUP)
|
gpio.init(ENDSTOP_PIN_Z, rpgpio.GPIO.MODE_INPUT_PULLUP)
|
||||||
|
if ENABLE_SPINDLE:
|
||||||
gpio.init(SPINDLE_PWM_PIN, rpgpio.GPIO.MODE_OUTPUT)
|
gpio.init(SPINDLE_PWM_PIN, rpgpio.GPIO.MODE_OUTPUT)
|
||||||
gpio.init(FAN_PIN, rpgpio.GPIO.MODE_OUTPUT)
|
|
||||||
gpio.init(EXTRUDER_HEATER_PIN, rpgpio.GPIO.MODE_OUTPUT)
|
|
||||||
gpio.init(BED_HEATER_PIN, rpgpio.GPIO.MODE_OUTPUT)
|
|
||||||
gpio.init(STEPPERS_ENABLE_PIN, rpgpio.GPIO.MODE_OUTPUT)
|
|
||||||
gpio.clear(SPINDLE_PWM_PIN)
|
gpio.clear(SPINDLE_PWM_PIN)
|
||||||
|
if ENABLE_FAN:
|
||||||
|
gpio.init(FAN_PIN, rpgpio.GPIO.MODE_OUTPUT)
|
||||||
gpio.clear(FAN_PIN)
|
gpio.clear(FAN_PIN)
|
||||||
|
if ENABLE_EXTRUDER_HEATER:
|
||||||
|
gpio.init(EXTRUDER_HEATER_PIN, rpgpio.GPIO.MODE_OUTPUT)
|
||||||
gpio.clear(EXTRUDER_HEATER_PIN)
|
gpio.clear(EXTRUDER_HEATER_PIN)
|
||||||
|
if ENABLE_BED_HEATER:
|
||||||
|
gpio.init(BED_HEATER_PIN, rpgpio.GPIO.MODE_OUTPUT)
|
||||||
gpio.clear(BED_HEATER_PIN)
|
gpio.clear(BED_HEATER_PIN)
|
||||||
|
if ENABLE_STEPPER_ENABLE_PIN:
|
||||||
|
gpio.init(STEPPERS_ENABLE_PIN, rpgpio.GPIO.MODE_OUTPUT)
|
||||||
gpio.clear(STEPPERS_ENABLE_PIN)
|
gpio.clear(STEPPERS_ENABLE_PIN)
|
||||||
watchdog.start()
|
watchdog.start()
|
||||||
|
|
||||||
@@ -49,6 +62,7 @@ def spindle_control(percent):
|
|||||||
""" Spindle control implementation.
|
""" Spindle control implementation.
|
||||||
:param percent: spindle speed in percent 0..100. If 0, stop the spindle.
|
:param percent: spindle speed in percent 0..100. If 0, stop the spindle.
|
||||||
"""
|
"""
|
||||||
|
if ENABLE_SPINDLE:
|
||||||
logging.info("spindle control: {}%".format(percent))
|
logging.info("spindle control: {}%".format(percent))
|
||||||
if percent > 0:
|
if percent > 0:
|
||||||
pwm.add_pin(SPINDLE_PWM_PIN, percent)
|
pwm.add_pin(SPINDLE_PWM_PIN, percent)
|
||||||
@@ -61,6 +75,7 @@ def fan_control(on_off):
|
|||||||
Cooling fan control.
|
Cooling fan control.
|
||||||
:param on_off: boolean value if fan is enabled.
|
:param on_off: boolean value if fan is enabled.
|
||||||
"""
|
"""
|
||||||
|
if ENABLE_FAN:
|
||||||
if on_off:
|
if on_off:
|
||||||
logging.info("Fan is on")
|
logging.info("Fan is on")
|
||||||
gpio.set(FAN_PIN)
|
gpio.set(FAN_PIN)
|
||||||
@@ -73,6 +88,7 @@ def extruder_heater_control(percent):
|
|||||||
""" Extruder heater control.
|
""" Extruder heater control.
|
||||||
:param percent: heater power in percent 0..100. 0 turns heater off.
|
:param percent: heater power in percent 0..100. 0 turns heater off.
|
||||||
"""
|
"""
|
||||||
|
if ENABLE_EXTRUDER_HEATER:
|
||||||
if percent > 0:
|
if percent > 0:
|
||||||
pwm.add_pin(EXTRUDER_HEATER_PIN, percent)
|
pwm.add_pin(EXTRUDER_HEATER_PIN, percent)
|
||||||
else:
|
else:
|
||||||
@@ -83,6 +99,7 @@ def bed_heater_control(percent):
|
|||||||
""" Hot bed heater control.
|
""" Hot bed heater control.
|
||||||
:param percent: heater power in percent 0..100. 0 turns heater off.
|
:param percent: heater power in percent 0..100. 0 turns heater off.
|
||||||
"""
|
"""
|
||||||
|
if ENABLE_BED_HEATER:
|
||||||
if percent > 0:
|
if percent > 0:
|
||||||
pwm.add_pin(BED_HEATER_PIN, percent)
|
pwm.add_pin(BED_HEATER_PIN, percent)
|
||||||
else:
|
else:
|
||||||
@@ -93,21 +110,30 @@ def get_extruder_temperature():
|
|||||||
""" Measure extruder temperature.
|
""" Measure extruder temperature.
|
||||||
:return: temperature in Celsius.
|
:return: temperature in Celsius.
|
||||||
"""
|
"""
|
||||||
|
if ENABLE_EXTRUDER_HEATER:
|
||||||
return thermistor.get_temperature(EXTRUDER_TEMPERATURE_SENSOR_CHANNEL)
|
return thermistor.get_temperature(EXTRUDER_TEMPERATURE_SENSOR_CHANNEL)
|
||||||
|
else:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def get_bed_temperature():
|
def get_bed_temperature():
|
||||||
""" Measure bed temperature.
|
""" Measure bed temperature.
|
||||||
:return: temperature in Celsius.
|
:return: temperature in Celsius.
|
||||||
"""
|
"""
|
||||||
|
if ENABLE_BED_HEATER:
|
||||||
return thermistor.get_temperature(BED_TEMPERATURE_SENSOR_CHANNEL)
|
return thermistor.get_temperature(BED_TEMPERATURE_SENSOR_CHANNEL)
|
||||||
|
else:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def disable_steppers():
|
def disable_steppers():
|
||||||
""" Disable all steppers until any movement occurs.
|
""" Disable all steppers until any movement occurs.
|
||||||
"""
|
"""
|
||||||
|
if ENABLE_STEPPER_ENABLE_PIN:
|
||||||
logging.info("disable steppers")
|
logging.info("disable steppers")
|
||||||
gpio.set(STEPPERS_ENABLE_PIN)
|
gpio.set(STEPPERS_ENABLE_PIN)
|
||||||
|
else:
|
||||||
|
logging.info("command disabled ...")
|
||||||
|
|
||||||
|
|
||||||
def __calibrate_private(x, y, z, invert):
|
def __calibrate_private(x, y, z, invert):
|
||||||
@@ -202,6 +228,7 @@ def calibrate(x, y, z):
|
|||||||
:return: boolean, True if all specified end stops were triggered.
|
:return: boolean, True if all specified end stops were triggered.
|
||||||
"""
|
"""
|
||||||
# enable steppers
|
# enable steppers
|
||||||
|
if ENABLE_STEPPER_ENABLE_PIN:
|
||||||
gpio.clear(STEPPERS_ENABLE_PIN)
|
gpio.clear(STEPPERS_ENABLE_PIN)
|
||||||
logging.info("hal calibrate, x={}, y={}, z={}".format(x, y, z))
|
logging.info("hal calibrate, x={}, y={}, z={}".format(x, y, z))
|
||||||
if not __calibrate_private(x, y, z, True): # move from endstop switch
|
if not __calibrate_private(x, y, z, True): # move from endstop switch
|
||||||
@@ -220,6 +247,7 @@ def move(generator):
|
|||||||
# calculation is done.
|
# calculation is done.
|
||||||
|
|
||||||
# enable steppers
|
# enable steppers
|
||||||
|
if ENABLE_STEPPER_ENABLE_PIN:
|
||||||
gpio.clear(STEPPERS_ENABLE_PIN)
|
gpio.clear(STEPPERS_ENABLE_PIN)
|
||||||
# 4 control blocks per 32 bytes
|
# 4 control blocks per 32 bytes
|
||||||
bytes_per_iter = 4 * dma.control_block_size()
|
bytes_per_iter = 4 * dma.control_block_size()
|
||||||
@@ -326,9 +354,13 @@ def deinit():
|
|||||||
join()
|
join()
|
||||||
disable_steppers()
|
disable_steppers()
|
||||||
pwm.remove_all()
|
pwm.remove_all()
|
||||||
|
if ENABLE_SPINDLE:
|
||||||
gpio.clear(SPINDLE_PWM_PIN)
|
gpio.clear(SPINDLE_PWM_PIN)
|
||||||
|
if ENABLE_FAN:
|
||||||
gpio.clear(FAN_PIN)
|
gpio.clear(FAN_PIN)
|
||||||
|
if ENABLE_EXTRUDER_HEATER:
|
||||||
gpio.clear(EXTRUDER_HEATER_PIN)
|
gpio.clear(EXTRUDER_HEATER_PIN)
|
||||||
|
if ENABLE_BED_HEATER:
|
||||||
gpio.clear(BED_HEATER_PIN)
|
gpio.clear(BED_HEATER_PIN)
|
||||||
watchdog.stop()
|
watchdog.stop()
|
||||||
|
|
||||||
|
|||||||
@@ -19,17 +19,23 @@ def spindle_control(percent):
|
|||||||
""" Spindle control implementation 0..100.
|
""" Spindle control implementation 0..100.
|
||||||
:param percent: Spindle speed in percent.
|
:param percent: Spindle speed in percent.
|
||||||
"""
|
"""
|
||||||
|
if ENABLE_SPINDLE:
|
||||||
logging.info("spindle control: {}%".format(percent))
|
logging.info("spindle control: {}%".format(percent))
|
||||||
|
else:
|
||||||
|
logging.info("spindle control disabled")
|
||||||
|
|
||||||
|
|
||||||
def fan_control(on_off):
|
def fan_control(on_off):
|
||||||
"""Cooling fan control.
|
"""Cooling fan control.
|
||||||
:param on_off: boolean value if fan is enabled.
|
:param on_off: boolean value if fan is enabled.
|
||||||
"""
|
"""
|
||||||
|
if ENABLE_FAN:
|
||||||
if on_off:
|
if on_off:
|
||||||
logging.info("Fan is on")
|
logging.info("Fan is on")
|
||||||
else:
|
else:
|
||||||
logging.info("Fan is off")
|
logging.info("Fan is off")
|
||||||
|
else:
|
||||||
|
logging.info("fan control disabled")
|
||||||
|
|
||||||
|
|
||||||
# noinspection PyUnusedLocal
|
# noinspection PyUnusedLocal
|
||||||
|
|||||||
Reference in New Issue
Block a user