Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 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
c68d5c7
Merge pull request #20 from jwarshaw/detectLines
farrellw Nov 8, 2016
55f06ba
Update analyze module
Nov 8, 2016
ba1f783
Merge pull request #21 from jwarshaw/detectLines
farrellw Nov 8, 2016
68be584
Change controller logic to implment John/Henry analyzeLine
Nov 8, 2016
bfcc75d
Fix merge conflict in analyzeLine
Nov 8, 2016
cf5268b
Organize logic for first test run. Call run Analyze lines in control…
Nov 8, 2016
4052376
Merge pull request #22 from jwarshaw/test_run_1
farrellw Nov 8, 2016
40253e3
Flip cam vert and horiz
Nov 8, 2016
4eefa90
Merge pull request #23 from jwarshaw/camera
farrellw Nov 8, 2016
36ddf99
Remove views folder including artifact and duplicte files
Nov 9, 2016
5639776
Remove init file from controllers folder
Nov 9, 2016
c815bed
Remove artifact files from models folder
Nov 9, 2016
0d485da
Remove models folder and copy pertinent files to root directory
Nov 9, 2016
02e82a7
Add gitignore file
Nov 9, 2016
9aefad7
Add images folder to gitignore file
Nov 9, 2016
cc1b1c1
Remove artifact files from root directory and add library to readme
Nov 9, 2016
23d61b2
Remove artifact pyc files
Nov 9, 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.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
images/
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# RaspberryDrive
Use a Raspberry Pi 3 to drive an RC Car

## Libraries
Python 2
SimpleCV
PiCamera
File renamed without changes.
24 changes: 24 additions & 0 deletions analyzeLine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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):
if (blob.maxY() > img.size()[1] * 0.4):
return True

def lengthSufficientToBlock(img,blob):
if (blob.width() > img.size()[0] * 0.55):
return True

Binary file added analyzeLine.pyc
Binary file not shown.
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.
56 changes: 56 additions & 0 deletions controllers/controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import os
import sys
from time import sleep
sys.path.insert(0, os.getcwd())
from models import analyzeLine
from models import runAnalyzeLine
from models.runAnalyzeLine import runAnalyzeLines
# from models.analyze import findBlockingBlobs
from models.analyzeLine import findBlockingBlobs
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):
instruction = "forward"
get_image()
if valid_image(os.getcwd() + "/gregTest.jpg"):
in_way = runAnalyzeLines(os.getcwd() + "/gregTest.jpg")
if (in_way == True):
instruction = "stop"
send_command(s, instruction, "0.5")
receive_confirmation(s)
# sleep(0.25)
print instruction
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()
48 changes: 0 additions & 48 deletions distance_to_camera.py

This file was deleted.

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()
15 changes: 15 additions & 0 deletions get_images_from_pi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import os
from PIL import Image

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 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.
Empty file removed models/ident.py
Empty file.
13 changes: 0 additions & 13 deletions models/send.py

This file was deleted.

3 changes: 0 additions & 3 deletions pseudocode.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@



def driveforward(time):
FOR each second in time
goforward(1)
Expand Down
14 changes: 14 additions & 0 deletions runAnalyzeLine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import SimpleCV
import cv2
import time
from analyzeLine import *

def runAnalyzeLines(image):
scvImg = SimpleCV.Image(image)
segmented = scvImg.stretch(160,161)
blobs = segmented.findBlobs(minsize=100)
if (blobs and (len(blobs) > 0)):
return findBlockingBlobs(scvImg,blobs)
return False
# print x
# print blob
Binary file added runAnalyzeLine.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.
20 changes: 20 additions & 0 deletions takePicture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import picamera as p
import os
import time

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

cam = p.PiCamera()
cam.resolution = (320,240)
cam.hflip = True
cam.vflip = True

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
exit()
Empty file removed views/input.py
Empty file.
Empty file removed views/output.py
Empty file.