From a02fcee4b19d20ae87c2cec5197ebc629d0f5591 Mon Sep 17 00:00:00 2001 From: Ben Morris Date: Thu, 3 Oct 2013 13:13:49 -0400 Subject: [PATCH 1/5] Deleted --- hello.c | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 hello.c diff --git a/hello.c b/hello.c deleted file mode 100644 index 8fef1b8..0000000 --- a/hello.c +++ /dev/null @@ -1,10 +0,0 @@ -#include - -int main(void) -{ - - printf("Yo what's up?\n"); - - printf("Hello world!\n"); - return 0; -} \ No newline at end of file From 8fc4a3600e1478b57141de412d6364e59a628a10 Mon Sep 17 00:00:00 2001 From: Ben Morris Date: Tue, 29 Oct 2013 11:48:15 -0400 Subject: [PATCH 2/5] the first versions of jimmy's brains turnandgo is a simple as fuck program that makes jimmy "strafe" to the right Jimmybrain is the "main" function ObstacleAnalysis has all the functions that we'll use to get sensor info from jimmy, and a ton of other useful stuff! Try no to change obstacleAnalysis without explaining the change beforehand, kay? --- ObstacleAnalysis.py | 102 ++++++++++++++++++++++++++++++++++++++++++++ jimmyBrain.py | 20 +++++++++ turnAndGo.py | 5 +++ 3 files changed, 127 insertions(+) create mode 100644 ObstacleAnalysis.py create mode 100644 jimmyBrain.py create mode 100644 turnAndGo.py diff --git a/ObstacleAnalysis.py b/ObstacleAnalysis.py new file mode 100644 index 0000000..3d2fa82 --- /dev/null +++ b/ObstacleAnalysis.py @@ -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) diff --git a/jimmyBrain.py b/jimmyBrain.py new file mode 100644 index 0000000..9702d3d --- /dev/null +++ b/jimmyBrain.py @@ -0,0 +1,20 @@ +from myro import * +def fun(): + count = 0 + initialize("COM3") + while (count < 1): + temp = returnMostCommonObstacle(10, 130) + print 'TEMP: ' + str(temp) + while (temp < 300): + forward(1, 1) + temp = returnMostCommonObstacle(10, 130) + print 'TEMP: ' + str(temp) + + while (temp < 1000): + forward(1, 0.5) + temp = returnMostCommonObstacle(10, 130) + print 'TEMP: ' + str(temp) + + turnAndGo() + + diff --git a/turnAndGo.py b/turnAndGo.py new file mode 100644 index 0000000..dc9f965 --- /dev/null +++ b/turnAndGo.py @@ -0,0 +1,5 @@ +def turnAndGo(): + turnLeft(-0.79, 1) + forward(1,2) + turnLeft(0.79, 1) + From 8ff0f46344c79bbe7815071a4fb365d7102521d4 Mon Sep 17 00:00:00 2001 From: Ben Morris Date: Thu, 31 Oct 2013 17:17:24 -0400 Subject: [PATCH 3/5] Adding the position tracking This adds position tracking capabilities AND obstacle avoidance and stuff --- jimmyBrain.py | 31 ++++++++++++++++++++++++++++++- turnAndGo.py | 9 +++++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/jimmyBrain.py b/jimmyBrain.py index 9702d3d..b02f5ff 100644 --- a/jimmyBrain.py +++ b/jimmyBrain.py @@ -1,20 +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) - turnAndGo() + while (temp > 1000): + turnAndGo() + whereAmIX += 2 + temp = returnMostCommonObstacle(10, 130) + diff --git a/turnAndGo.py b/turnAndGo.py index dc9f965..b264a2b 100644 --- a/turnAndGo.py +++ b/turnAndGo.py @@ -1,5 +1,10 @@ def turnAndGo(): turnLeft(-0.79, 1) - forward(1,2) - 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 From 7b0d1c9dd56b69dcebe872b08f1b7c57d674aa06 Mon Sep 17 00:00:00 2001 From: Eaco Date: Mon, 4 Nov 2013 15:14:14 -0500 Subject: [PATCH 4/5] Create README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..0f5574c --- /dev/null +++ b/README.md @@ -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. From 306b2eafd5b6056d553bc1e4d08207852ae891b4 Mon Sep 17 00:00:00 2001 From: Ben Morris Date: Thu, 7 Nov 2013 12:29:46 -0500 Subject: [PATCH 5/5] LeftRightCheck added Here's a code that checks what is 45 deg to each side of the scribbler, and returns a 3 value array that tells if there is something to the right and left of the robot --- leftRightCheck | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 leftRightCheck diff --git a/leftRightCheck b/leftRightCheck new file mode 100644 index 0000000..f06781b --- /dev/null +++ b/leftRightCheck @@ -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 +