I'm starting out with an EV3 lego robot and my first project to pop the cherry was getting it to move a certain distance, and having it stop when the ultrasonic sensor dectects something 3 cm away. But I have tried so many things and can't get it to work right. here is my code:
#!/usr/bin/env python3
from ev3dev2.motor import MoveTank, OUTPUT_B, OUTPUT_C, seconds
from ev3dev2.sensor.lego import TouchSensor
from ev3dev2.sensor.lego import UltrasonicSensor
from time import sleep
from time import seconds
us = UltrasonicSensor()
tank_pair = MoveTank(OUTPUT_B, OUTPUT_C, seconds)
tank_pair.on(left_speed=30, right_speed=30)
if distance_centimeters(10):
tank_pair.off()
Any help would be appreciated.
I believe you need something like this: