From 8273c00881cf953f85992fad10476def879766c3 Mon Sep 17 00:00:00 2001 From: Laurens Valk Date: Tue, 26 May 2020 15:28:08 +0200 Subject: [PATCH] api/pupdevices/UltrasonicSensor: add methods This is identical to the EV3 Ultrasonic Sensor methods. --- doc/api/pupdevices.rst | 4 ++++ pybricks/pupdevices.py | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/doc/api/pupdevices.rst b/doc/api/pupdevices.rst index 5e115a4..f7df9eb 100644 --- a/doc/api/pupdevices.rst +++ b/doc/api/pupdevices.rst @@ -159,6 +159,10 @@ Ultrasonic Sensor .. autoclass:: pybricks.pupdevices.UltrasonicSensor :no-members: + .. automethod:: pybricks.pupdevices.UltrasonicSensor.distance + + .. automethod:: pybricks.pupdevices.UltrasonicSensor.presence + .. rubric:: Built-in lights This sensor has 4 built-in lights. You can adjust the brightness of each diff --git a/pybricks/pupdevices.py b/pybricks/pupdevices.py index a280416..7877168 100644 --- a/pybricks/pupdevices.py +++ b/pybricks/pupdevices.py @@ -226,6 +226,44 @@ class UltrasonicSensor: lights = _LightArray(3) + def __init__(self, port): + """UltrasonicSensor(port) + + Arguments: + port (Port): Port to which the sensor is connected. + + """ + pass + + def distance(self, silent=False): + """Measures the distance between the sensor and an object using + ultrasonic sound waves. + + Arguments: + silent (bool): Choose ``True`` to turn the sensor off after + measuring the distance. This reduces interference + with other ultrasonic sensors. + + Returns: + :ref:`distance`: Distance. + + """ + pass + + def presence(self): + """Checks for the presence of other ultrasonic sensors by detecting + ultrasonic sounds. + + If the other ultrasonic sensor is operating in silent mode, you can + only detect the presence of that sensor while it is taking a + measurement. + + Returns: + bool: ``True`` if ultrasonic sounds are detected, + ``False`` if not. + """ + pass + class ForceSensor: """LEGO® SPIKE Force Sensor."""