-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from AlphaKnights/command-based
convert all drive into command based
- Loading branch information
Showing
9 changed files
with
124 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import commands2 | ||
import typing | ||
from subsystems.drivetrain import arcadeDrive | ||
|
||
class ArcadeDrive(commands2.CommandBase): | ||
def __init__(self, arcade_drive: arcadeDrive, y: typing.Callable[[], float], z: typing.Callable[[], float]) -> None: | ||
super().__init__() | ||
self.arcade_drive = arcade_drive | ||
self.y = y | ||
self.z = z | ||
self.addRequirements(arcade_drive) | ||
|
||
def execute(self) -> None: | ||
self.arcade_drive.arcadeDrive(self.y(), self.z()) | ||
|
||
def isFinished(self) -> bool: | ||
return False | ||
|
||
def end(self) -> None: | ||
self.arcade_drive.arcadeDrive(0, 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import commands2 | ||
import typing | ||
from subsystems.limelight import limelightSystem | ||
|
||
class limelightDisplay(commands2.CommandBase): | ||
def __init__(self, limelight: limelightSystem) -> None: | ||
super().__init__() | ||
self.limelight = limelight | ||
self.addRequirements(limelight) | ||
|
||
def execute(self) -> None: | ||
# print(self.limelight.get_results().tagId) | ||
results = self.limelight.get_results() | ||
print(results.tagId if results else 'none') | ||
|
||
def isFinished(self) -> bool: | ||
return False | ||
|
||
def end(self) -> None: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
|
||
PITCH_MOTOR_ID = 42 | ||
|
||
DRIVE_JOYSTICK_PORT = 0 | ||
DRIVE_JOYSTICK_PORT = 1 | ||
|
||
|
||
FIRE_UPPER_BUTTON_ID = 1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class limelightResults: | ||
tagId: int | ||
|
||
def __init__(self, data: dict) -> None: | ||
self.tagId = data["Fiducial"][0]["fID"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import constants | ||
|
||
import commands2 | ||
import commands2.button | ||
|
||
import wpilib | ||
|
||
# from subsystems.drivetrain import arcadeDrive | ||
# from commands.arcadedrive import ArcadeDrive | ||
|
||
from subsystems.limelight import limelightSystem | ||
from commands.limelightdisplay import limelightDisplay | ||
|
||
class RobotContainer: | ||
def __init__(self) -> None: | ||
self.limelight = limelightSystem() | ||
self.stick = wpilib.Joystick(constants.DRIVE_JOYSTICK_PORT) | ||
self.configureButtonBindings() | ||
|
||
def configureButtonBindings(self) -> None: | ||
# self.drivetrain.setDefaultCommand(ArcadeDrive(self.drivetrain, lambda: self.stick.getX(), lambda: self.stick.getY())) | ||
self.limelight.setDefaultCommand(limelightDisplay(self.limelight)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import commands2 | ||
import phoenix5 | ||
import constants | ||
import wpilib | ||
import wpilib.drive | ||
|
||
class arcadeDrive(commands2.Subsystem): | ||
def __init__(self) -> None: | ||
super().__init__() | ||
self.left_motor_1 = phoenix5.WPI_TalonSRX(constants.LEFT_MOTOR_1_ID) | ||
self.left_motor_2 = phoenix5.WPI_TalonSRX(constants.LEFT_MOTOR_2_ID) | ||
self.right_motor_1 = phoenix5.WPI_TalonSRX(constants.RIGHT_MOTOR_1_ID) | ||
self.right_motor_2 = phoenix5.WPI_TalonSRX(constants.RIGHT_MOTOR_2_ID) | ||
self.left_motor_1.follow(self.left_motor_2) | ||
self.right_motor_1.follow(self.right_motor_2) | ||
self.robot_drive = wpilib.drive.DifferentialDrive(self.left_motor_1, self.right_motor_1) | ||
|
||
def arcadeDrive(self, y: float, z: float) -> None: | ||
self.robot_drive.arcadeDrive(y, z) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import typing | ||
import commands2 | ||
import constants | ||
import wpilib | ||
import limelight | ||
from interfaces.limelight_results import limelightResults | ||
|
||
class limelightSystem(commands2.Subsystem): | ||
def __init__(self) -> None: | ||
super().__init__() | ||
|
||
limelights = limelight.discover_limelights(debug=True) | ||
|
||
if not limelights: | ||
raise ValueError("No limelights found") | ||
|
||
self.limelight = limelight.Limelight(limelights[0]) | ||
|
||
def get_results(self, debug=False) -> typing.Optional[limelightResults]: | ||
results = self.limelight.get_results() | ||
|
||
if results["botpose_tagcount"] == 0: | ||
return | ||
|
||
return limelightResults(results) |