j5.components.derived.ultrasound module¶
Ultrasonic distance sensor.
A sensor that utilises the reflection of ultrasound to calculate the distance to a nearby object.
-
class
j5.components.derived.ultrasound.
UltrasoundInterface
[source]¶ Bases:
j5.components.component.Interface
An interface containing the methods required for an UltrasoundSensor.
-
get_ultrasound_distance
(trigger_pin_identifier: int, echo_pin_identifier: int) → Optional[float][source]¶ Get a distance in metres.
Parameters: - trigger_pin_identifier – pin number of the trigger pin.
- echo_pin_identifier – pin number of the echo pin.
Returns: Distance measured in metres, or None if it timed out.
-
get_ultrasound_pulse
(trigger_pin_identifier: int, echo_pin_identifier: int) → Optional[datetime.timedelta][source]¶ Get a timedelta for the ultrasound time.
Parameters: - trigger_pin_identifier – pin number of the trigger pin.
- echo_pin_identifier – pin number of the echo pin.
Returns: Time taken for the pulse, or None if it timed out.
-
-
class
j5.components.derived.ultrasound.
UltrasoundSensor
(gpio_trigger: j5.components.gpio_pin.GPIOPin, gpio_echo: j5.components.gpio_pin.GPIOPin, backend: j5.components.derived.ultrasound.UltrasoundInterface, *, distance_mode: bool = True)[source]¶ Bases:
j5.components.component.DerivedComponent
Ultrasonic distance sensor.
A sensor that utilises the reflection of ultrasound to calculate the distance to a nearby object.
-
distance
() → Optional[float][source]¶ Send a pulse and return the distance to the object.
Returns: Distance measured in metres, or None if it timed out. Raises: Exception – distance mode is disabled.
-