Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add emergency relais support, inspired by pr60 #198

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,21 @@
#######################################
# Output to control the relay
#######################################
# A single GPIO pin is used to control a relay which controls the kiln.
# One GPIO pin is used to control a relay which controls the kiln.
# I use GPIO pin 23.
#
# A second GPIO pin is used to control an emergency cutoff relay which
# stops the kiln even if the SSRs short out.

try:
import board
spi_sclk = board.D17 #spi clock
spi_miso = board.D27 #spi Microcomputer In Serial Out
spi_cs = board.D22 #spi Chip Select
spi_mosi = board.D10 #spi Microcomputer Out Serial In (not connected)
gpio_heat = board.D23 #output that controls relay
gpio_heat_invert = False #invert the output state
spi_sclk = board.D17 #spi clock
spi_miso = board.D27 #spi Microcomputer In Serial Out
spi_cs = board.D22 #spi Chip Select
spi_mosi = board.D10 #spi Microcomputer Out Serial In (not connected)
gpio_heat = board.D23 #output that controls relay
gpio_heat_invert = False #invert the output state
gpio_emergency = board.D26 #output that controls emergency relay
except (NotImplementedError,AttributeError):
print("not running on blinka recognized board, probably a simulation")

Expand Down
29 changes: 29 additions & 0 deletions emergency-off.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env python
import config
import digitalio
import time
import datetime

try:
import board
except NotImplementedError:
print("not running a recognized blinka board, exiting...")
import sys
sys.exit()

########################################################################
#
# shut down the mergency relais

# Edit config.py and set the following in that file to match your
# hardware setup: gpio_emergency
########################################################################

emergency = digitalio.DigitalInOut(config.gpio_emergency)
emergency.direction = digitalio.Direction.OUTPUT

print("\nboard: %s" % (board.board_id))
print("emergency configured as config.gpio_emergency = %s BCM pin\n" % (config.gpio_emergency))

print("\nsetting emergency IO low")
emergency.value = False
1 change: 1 addition & 0 deletions lib/init/kiln-controller.service
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Description=kiln-controller

[Service]
ExecStart=/home/pi/kiln-controller/venv/bin/python /home/pi/kiln-controller/kiln-controller.py
ExecStopPost=/home/pi/kiln-controller/venv/bin/python /home/pi/kiln-controller/emergency-off.py

[Install]
WantedBy=multi-user.target
23 changes: 23 additions & 0 deletions lib/oven.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,21 @@ class Output(object):
inputs
config.gpio_heat
config.gpio_heat_invert
config.gpio_emergency
'''
def __init__(self):
self.active = False
self.heater = digitalio.DigitalInOut(config.gpio_heat)
self.heater.direction = digitalio.Direction.OUTPUT
self.emergency = digitalio.DigitalInOut(config.gpio_emergency)
self.emergency.direction = digitalio.Direction.OUTPUT
self.off = config.gpio_heat_invert
self.on = not self.off

def emergency_set(self,state):
log.info("emergency relais = %s" %(state))
self.emergency.value = state

def heat(self,sleepfor):
self.heater.value = self.on
time.sleep(sleepfor)
Expand Down Expand Up @@ -346,6 +353,7 @@ def reset(self):
self.heat_rate_temps = []
self.pid = PID(ki=config.pid_ki, kd=config.pid_kd, kp=config.pid_kp)
self.catching_up = False
self.emergency_trigger()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why an emergency is triggered here. I think you are using this to shut down power to the kiln relays after each heating cycle.... which seems odd to me.

I would think you would want to shut power to the kiln down when there is a known problem, not 20,000 times during a firing.

Maybe I'm misunderstanding the change?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most everything else looks fine. I would like to see this as optional... so it needs to be tested with and without the setting existing in config.py. It should not error out if the setting does not exist.


@staticmethod
def get_start_from_temperature(profile, temp):
Expand Down Expand Up @@ -392,11 +400,13 @@ def run_profile(self, profile, startat=0, allow_seek=True):
self.totaltime = profile.get_duration()
self.state = "RUNNING"
log.info("Running schedule %s starting at %d minutes" % (profile.name,startat))
self.emergency_release()
log.info("Starting")

def abort_run(self):
self.reset()
self.save_automatic_restart_state()
self.emergency_trigger()

def get_start_time(self):
return datetime.datetime.now() - datetime.timedelta(milliseconds = self.runtime * 1000)
Expand Down Expand Up @@ -676,6 +686,11 @@ def heat_then_cool(self):
# a simulation, so sleep.
time.sleep(self.time_step / self.speedup_factor)

def emergency_trigger(self):
log.info("emergency triggered -> heating disabled.")

def emergency_release(self):
log.info("emergency released -> heating enabled.")

class RealOven(Oven):

Expand Down Expand Up @@ -729,6 +744,14 @@ def heat_then_cool(self):
except KeyError:
pass

def emergency_trigger(self):
log.info("emergency triggered -> heating disabled.")
self.output.emergency_set(0)

def emergency_release(self):
log.info("emergency released -> heating enabled.")
self.output.emergency_set(1)

class Profile():
def __init__(self, json_data):
obj = json.loads(json_data)
Expand Down