Python 如何更新机器人和对象的位置而不重复其值
我想知道我如何解决值被反复传递到激活(valueList)方法的问题。程序的工作方式是机器人和球,主循环不断地传递值列表方法。我的目标是将机器人转向球的方向并向它移动。问题是,如果球仍在移动,则值保持不变,直到它停止,从而导致机器人转向先前向下传递的角度。有没有具体的方法来解决这个问题?请注意,即使机器人和球处于静止状态,向下传递的值列表中的值也会区分+2或-2。另外,我正在使用乐高nxt(nxt python),它通过网络连接到一个传递数值的摄像头 例如: 返回值的方法:Python 如何更新机器人和对象的位置而不重复其值,python,lego,nxt,Python,Lego,Nxt,我想知道我如何解决值被反复传递到激活(valueList)方法的问题。程序的工作方式是机器人和球,主循环不断地传递值列表方法。我的目标是将机器人转向球的方向并向它移动。问题是,如果球仍在移动,则值保持不变,直到它停止,从而导致机器人转向先前向下传递的角度。有没有具体的方法来解决这个问题?请注意,即使机器人和球处于静止状态,向下传递的值列表中的值也会区分+2或-2。另外,我正在使用乐高nxt(nxt python),它通过网络连接到一个传递数值的摄像头 例如: 返回值的方法: def update
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
激活方法:
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)
所以听起来你只是想在改变中前进。在这种情况下,您可能只想保留前面的值并进行比较。然后,仅在检测到更改时调用
activate()
last_valueList = []
while True:
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 != last_valueList
activate(valueList)
last_valueList = valueList[:] # copy list
所以听起来你只是想在改变中前进。在这种情况下,您可能只想保留前面的值并进行比较。然后,仅在检测到更改时调用
activate()
last_valueList = []
while True:
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 != last_valueList
activate(valueList)
last_valueList = valueList[:] # copy list
摄像机确实应该提供连续的位置反馈。(例如,我们的眼睛跟踪系统将以500Hz的频率捕捉眼睛的位置)。机器人需要预测目标运动并绘制截获路线:)摄像机确实应该提供连续的位置反馈。(例如,我们的眼睛跟踪系统将以500Hz的频率捕捉眼睛的位置)。机器人需要预测目标运动并绘制截获路线:)如果传递的值在+2或-2之间变化会怎样,即使由于使用摄像机检测到的对象而使对象处于静止状态,我不熟悉nxt接口。为什么会有+2/-2的差异?啊,也许这就是相机的问题。不用担心。无论如何谢谢你(:我发现+2/-2差异是由于拍摄图像时相机的噪音造成的。这是否意味着我必须先对值列表进行平均,然后才能使用它们?我该怎么做?如果传递的值在+2或-2之间变化,即使由于相机检测到的对象处于静止状态,该怎么办我不熟悉nxt接口。为什么会有+2/-2的差异?啊,可能是相机的问题。不用担心。无论如何,谢谢(:我发现+2/-2差异是由于拍摄图像时相机的噪音造成的。这是否意味着我必须先对值列表进行平均,然后才能使用它们?我将如何处理?