Skip to content

Commit 537f1ea

Browse files
committed
Made default motor throw an error on bad index
1 parent 809ff5f commit 537f1ea

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

XRPLib/encoded_motor.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,14 @@ def get_default_encoded_motor(cls, index:int = 1):
2020
:param index: The index of the motor to get; 1 for left, 2 for right, 3 for motor 3, 4 for motor 4
2121
:type index: int
2222
"""
23-
24-
if index == 2:
23+
if index == 1:
24+
if cls._DEFAULT_LEFT_MOTOR_INSTANCE is None:
25+
cls._DEFAULT_LEFT_MOTOR_INSTANCE = cls(
26+
Motor(6, 7, flip_dir=True),
27+
Encoder(0, 4, 5)
28+
)
29+
motor = cls._DEFAULT_LEFT_MOTOR_INSTANCE
30+
elif index == 2:
2531
if cls._DEFAULT_RIGHT_MOTOR_INSTANCE is None:
2632
cls._DEFAULT_RIGHT_MOTOR_INSTANCE = cls(
2733
Motor(14, 15),
@@ -43,13 +49,7 @@ def get_default_encoded_motor(cls, index:int = 1):
4349
)
4450
motor = cls._DEFAULT_MOTOR_FOUR_INSTANCE
4551
else:
46-
# Left Motor
47-
if cls._DEFAULT_LEFT_MOTOR_INSTANCE is None:
48-
cls._DEFAULT_LEFT_MOTOR_INSTANCE = cls(
49-
Motor(6, 7, flip_dir=True),
50-
Encoder(0, 4, 5)
51-
)
52-
motor = cls._DEFAULT_LEFT_MOTOR_INSTANCE
52+
return Exception("Invalid default motor instance")
5353
return motor
5454

5555
def __init__(self, motor: Motor, encoder: Encoder):

0 commit comments

Comments
 (0)