File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed
Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,13 @@ Remote Control
2222
2323 .. rubric :: Member functions and properties
2424
25+ Beacon Seeker
26+ -------------
27+
28+ .. autoclass :: BeaconSeeker
29+ :members:
30+ :inherited-members:
31+
2532Button
2633------
2734
Original file line number Diff line number Diff line change @@ -2716,6 +2716,42 @@ def buttons_pressed(self):
27162716 return RemoteControl ._BUTTON_VALUES .get (self ._sensor .value (self ._channel ), [])
27172717
27182718
2719+ class BeaconSeeker (object ):
2720+ """
2721+ Seeks EV3 Remote Controller in beacon mode.
2722+ """
2723+
2724+ def __init__ (self , sensor = None , channel = 1 ):
2725+ self ._sensor = InfraredSensor () if sensor is None else sensor
2726+ self ._channel = max (1 , min (4 , channel )) - 1
2727+
2728+ if self ._sensor .connected :
2729+ self ._sensor .mode = 'IR-SEEK'
2730+
2731+ @property
2732+ def heading (self ):
2733+ """
2734+ Returns heading (-25, 25) to the beacon on the given channel.
2735+ """
2736+ return self ._sensor .value (self ._channel * 2 )
2737+
2738+ @property
2739+ def distance (self ):
2740+ """
2741+ Returns distance (0, 100) to the beacon on the given channel.
2742+ Returns -128 when beacon is not found.
2743+ """
2744+ return self ._sensor .value (self ._channel * 2 + 1 )
2745+
2746+ @property
2747+ def heading_and_distance (self ):
2748+ """
2749+ Returns heading and distance to the beacon on the given channel as a
2750+ tuple.
2751+ """
2752+ return self ._sensor .value (self ._channel * 2 ), self ._sensor .value (self ._channel * 2 + 1 )
2753+
2754+
27192755# ~autogen generic-class classes.powerSupply>currentClass
27202756
27212757class PowerSupply (Device ):
You can’t perform that action at this time.
0 commit comments