44# the WPILib BSD license file in the root directory of this project.
55#
66
7- import wpilib
8- import wpilib .drive
7+ from wpilib import PWMSparkMax , Encoder
8+ from wpilib .drive import DifferentialDrive
99import commands2
1010
1111import constants
@@ -16,30 +16,29 @@ def __init__(self) -> None:
1616 """Creates a new DriveSubsystem"""
1717 super ().__init__ ()
1818
19- # The motors on the left side of the drive.
20- self .leftMotors = wpilib .MotorControllerGroup (
21- wpilib .PWMSparkMax (constants .DriveConstants .kLeftMotor1Port ),
22- wpilib .PWMSparkMax (constants .DriveConstants .kLeftMotor2Port ),
23- )
19+ # The motors on the left side of the drive.
20+ self .left1 = PWMSparkMax (constants .DriveConstants .kLeftMotor1Port )
21+ self .left2 = PWMSparkMax (constants .DriveConstants .kLeftMotor2Port )
2422
2523 # The motors on the right side of the drive.
26- self .rightMotors = wpilib .MotorControllerGroup (
27- wpilib .PWMSparkMax (constants .DriveConstants .kRightMotor1Port ),
28- wpilib .PWMSparkMax (constants .DriveConstants .kRightMotor2Port ),
29- )
24+ self .right1 = PWMSparkMax (constants .DriveConstants .kRightMotor1Port )
25+ self .right2 = PWMSparkMax (constants .DriveConstants .kRightMotor2Port )
26+
27+ self .left1 .addFollower (self .left2 )
28+ self .right1 .addFollower (self .right2 )
3029
3130 # The robot's drive
32- self .drive = wpilib . drive . DifferentialDrive (self .leftMotors , self .rightMotors )
31+ self .drive = DifferentialDrive (self .left1 , self .right1 )
3332
3433 # The left-side drive encoder
35- self .leftEncoder = wpilib . Encoder (
34+ self .leftEncoder = Encoder (
3635 constants .DriveConstants .kLeftEncoderPorts [0 ],
3736 constants .DriveConstants .kLeftEncoderPorts [1 ],
3837 constants .DriveConstants .kLeftEncoderReversed ,
3938 )
4039
4140 # The right-side drive encoder
42- self .rightEncoder = wpilib . Encoder (
41+ self .rightEncoder = Encoder (
4342 constants .DriveConstants .kRightEncoderPorts [0 ],
4443 constants .DriveConstants .kRightEncoderPorts [1 ],
4544 constants .DriveConstants .kRightEncoderReversed ,
@@ -48,7 +47,7 @@ def __init__(self) -> None:
4847 # We need to invert one side of the drivetrain so that positive voltages
4948 # result in both sides moving forward. Depending on how your robot's
5049 # gearbox is constructed, you might have to invert the left side instead.
51- self .rightMotors .setInverted (True )
50+ self .right1 .setInverted (True )
5251
5352 # Sets the distance per pulse for the encoders
5453 self .leftEncoder .setDistancePerPulse (
@@ -80,15 +79,15 @@ def getAverageEncoderDistance(self):
8079 """
8180 return (self .leftEncoder .getDistance () + self .rightEncoder .getDistance ()) / 2.0
8281
83- def getLeftEncoder (self ) -> wpilib . Encoder :
82+ def getLeftEncoder (self ) -> Encoder :
8483 """
8584 Gets the left drive encoder.
8685
8786 :returns: the left drive encoder
8887 """
8988 return self .leftEncoder
9089
91- def getRightEncoder (self ) -> wpilib . Encoder :
90+ def getRightEncoder (self ) -> Encoder :
9291 """
9392 Gets the right drive encoder.
9493
0 commit comments