fusion_hat.modules.ultrasonic module
- class fusion_hat.modules.ultrasonic.Ultrasonic(trig, echo, timeout=0.02)[source]
Bases:
objectUltrasonic sensor module.
- Parameters:
- Raises:
TypeError – If trig or echo is not a Pin object.
- SOUND_SPEED = 343.3
Sound speed in meters per second.
- read_raw()[source]
Read raw distance value from ultrasonic sensor.
- Returns:
- Distance in centimeters. Returns -1 if timeout occurs,
-2 if pulse start or end is 0, or any other error.
- Return type:
float
- read_with_retry(times=10)[source]
Read distance value with retry mechanism.
- Parameters:
times (int, optional) – Number of retry attempts. Default is 10.
- Returns:
Distance in centimeters. Returns -1 if all attempts fail.
- Return type:
float
- read()[source]
Read distance value.
- Returns:
- Distance in centimeters. Returns -1 if thread is running,
otherwise returns the last read value.
- Return type:
float