我正在和一个带测线传感器和超声波回避传感器的PiCar-S合作。我们的皮卡是在一个迷宫的黑色磁带,我们希望皮车只使用2个传感器的权利线传感器。我们将在迷宫上放置物体,当它用超声波回避传感器检测到物体时,它将停止,拍照(不可移动的物体用O标记,可移动的物体用X标记),可移动的物体从迷宫中移开。对于不可移动的物体,PiCar需要绕过它们并继续回到线上。如何开始在我的代码中修复此部分(粗体):
def avoidObject(within_a_distance):
within_a_distance = within_a_distance*2.54
average = (objSensor.distance()+objSensor.distance()+objSensor.distance()) / 3
if average <= within_a_distance:
motors.stop()
camera.start_preview()
objResponse = input("What is this?: ")
if objResponse == "X":
print("MoOb...waiting for MoOb extraction...")
**elif objResponse == "O":
print("non-MoOb...going around...")
while objSensor.distance() <= within_a_distance:
motors.backward()
time.sleep(1)
motors.stop()
steering.turn_left()
motors.forward()
time.sleep(1.5)
steering.turn_right()
time.sleep(1.5)
steering.turn(1)
steering.turn_straight()**
elif objResponse == "Q":
print("Found the Ore...collecting sample...Mission Complete")
elif isMoObDetected(DISTANCE_THRESHOLD) == True:
print("The cow says MooooooooOb!")
while objSensor.distance() > 6:
walk()
#the car will wait until we move the moOb
# and then continue to follow the line
If object is X
motors.backward() #Go back to give it enough room to turn
time.sleep(1)
steering.turn(135) #I want it to make a right
Time.sleep(1)
Steering.turn_straight() #Straighten out
Time.sleep(1)
Steering.turn_left() #Make some sort of left turn to get back on the line
Continue following the line
目前没有回答
相关问题 更多 >
编程相关推荐