Skip to content
Snippets Groups Projects
Verified Commit cd8b394f authored by Jakub Vaněk's avatar Jakub Vaněk
Browse files

Use EV3 ultrasonic single-shot measurement algorithm from EV3 Lab software

parent 38a5cf59
No related merge requests found
Pipeline #109879 passed
......@@ -25,12 +25,14 @@ class UltrasonicSensor(EV3UartSensor):
def distance(self, silent=False) -> int:
"""
Measure the distance to the nearest obstacle in front of the sensor.
:param silent: If true, the ultrasonic sensor will not emit more
sound waves after the measurement finishes.
:return: Distance in millimeters or a magic value of 2550 if the measurement fails.
"""
cont_value = self.read_raw_mode(UltrasonicSensor.MODE_CONTINUOUS_CM)[0]
value = self.read_raw_mode(UltrasonicSensor.MODE_CONTINUOUS_CM)[0]
if silent:
self.start_set_mode(UltrasonicSensor.MODE_SINGLE_CM)
return cont_value
value = self.read_raw_mode(UltrasonicSensor.MODE_SINGLE_CM)[0]
return value
def presence(self) -> bool:
"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment