diff --git a/cnc/config.py b/cnc/config.py index 15668a5..803c8fb 100644 --- a/cnc/config.py +++ b/cnc/config.py @@ -53,23 +53,36 @@ BED_PID = {"P": 0.226740848076, # Pins configuration. # Enable pin for all steppers, low level is enabled. +ENABLE_STEPPER_ENABLE_PIN = False STEPPERS_ENABLE_PIN = 26 STEPPER_STEP_PIN_X = 21 STEPPER_STEP_PIN_Y = 16 STEPPER_STEP_PIN_Z = 12 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_Y = 19 STEPPER_DIR_PIN_Z = 13 STEPPER_DIR_PIN_E = 7 +ENABLE_SPINDLE = False SPINDLE_PWM_PIN = 4 +ENABLE_FAN = False FAN_PIN = 27 +ENABLE_EXTRUDER_HEATER = False EXTRUDER_HEATER_PIN = 18 +ENABLE_BED_HEATER = False BED_HEATER_PIN = 22 -EXTRUDER_TEMPERATURE_SENSOR_CHANNEL = 2 -BED_TEMPERATURE_SENSOR_CHANNEL = 1 +if ENABLE_EXTRUDER_HEATER: + EXTRUDER_TEMPERATURE_SENSOR_CHANNEL = 2 +if ENABLE_BED_HEATER: + BED_TEMPERATURE_SENSOR_CHANNEL = 1 ENDSTOP_PIN_X = 23 ENDSTOP_PIN_Y = 10 diff --git a/cnc/hal.py b/cnc/hal.py index 25e9893..197918a 100644 --- a/cnc/hal.py +++ b/cnc/hal.py @@ -107,19 +107,19 @@ except ImportError: # check if all methods that is needed is implemented if 'init' not in locals(): 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") -if 'fan_control' not in locals(): +if ENABLE_FAN and 'fan_control' not in locals(): 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") -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") -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") -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") -if 'disable_steppers' not in locals(): +if ENABLE_STEPPER_ENABLE_PIN and 'disable_steppers' not in locals(): raise NotImplementedError("hal.disable_steppers() not implemented") if 'calibrate' not in locals(): raise NotImplementedError("hal.calibrate() not implemented") diff --git a/cnc/hal_raspberry/hal.py b/cnc/hal_raspberry/hal.py index 6a15824..0face76 100644 --- a/cnc/hal_raspberry/hal.py +++ b/cnc/hal_raspberry/hal.py @@ -21,8 +21,16 @@ STEP_PIN_MASK_E = 1 << STEPPER_STEP_PIN_E def init(): """ Initialize GPIO pins and machine itself. """ - gpio.init(STEPPER_STEP_PIN_X, rpgpio.GPIO.MODE_OUTPUT) - gpio.init(STEPPER_STEP_PIN_Y, rpgpio.GPIO.MODE_OUTPUT) + 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) + 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_Z, rpgpio.GPIO.MODE_OUTPUT) gpio.init(STEPPER_STEP_PIN_E, rpgpio.GPIO.MODE_OUTPUT) gpio.init(STEPPER_DIR_PIN_X, rpgpio.GPIO.MODE_OUTPUT) @@ -32,16 +40,21 @@ def init(): gpio.init(ENDSTOP_PIN_X, 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(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(FAN_PIN) - gpio.clear(EXTRUDER_HEATER_PIN) - gpio.clear(BED_HEATER_PIN) - gpio.clear(STEPPERS_ENABLE_PIN) + if ENABLE_SPINDLE: + gpio.init(SPINDLE_PWM_PIN, rpgpio.GPIO.MODE_OUTPUT) + gpio.clear(SPINDLE_PWM_PIN) + if ENABLE_FAN: + gpio.init(FAN_PIN, rpgpio.GPIO.MODE_OUTPUT) + gpio.clear(FAN_PIN) + if ENABLE_EXTRUDER_HEATER: + gpio.init(EXTRUDER_HEATER_PIN, rpgpio.GPIO.MODE_OUTPUT) + gpio.clear(EXTRUDER_HEATER_PIN) + if ENABLE_BED_HEATER: + gpio.init(BED_HEATER_PIN, rpgpio.GPIO.MODE_OUTPUT) + gpio.clear(BED_HEATER_PIN) + if ENABLE_STEPPER_ENABLE_PIN: + gpio.init(STEPPERS_ENABLE_PIN, rpgpio.GPIO.MODE_OUTPUT) + gpio.clear(STEPPERS_ENABLE_PIN) watchdog.start() @@ -49,11 +62,12 @@ def spindle_control(percent): """ Spindle control implementation. :param percent: spindle speed in percent 0..100. If 0, stop the spindle. """ - logging.info("spindle control: {}%".format(percent)) - if percent > 0: - pwm.add_pin(SPINDLE_PWM_PIN, percent) - else: - pwm.remove_pin(SPINDLE_PWM_PIN) + if ENABLE_SPINDLE: + logging.info("spindle control: {}%".format(percent)) + if percent > 0: + pwm.add_pin(SPINDLE_PWM_PIN, percent) + else: + pwm.remove_pin(SPINDLE_PWM_PIN) def fan_control(on_off): @@ -61,53 +75,65 @@ def fan_control(on_off): Cooling fan control. :param on_off: boolean value if fan is enabled. """ - if on_off: - logging.info("Fan is on") - gpio.set(FAN_PIN) - else: - logging.info("Fan is off") - gpio.clear(FAN_PIN) + if ENABLE_FAN: + if on_off: + logging.info("Fan is on") + gpio.set(FAN_PIN) + else: + logging.info("Fan is off") + gpio.clear(FAN_PIN) def extruder_heater_control(percent): """ Extruder heater control. :param percent: heater power in percent 0..100. 0 turns heater off. """ - if percent > 0: - pwm.add_pin(EXTRUDER_HEATER_PIN, percent) - else: - pwm.remove_pin(EXTRUDER_HEATER_PIN) + if ENABLE_EXTRUDER_HEATER: + if percent > 0: + pwm.add_pin(EXTRUDER_HEATER_PIN, percent) + else: + pwm.remove_pin(EXTRUDER_HEATER_PIN) def bed_heater_control(percent): """ Hot bed heater control. :param percent: heater power in percent 0..100. 0 turns heater off. """ - if percent > 0: - pwm.add_pin(BED_HEATER_PIN, percent) - else: - pwm.remove_pin(BED_HEATER_PIN) + if ENABLE_BED_HEATER: + if percent > 0: + pwm.add_pin(BED_HEATER_PIN, percent) + else: + pwm.remove_pin(BED_HEATER_PIN) def get_extruder_temperature(): """ Measure extruder temperature. :return: temperature in Celsius. """ - return thermistor.get_temperature(EXTRUDER_TEMPERATURE_SENSOR_CHANNEL) + if ENABLE_EXTRUDER_HEATER: + return thermistor.get_temperature(EXTRUDER_TEMPERATURE_SENSOR_CHANNEL) + else: + return 0 def get_bed_temperature(): """ Measure bed temperature. :return: temperature in Celsius. """ - return thermistor.get_temperature(BED_TEMPERATURE_SENSOR_CHANNEL) + if ENABLE_BED_HEATER: + return thermistor.get_temperature(BED_TEMPERATURE_SENSOR_CHANNEL) + else: + return 0 def disable_steppers(): """ Disable all steppers until any movement occurs. """ - logging.info("disable steppers") - gpio.set(STEPPERS_ENABLE_PIN) + if ENABLE_STEPPER_ENABLE_PIN: + logging.info("disable steppers") + gpio.set(STEPPERS_ENABLE_PIN) + else: + logging.info("command disabled ...") def __calibrate_private(x, y, z, invert): @@ -202,7 +228,8 @@ def calibrate(x, y, z): :return: boolean, True if all specified end stops were triggered. """ # enable steppers - gpio.clear(STEPPERS_ENABLE_PIN) + if ENABLE_STEPPER_ENABLE_PIN: + gpio.clear(STEPPERS_ENABLE_PIN) logging.info("hal calibrate, x={}, y={}, z={}".format(x, y, z)) if not __calibrate_private(x, y, z, True): # move from endstop switch return False @@ -220,7 +247,8 @@ def move(generator): # calculation is done. # enable steppers - gpio.clear(STEPPERS_ENABLE_PIN) + if ENABLE_STEPPER_ENABLE_PIN: + gpio.clear(STEPPERS_ENABLE_PIN) # 4 control blocks per 32 bytes bytes_per_iter = 4 * dma.control_block_size() # prepare and run dma @@ -326,10 +354,14 @@ def deinit(): join() disable_steppers() pwm.remove_all() - gpio.clear(SPINDLE_PWM_PIN) - gpio.clear(FAN_PIN) - gpio.clear(EXTRUDER_HEATER_PIN) - gpio.clear(BED_HEATER_PIN) + if ENABLE_SPINDLE: + gpio.clear(SPINDLE_PWM_PIN) + if ENABLE_FAN: + gpio.clear(FAN_PIN) + if ENABLE_EXTRUDER_HEATER: + gpio.clear(EXTRUDER_HEATER_PIN) + if ENABLE_BED_HEATER: + gpio.clear(BED_HEATER_PIN) watchdog.stop() diff --git a/cnc/hal_virtual.py b/cnc/hal_virtual.py index c44dac9..0ff3090 100644 --- a/cnc/hal_virtual.py +++ b/cnc/hal_virtual.py @@ -19,17 +19,23 @@ def spindle_control(percent): """ Spindle control implementation 0..100. :param percent: Spindle speed in percent. """ - logging.info("spindle control: {}%".format(percent)) + if ENABLE_SPINDLE: + logging.info("spindle control: {}%".format(percent)) + else: + logging.info("spindle control disabled") def fan_control(on_off): """Cooling fan control. :param on_off: boolean value if fan is enabled. """ - if on_off: - logging.info("Fan is on") + if ENABLE_FAN: + if on_off: + logging.info("Fan is on") + else: + logging.info("Fan is off") else: - logging.info("Fan is off") + logging.info("fan control disabled") # noinspection PyUnusedLocal