forked from Ridhwanluthra/NLMS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ridhwanluthra
committed
Feb 22, 2016
1 parent
18eb041
commit 6d8d3f1
Showing
10 changed files
with
433 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
from gpiozero import Motor | ||
#from gpiozero.Pin import | ||
#import RPi.GPIO as GPIO | ||
from encoders import d_move, refresh | ||
|
||
ml = Motor(2, 3) | ||
mr = Motor(14, 15) | ||
ml.stop() | ||
mr.stop() | ||
""" | ||
I am assuming that the initial location of the bot | ||
is facing upwards at 0,0 | ||
the bot can make only 90 degree turns | ||
""" | ||
|
||
|
||
|
||
direction = 'n' # n,e,w,s for different locations that it is facing | ||
usfront = 20 | ||
|
||
try: | ||
# ADD SOMETHING TO DO WHEN US IS LESS THAN 5; | ||
def forward(): | ||
if usfront <= 5: | ||
print "error" | ||
else: | ||
ml.forward() | ||
mr.forward() | ||
|
||
def sstop(): | ||
ml.stop() | ||
mr.stop() | ||
def turn_left(): | ||
while d_move()[0] <= 20 and d_move()[1] <= 20: | ||
ml.backward() | ||
mr.forward() | ||
sstop() | ||
refresh() | ||
|
||
def turn_right(): | ||
while d_move()[0] <= 20 and d_move()[1] <= 20: | ||
ml.forward() | ||
mr.backward() | ||
sstop() | ||
refresh() | ||
|
||
def up(): | ||
look_up() | ||
while d_move()[0] <= 20 and d_move()[1] <= 20: | ||
forward() | ||
sstop() | ||
refresh() | ||
|
||
def left(): | ||
look_left() | ||
while d_move()[0] <= 20 and d_move()[1] <= 20: | ||
forward() | ||
sstop() | ||
refresh() | ||
|
||
def right(): | ||
look_right() | ||
while d_move()[0] <= 20 and d_move()[1] <= 20: | ||
forward() | ||
sstop() | ||
refresh() | ||
|
||
def down(): | ||
look_down() | ||
while d_move()[0] <= 20 and d_move()[1] <= 20: | ||
forward() | ||
sstop() | ||
refresh() | ||
|
||
def look_up(): | ||
global direction | ||
if (direction == 'n'): | ||
pass | ||
elif (direction == 'e'): | ||
turn_left() | ||
elif (direction == 'w'): | ||
turn_right() | ||
elif (drection == 's'): | ||
turn_left() | ||
turn_left() | ||
direction = 'n' | ||
|
||
def look_down(): | ||
global direction | ||
if (direction == 'n'): | ||
turn_left() | ||
turn_left() | ||
elif (direction == 'e'): | ||
turn_right() | ||
elif (direction == 'w'): | ||
turn_left() | ||
elif (drection == 's'): | ||
pass | ||
direction = 's' | ||
|
||
def look_left(): | ||
global direction | ||
if (direction == 'n'): | ||
turn_left() | ||
elif (direction == 'e'): | ||
turn_left() | ||
turn_left() | ||
elif (direction == 'w'): | ||
pass | ||
elif (drection == 's'): | ||
turn_right() | ||
direction = 'w' | ||
|
||
def look_right(): | ||
global direction | ||
if (direction == 'n'): | ||
turn_right() | ||
elif (direction == 'e'): | ||
pass | ||
elif (direction == 'w'): | ||
turn_left() | ||
turn_left() | ||
elif (drection == 's'): | ||
turn_left() | ||
direction = 'e' | ||
except KeyboardInterrupt: | ||
print "cleaning" | ||
finally: | ||
#GPIO.cleanup() | ||
print"check it" |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import picamera | ||
|
||
camera = picamera.PiCamera() | ||
|
||
""" | ||
i need ultrasonic reading | ||
usfront, usleft, usright, usback | ||
if any are less than lets say 10cm click | ||
""" | ||
|
||
def click_picture(int k,int l): | ||
camera.capture('img_%d_%d.jpg'%k %l) | ||
|
||
#analysis of image |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import cv2 | ||
import numpy as np | ||
|
||
def countArray(i, j): | ||
counter=0 | ||
for row in range(i, i+m): | ||
for column in range(j, j+n): | ||
if(inputArray[i][j]==255): | ||
counter+=1 | ||
return counter | ||
|
||
def edging(dir): | ||
img = cv2.imread(dir, cv2.IMREAD_COLOR) | ||
edges=cv2.Canny(img,100,200) | ||
oppp=[] | ||
for x in xrange(edges.shape[0]): | ||
opp=[] | ||
for y in xrange(edges.shape[1]): | ||
opp.append(edges[x][y]) | ||
pass | ||
oppp.append(opp) | ||
pass | ||
#Save image to storage with a pseudo-unique name | ||
cv2.imwrite('img.png', edges) | ||
|
||
#if the number of cells in inputArray having value 255 are greater than "K",then value is 1 in output | ||
#here I am setting k=50 | ||
k=20 | ||
s01_=edges.shape[0] | ||
s02_=edges.shape[1] | ||
m=edges.shape[0]/10 | ||
n=edges.shape[1]/10 | ||
|
||
c=[] | ||
inputArray=[] | ||
#populating input array with random numbers 0 and 255 for testing purposes | ||
for i in range (s01_): | ||
for j in range (s02_): | ||
c.append(edges[i][j]) | ||
inputArray.append(c) | ||
c=[] | ||
outputArrayRows=s01_/m | ||
outputArrayColumns=s02_/n | ||
outputArray=[[] for i in range (outputArrayColumns)] | ||
for i in range (outputArrayRows): | ||
for j in range (outputArrayColumns): | ||
if countArray(i*m,j*n)>=k: | ||
outputArray[i].append(1) | ||
else: | ||
outputArray[i].append(0) | ||
return outputArray |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import RPi.GPIO as gpio | ||
gpio.setmode(gpio.BCM) | ||
|
||
leften = 18 | ||
righten = 17 | ||
dps = 30/24 #distance per spoke | ||
gpio.setup(leften,gpio.IN) | ||
gpio.setup(righten,gpio.IN) | ||
counter_left = 0 | ||
counter_right = 0 | ||
c = 0 | ||
a = 0 | ||
def d_move(): | ||
while True: | ||
global a | ||
global c | ||
global counter_left | ||
global counter_right | ||
b = a | ||
d = c | ||
a = gpio.input(leften) | ||
c = gpio.input(righten) | ||
if (a == 1 and b == 0): | ||
counter_left += 1 | ||
#print "left counter " | ||
#print counter_left | ||
if (c == 1 and d == 0): | ||
counter_right += 1 | ||
#print "right coutner " | ||
#print counter_right | ||
return [counter_left*dps, counter_right*dps] | ||
def refresh(): | ||
global a | ||
global c | ||
global counter_left | ||
global counter_right | ||
counter_left = 0 | ||
counter_right = 0 | ||
c = 0 | ||
a = 0 |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# RUN THIS SCRIPT AND THE REST WILL RUN THEMSELVES | ||
|
||
from sys import argv | ||
from traversal import mapping | ||
from edging import edging | ||
|
||
image_matrix = edging(argv[1]) # convert the picture into edges and return the sub_matrix | ||
x=0 | ||
y=0 | ||
# now i have the completed map of the room ready | ||
|
||
# add the ultrasonic sensors to find and save from obstacles. | ||
|
||
while True: | ||
mapping(x,y,image_matrix) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import bot_movement as bm | ||
|
||
try: | ||
bm.up() | ||
print "turning left" | ||
bm.turn_left() | ||
print "turning right" | ||
bm.turn_right() | ||
except KeyboardInterrupt: | ||
print "cleaning ptest.py" | ||
finally: | ||
print "done execution" |
Oops, something went wrong.