Skip to content

Commit

Permalink
api/pupdevices/ForceSensor: add methods
Browse files Browse the repository at this point in the history
  • Loading branch information
laurensvalk committed May 26, 2020
1 parent 2efa8d7 commit 4788acc
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 8 deletions.
13 changes: 7 additions & 6 deletions doc/api/pupdevices.rst
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ Color and Distance Sensor
Color Sensor
^^^^^^^^^^^^^^^^^^^^^^^^^

.. todo:: Support for this sensor is not yet implemented. API is experimental.

.. figure:: ../api/images/sensor_color_lights_label.png
:width: 70 %

Expand Down Expand Up @@ -151,8 +149,6 @@ Color Sensor
Ultrasonic Sensor
^^^^^^^^^^^^^^^^^^^^^^^^^

.. todo:: Support for this sensor is not yet implemented. API is experimental.

.. figure:: ../api/images/sensor_ultrasonic_lights_label.png
:width: 80 %

Expand All @@ -175,14 +171,19 @@ Ultrasonic Sensor
Force Sensor
^^^^^^^^^^^^^^^^^^^^^^^^^

.. todo:: Support for this sensor is not yet implemented. API is experimental.

.. figure:: ../api/images/sensor_force.png
:width: 35 %

.. autoclass:: pybricks.pupdevices.ForceSensor
:no-members:

.. automethod:: pybricks.pupdevices.ForceSensor.force

.. automethod:: pybricks.pupdevices.ForceSensor.distance

.. automethod:: pybricks.pupdevices.ForceSensor.pressed

.. automethod:: pybricks.pupdevices.ForceSensor.touched

.. Tilt Sensor
.. ^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
58 changes: 56 additions & 2 deletions pybricks/pupdevices.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ class ColorSensor:

lights = _LightArray(3)

def __init__(self, port):
"""
Arguments:
port (Port): Port to which the sensor is connected.
"""
pass

def color(self, illuminate=True):
"""Scans the color of a surface or an external light source.
Expand Down Expand Up @@ -227,7 +236,7 @@ class UltrasonicSensor:
lights = _LightArray(3)

def __init__(self, port):
"""UltrasonicSensor(port)
"""
Arguments:
port (Port): Port to which the sensor is connected.
Expand Down Expand Up @@ -267,4 +276,49 @@ def presence(self):

class ForceSensor:
"""LEGO® SPIKE Force Sensor."""
pass

def __init__(self, port):
"""
Arguments:
port (Port): Port to which the sensor is connected.
"""
pass

def force(self):
"""Measures the force exerted on the sensor.
Returns:
:ref:`force`: Measured force (up to approximately 10.00 N).
"""

def distance(self):
"""Measures by how much the sensor button has moved.
Returns:
:ref:`distance`: How much the sensor button has
moved (up to approximately 8.00 mm).
"""

def pressed(self, force=3):
"""Checks if the sensor button is pressed.
Arguments:
force (:ref:`force`): Minimum force to be considered pressed.
Returns:
bool: ``True`` if the sensor is pressed, ``False`` if it is not.
"""

def touched(self):
"""Checks if the sensor is touched.
This is similar to :meth:`pressed`, but it detects slight movements of
the button even when the measured force is still considered zero.
Returns:
bool: ``True`` if the sensor is touched or pressed, ``False``
if it is not.
"""

pass

0 comments on commit 4788acc

Please sign in to comment.