I'm using a scribbler robot and writing code in Python. I'm trying to get it to stop when it sees an obstacle
So I created variables for the left obstacle sensor, the center obstacle sensor and the right obstacle sensor
left = getObstacle(0)
center = getObstacle(1)
right = getObstacle(2)
Then an if statement
if (left < 6400 & center < 6400 & right < 6400):
forward(1,1)
else:
stop()
Basically the idea is if the sensors read less than 6400, it should move forward, otherwise, it should stop. When testing the scribbler with the senses
function, I noticed when I put the robot close to an object, it would read around 6400.
Here's what I have for the main()
code
def main():
while True:
left = getObstacle(0)
center = getObstacle(1)
right = getObstacle(2)
lir = getIR(0)
rir = getIR(1)
if (left < 6400 & center < 6400 & right < 6400):
forward(1,1)
else:
stop()
Why isn't my robot responding? The Python code doesn't show any errors when I put it into the shell, but nothing is happening with my robot.
EDIT:
Some code changes. So far the robot will move, but it won't stop. Are my if and else statements incorrect?
center = getObstacle(1)
def main():
if (center < 5400):
forward(0.5)
else:
stop()