使用连接到检测球和机器人位置的摄像头的服务器。当客户端请求球和机器人的坐标时,由于图像的噪声,向下传递的坐标值在+2/-2 范围内变化。无论如何我想要一个绝对值来解决它,因为我会根据更改的值调用一个方法,并且如果值每次都在变化,它会在我运行它时导致程序中的错误
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect(('59.191.193.42',5555))
def updateBallx(valueList):
# updates red ball x-axis position
ballx = int(valueList[8])
return ballx
def updateBally(valueList):
# updates red ball y-axis position
bally = int(valueList[9])
return bally
def updateRobotx(valueList):
# updates robot x-axis position
robotx = int(valueList[12])
return robotx
def updateRoboty(valueList):
# updates robot x-axis position
roboty = int(valueList[13])
return roboty
def updateRobota(valueList):
# updates robot angle position
robota = int(valueList[14])
return robota
def activate():
new_x = 413 #updateBallx(valueList)
print new_x
new_y = 351 #updateBally(valueList)
print new_y
old_x = 309 #updateRobotx(valueList)
print old_x
old_y = 261 #updateRoboty(valueList)
print old_y
angle = 360 #updateRobota(valueList)
print angle
turn_to(brick,new_x, new_y, old_x, old_y, angle)
move_to(brick,new_x, new_y, old_x, old_y)
screenw = 0
screenh = 0
old_valueList = []
while 1:
client_socket.send("loc\n")
data = client_socket.recv(8192)
valueList = data.split()
if (not(valueList[-1] == "eom" and valueList[0] == "start")):
#print "continuing.."
continue
if(screenw != int(valueList[2])):
screenw = int(valueList[2])
screenh = int(valueList[3])
if valueList != old_valueList:
activate(valueList)
old_valueList = valueList[:]