Skip to content
This repository has been archived by the owner on Jan 5, 2019. It is now read-only.

Safe shutdown #165

Open
wants to merge 29 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
111cf1d
created ros node to check fo shutdown signal from power supply
Apr 12, 2017
f90a0ae
Merge branch 'safe_shutdown' of https://github.com/rwdavis513/openag_…
Apr 12, 2017
d4e082c
added signal_shutdown to launch file
Apr 12, 2017
953a930
Merge branch 'safe_shutdown' of https://github.com/rwdavis513/openag_…
Apr 12, 2017
772ec35
updated settings to test signal_shutdown
Apr 12, 2017
3b94174
updated pin references to use BOARD config
Apr 12, 2017
a9259e5
Merge branch 'safe_shutdown' of https://github.com/rwdavis513/openag_…
Apr 12, 2017
f3eb9bf
updated pin reference (fixed typo)
Apr 12, 2017
e84f5d2
Added publish signal
Apr 12, 2017
6e95dc7
Merge branch 'master' of https://github.com/OpenAgInitiative/openag_b…
Apr 21, 2017
b2f1e8f
Updated debounce to use an average instead of requiring all off signa…
Apr 21, 2017
58576d0
Modified shutdown to include -h flag
Apr 21, 2017
37e5e56
Modified debounce signal from break to continue
Apr 21, 2017
d5a2d0a
Fixed typo in cutoff threshold.
Apr 21, 2017
a3ecd3c
removed debug flag
Apr 21, 2017
fe5ad3b
Merge branch 'master' of https://github.com/OpenAgInitiative/openag_b…
Apr 25, 2017
72a784e
Moved from RPi.GPIO to periphery GPIO library
Apr 25, 2017
7b5d410
Added test case for signal shutdown
Apr 25, 2017
6194c14
modified main section in test file
Apr 25, 2017
d0f3800
modified gpio pins from global variables to local
Apr 25, 2017
946fbdd
Updated to address issues with python-periphery package not setting u…
gordonbrander May 5, 2017
54e145c
modified to use RPi again
rwdavis513 May 5, 2017
76bde17
Removed publish gpio values and replaced with logdebug
gordonbrander May 5, 2017
0c6ed2a
Merge branch 'master' into safe_shutdown
rwdavis513 May 24, 2017
f6ab43a
Merge pull request #257 from OpenAgInitiative/decouple_recipe_persist…
spaghet Jun 15, 2017
95fa124
Revert "Decouple recipe persistence"
spaghet Jun 15, 2017
52b929c
Merge pull request #282 from OpenAgInitiative/revert-257-decouple_rec…
rbaynes Jun 15, 2017
3902cf6
Merge branch 'master' into safe_shutdown
rwdavis513 Jun 15, 2017
963fb22
Merge branch 'develop' into safe_shutdown
rwdavis513 Jun 20, 2017
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
24 changes: 11 additions & 13 deletions nodes/signal_shutdown.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python
# Simple script for shutting down the raspberry Pi at the press of a button.
# by Inderpreet Singh
# Adapted by Jake Rye and Bob Davis
# Adapted by Jake Rye and Bob Davis in April, 2017

import RPi.GPIO as GPIO
from periphery import GPIO
import time
import os
import logging
Expand All @@ -20,27 +20,26 @@ def setup_gpio_pins():
# Use the Broadcom SOC Pin numbers
# Setup the Pin with Internal pullups enabled and PIN in reading mode.
rospy.logdebug('Setting GPIO27 / PIN13 to INPUT PULLUP')
GPIO.setmode(GPIO.BOARD)
# PIN13 / BCM 27 YELLOW / SW-COM - Signals Shutdown
GPIO.setup(13, GPIO.IN, pull_up_down = GPIO.PUD_UP)
gpio_13 = GPIO(13, "in") # Might need to pull the pin up?
Copy link
Contributor

Choose a reason for hiding this comment

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

do we know if this works? Sounds like from the comment that we're not sure.


# Turn delay relay on
# Sends signal to the relay to stay on until this drops low.
rospy.logdebug('Setting GPIO22 / PIN15 to OUTPUT HIGH')
GPIO.setup(15, GPIO.OUT) # PIN15 / BCM 22 / WHITE / CH1
GPIO.output(15, GPIO.HIGH)
gpio_15 = GPIO(15, "out") # PIN15 / BCM 22 / WHITE / CH1


def check_for_shutdown(pub13):
def check_for_shutdown():
# Monitor pin for stable signal to safely shutdown
while not rospy.is_shutdown():
pub13.publish(GPIO.input(13))
if not GPIO.input(13):
shutdown_signal_pin = gpio_13.read()
rospy.logdebug(shutdown_signal_pin)
if not shutdown_signal_pin:
rospy.logdebug('Initiating safe shutdown sequence')
successful_debounce = True
input_sum = 0
for i in range(VERIFICATION_TIME_SEC * 1000):
input_sum += GPIO.input(13)
input_sum += gpio_13.read()
time.sleep(0.001)
avg_signal = input_sum / ( VERIFICATION_TIME_SEC * 1000)
rospy.logdebug('The average signal after {} seconds was {}'.format(
Expand All @@ -54,17 +53,16 @@ def check_for_shutdown(pub13):
rospy.logdebug('Safely shutting down')
rospy.signal_shutdown('Safely shutting down due to Power Off Button')
time.sleep(5)
GPIO.output(15, GPIO.LOW)
gpio_15.write(0)
os.system("sudo shutdown -h now")
break
rospy.sleep(1.)


if __name__ == '__main__':
rospy.init_node('signal_shutdown')
pub13 = rospy.Publisher("/GPIO/13", Float64, queue_size=10)
setup_gpio_pins()
try:
check_for_shutdown(pub13)
check_for_shutdown()
except rospy.ROSInterruptException:
pass
2 changes: 1 addition & 1 deletion package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<run_depend>python-requests</run_depend>
<run_depend>python-gevent</run_depend>
<run_depend>python-flask</run_depend>

<run_depend>python-periphery-pip</run_depend>
<test_depend>rostest</test_depend>
<!-- The export tag contains other, unspecified, tags -->
<export>
Expand Down