Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
371078f
Add picture
farrellw Nov 6, 2016
1f473e6
Add more comm test files
Nov 6, 2016
b855aa0
Merge branch 'master' of https://github.com/jwarshaw/RaspberryDrive i…
farrellw Nov 6, 2016
cb3876e
Merge pull request #2 from jwarshaw/distance_camera
farrellw Nov 6, 2016
e847e45
Merge pull request #3 from jwarshaw/folders
jwarshaw Nov 6, 2016
024b6ad
Merge pull request #4 from jwarshaw/comm
jwarshaw Nov 6, 2016
ff96c30
Add images
farrellw Nov 6, 2016
cc6cb57
Merge pull request #5 from jwarshaw/picture_branch
farrellw Nov 6, 2016
4f5168c
Change blob loop in infinite loop
hfyfe Nov 6, 2016
f2ae292
Merge pull request #6 from jwarshaw/change_blob_branch
farrellw Nov 6, 2016
549d0e0
Add file that loops and gets images from pi camera
farrellw Nov 7, 2016
90aa14d
Merge pull request #7 from jwarshaw/transfer_picture_branch
farrellw Nov 7, 2016
4c33991
Merge branch 'master' of https://github.com/chi-bobolinks-2016/Raspbe…
hfyfe Nov 7, 2016
be7ca05
add picar class with initialize, drive forward, drive backward, drive…
hfyfe Nov 7, 2016
d6a3027
Refactor into two separate methods
farrellw Nov 7, 2016
01a3967
add first attempt at server
hfyfe Nov 7, 2016
021f1e4
Merge pull request #8 from jwarshaw/analyze_pic_server
hfyfe Nov 7, 2016
0152fd1
Spread responsibility between analyze pic server and analyze
farrellw Nov 7, 2016
39bd878
add control statements
hfyfe Nov 7, 2016
0eb781a
Add relative path to analyze pic server
farrellw Nov 7, 2016
78be1f5
Delete line loading an unnecessary module
farrellw Nov 7, 2016
bf8f582
Merge pull request #9 from jwarshaw/combine_analysis_branch
farrellw Nov 7, 2016
5ecf3b5
update
hfyfe Nov 7, 2016
c3a96e4
Add controller aka analyze pic server
Nov 7, 2016
17114ca
add connect simple lib
hfyfe Nov 7, 2016
cef3438
refactor to clean up
Nov 7, 2016
da1faf1
Merge pull request #11 from jwarshaw/driver-code
farrellw Nov 7, 2016
5358e03
update
hfyfe Nov 7, 2016
4e939a4
Merge pull request #10 from jwarshaw/putting_parts_together
hfyfe Nov 7, 2016
0b78ac3
cleaning up server file
hfyfe Nov 7, 2016
22cfe55
Merge branch 'master' of https://github.com/jwarshaw/RaspberryDrive i…
hfyfe Nov 7, 2016
16159e5
refactor controller to get image, analyze image, send instruction
Nov 7, 2016
5b123d6
server update
hfyfe Nov 7, 2016
ab306d5
Add logic to only analyze picture if the picture is a valid image
Nov 8, 2016
7d5011a
Refactor around error statement. Change from getting greg to getting…
Nov 8, 2016
9c9a11a
Delete unnecessary function, get image x times. That logic done in c…
Nov 8, 2016
b385d24
Fix merge conflict. Kept Henry's changes on driving server. Fixed i…
Nov 8, 2016
9837da4
Merge pull request #12 from jwarshaw/controller_branch
jwarshaw Nov 8, 2016
33675b3
Move logic from analyze pic path to controller/controller
Nov 8, 2016
725dbac
Merge pull request #13 from jwarshaw/controller_organization
hfyfe Nov 8, 2016
e5071b2
add verbosity to server
hfyfe Nov 8, 2016
e948739
Add psuedocode logic
Nov 8, 2016
932eb7e
Relocate view for easy accessiblility in ssh command from server.
farrellw Nov 8, 2016
5fed127
Merge pull request #14 from jwarshaw/relocate_view_take_picture
farrellw Nov 8, 2016
5a39c3f
Merge branch 'master' into start_organization
Nov 8, 2016
360d35a
Add start camera function and controller psuedocode logic
Nov 8, 2016
e21acf6
Add start camera functionality to controller
Nov 8, 2016
ff174fe
Add exit logic
farrellw Nov 8, 2016
23e1682
Merge pull request #15 from jwarshaw/relocate_view_take_picture
farrellw Nov 8, 2016
da59c55
save
hfyfe Nov 8, 2016
155a480
resolving conflicts
hfyfe Nov 8, 2016
219e0a5
Remove dead files
Nov 8, 2016
a5adf8d
Remove artifact file
Nov 8, 2016
e400126
cleaning up errors
hfyfe Nov 8, 2016
81f711f
syntax error
hfyfe Nov 8, 2016
de54136
Start thread logic to start camera while async running program
Nov 8, 2016
4b15bea
Merge branch 'master' into start_organization
Nov 8, 2016
ced4a90
adding driver files
hfyfe Nov 8, 2016
88b18a4
Start thread for starting server. Needs work
Nov 8, 2016
76d6476
Commented out
Nov 8, 2016
b8f7454
Merge branch 'master' into start_organization
Nov 8, 2016
8de1659
removing driver code
hfyfe Nov 8, 2016
f11e862
Merge pull request #17 from jwarshaw/start_organization
Garner412 Nov 8, 2016
2b5c105
Run pictures, server, analyzation at the same time. Still need to im…
Nov 8, 2016
a008e81
Merge pull request #18 from jwarshaw/auto_start_server
Garner412 Nov 8, 2016
c216511
Move psuedocode around for readability. Push server ending function …
Nov 8, 2016
786da1e
Merge pull request #19 from jwarshaw/refactor_controller
Garner412 Nov 8, 2016
7248504
Merge branch 'master' into detectLines
Nov 8, 2016
782af93
Add line detector file
Nov 8, 2016
55f06ba
Update analyze module
Nov 8, 2016
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
Binary file added .DS_Store
Binary file not shown.
Empty file added __init__.py
Empty file.
23 changes: 23 additions & 0 deletions connect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import socket

