- improved Ev3Server

- implemted PID controller in Lasertrack. Provide motor power directly to EV3
  (use lasertracker.ev3)



git-svn-id: http://moon:8086/svn/software/trunk/projects/opencv@343 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
2016-10-25 18:05:21 +00:00
parent 97c2eefe85
commit 64308aa3b7
2 changed files with 65 additions and 20 deletions
+6 -5
View File
@@ -12,6 +12,7 @@ class LocalServer(object):
self.thread = None
self.cancel = False
self.sockTcpEv3 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sockTcpEv3.settimeout(1.0)
self.sockTcpEv3.connect((ip, port))
print ("EV3 connected")
self.sockTcpEv3.send(b'ET /target?sn=')
@@ -59,7 +60,7 @@ class LocalServer(object):
if sock == conn:
data = sock.recv(1024)
if data:
print ("Client: Received data (" + str(len(data)) + ")")
# print ("Client: Received data (" + str(len(data)) + ")")
self.sockTcpEv3.send(data) # send to EV3
else:
print ('Client: Connection closed:' + str(addr))
@@ -67,7 +68,7 @@ class LocalServer(object):
if sock == self.sockTcpEv3:
data = sock.recv(1024)
if data:
print ("EV3: Received data (" + str(len(data)) + ")")
# print ("EV3: Received data (" + str(len(data)) + ")")
conn.send(data) # send to Client
else:
print ('EV3: Connection closed:' + str(addr))
@@ -88,7 +89,7 @@ if ("__main__" == __name__):
UDP_IP = "0.0.0.0"
UDP_PORT = 3015
sockUdp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sockUdp.settimeout(10.0)
sockUdp.settimeout(30.0)
sockUdp.bind((UDP_IP, UDP_PORT))
localTcpServer = None
while True:
@@ -114,17 +115,17 @@ if ("__main__" == __name__):
# print (keyValueDict)
if keyValueDict['Protocol'] == 'EV3':
print ("EV3 discovered")
sockUdp.sendto(b'A', addr)
if localTcpServer is None:
print ("EV3 discovered")
try:
localTcpServer = LocalServer(addr[0], int(keyValueDict['Port']))
localTcpServer.start()
except Exception as e:
print (e)
if localTcpServer is not None:
localTcpServer = None
del localTcpServer
localTcpServer = None
if localTcpServer is not None:
localTcpServer.stop()