Using a server that is connected to a camera that detects the location of a ball and a robot. When the client request for the coordinates of the ball and the robot, the value of the coordinates that are passed down are varying in +2/-2 due to the noise of the image. Is there anyway to solve it in the sense that i want an absolute value because i would be calling a method based on the values changed and if the values keep on varying each time it will cause a bug in the program when i run it
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[:]