Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
102 changes: 102 additions & 0 deletions ObstacleAnalysis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
def getObstacleArray(maxIt = 100, power = 135, returnArray = 'center'):
setIRPower(power)
counter = 0
arrayOfLeftValue = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
arrayOfCenterValue = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
arrayOfRightValue = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
while counter < maxIt:
temp = getObstacle()
print str(temp[0]) + " "*(5-len(str(temp[0]))) + str(temp[1]) + " "*(5-len(str(temp[1]))) + str(temp[2])
arrayOfLeftValue[temp[0]/100] += 1
arrayOfCenterValue[temp[1]/100] += 1
arrayOfRightValue[temp[2]/100] += 1
counter += 1
if returnArray == 'center':
return arrayOfCenterValue
elif returnArray == 'left':
return arrayOfLeftValue
elif returnArray == 'right':
return arrayOfRightValue
elif returnArray == 'all':
return [arrayOfLeftValue, arrayOfCenterValue, arrayOfRightValue]

def printObstacle(maxIt = 100, power = 135, printArray = 'center'):
arrayOfValues = getObstacleArray(maxIt, power, printArray) #NOTE DO NOT PASS IN ALL
print "/n/n"
counter = 0
while counter < len(arrayOfValues):
print str(counter*100) + "-" + str((counter + 1)*100 - 1) + ": " + str(arrayOfValue[counter])
counter += 1

def returnMostCommonObstacle(maxIt = 100, power = 135, printArray = 'all'):
arrayOfValues = getObstacleArray(maxIt, power, printArray)

if printArray == 'left': #Converts the one dimensional array to a
arrayOfValues = [arrayOfValues] #3 dimensional array with the original
arrayOfValues.append([0]) #array at the new array[1]
arrayOfValues.append([0])

counter = 0
highestValueLeftIndex = 0
while counter < len(arrayOfValues[0]):
if arrayOfValues[0][counter] > arrayOfValues[0][highestValueLeftIndex]:
highestValueLeftIndex = counter
counter += 1

highestValueLeftIndex *=100

if printArray == 'left':
return highestValueLeftIndex

if printArray == 'center': #Converts the one dimensional array to a
arrayOfValues = [arrayOfValues] #3 dimensional array with the original
arrayOfValues.append([0]) #array at the new array[1]
arrayOfValues.append([0])
arrayOfValues[1] = arrayOfValues[0]
arrayOfValues[0] = [0]

counter = 0
highestValueCenterIndex = 0
while counter < len(arrayOfValues[1]):
if arrayOfValues[1][counter] > arrayOfValues[1][highestValueCenterIndex]:
highestValueCenterIndex = counter
counter += 1

highestValueCenterIndex *=100

if printArray == 'center':
return highestValueCenterIndex

if printArray == 'right': #Converts the one dimensional array to a
arrayOfValues = [arrayOfValues] #3 dimensional array with the original
arrayOfValues.append([0]) #array at the new array[2]
arrayOfValues.append([0])
arrayOfValues[2] = arrayOfValues[0]
arrayOfValues[0] = [0]

counter = 0
highestValueRightIndex = 0
while counter < len(arrayOfValues[2]):
if arrayOfValues[2][counter] > arrayOfValues[2][highestValueRightIndex]:
highestValueRightIndex = counter
counter += 1

highestValueRightIndex *=100

if printArray == 'right':
return highestValueRightIndex

return highestValueLeftIndex + highestValueCenterIndex + highestValueRightIndex



def printIR(maxIt = 100):
counter = 0
while counter < maxIt:
temp = getIR()
print temp
counter += 1

#printObstacle(20)
#returnObstacle(20)
#printIR(1000)
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Scribbler
=========

this is some simple AI forr a scribbler v2 robot, it is eventually going to be able to guide people away from an emergency situation.
10 changes: 0 additions & 10 deletions hello.c

This file was deleted.

49 changes: 49 additions & 0 deletions jimmyBrain.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from myro import *
def fun():
count = 0
direction = 1
whereAmIX = 0
whereAmIY = 0
initialize("COM3")
while (count < 1):
temp = returnMostCommonObstacle(10, 130)
print 'TEMP: ' + str(temp)
while (temp < 300):
while (whereAmIX > 0): #if jimmy is not on it's original x
forward(1,2);
whereAmIY += 2
turnLeft(.79, 1) #he turns to the left
temp = returnMostCommonObstacle(10, 130) #checks if there is somthing in front of him
while (temp > 1000):
turnRight(.79, 1) #if there is something in front of him turns back to right
forward(1,1) #goes forward
turnLeft(.79, 1) #turns left again
temp = returnMostCommonObstacle() #checks the obstacle again
while (whereAmIX != 0 and temp < 1000):
forward(1,1)
whereAmIX -= 1
temp = returnMostCommonObstacle(10, 130)
print 'done yo'
turnRight(.79, 1)


whereAmIY += 1
forward(1, 1)
temp = returnMostCommonObstacle(10, 130)
print 'TEMP: ' + str(temp)
print 'position in y' + str(whereAmIY)

while (temp < 1000):
whereAmIY += 0.5
forward(1, 0.5)
temp = returnMostCommonObstacle(10, 130)
print 'TEMP: ' + str(temp)
print 'position ' + str(whereAmIY) + str(whereAmIX)

while (temp > 1000):
turnAndGo()
whereAmIX += 2
temp = returnMostCommonObstacle(10, 130)



28 changes: 28 additions & 0 deletions leftRightCheck
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# call checkObstacleLFR to get an obstacle array
# DO NOT call checkObstacle. It's called by checkObstacleLFR
# put the distance you want as the parameter
def checkObstacle(thresholdDistance, Direction):
if Direction == "Forward":
Distance = getObstacle("middle")
elif Direction == "Left":
turnLeft(0.5,1.5)
Distance = getObstacle("middle")
turnRight(0.5,1.5)
elif Direction == "Right":
turnRight(0.5,1.5)
Distance = getObstacle("middle")
turnLeft(0.5,1.5)
else:
return 1
if Distance < thresholdDistance:
return 0
else:
return 1

def checkObstacleLFR(thresholdDistance):
a = [0,0,0]
a[0] = checkObstacle(thresholdDistance,"Left")
a[2] = checkObstacle(thresholdDistance,"Right")
a[1] = checkObstacle(thresholdDistance,"Forward")
return a

10 changes: 10 additions & 0 deletions turnAndGo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def turnAndGo():
turnLeft(-0.79, 1)
temp = returnMostCommonObstacle(10, 130)
if (temp <= 1000): #this checks if the most common is zero and drives forward if nothing is in front of it
forward(1,1.75)
turnLeft(0.79, 1)
# elif(temp > 1000):
# turnRight(1.58, 1)
# forward