Skip to content

Commit a187cac

Browse files
committed
Added the second default servo
1 parent 5d7acd0 commit a187cac

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

XRPLib/defaults.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
drivetrain = DifferentialDrive.get_default_differential_drive()
2121
rangefinder = Rangefinder.get_default_rangefinder()
2222
reflectance = Reflectance.get_default_reflectance()
23-
servo_one = Servo.get_default_servo()
23+
servo_one = Servo.get_default_servo(index=1)
24+
servo_two = Servo.get_default_servo(index=2)
2425
webserver = Webserver.get_default_webserver()
2526
board = Board.get_default_board()

XRPLib/servo.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,29 @@
22

33
class Servo:
44

5-
_DEFAULT_SERVO_INSTANCE = None
5+
_DEFAULT_SERVO_ONE_INSTANCE = None
6+
_DEFAULT_SERVO_TWO_INSTANCE = None
67

78
@classmethod
8-
def get_default_servo(cls):
9+
def get_default_servo(cls, index:int):
910
"""
10-
Get the default XRP v2 servo instance. This is a singleton, so only one instance of the servo will ever exist.
11-
"""
12-
if cls._DEFAULT_SERVO_INSTANCE is None:
13-
cls._DEFAULT_SERVO_INSTANCE = cls(16)
14-
return cls._DEFAULT_SERVO_INSTANCE
11+
Gets one of the default XRP v2 servo instances. These are singletons, so only one instance of each servo will ever exist.
12+
Raises an exception if an invalid index is requested.
13+
14+
:param index: The index of the servo to get (1 or 2)
15+
:type index: int
16+
"""
17+
if index == 1:
18+
if cls._DEFAULT_SERVO_ONE_INSTANCE is None:
19+
cls._DEFAULT_SERVO_ONE_INSTANCE = cls(16)
20+
servo = cls._DEFAULT_SERVO_ONE_INSTANCE
21+
elif index == 2:
22+
if cls._DEFAULT_SERVO_TWO_INSTANCE is None:
23+
cls._DEFAULT_SERVO_TWO_INSTANCE = cls(17)
24+
servo = cls._DEFAULT_SERVO_TWO_INSTANCE
25+
else:
26+
return Exception("Invalid servo index")
27+
return servo
1528

1629
def __init__(self, signal_pin:int):
1730
"""

0 commit comments

Comments
 (0)