activate(valueList) メソッドに繰り返し渡される値の問題を解決する方法を知りたいです。プログラムは、ロボットとボールがあり、メイン ループが値リスト メソッドを継続的に渡すように動作します。私の目標は、ロボットをボールの方向に向けて、それに向かって移動することです。問題は、ボールがまだ動いている場合、停止するまで値が同じままであり、ロボットが以前の角度に回転することです。受け継がれました。これを回避する具体的な方法はありますか?ロボットとボールが静止していても、渡される valueList の値は +2 または -2 で区別されることに注意してください。PS。ネットワーク経由で値を渡すカメラに接続されているレゴ nxt (nxt-python) を使用しています
例えば:
値を返すメソッド:
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
activate メソッド: Ps turn_to および move_to メソッドは、オブジェクトに向かって回転および移動することを示します。
def activate():
new_x = updateBallx(valueList)
print 'Ball x',new_x
new_y = updateBally(valueList)
print 'Ball y',new_y
old_x = updateRobotx(valueList)
print 'Robot x',old_x
old_y = updateRoboty(valueList)
print 'Robot y',old_y
angle = updateRobota(valueList)
print 'Robot angle',angle
turn_to(brick,new_x, new_y, old_x, old_y, angle)
#time.sleep(2)
#move_to(brick,new_x, new_y, old_x, old_y)
#time.sleep(3)
#kickBall(brick,new_y, old_y)
#time.sleep(3)
そして、valueList に値を渡し続けるこのメイン ループ
screenw = 0
screenh = 0
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])
activate(valueList)