Skip to content

Commit

Permalink
Created Core functions to get and store FMS alliance
Browse files Browse the repository at this point in the history
  • Loading branch information
fruzyna committed Mar 10, 2024
1 parent 90d1245 commit da7e287
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/main/java/org/wildstang/framework/core/Core.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.wildstang.framework.core;

import java.util.Optional;

import org.wildstang.framework.CoreUtils;
import org.wildstang.framework.auto.AutoManager;
import org.wildstang.framework.auto.AutoProgram;
Expand All @@ -14,6 +16,9 @@
import org.wildstang.framework.subsystems.Subsystem;
import org.wildstang.framework.subsystems.SubsystemManager;

import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.DriverStation.Alliance;

/**
* Core of robot framework.
*/
Expand All @@ -26,6 +31,7 @@ public class Core {
private static InputFactory s_inputFactory;
private static OutputFactory s_outputFactory;
private static AutoManager s_autoManager;
private static Alliance alliance;

private Class<?> m_inputFactoryClass;
private Class<?> m_outputFactoryClass;
Expand Down Expand Up @@ -220,4 +226,35 @@ public void executeUpdate() {
s_outputManager.update();
}

/**
* Returns the stored FMS alliance. If nothing is stored, fetch and store the alliance.
* @return Stored Alliance value or null if not present.
*/
public static Alliance getAlliance() {
if (Core.alliance == null) {
Optional<Alliance> alliance = DriverStation.getAlliance();
if (alliance.isPresent()) {
Core.alliance = alliance.get();
}
}
return Core.alliance;
}

/**
* Return whether the stored alliance is blue.
* Note, if the alliance could not be determined false will always be returned.
* @return True if the FMS alliance is blue.
*/
public boolean isBlueAlliance() {
return getAlliance() == Alliance.Blue;
}

/**
* Return whether the stored alliance is red.
* Note, if the alliance could not be determined false will always be returned.
* @return True if the FMS alliance is red.
*/
public boolean isRedAlliance() {
return getAlliance() == Alliance.Red;
}
}

0 comments on commit da7e287

Please sign in to comment.