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

Conversation

rwdavis513
Copy link
Contributor

Created a node to watch for the safe shutdown signal to come from the power off switch.

# by Inderpreet Singh
# Adapted by Jake Rye and Bob Davis

import RPi.GPIO as GPIO
Copy link
Contributor

Choose a reason for hiding this comment

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

What if we use Python Periphery, rather than RPi for GPIO access? This would avoid an explicit RPi dependency. It also happens to be the dependency we will probably use for I2C access if we get the sensors talking directly to the Pi.

A while back, I made a PR to include python-periphery in rosdep as python-periphery-pip ros/rosdistro#14364. If we go this route, we can add it to package.xml as <run_depend>python-periphery-pip</run_depend>.

WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That sounds good to me. I'll make the change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like moving to python-periphery requires the appropriate access to the GPIO files. As a workaround access can be granted for the user running the code.

https://superuser.com/questions/826124/use-sys-class-gpio-in-python-without-root-permissions

In short, we'll need to add these two lines to the install script (something similar):

sudo echo
SUBSYSTEM=="gpio*", PROGRAM="/bin/sh -c \
'chown -R root:gpio /sys/class/gpio && chmod -R 770 /sys/class/gpio;
chown -R root:gpio /sys/devices/virtual/gpio && chmod -R 770 /sys/devices/virtual/gpio'" \ >> /etc/udev/rules.d/99-com.rules

Copy link
Contributor Author

@rwdavis513 rwdavis513 May 5, 2017

Choose a reason for hiding this comment

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

Unfortunately this wasn't as easy as we might have hoped. I found out the permissions error is a timing issue because the gpio pins need to be setup before sending commands to them. I submitted an issue for this on the python-periphery package: here

The other problem is the python-periphery package doesn't have a pull_up feature when setting up a pin to monitor. The RPi.GPIO library allows the pin to be pulled high and then watch when it goes low. The python-periphery package drops the pin low when set up as an input. I don't see how to get around this issue at this time.

I'd recommend we land this change using the RPi.GPIO library and identify another library or fix if we decide to move to different hardware. @gordonbrander Does that sound reasonable?

def check_for_shutdown(pub13):
# Monitor pin for stable signal to safely shutdown
while not rospy.is_shutdown():
pub13.publish(GPIO.input(13))
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason to publish this rather than log it? I don't see any subscribers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. This was mainly put in for debugging and left it thinking it could be useful to have in the future to help debugging. I'll move it over to the logdebug.

# 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.

@rwdavis513
Copy link
Contributor Author

@rbaynes and @spaghet Could one of you review this and merge it if everything looks ok?

@rbaynes
Copy link
Contributor

rbaynes commented May 31, 2017

@rwdavis513 so, from reading the comments it looks like this change will use the RPi library. I'm guessing @gordonbrander's suggestion to use the python-periphery lib was so that we would not have two libs that do similar things. @spaghet is working on the replacement for rosserial right now, and I think it just uses the standard python 'serial' lib and not either RPi or python-periphery (right Rikuo?). So if the best way to get this working is RPi, then I'm for it, if it doesn't conflict with the new work to replace the serial connection to the Arduino.

@rwdavis513 how do I wire up my bot so I can test this PR as it is?

Thanks!

@sp4ghet
Copy link
Collaborator

sp4ghet commented May 31, 2017

This PR shouldn't conflict with the serial patch I'm working on.
I've been using PySerial instead of python-periphery because it was less clunky. I can use python-periphery but it's low priority for me right now.

…e/decouple_recipe_persistence

Decouple recipe persistence
@rwdavis513 rwdavis513 changed the base branch from master to develop June 15, 2017 21:24
@rwdavis513
Copy link
Contributor Author

@rbaynes Could you please review and approve this change? Here are the directions to install it. I've tested on several PFCs already and it works correctly.
https://github.com/OpenAgInitiative/openag_safe_shutdown

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants