i'm fairly new to programming and robotics and struggling with the following. i'm using the Lego Mindstorms EV3 brick and setup the ev3dev2 environment. i would like to program the robot in the way, that it gets the constantly the distance from the ultrasonic sensor and stops when it falls under some value. my first attempt was something like this:
from ev3dev2.auto import *m_right = LargeMotor(OUTPUT_A)m_left = LargeMotor(OUTPUT_D)us = UltrasonicSensor(INPUT_4)us.MODE_US_DIST_CM = 'US_DIST_CM'def move_timed(): m_right.run_timed(time_sp=3000, speed_sp=400) m_left.run_timed(time_sp=3000, speed_sp=400) m_right.wait_while('running') m_left.wait_while('running')def move_stop(): m_right.stop() m_left.stop()def start_moving(): dist=us.value()/10 while dist < 20: move_timed() else: move_stop()start_moving()when those functions are called us.value() measured the distance only once and not continuously. within the ev3dev-lib there is also the property UltrasonicSensor.distance_centimeters, but I'm not able get its value. though my attempts to get those values failed. when i changed it into:
def start_moving(): dist=us.distance_centimeters while dist < 20: move_timed() else: move_stop()i always get "One ore more arguments were out of range or invalid". thankful for any ideas how to get the value continuously!
ev3dev version: 4.14.96-ev3dev-2.3.2-ev3
ev3dev-lang-python version: python3-ev3dev 1.2.0