附加是一種將機器人移動到特定距離的代碼,但是我希望它在接近和障礙時停止移動。我該怎麼做呢?我曾嘗試添加超聲波來檢測障礙物。我使用NXT-python的機器人不會停止
def move_to(brick, bx, by ,rx, ry):
wheel_circumference = (pi * wheel_diameter)
distance_per_turn = (wheel_circumference/360)
distance = math.sqrt((math.pow((bx - rx),2)) + (math.pow((by - ry),2)))
rotations = ((distance/distance_per_turn)/360)
tacho_units = (round((rotations) * 360))
both.turn(power=power, tacho_units=tacho_units, brake=False)
if(ultrasonic.get_sample() < 20):
both.brake()
def activate2():
update_coordinates()
bx,by = get_ballxy()
rx,ry,a = get_robotxya()
if(ultrasonic.get_sample() < 15):
both.turn(power=-65, tacho_units=380, brake= False)
time.sleep(1)
turn_to(brick,bx,by,rx,ry,a)
time.sleep(0.5)
move_to(brick,bx,by,rx,ry)
kickBall(brick,by,ry)
Thread(target=update_coordinates).start()
connect()
update_coordinates()
while True:
#activate()
activate2()
time.sleep(3)
大聲笑...我希望你選擇了一個這實際上有助於解決您提出的問題。無論如何,我不能幫你解決這個問題 – musefan
btw,你使用的是哪種nxt-python版本? – sloth
@ Mr.Steak nxt-python 2.2.2 – Edward