-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfull_test1.py
More file actions
54 lines (36 loc) · 1.24 KB
/
full_test1.py
File metadata and controls
54 lines (36 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from SimpleCV import Camera, Image, Display, DrawingLayer, Color, ColorModel
from time import sleep
from subprocess import call
import math
def convertAngle( angle ):
return angle*200/180 + 50
myCamera = Camera(prop_set={'width' : 640, 'height' : 480})
delay = 0.5 # in s
angle = 0 # in degrees
launchSpeed = 5 # in m/s
g = 9.81 # in m/s^2
h = 0.12 # in m
while True:
frame = myCamera.getImage().colorDistance(Color.RED)
negative = frame.colorDistance(Color.WHITE)
blobs = negative.findBlobs(threshval=(210,210,210),minsize=10)
height = blobs[-1].height()
for b in blobs:
b.drawOutline(color=Color.RED)
distance = 0.01*9249/height # in m
print "max height is " + str(height) + " pixels"
print "distance to target is " + str(distance) + "m"
d2 = math.pow(distance,2)
v2 = math.pow(launchSpeed,2)
desc = d2 - 4*g*d2*(h+g*d2/(2*v2))/(2*v2)
if desc < 0:
angle = 0
else:
angle = 180/math.pi * math.atan( (distance + math.sqrt( desc ))/(g*d2/v2) )
if angle > 89:
angle = 180/math.pi * math.atan( (distance - math.sqrt( desc ))/(g*d2/v2) )
print "optimal angle is " + str(angle) + " degrees"
pwmTime = convertAngle(angle)
echoString = "echo 2=" + str(pwmTime) + " > /dev/servoblaster"
call([echoString],shell=True)
sleep(delay)