mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[wpilib] Split DriverStation into smaller classes (#8628)
This commit is contained in:
@@ -31,19 +31,19 @@ class MyRobot(wpilib.TimedRobot):
|
||||
|
||||
def robotPeriodic(self):
|
||||
setAlliance = False
|
||||
alliance = wpilib.DriverStation.getAlliance()
|
||||
alliance = wpilib.MatchState.getAlliance()
|
||||
if alliance:
|
||||
setAlliance = alliance == wpilib.DriverStation.Alliance.RED
|
||||
setAlliance = alliance == wpilib.Alliance.RED
|
||||
|
||||
# pull alliance port high if on red alliance, pull low if on blue alliance
|
||||
self.allianceOutput.set(setAlliance)
|
||||
|
||||
# pull enabled port high if enabled, low if disabled
|
||||
self.enabledOutput.set(wpilib.DriverStation.isEnabled())
|
||||
self.enabledOutput.set(wpilib.RobotState.isEnabled())
|
||||
|
||||
# pull auto port high if in autonomous, low if in teleop (or disabled)
|
||||
self.autonomousOutput.set(wpilib.DriverStation.isAutonomous())
|
||||
self.autonomousOutput.set(wpilib.RobotState.isAutonomous())
|
||||
|
||||
# pull alert port high if match time remaining is between 30 and 25 seconds
|
||||
matchTime = wpilib.DriverStation.getMatchTime()
|
||||
matchTime = wpilib.MatchState.getMatchTime()
|
||||
self.alertOutput.set(30 >= matchTime >= 25)
|
||||
|
||||
@@ -41,15 +41,15 @@ class MyRobot(wpilib.TimedRobot):
|
||||
# For example, "RET043" would indicate that the robot is on the red
|
||||
# alliance, enabled in teleop mode, with 43 seconds left in the match.
|
||||
allianceString = "U"
|
||||
alliance = wpilib.DriverStation.getAlliance()
|
||||
alliance = wpilib.MatchState.getAlliance()
|
||||
if alliance is not None:
|
||||
allianceString = (
|
||||
"R" if alliance == wpilib.DriverStation.Alliance.RED else "B"
|
||||
"R" if alliance == wpilib.Alliance.RED else "B"
|
||||
)
|
||||
|
||||
enabledString = "E" if wpilib.DriverStation.isEnabled() else "D"
|
||||
autoString = "A" if wpilib.DriverStation.isAutonomous() else "T"
|
||||
matchTime = wpilib.DriverStation.getMatchTime()
|
||||
enabledString = "E" if wpilib.RobotState.isEnabled() else "D"
|
||||
autoString = "A" if wpilib.RobotState.isAutonomous() else "T"
|
||||
matchTime = wpilib.MatchState.getMatchTime()
|
||||
|
||||
stateMessage = f"{allianceString}{enabledString}{autoString}{matchTime:03f}"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user