Skip to content

Commit c44a48f

Browse files
committed
Having issues with EncodedMotor classmethod
1 parent 7ec7b78 commit c44a48f

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

XRPLib/defaults.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
Run "from XRPLib.defaults import *" to use
1515
"""
1616

17-
left_motor = EncodedMotor.get_default_encoded_motor(0)
18-
right_motor = EncodedMotor.get_default_encoded_motor(1)
17+
left_motor = EncodedMotor.get_default_encoded_motor(index=0)
18+
right_motor = EncodedMotor.get_default_encoded_motor(index=1)
1919
imu = IMU.get_default_imu()
2020
drivetrain = DifferentialDrive.get_default_differential_drive()
2121
rangefinder = Rangefinder.get_default_rangefinder()

XRPLib/encoded_motor.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ class EncodedMotor:
1212
_DEFAULT_MOTOR_FOUR_INSTANCE = None
1313

1414
@classmethod
15-
def get_default_encoded_motor(cls, index:int):
15+
def get_default_encoded_motor(cls, index:int = 0):
1616
"""
1717
Get one of the default XRP v2 motor instances. These are singletons, so only one instance of each of these will ever exist.
18+
Motor indexes:
19+
0 - Left Motor
20+
1 - Right Motor
21+
2 - Motor 3
22+
3 - Motor 4
23+
Left Motor is the default, so if no index is specified, the left motor will be returned.
1824
"""
19-
if index == 0: # Left Motor
20-
if cls._DEFAULT_LEFT_MOTOR_INSTANCE is None:
21-
cls._DEFAULT_LEFT_MOTOR_INSTANCE = cls(
22-
Motor(6, 7, flip_dir=True),
23-
Encoder(0, 4, 5)
24-
)
25-
motor = cls._DEFAULT_LEFT_MOTOR_INSTANCE
26-
elif index == 1:
25+
26+
if index == 1:
2727
if cls._DEFAULT_RIGHT_MOTOR_INSTANCE is None:
2828
cls._DEFAULT_RIGHT_MOTOR_INSTANCE = cls(
2929
Motor(14, 15),
@@ -44,8 +44,16 @@ def get_default_encoded_motor(cls, index:int):
4444
Encoder(3, 8, 9)
4545
)
4646
motor = cls._DEFAULT_MOTOR_FOUR_INSTANCE
47+
else:
48+
# Left Motor
49+
if cls._DEFAULT_LEFT_MOTOR_INSTANCE is None:
50+
cls._DEFAULT_LEFT_MOTOR_INSTANCE = cls(
51+
Motor(6, 7, flip_dir=True),
52+
Encoder(0, 4, 5)
53+
)
54+
motor = cls._DEFAULT_LEFT_MOTOR_INSTANCE
4755
return motor
48-
56+
4957
@classmethod
5058
def get_default_encoded_motor(cls):
5159
"""

0 commit comments

Comments
 (0)