Skip to content

Commit 725d4ad

Browse files
committed
Send position to server
Now this sends the position info to the server.
1 parent f0fce4c commit 725d4ad

File tree

1 file changed

+46
-3
lines changed

1 file changed

+46
-3
lines changed

BlimpDetect-8-28_JB.py

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
import numpy as np
88
from numpy import linalg as LA
99

10+
import socket
11+
import time
12+
1013
global imghsv
1114
global x_3d, y_3d, z_3d
1215

@@ -26,6 +29,22 @@
2629

2730
# to modify color thresholds, change the cv.Scalar values in the InRange method in the gettresholdedimg function below
2831

32+
def connect(ip,port):
33+
#make a client socket
34+
35+
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
36+
s.settimeout(1)
37+
#keep trying to connect to the server until success
38+
print("connecting to control server...")
39+
connected = False
40+
#while not connected:
41+
try:
42+
s.connect((ip, port))
43+
connected = True
44+
except Exception as err:
45+
pass
46+
#print("connected")
47+
return s
2948

3049
#The following function takes coordinates from the images and convertes them to 3D spatial positions
3150
#The calibration constants are in R1, T1, R2, and T2 for cameras 1 (west) and 2 (east)
@@ -160,6 +179,14 @@ def getthresholdedimg(im):
160179
# blank lists to store coordinates of blue blob
161180
blue = []
162181

182+
#address of the control server
183+
ip = "md-red5.discovery.wisc.edu"
184+
port = 7779
185+
size = 1024
186+
187+
#first get a connection to the server
188+
s = connect(ip,port)
189+
163190
while(1):
164191
urllib.urlretrieve(url_west,fname_west)
165192
urllib.urlretrieve(url_east,fname_east)
@@ -181,6 +208,10 @@ def getthresholdedimg(im):
181208
contour = cv.FindContours(imgbluethresh, storage, cv.CV_RETR_CCOMP, cv.CV_CHAIN_APPROX_SIMPLE)
182209
# blank list into which points for bounding rectangles around blobs are appended
183210
points = []
211+
212+
centroidx = 0
213+
centroidy = 0
214+
184215
while contour:
185216

186217
# Draw bounding rectangles
@@ -296,8 +327,20 @@ def getthresholdedimg(im):
296327

297328
triang_3D(centx_west, centy_west, centx_east, centy_east)
298329

299-
print("x_3d: " + str(x_3d))
300-
print("y_3d: " + str(y_3d))
301-
print("z_3d: " + str(z_3d))
330+
print("x_3d: " + str(x_3d[0]))
331+
print("y_3d: " + str(y_3d[0]))
332+
print("z_3d: " + str(z_3d[0]))
333+
334+
try:
335+
#x,y,z = getPosition()
336+
msg = "" + str(x_3d[0]) + "," + str(y_3d[0]) + "," + str(z_3d[0]) + "\n"
337+
s.send(msg)
338+
#time.sleep(1)
339+
except Exception as err:
340+
print("disconnected")
341+
#we got disconnected somehow, reconnect
342+
s = connect(ip,port)
343+
344+
302345

303346
######################################################

0 commit comments

Comments
 (0)