Skip to content

Commit 18f43f2

Browse files
committed
update offboardArmBot
1 parent 304d740 commit 18f43f2

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

ArmBotOffboard/subsystems/drivesubsystem.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,43 @@
44
# the WPILib BSD license file in the root directory of this project.
55
#
66

7+
import typing
8+
79
import commands2
810
import commands2.cmd
11+
from wpilib import PWMSparkMax, Encoder
12+
from wpilib.drive import DifferentialDrive
13+
914
import constants
10-
import wpilib
11-
import wpilib.drive
12-
import typing
1315

1416

1517
class DriveSubsystem(commands2.Subsystem):
1618
def __init__(self) -> None:
1719
super().__init__()
1820

19-
# The motors on the left side of the drive.
20-
self.left = wpilib.MotorControllerGroup(
21-
wpilib.PWMSparkMax(constants.kLeftMotor1Port),
22-
wpilib.PWMSparkMax(constants.kLeftMotor2Port),
23-
)
21+
# The motors on the left side of the drive.
22+
self.left1 = PWMSparkMax(constants.kLeftMotor1Port)
23+
self.left2 = PWMSparkMax(constants.kLeftMotor2Port)
2424

2525
# The motors on the right side of the drive.
26-
self.right = wpilib.MotorControllerGroup(
27-
wpilib.PWMSparkMax(constants.kRightMotor1Port),
28-
wpilib.PWMSparkMax(constants.kRightMotor2Port),
29-
)
26+
self.right1 = PWMSparkMax(constants.kRightMotor1Port)
27+
self.right2 = PWMSparkMax(constants.kRightMotor2Port)
28+
29+
self.left1.addFollower(self.left2)
30+
self.right1.addFollower(self.right2)
3031

3132
# The robot's drive
32-
self.drive = wpilib.drive.DifferentialDrive(self.left, self.right)
33+
self.drive = DifferentialDrive(self.left1, self.right1)
3334

3435
# The left-side drive encoder
35-
self.left_encoder = wpilib.Encoder(
36+
self.left_encoder = Encoder(
3637
constants.kLeftEncoderPorts[0],
3738
constants.kLeftEncoderPorts[1],
3839
constants.kLeftEncoderReversed,
3940
)
4041

4142
# The right-side drive encoder
42-
self.right_encoder = wpilib.Encoder(
43+
self.right_encoder = Encoder(
4344
constants.kRightEncoderPorts[0],
4445
constants.kRightEncoderPorts[1],
4546
constants.kRightEncoderReversed,
@@ -52,7 +53,7 @@ def __init__(self) -> None:
5253
# We need to invert one side of the drivetrain so that positive voltages
5354
# result in both sides moving forward. Depending on how your robot's
5455
# gearbox is constructed, you might have to invert the left side instead.
55-
self.right.setInverted(True)
56+
self.right1.setInverted(True)
5657

5758
def arcadeDriveCommand(
5859
self, fwd: typing.Callable[[], float], rot: typing.Callable[[], float]
@@ -71,8 +72,8 @@ def arcadeDriveCommand(
7172

7273
def resetEncoders(self) -> None:
7374
"""Resets the drive encoders to currently read a position of 0."""
74-
self.left.reset()
75-
self.right.reset()
75+
self.left_encoder.reset()
76+
self.right_encoder.reset()
7677

7778
def getAverageEncoderDistance(self) -> float:
7879
"""Gets the average distance of the two encoders.
@@ -82,15 +83,15 @@ def getAverageEncoderDistance(self) -> float:
8283
"""
8384
return (self.left_encoder.getDistance() + self.right_encoder.getDistance()) / 2
8485

85-
def getLeftEncoder(self) -> wpilib.Encoder:
86+
def getLeftEncoder(self) -> Encoder:
8687
"""Gets the left drive encoder.
8788
8889
Returns:
8990
The left drive encoder.
9091
"""
9192
return self.left_encoder
9293

93-
def getRightEncoder(self) -> wpilib.Encoder:
94+
def getRightEncoder(self) -> Encoder:
9495
"""Gets the right drive encoder.
9596
9697
Returns:

0 commit comments

Comments
 (0)