No echo received. Why? I want to have a robot that will move, when it gets to a wall move backwards and turn the way with lesser objects, I am using Thonny on a pi3 and I am seven years old. I put:
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()
Why is there no echo receiving?