def new_connection():
host = '192.168.2.4'
port = 9000
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))
return s;

def send_command(connection,command,time):
connection.send('' + command + ' ; ' + time)

def receive_confirmation(connection):
received = connection.recv(20)
return received;

def send_end_connection(connection):
connection.send('quit')
return

# example:
# con = new_conntection
# send_command(con,"forward",0.5)
Binary file added connect.pyc
Binary file not shown.
Binary file added controllers/.DS_Store
Binary file not shown.
Empty file added controllers/__init__.py
Empty file.
48 changes: 48 additions & 0 deletions controllers/controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import os
import sys
from time import sleep
sys.path.insert(0, os.getcwd())
from models.analyze import check_blob_in_direct_path
from get_images_from_pi import get_image, valid_image
from connect import new_connection, send_command, receive_confirmation,send_end_connection
from start_camera import start_camera
from start_server import start_server
import threading

#Start-all
threads = []
#start the server listening on contr pi
server_thread = threading.Thread(target=start_server)
threads.append(server_thread)
server_thread.start()
#Sleep for testing
sleep(2)
#start the camera taking pictures on camera pi
camera_thread = threading.Thread(target=start_camera)
threads.append(camera_thread)
camera_thread.start()
# Sleep to make sure server connects
sleep(5)
#start the server connection on this current server
s = new_connection()

#Run-All. X times do
#retrieve image. #Blog Detection
#send instruction over server
count = 0
while (count < 20):
get_image()
if valid_image(os.getcwd() + "/images/gregTest.jpg"):
instruction = check_blob_in_direct_path(os.getcwd() + "/images/gregTest.jpg")
send_command(s, instruction, "0.5")
count += 1
receive_confirmation(s)
count += 1

# #End-all
# #Stop the camera taking pictures on the camera pi -- still needs to be implemented
# #close the server connection
send_end_connection(s)
# #Kill the server listening process
s.close()
exit()
27 changes: 8 additions & 19 deletions distance_to_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import SimpleCV
import sys
from SimpleCV import Image

def check_image(image_path):
#Find file by path and import. File currently resides in same directory.
#Find file by path and import. File currently resides in same directory.
image = Image(image_path)
# grey = image.grayscale()

Expand All @@ -19,7 +19,7 @@ def check_image(image_path):
#check if the blob is in the middle 1/2 of screen and is too high
for blob in blobs[:-1]:
# print blob.contains()

