Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created a set of functions that fetch and store the FMS alliance #33

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 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,40 @@ 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.
* @see <a href="https://docs.wpilib.org/en/stable/docs/software/basic-programming/alliancecolor.html">WPILib Get Alliance Color</a>
*/
public static Alliance getAlliance() {
if (Core.alliance == null) {
Optional<Alliance> alliance = DriverStation.getAlliance();
if (alliance.isPresent()) {
Core.alliance = alliance.get();
Log.info("Alliance updated to " + Core.alliance.toString());
}
else {
Log.warn("No Alliance could be retrieved from DriverStation");
}
}
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 static 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 static boolean isRedAlliance() {
return getAlliance() == Alliance.Red;
}
}
Loading