The picture shows the hardware. The push button is wired to pin 14 of the GPIO bus (blue wire). A 10k resistor connects that lead to ground (brown wire). The 3v power supply is connected to the other side of the push button. If the button is depressed during start-up the 'Bot will abort prior to starting any of it's modules. If it is pressed any time while the 'Bot is running it will shutdown cleanly.
Here is the code for the abort of start-up:
# *****
# Abort startup if the kill switch is pressed
# *****
GPIO.setmode(GPIO.BCM)
GPIO.setup(intercom["pins"]["startRobot"], GPIO.IN)
GPIO.setwarnings(False)
if GPIO.input(intercom["pins"]["startRobot"]):
logger.critical("Aborting startup - kill switch pressed")
sys.exit(1)
# Abort startup if the kill switch is pressed
# *****
GPIO.setmode(GPIO.BCM)
GPIO.setup(intercom["pins"]["startRobot"], GPIO.IN)
GPIO.setwarnings(False)
if GPIO.input(intercom["pins"]["startRobot"]):
logger.critical("Aborting startup - kill switch pressed")
sys.exit(1)
No comments:
Post a Comment