if (blob.coordinates()[0] > array_bounds_possible_widths[0] and blob.coordinates()[0] < array_bounds_possible_widths[1]) and (blob.height() > image.height / 5 and blob.coordinates()[1] > image.height / 5 * 2):
# print grey.height
print blob.coordinates()[1]
Expand All @@ -28,21 +28,10 @@ def check_image(image_path):
instruction = "stop"

# Display the blob until you click on the left side of the picture.
display = SimpleCV.Display()
while display.isNotDone():
image.show()
if display.mouseLeft:
break
#display = SimpleCV.Display()
#while display.isNotDone():
#image.show()
##\#if display.mouseLeft:
#break

return instruction

print sys.argv[1]
instruction = check_image(sys.argv[1])
print instruction


# def check_width(image, blob):
# print check_width
# def check_height(image, blob):
# return (blob.height() > image.height / 1.5) and blob

Binary file added distance_to_camera.pyc
Binary file not shown.
45 changes: 45 additions & 0 deletions driving_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from socket import *
import run_rc_car as picar

def createPiReceiver():
serversocket = socket(AF_INET, SOCK_STREAM)
port = 9000
new_picar = picar.PiCar()
serversocket.bind(('',port))
serversocket.listen(5)
print "New Server Created, listening on port " + str(port)
while(1):
(clientsocket, address) = serversocket.accept()
print "accepted connection from " + str(address)
while(1):
transfer = clientsocket.recv(20).split(';')
if not transfer: break
if transfer == ['']: break
print "received: " + transfer
try:
inputParser(transfer[0].strip(),float(transfer[1]),new_picar)
clientsocket.send("true")
except Exception:
clientsocket.send("false")
continue


def inputParser(command,number,car):
print 'executing ' + command + ' for ' + str(number) +' seconds'
if command == "forward":
car.go_forward(number)
elif command == "backward":
car.go_backward(number)
elif command == "right":
car.go_forward_right(number)
elif command == "left":
car.go_forward_left(number)
elif command == "backward right":
car.go_backward_right(number)
elif command == "backward left":
car.go_backward_left(number)
else:
car.stop()


createPiReceiver()
22 changes: 22 additions & 0 deletions get_images_from_pi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import os
from PIL import Image

def get_image_x_times(times):
count = 0
while count < times:
#replace sleep with the amount of time needed to sleep in between getting pictures.
time.sleep(0.5)
count += 1

def get_image():
os.system('scp pi@192.168.2.5:Desktop/gregTest.jpg gregTest.jpg')
return
#if on a new computer and the pi address isn't connecting right away, need to create a key. Use the following website to do so
#https://www.raspberrypi.org/documentation/remote-access/ssh/passwordless.md

def valid_image(path):
try:
Image.open(path)
except IOError:
return False
return True
Binary file added get_images_from_pi.pyc
Binary file not shown.
Binary file added greg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file added gregTest.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/five.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/four.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/greg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/gregTest.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/one.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/seven.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/six.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/two.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions loop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import distance_to_camera as d


print "GOod idea"

instruction = d.check_image('images/two.jpg')

for x in range(0, 100):
print "We're on time %d" % (x)
instruction = d.check_image('images/two.jpg')


exit()
Binary file added models/.DS_Store
Binary file not shown.
Empty file added models/__init__.py
Empty file.
Binary file added models/__init__.pyc
Binary file not shown.
28 changes: 28 additions & 0 deletions models/analyze.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Import image library necessary for file
import SimpleCV
import sys
from SimpleCV import Image

def check_blob_in_direct_path(image_path):

image = Image(image_path)
# grey = image.grayscale()

instruction = "forward"
array_bounds_possible_widths = [image.width / 4, image.width / 4 * 3]
shapes_pic_attributes = image.size()

shapes_pic_size = shapes_pic_attributes[0] * shapes_pic_attributes[1]
# dist = img.colorDistance(SimpleCV.Color.Black).dilate(2)
blobs = image.findBlobs()

#check if the blob is in the middle 1/2 of screen and is too high
for blob in blobs[:-1]:
blob.draw(color=(255,0,0))
if (blob.coordinates()[0] > array_bounds_possible_widths[0] and blob.coordinates()[0] < array_bounds_possible_widths[1]) and (blob.height() > image.height / 5 and blob.coordinates()[1] > image.height / 5 * 2):
# print grey.height
blob.draw(color=(255,0,0))
instruction = "stop"

