Эхо не получено. Зачем? Я хочу иметь робота, который будет двигаться, когда он доберется до стены, двигается назад и поворачивает путь с меньшими объектами, я использую Тонни на пи3, и мне семь лет. Ставлю:
import time
from gpiozero import CamJamKitRobot, DistanceSensor
pintrigger = 27
pinecho = 22
pinTrigger = 17
pinEcho = 18
robot = CamJamKitRobot()
sensor = DistanceSensor(echo=pinecho, trigger=pintrigger)
sensor2 = DistanceSensor(echo=pinEcho, trigger=pinTrigger)
hownear = 50.0
reversetime = 0.5
turntime = 0.75
leftmotorspeed = 0.5
rightmotorspeed = 0.5
motorforward = (leftmotorspeed, rightmotorspeed)
motorbackward = (-leftmotorspeed, -rightmotorspeed)
motorleft = (leftmotorspeed, 0)
motorright = (0, rightmotorspeed)
def isnearobstacle(localhownear):
distance = sensor.distance
if distance < localhownear:
return True
else:
return False
def avoidobstacle():
print("Backwards")
robot.value = motorright
time.sleep(reversetime)
robot.stop()
while sensor2.distance < 50:
print("Right")
robot.value = motorright
time.sleep(turntime)
robot.stop()
print(sensor2.distance * 100)
while sensor2.distance < 50:
print("Right")
robot.value = motorright
time.sleep(turntime)
robot.stop()
print(sensor2.distance * 100)
while sensor2.distance < 50:
print("Right")
robot.value = motorright
time.sleep(turntime)
robot.stop()
print(sensor2.distance * 100)
while sensor.distance < 50:
print("Left")
robot.value = motorleft
time.sleep(turntime)
robot.stop()
print(sensor.distance * 100)
try:
while True:
robot.value = motorforward
time.sleep(0.1)
if isnearobstacle(hownear):
robot.stop()
avoidobstacle()
except keyboardInterupt:
robot.stop()
Почему нет приема эха?