Permalink
Browse files

tidied code for pushing to github

  • Loading branch information...
fridgehead committed Jan 17, 2012
1 parent 8e1e7b9 commit 1dbfbc0816ebf55a9d4c77c760873b396c96819e
Showing with 68 additions and 31 deletions.
  1. +46 −20 annoyances.py
  2. +3 −3 settings
  3. +19 −8 this.py
View
@@ -1,46 +1,72 @@
-import serial
+import sys
+import socket
+import urllib, urllib2
+'''
+annoyances.py
+Things to annoy people with.
+
+Each function is in the table-o-annoyances and is called with the doAlarm method
+THESE WILL NEED EDITING FOR YOUR CONFIGURATION. All of these are specific to our network
+'''
class alarms:
+ #change the status of our traffic light
+ def sendTraffic(self, lev):
+ if 0 <= lev < 4:
+ message = urllib.quote("$rage" + str(lev))
+ urllib2.urlopen("http://babbage:8020/%s" % message)
+ else:
+ print "invalid level"
+ #first annoyance
def first(self, state):
if state:
- self.ser.write(chr(1))
+ self.sendTraffic(1)
+ self.ircSpeak("The sink has stuff in it")
else:
- self.ser.write(chr(0))
+ self.sendTraffic(0)
+ #second annoyance
def second(self, state):
if state:
- self.ser.write(chr(2))
+ self.sendTraffic(2)
+ self.ircSpeak("The sink *still* has washing up in it")
else:
- self.ser.write(chr(0))
-
+ self.sendTraffic(0)
+ #third annoyance
def third(self,state):
- print "third"
+ if state:
+ self.sendTraffic(3)
+ self.ircSpeak("FFS the sink needs cleaning, someone sort it out!")
+ else:
+ self.sendTraffic(0)
+ #build a function list to call from doAlarm
alarmList = [first, second, third]
- ser = None
+
def __init__ (self):
- try:
- self.ser = serial.Serial('/dev/ttyUSB1', baudrate=9600)
- self.ser.open()
- except:
- print "serial port not available"
+ #I used to ping things to the serial port until I decided that the traffic lights were a better idea
+ print "serial port not available, using IRC and traffic lights"
+
+ #send a string through IRC, this depends on our network setup so will need rewriting for yours
+ def ircSpeak(self, text):
+ sc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ sc.connect(("babbage",12345))
+ sc.send(text)
+ sc.close()
+ #trigger an alarm, first stop all other alarms, then start our requested one
def doAlarm(self, level):
- if self.ser == None:
- print "serial port busted for level: ", level
- return
if 0 <= level < len(self.alarmList):
for a in self.alarmList:
a(self, False)
self.alarmList[level](self, True)
-
+ #cycle through all alarm methods and run the "stop" command
def stopAllAlarms(self):
- if self.ser == None:
- print "stoppig alarms but serial port dead"
- return
for a in self.alarmList:
a(self, False)
+ #the next line got annoying
+# self.ircSpeak("The sink has been cleared, happy days")
View
@@ -1,3 +1,3 @@
-radius=30,5
-x=300,10
-y=164,10
+radius=10,62
+x=314,15
+y=408,15
View
27 this.py
@@ -2,7 +2,7 @@
import time
import sys
import cv
-import numpy as np
+
def getBrightness(img):
hue = cv.CreateImage(cv.GetSize(img), cv.IPL_DEPTH_8U,1)
sat = cv.CreateImage(cv.GetSize(img), cv.IPL_DEPTH_8U,1)
@@ -34,7 +34,7 @@ def main(debug=False, fromCam=False):
#get an image
im = None
if fromCam == True:
- capture = cv.CaptureFromCAM(0)
+ capture = cv.CaptureFromCAM(1)
im = cv.QueryFrame(capture)
else:
im = cv.LoadImage(sys.argv[1])
@@ -59,7 +59,7 @@ def main(debug=False, fromCam=False):
#create storage for hough cirlces
storage = cv.CreateMat(640, 1, cv.CV_32FC3)
#find the circles
- cv.HoughCircles(gray, storage, cv.CV_HOUGH_GRADIENT, 2, gray.width / 18, thresh, 200,0,0)
+ cv.HoughCircles(gray, storage, cv.CV_HOUGH_GRADIENT, 2, gray.width / 18, thresh, 300,0,0)
#how much shit have we detected?
detectedShit = 0
@@ -70,13 +70,23 @@ def main(debug=False, fromCam=False):
center = (int(val[0]), int(val[1]))
print "circular feature at: " + str(center), "size: " , str(radius)
+ sinkFound = False
#try and classify this as sink
if sinkx[0] - sinkx[1] < center[0] < sinkx[0] + sinkx[1]:
if sinky[0] - sinky[1] < center[1] < sinky[0] + sinky[1]:
- if plugradius[0] - plugradius[1] < radius < plugradius[0] + plugradius[1]:
+ #plugradius is now min/max
+ if plugradius[0] < radius < plugradius[1]:
print "..probably the PLUGHOLE"
cv.Circle(im, center, radius, (255, 0, 255), 3, 8, 0)
+ sinkFound = True
+ else:
+ print "..PH failed radius check"
+ else:
+ print "..PH failed Y check"
+
else:
+ print "..PH failed X check"
+ if not sinkFound:
print "..probably some unwashed shit"
detectedShit = detectedShit + 1
cv.Circle(im, center, radius, (0, 0, 255), 3, 8, 0)
@@ -114,7 +124,7 @@ def main(debug=False, fromCam=False):
else:
- print "Last status was dirty and now were CLEAN"
+ print "Last status was dirty and now we're CLEAN"
f = open("status", "w")
f.write("clean")
f.close()
@@ -132,6 +142,7 @@ def main(debug=False, fromCam=False):
cv.WaitKey(0)
if __name__ == '__main__':
-
- main(debug=True, fromCam=False)
-
+ from time import time
+ n = time()
+ main(debug=True, fromCam=True)
+ print str(time() - n)

0 comments on commit 1dbfbc0

Please sign in to comment.