Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/other.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ Remote Control

.. rubric:: Member functions and properties

Beacon Seeker
-------------

.. autoclass:: BeaconSeeker
:members:
:inherited-members:

Button
------

Expand Down
36 changes: 36 additions & 0 deletions ev3dev/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2716,6 +2716,42 @@ def buttons_pressed(self):
return RemoteControl._BUTTON_VALUES.get(self._sensor.value(self._channel), [])


class BeaconSeeker(object):
"""
Seeks EV3 Remote Controller in beacon mode.
"""

def __init__(self, sensor=None, channel=1):
self._sensor = InfraredSensor() if sensor is None else sensor
self._channel = max(1, min(4, channel)) - 1

if self._sensor.connected:
self._sensor.mode = 'IR-SEEK'

@property
def heading(self):
"""
Returns heading (-25, 25) to the beacon on the given channel.
"""
return self._sensor.value(self._channel * 2)

@property
def distance(self):
"""
Returns distance (0, 100) to the beacon on the given channel.
Returns -128 when beacon is not found.
"""
return self._sensor.value(self._channel * 2 + 1)

@property
def heading_and_distance(self):
"""
Returns heading and distance to the beacon on the given channel as a
tuple.
"""
return self._sensor.value(self._channel * 2), self._sensor.value(self._channel * 2 + 1)


# ~autogen generic-class classes.powerSupply>currentClass

class PowerSupply(Device):
Expand Down