return instruction

Binary file added models/analyze.pyc
Binary file not shown.
26 changes: 26 additions & 0 deletions models/analyzeLine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import SimpleCV
import cv2
import time


def findBlockingBlobs(img,blobs):
for blob in blobs:
if blockingBlob(img,blob):
return True
return False

def blockingBlob(img,blob):
if heightBelowThreshold(img,blob):
if lengthSufficientToBlock(img,blob):
return True


def heightBelowThreshold(img,blob):
print "blob's maxY: "
print blob.maxY()
if (blob.maxY() > img.size()[1] * 0.4):
return True

def lengthSufficientToBlock(img,blob):
if (blob.width() > img.size()[0] * 0.55):
return True
13 changes: 13 additions & 0 deletions models/runAnalyzeLine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import SimpleCV
import cv2
import time
from analyzeLine import *

def runAnalyzeLines(image):
scvImg = SimpleCV(image)
segmented = scvImg.stretch(160,161)
blob = segmented.findBlobs(minsize=100)

# print x
# print blob
return findBlockingBlobs(scvImg,blob)
4 changes: 2 additions & 2 deletions models/send.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import socket

UDP_IP = "10.50.111.176"
UDP_PORT = 5005
UDP_IP = "38.140.126.106"
UDP_PORT = 10000
MESSAGE = "Hello, World!"

print "UDP target IP:", UDP_IP
Expand Down
15 changes: 15 additions & 0 deletions models/send_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/python

import socket #import socket module

s = socket.socket() #create a socket object
print "socket made"

host = '10.98.76.121' #Host i.p
port = 12397 #Reserve a port for your service

print "before connect"
s.connect((host,port))
print "after connect"
print s.recv(1024)
s.close
Empty file added models/webpy.py
Empty file.
Binary file added run_py_car.pyc
Binary file not shown.
63 changes: 63 additions & 0 deletions run_rc_car.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import RPi.GPIO as GPIO
from time import sleep

class PiCar(object):

def __init__(self):
GPIO.setmode(GPIO.BOARD)
self.pins = {'left' : 11,
'right' : 18,
'forward' : 16,
'backward' : 12 }
for pin_number in self.pins.itervalues():
GPIO.setup(pin_number,GPIO.OUT)
self.stop()


def stop(self):
for pin_number in self.pins.itervalues():
GPIO.output(pin_number,0)

def go_forward(self,time):
self.stop()
GPIO.output(self.pins['forward'],1)
sleep(int(time))
self.stop()

def go_backward(self,time):
self.stop()
GPIO.output(self.pins['backward'],1)
sleep(int(time))
self.stop()

def go_forward_right(self,time):
self.stop()
GPIO.output(self.pins['right'],1)
GPIO.output(self.pins['forward'],1)
sleep(int(time))
self.stop()

def go_forward_left(self,time):
self.stop()
GPIO.output(self.pins['left'],1)
GPIO.output(self.pins['forward'],1)
sleep(int(time))
self.stop()

def go_backward_right(self,time):
self.stop()
GPIO.output(self.pins['right'],1)
GPIO.output(self.pins['backward'],1)
sleep(int(time))
self.stop()

def go_backward_left(self,time):
self.stop()
GPIO.output(self.pins['left'],1)
GPIO.output(self.pins['backward'],1)
sleep(int(time))
self.stop()


picar = PiCar()

Binary file added run_rc_car.pyc
Binary file not shown.
6 changes: 6 additions & 0 deletions start_camera.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import os

def start_camera():
os.system('ssh pi@192.168.2.5 python RaspberryDrive/views/takePicture.py &')
return

Binary file added start_camera.pyc
Binary file not shown.
6 changes: 6 additions & 0 deletions start_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import os

def start_server():
os.system('ssh pi@192.168.2.4 python python-libs/RaspberryDrive/driving_server.py &')
return

Binary file added start_server.pyc
Binary file not shown.
17 changes: 17 additions & 0 deletions takePicture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import picamera as p
import os
import time

os.chdir('/home/pi/Desktop')

cam = p.PiCamera()
cam.resolution = (320,240)

x = 0

while x < 50:
#os.unlink('greg.jpg')
img = cam.capture('gregTest.jpg')
time.sleep(.25)
#oc.rename('gregTemp.jpg', 'greg.jpg')
x +=1
Binary file added three.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading