[wpilib] Deprecate getInstance() in favor of static functions (#3440)

Co-authored-by: Noam Zaks <imnoamzaks@gmail.com>
This commit is contained in:
Peter Johnson
2021-06-15 23:06:03 -07:00
committed by GitHub
parent 26ff9371d9
commit 362066a9b7
105 changed files with 1500 additions and 1539 deletions

View File

@@ -63,18 +63,14 @@ public class DriverStation {
}
private static final double JOYSTICK_UNPLUGGED_MESSAGE_INTERVAL = 1.0;
private double m_nextMessageTime;
private static double m_nextMessageTime;
private static class DriverStationTask implements Runnable {
private final DriverStation m_ds;
DriverStationTask(DriverStation ds) {
m_ds = ds;
}
DriverStationTask() {}
@Override
public void run() {
m_ds.run();
DriverStation.run();
}
} /* DriverStationTask */
@@ -155,7 +151,7 @@ public class DriverStation {
controlWord.forceSetDouble(0);
}
private void sendMatchData(DriverStation driverStation) {
private void sendMatchData() {
AllianceStationID allianceID = HAL.getAllianceStation();
boolean isRedAlliance = false;
int stationNumber = 1;
@@ -192,12 +188,12 @@ public class DriverStation {
int currentReplayNumber;
int currentMatchType;
int currentControlWord;
synchronized (driverStation.m_cacheDataMutex) {
currentEventName = driverStation.m_matchInfo.eventName;
currentGameSpecificMessage = driverStation.m_matchInfo.gameSpecificMessage;
currentMatchNumber = driverStation.m_matchInfo.matchNumber;
currentReplayNumber = driverStation.m_matchInfo.replayNumber;
currentMatchType = driverStation.m_matchInfo.matchType;
synchronized (DriverStation.m_cacheDataMutex) {
currentEventName = DriverStation.m_matchInfo.eventName;
currentGameSpecificMessage = DriverStation.m_matchInfo.gameSpecificMessage;
currentMatchNumber = DriverStation.m_matchInfo.matchNumber;
currentReplayNumber = DriverStation.m_matchInfo.replayNumber;
currentMatchType = DriverStation.m_matchInfo.matchType;
}
currentControlWord = HAL.nativeGetControlWord();
@@ -239,56 +235,59 @@ public class DriverStation {
private static DriverStation instance = new DriverStation();
// Joystick User Data
private HALJoystickAxes[] m_joystickAxes = new HALJoystickAxes[kJoystickPorts];
private HALJoystickPOVs[] m_joystickPOVs = new HALJoystickPOVs[kJoystickPorts];
private HALJoystickButtons[] m_joystickButtons = new HALJoystickButtons[kJoystickPorts];
private MatchInfoData m_matchInfo = new MatchInfoData();
private static HALJoystickAxes[] m_joystickAxes = new HALJoystickAxes[kJoystickPorts];
private static HALJoystickPOVs[] m_joystickPOVs = new HALJoystickPOVs[kJoystickPorts];
private static HALJoystickButtons[] m_joystickButtons = new HALJoystickButtons[kJoystickPorts];
private static MatchInfoData m_matchInfo = new MatchInfoData();
// Joystick Cached Data
private HALJoystickAxes[] m_joystickAxesCache = new HALJoystickAxes[kJoystickPorts];
private HALJoystickPOVs[] m_joystickPOVsCache = new HALJoystickPOVs[kJoystickPorts];
private HALJoystickButtons[] m_joystickButtonsCache = new HALJoystickButtons[kJoystickPorts];
private MatchInfoData m_matchInfoCache = new MatchInfoData();
private static HALJoystickAxes[] m_joystickAxesCache = new HALJoystickAxes[kJoystickPorts];
private static HALJoystickPOVs[] m_joystickPOVsCache = new HALJoystickPOVs[kJoystickPorts];
private static HALJoystickButtons[] m_joystickButtonsCache =
new HALJoystickButtons[kJoystickPorts];
private static MatchInfoData m_matchInfoCache = new MatchInfoData();
// Joystick button rising/falling edge flags
private int[] m_joystickButtonsPressed = new int[kJoystickPorts];
private int[] m_joystickButtonsReleased = new int[kJoystickPorts];
private static int[] m_joystickButtonsPressed = new int[kJoystickPorts];
private static int[] m_joystickButtonsReleased = new int[kJoystickPorts];
// preallocated byte buffer for button count
private final ByteBuffer m_buttonCountBuffer = ByteBuffer.allocateDirect(1);
private static final ByteBuffer m_buttonCountBuffer = ByteBuffer.allocateDirect(1);
private final MatchDataSender m_matchDataSender;
private static final MatchDataSender m_matchDataSender;
// Internal Driver Station thread
private Thread m_thread;
private static Thread m_thread;
private volatile boolean m_threadKeepAlive = true;
private static volatile boolean m_threadKeepAlive = true;
private final ReentrantLock m_cacheDataMutex = new ReentrantLock();
private static final ReentrantLock m_cacheDataMutex = new ReentrantLock();
private final Lock m_waitForDataMutex;
private final Condition m_waitForDataCond;
private int m_waitForDataCount;
private final ThreadLocal<Integer> m_lastCount = ThreadLocal.withInitial(() -> 0);
private static final Lock m_waitForDataMutex;
private static final Condition m_waitForDataCond;
private static int m_waitForDataCount;
private static final ThreadLocal<Integer> m_lastCount = ThreadLocal.withInitial(() -> 0);
private boolean m_silenceJoystickWarning;
private static boolean m_silenceJoystickWarning;
// Robot state status variables
private boolean m_userInDisabled;
private boolean m_userInAutonomous;
private boolean m_userInTeleop;
private boolean m_userInTest;
private static boolean m_userInDisabled;
private static boolean m_userInAutonomous;
private static boolean m_userInTeleop;
private static boolean m_userInTest;
// Control word variables
private final Object m_controlWordMutex;
private final ControlWord m_controlWordCache;
private long m_lastControlWordUpdate;
private static final Object m_controlWordMutex;
private static final ControlWord m_controlWordCache;
private static long m_lastControlWordUpdate;
/**
* Gets an instance of the DriverStation.
*
* @return The DriverStation.
* @deprecated Use the static methods
*/
@Deprecated
public static DriverStation getInstance() {
return DriverStation.instance;
}
@@ -299,7 +298,9 @@ public class DriverStation {
* <p>The single DriverStation instance is created statically with the instance static member
* variable.
*/
private DriverStation() {
private DriverStation() {}
static {
HAL.initialize(500, 0);
m_waitForDataCount = 0;
m_waitForDataMutex = new ReentrantLock();
@@ -321,14 +322,14 @@ public class DriverStation {
m_matchDataSender = new MatchDataSender();
m_thread = new Thread(new DriverStationTask(this), "FRCDriverStation");
m_thread = new Thread(new DriverStationTask(), "FRCDriverStation");
m_thread.setPriority((Thread.NORM_PRIORITY + Thread.MAX_PRIORITY) / 2);
m_thread.start();
}
/** Kill the thread. */
public void release() {
public static synchronized void release() {
m_threadKeepAlive = false;
if (m_thread != null) {
try {
@@ -425,7 +426,7 @@ public class DriverStation {
* @param button The button index, beginning at 1.
* @return The state of the joystick button.
*/
public boolean getStickButton(final int stick, final int button) {
public static boolean getStickButton(final int stick, final int button) {
if (stick < 0 || stick >= kJoystickPorts) {
throw new IllegalArgumentException("Joystick index is out of range, should be 0-3");
}
@@ -459,7 +460,7 @@ public class DriverStation {
* @param button The button index, beginning at 1.
* @return Whether the joystick button was pressed since the last check.
*/
public boolean getStickButtonPressed(final int stick, final int button) {
public static boolean getStickButtonPressed(final int stick, final int button) {
if (button <= 0) {
reportJoystickUnpluggedError("Button indexes begin at 1 in WPILib for C++ and Java\n");
return false;
@@ -499,7 +500,7 @@ public class DriverStation {
* @param button The button index, beginning at 1.
* @return Whether the joystick button was released since the last check.
*/
public boolean getStickButtonReleased(final int stick, final int button) {
public static boolean getStickButtonReleased(final int stick, final int button) {
if (button <= 0) {
reportJoystickUnpluggedError("Button indexes begin at 1 in WPILib for C++ and Java\n");
return false;
@@ -540,7 +541,7 @@ public class DriverStation {
* @param axis The analog axis value to read from the joystick.
* @return The value of the axis on the joystick.
*/
public double getStickAxis(int stick, int axis) {
public static double getStickAxis(int stick, int axis) {
if (stick < 0 || stick >= kJoystickPorts) {
throw new IllegalArgumentException("Joystick index is out of range, should be 0-5");
}
@@ -573,7 +574,7 @@ public class DriverStation {
* @param pov The POV to read.
* @return the angle of the POV in degrees, or -1 if the POV is not pressed.
*/
public int getStickPOV(int stick, int pov) {
public static int getStickPOV(int stick, int pov) {
if (stick < 0 || stick >= kJoystickPorts) {
throw new IllegalArgumentException("Joystick index is out of range, should be 0-5");
}
@@ -605,7 +606,7 @@ public class DriverStation {
* @param stick The joystick to read.
* @return The state of the buttons on the joystick.
*/
public int getStickButtons(final int stick) {
public static int getStickButtons(final int stick) {
if (stick < 0 || stick >= kJoystickPorts) {
throw new IllegalArgumentException("Joystick index is out of range, should be 0-3");
}
@@ -624,7 +625,7 @@ public class DriverStation {
* @param stick The joystick port number
* @return The number of axes on the indicated joystick
*/
public int getStickAxisCount(int stick) {
public static int getStickAxisCount(int stick) {
if (stick < 0 || stick >= kJoystickPorts) {
throw new IllegalArgumentException("Joystick index is out of range, should be 0-5");
}
@@ -643,7 +644,7 @@ public class DriverStation {
* @param stick The joystick port number
* @return The number of POVs on the indicated joystick
*/
public int getStickPOVCount(int stick) {
public static int getStickPOVCount(int stick) {
if (stick < 0 || stick >= kJoystickPorts) {
throw new IllegalArgumentException("Joystick index is out of range, should be 0-5");
}
@@ -662,7 +663,7 @@ public class DriverStation {
* @param stick The joystick port number
* @return The number of buttons on the indicated joystick
*/
public int getStickButtonCount(int stick) {
public static int getStickButtonCount(int stick) {
if (stick < 0 || stick >= kJoystickPorts) {
throw new IllegalArgumentException("Joystick index is out of range, should be 0-5");
}
@@ -681,7 +682,7 @@ public class DriverStation {
* @param stick The joystick port number
* @return A boolean that returns the value of isXbox
*/
public boolean getJoystickIsXbox(int stick) {
public static boolean getJoystickIsXbox(int stick) {
if (stick < 0 || stick >= kJoystickPorts) {
throw new IllegalArgumentException("Joystick index is out of range, should be 0-5");
}
@@ -695,7 +696,7 @@ public class DriverStation {
* @param stick The joystick port number
* @return The value of type
*/
public int getJoystickType(int stick) {
public static int getJoystickType(int stick) {
if (stick < 0 || stick >= kJoystickPorts) {
throw new IllegalArgumentException("Joystick index is out of range, should be 0-5");
}
@@ -709,7 +710,7 @@ public class DriverStation {
* @param stick The joystick port number
* @return The value of name
*/
public String getJoystickName(int stick) {
public static String getJoystickName(int stick) {
if (stick < 0 || stick >= kJoystickPorts) {
throw new IllegalArgumentException("Joystick index is out of range, should be 0-5");
}
@@ -724,7 +725,7 @@ public class DriverStation {
* @param axis The target axis
* @return What type of axis the axis is reporting to be
*/
public int getJoystickAxisType(int stick, int axis) {
public static int getJoystickAxisType(int stick, int axis) {
if (stick < 0 || stick >= kJoystickPorts) {
throw new IllegalArgumentException("Joystick index is out of range, should be 0-5");
}
@@ -741,7 +742,7 @@ public class DriverStation {
* @param stick The joystick port number
* @return true if a joystick is connected
*/
public boolean isJoystickConnected(int stick) {
public static boolean isJoystickConnected(int stick) {
return getStickAxisCount(stick) > 0
|| getStickButtonCount(stick) > 0
|| getStickPOVCount(stick) > 0;
@@ -752,7 +753,7 @@ public class DriverStation {
*
* @return True if the robot is enabled, false otherwise.
*/
public boolean isEnabled() {
public static boolean isEnabled() {
synchronized (m_controlWordMutex) {
updateControlWord(false);
return m_controlWordCache.getEnabled() && m_controlWordCache.getDSAttached();
@@ -764,7 +765,7 @@ public class DriverStation {
*
* @return True if the robot should be disabled, false otherwise.
*/
public boolean isDisabled() {
public static boolean isDisabled() {
return !isEnabled();
}
@@ -773,7 +774,7 @@ public class DriverStation {
*
* @return True if the robot is e-stopped, false otherwise.
*/
public boolean isEStopped() {
public static boolean isEStopped() {
synchronized (m_controlWordMutex) {
updateControlWord(false);
return m_controlWordCache.getEStop();
@@ -786,7 +787,7 @@ public class DriverStation {
*
* @return True if autonomous mode should be enabled, false otherwise.
*/
public boolean isAutonomous() {
public static boolean isAutonomous() {
synchronized (m_controlWordMutex) {
updateControlWord(false);
return m_controlWordCache.getAutonomous();
@@ -799,7 +800,7 @@ public class DriverStation {
*
* @return True if autonomous should be set and the robot should be enabled.
*/
public boolean isAutonomousEnabled() {
public static boolean isAutonomousEnabled() {
synchronized (m_controlWordMutex) {
updateControlWord(false);
return m_controlWordCache.getAutonomous() && m_controlWordCache.getEnabled();
@@ -812,7 +813,7 @@ public class DriverStation {
*
* @return True if operator-controlled mode should be enabled, false otherwise.
*/
public boolean isOperatorControl() {
public static boolean isOperatorControl() {
return !(isAutonomous() || isTest());
}
@@ -822,7 +823,7 @@ public class DriverStation {
*
* @return True if operator-controlled mode should be set and the robot should be enabled.
*/
public boolean isOperatorControlEnabled() {
public static boolean isOperatorControlEnabled() {
synchronized (m_controlWordMutex) {
updateControlWord(false);
return !m_controlWordCache.getAutonomous()
@@ -837,7 +838,7 @@ public class DriverStation {
*
* @return True if test mode should be enabled, false otherwise.
*/
public boolean isTest() {
public static boolean isTest() {
synchronized (m_controlWordMutex) {
updateControlWord(false);
return m_controlWordCache.getTest();
@@ -849,7 +850,7 @@ public class DriverStation {
*
* @return True if Driver Station is attached, false otherwise.
*/
public boolean isDSAttached() {
public static boolean isDSAttached() {
synchronized (m_controlWordMutex) {
updateControlWord(false);
return m_controlWordCache.getDSAttached();
@@ -862,7 +863,7 @@ public class DriverStation {
*
* @return True if the control data has been updated since the last call.
*/
public boolean isNewControlData() {
public static boolean isNewControlData() {
m_waitForDataMutex.lock();
try {
int currentCount = m_waitForDataCount;
@@ -881,7 +882,7 @@ public class DriverStation {
*
* @return true if the robot is competing on a field being controlled by a Field Management System
*/
public boolean isFMSAttached() {
public static boolean isFMSAttached() {
synchronized (m_controlWordMutex) {
updateControlWord(false);
return m_controlWordCache.getFMSAttached();
@@ -893,7 +894,7 @@ public class DriverStation {
*
* @return the game specific message
*/
public String getGameSpecificMessage() {
public static String getGameSpecificMessage() {
m_cacheDataMutex.lock();
try {
return m_matchInfo.gameSpecificMessage;
@@ -907,7 +908,7 @@ public class DriverStation {
*
* @return the event name
*/
public String getEventName() {
public static String getEventName() {
m_cacheDataMutex.lock();
try {
return m_matchInfo.eventName;
@@ -921,7 +922,7 @@ public class DriverStation {
*
* @return the match type
*/
public MatchType getMatchType() {
public static MatchType getMatchType() {
int matchType;
m_cacheDataMutex.lock();
try {
@@ -946,7 +947,7 @@ public class DriverStation {
*
* @return the match number
*/
public int getMatchNumber() {
public static int getMatchNumber() {
m_cacheDataMutex.lock();
try {
return m_matchInfo.matchNumber;
@@ -960,7 +961,7 @@ public class DriverStation {
*
* @return the replay number
*/
public int getReplayNumber() {
public static int getReplayNumber() {
m_cacheDataMutex.lock();
try {
return m_matchInfo.replayNumber;
@@ -974,7 +975,7 @@ public class DriverStation {
*
* @return the current alliance
*/
public Alliance getAlliance() {
public static Alliance getAlliance() {
AllianceStationID allianceStationID = HAL.getAllianceStation();
if (allianceStationID == null) {
return Alliance.Invalid;
@@ -1001,7 +1002,7 @@ public class DriverStation {
*
* @return the location of the team's driver station controls: 1, 2, or 3
*/
public int getLocation() {
public static int getLocation() {
AllianceStationID allianceStationID = HAL.getAllianceStation();
if (allianceStationID == null) {
return 0;
@@ -1030,7 +1031,7 @@ public class DriverStation {
* <p>Checks if new control data has arrived since the last waitForData call on the current
* thread. If new data has not arrived, returns immediately.
*/
public void waitForData() {
public static void waitForData() {
waitForData(0);
}
@@ -1044,7 +1045,7 @@ public class DriverStation {
* @param timeout The maximum time in seconds to wait.
* @return true if there is new data, otherwise false
*/
public boolean waitForData(double timeout) {
public static boolean waitForData(double timeout) {
long startTime = RobotController.getFPGATime();
long timeoutMicros = (long) (timeout * 1000000);
m_waitForDataMutex.lock();
@@ -1093,7 +1094,7 @@ public class DriverStation {
*
* @return Time remaining in current match period (auto or teleop) in seconds
*/
public double getMatchTime() {
public static double getMatchTime() {
return HAL.getMatchTime();
}
@@ -1104,7 +1105,7 @@ public class DriverStation {
* @param entering If true, starting disabled code; if false, leaving disabled code
*/
@SuppressWarnings("MethodName")
public void InDisabled(boolean entering) {
public static void InDisabled(boolean entering) {
m_userInDisabled = entering;
}
@@ -1115,7 +1116,7 @@ public class DriverStation {
* @param entering If true, starting autonomous code; if false, leaving autonomous code
*/
@SuppressWarnings("MethodName")
public void InAutonomous(boolean entering) {
public static void InAutonomous(boolean entering) {
m_userInAutonomous = entering;
}
@@ -1126,7 +1127,7 @@ public class DriverStation {
* @param entering If true, starting teleop code; if false, leaving teleop code
*/
@SuppressWarnings("MethodName")
public void InOperatorControl(boolean entering) {
public static void InOperatorControl(boolean entering) {
m_userInTeleop = entering;
}
@@ -1137,12 +1138,12 @@ public class DriverStation {
* @param entering If true, starting test code; if false, leaving test code
*/
@SuppressWarnings("MethodName")
public void InTest(boolean entering) {
public static void InTest(boolean entering) {
m_userInTest = entering;
}
/** Forces waitForData() to return immediately. */
public void wakeupWaitForData() {
public static void wakeupWaitForData() {
m_waitForDataMutex.lock();
m_waitForDataCount++;
m_waitForDataCond.signalAll();
@@ -1156,7 +1157,7 @@ public class DriverStation {
*
* @param silence Whether warning messages should be silenced.
*/
public void silenceJoystickConnectionWarning(boolean silence) {
public static void silenceJoystickConnectionWarning(boolean silence) {
m_silenceJoystickWarning = silence;
}
@@ -1166,7 +1167,7 @@ public class DriverStation {
*
* @return Whether joystick connection warnings are silenced.
*/
public boolean isJoystickConnectionWarningSilenced() {
public static boolean isJoystickConnectionWarningSilenced() {
return !isFMSAttached() && m_silenceJoystickWarning;
}
@@ -1174,7 +1175,7 @@ public class DriverStation {
* Copy data from the DS task for the user. If no new data exists, it will just be returned,
* otherwise the data will be copied from the DS polling loop.
*/
protected void getData() {
protected static void getData() {
// Get the status of all of the joysticks
for (byte stick = 0; stick < kJoystickPorts; stick++) {
m_joystickAxesCache[stick].m_count =
@@ -1224,14 +1225,14 @@ public class DriverStation {
}
wakeupWaitForData();
m_matchDataSender.sendMatchData(this);
m_matchDataSender.sendMatchData();
}
/**
* Reports errors related to unplugged joysticks Throttles the errors so that they don't overwhelm
* the DS.
*/
private void reportJoystickUnpluggedError(String message) {
private static void reportJoystickUnpluggedError(String message) {
double currentTime = Timer.getFPGATimestamp();
if (currentTime > m_nextMessageTime) {
reportError(message, false);
@@ -1243,7 +1244,7 @@ public class DriverStation {
* Reports errors related to unplugged joysticks Throttles the errors so that they don't overwhelm
* the DS.
*/
private void reportJoystickUnpluggedWarning(String message) {
private static void reportJoystickUnpluggedWarning(String message) {
if (isFMSAttached() || !m_silenceJoystickWarning) {
double currentTime = Timer.getFPGATimestamp();
if (currentTime > m_nextMessageTime) {
@@ -1254,7 +1255,7 @@ public class DriverStation {
}
/** Provides the service routine for the DS polling m_thread. */
private void run() {
private static void run() {
int safetyCounter = 0;
while (m_threadKeepAlive) {
HAL.waitForDSData();
@@ -1290,7 +1291,7 @@ public class DriverStation {
*
* @param force True to force an update to the cache, otherwise update if 50ms have passed.
*/
private void updateControlWord(boolean force) {
private static void updateControlWord(boolean force) {
long now = System.currentTimeMillis();
synchronized (m_controlWordMutex) {
if (now - m_lastControlWordUpdate > 50 || force) {

View File

@@ -67,14 +67,12 @@ public abstract class GenericHID {
}
}
private DriverStation m_ds;
private final int m_port;
private int m_outputs;
private short m_leftRumble;
private short m_rightRumble;
public GenericHID(int port) {
m_ds = DriverStation.getInstance();
m_port = port;
}
@@ -125,7 +123,7 @@ public abstract class GenericHID {
* @return The state of the button.
*/
public boolean getRawButton(int button) {
return m_ds.getStickButton(m_port, (byte) button);
return DriverStation.getStickButton(m_port, (byte) button);
}
/**
@@ -139,7 +137,7 @@ public abstract class GenericHID {
* @return Whether the button was pressed since the last check.
*/
public boolean getRawButtonPressed(int button) {
return m_ds.getStickButtonPressed(m_port, (byte) button);
return DriverStation.getStickButtonPressed(m_port, (byte) button);
}
/**
@@ -153,7 +151,7 @@ public abstract class GenericHID {
* @return Whether the button was released since the last check.
*/
public boolean getRawButtonReleased(int button) {
return m_ds.getStickButtonReleased(m_port, button);
return DriverStation.getStickButtonReleased(m_port, button);
}
/**
@@ -163,7 +161,7 @@ public abstract class GenericHID {
* @return The value of the axis.
*/
public double getRawAxis(int axis) {
return m_ds.getStickAxis(m_port, axis);
return DriverStation.getStickAxis(m_port, axis);
}
/**
@@ -176,7 +174,7 @@ public abstract class GenericHID {
* @return the angle of the POV in degrees, or -1 if the POV is not pressed.
*/
public int getPOV(int pov) {
return m_ds.getStickPOV(m_port, pov);
return DriverStation.getStickPOV(m_port, pov);
}
public int getPOV() {
@@ -189,7 +187,7 @@ public abstract class GenericHID {
* @return the number of axis for the current HID
*/
public int getAxisCount() {
return m_ds.getStickAxisCount(m_port);
return DriverStation.getStickAxisCount(m_port);
}
/**
@@ -198,7 +196,7 @@ public abstract class GenericHID {
* @return the number of POVs for the current HID
*/
public int getPOVCount() {
return m_ds.getStickPOVCount(m_port);
return DriverStation.getStickPOVCount(m_port);
}
/**
@@ -207,7 +205,7 @@ public abstract class GenericHID {
* @return the number of buttons for the current HID
*/
public int getButtonCount() {
return m_ds.getStickButtonCount(m_port);
return DriverStation.getStickButtonCount(m_port);
}
/**
@@ -216,7 +214,7 @@ public abstract class GenericHID {
* @return true if the HID is connected
*/
public boolean isConnected() {
return m_ds.isJoystickConnected(m_port);
return DriverStation.isJoystickConnected(m_port);
}
/**
@@ -225,7 +223,7 @@ public abstract class GenericHID {
* @return the type of the HID.
*/
public HIDType getType() {
return HIDType.of(m_ds.getJoystickType(m_port));
return HIDType.of(DriverStation.getJoystickType(m_port));
}
/**
@@ -234,7 +232,7 @@ public abstract class GenericHID {
* @return the name of the HID.
*/
public String getName() {
return m_ds.getJoystickName(m_port);
return DriverStation.getJoystickName(m_port);
}
/**
@@ -244,7 +242,7 @@ public abstract class GenericHID {
* @return the axis type of a joystick axis.
*/
public int getAxisType(int axis) {
return m_ds.getJoystickAxisType(m_port, axis);
return DriverStation.getJoystickAxisType(m_port, axis);
}
/**

View File

@@ -33,13 +33,15 @@ public final class Preferences {
/** The singleton instance. */
private static Preferences instance;
/** The network table. */
private final NetworkTable m_table;
private static final NetworkTable m_table;
/**
* Returns the preferences instance.
*
* @return the preferences instance
* @deprecated Use the static methods
*/
@Deprecated
public static synchronized Preferences getInstance() {
if (instance == null) {
instance = new Preferences();
@@ -48,7 +50,9 @@ public final class Preferences {
}
/** Creates a preference class. */
private Preferences() {
private Preferences() {}
static {
m_table = NetworkTableInstance.getDefault().getTable(TABLE_NAME);
m_table.getEntry(".type").setString("RobotPreferences");
// Listener to set all Preferences values to persistent
@@ -64,7 +68,7 @@ public final class Preferences {
*
* @return a collection of the keys
*/
public Collection<String> getKeys() {
public static Collection<String> getKeys() {
return m_table.getKeys();
}
@@ -75,7 +79,7 @@ public final class Preferences {
* @param value the value
* @throws NullPointerException if value is null
*/
public void setString(String key, String value) {
public static void setString(String key, String value) {
requireNonNullParam(value, "value", "setString");
NetworkTableEntry entry = m_table.getEntry(key);
@@ -92,7 +96,7 @@ public final class Preferences {
* @deprecated Use {@link #setString(String, String)}
*/
@Deprecated
public void putString(String key, String value) {
public static void putString(String key, String value) {
setString(key, value);
}
@@ -102,7 +106,7 @@ public final class Preferences {
* @param key The key
* @param value The value
*/
public void initString(String key, String value) {
public static void initString(String key, String value) {
NetworkTableEntry entry = m_table.getEntry(key);
entry.setDefaultString(value);
}
@@ -113,7 +117,7 @@ public final class Preferences {
* @param key the key
* @param value the value
*/
public void setInt(String key, int value) {
public static void setInt(String key, int value) {
NetworkTableEntry entry = m_table.getEntry(key);
entry.setDouble(value);
entry.setPersistent();
@@ -127,7 +131,7 @@ public final class Preferences {
* @deprecated Use {@link #setInt(String, int)}
*/
@Deprecated
public void putInt(String key, int value) {
public static void putInt(String key, int value) {
setInt(key, value);
}
@@ -137,7 +141,7 @@ public final class Preferences {
* @param key The key
* @param value The value
*/
public void initInt(String key, int value) {
public static void initInt(String key, int value) {
NetworkTableEntry entry = m_table.getEntry(key);
entry.setDefaultDouble(value);
}
@@ -148,7 +152,7 @@ public final class Preferences {
* @param key the key
* @param value the value
*/
public void setDouble(String key, double value) {
public static void setDouble(String key, double value) {
NetworkTableEntry entry = m_table.getEntry(key);
entry.setDouble(value);
entry.setPersistent();
@@ -162,7 +166,7 @@ public final class Preferences {
* @deprecated Use {@link #setDouble(String, double)}
*/
@Deprecated
public void putDouble(String key, double value) {
public static void putDouble(String key, double value) {
setDouble(key, value);
}
@@ -172,7 +176,7 @@ public final class Preferences {
* @param key The key
* @param value The value
*/
public void initDouble(String key, double value) {
public static void initDouble(String key, double value) {
NetworkTableEntry entry = m_table.getEntry(key);
entry.setDefaultDouble(value);
}
@@ -183,7 +187,7 @@ public final class Preferences {
* @param key the key
* @param value the value
*/
public void setFloat(String key, float value) {
public static void setFloat(String key, float value) {
NetworkTableEntry entry = m_table.getEntry(key);
entry.setDouble(value);
entry.setPersistent();
@@ -197,7 +201,7 @@ public final class Preferences {
* @deprecated Use {@link #setFloat(String, float)}
*/
@Deprecated
public void putFloat(String key, float value) {
public static void putFloat(String key, float value) {
setFloat(key, value);
}
@@ -207,7 +211,7 @@ public final class Preferences {
* @param key The key
* @param value The value
*/
public void initFloat(String key, float value) {
public static void initFloat(String key, float value) {
NetworkTableEntry entry = m_table.getEntry(key);
entry.setDefaultDouble(value);
}
@@ -218,7 +222,7 @@ public final class Preferences {
* @param key the key
* @param value the value
*/
public void setBoolean(String key, boolean value) {
public static void setBoolean(String key, boolean value) {
NetworkTableEntry entry = m_table.getEntry(key);
entry.setBoolean(value);
entry.setPersistent();
@@ -232,7 +236,7 @@ public final class Preferences {
* @deprecated Use {@link #setBoolean(String, boolean)}
*/
@Deprecated
public void putBoolean(String key, boolean value) {
public static void putBoolean(String key, boolean value) {
setBoolean(key, value);
}
@@ -242,7 +246,7 @@ public final class Preferences {
* @param key The key
* @param value The value
*/
public void initBoolean(String key, boolean value) {
public static void initBoolean(String key, boolean value) {
NetworkTableEntry entry = m_table.getEntry(key);
entry.setDefaultBoolean(value);
}
@@ -253,7 +257,7 @@ public final class Preferences {
* @param key the key
* @param value the value
*/
public void setLong(String key, long value) {
public static void setLong(String key, long value) {
NetworkTableEntry entry = m_table.getEntry(key);
entry.setDouble(value);
entry.setPersistent();
@@ -267,7 +271,7 @@ public final class Preferences {
* @deprecated Use {@link #setLong(String, long)}
*/
@Deprecated
public void putLong(String key, long value) {
public static void putLong(String key, long value) {
setLong(key, value);
}
@@ -277,7 +281,7 @@ public final class Preferences {
* @param key The key
* @param value The value
*/
public void initLong(String key, long value) {
public static void initLong(String key, long value) {
NetworkTableEntry entry = m_table.getEntry(key);
entry.setDefaultDouble(value);
}
@@ -288,7 +292,7 @@ public final class Preferences {
* @param key the key
* @return if there is a value at the given key
*/
public boolean containsKey(String key) {
public static boolean containsKey(String key) {
return m_table.containsKey(key);
}
@@ -297,12 +301,12 @@ public final class Preferences {
*
* @param key the key
*/
public void remove(String key) {
public static void remove(String key) {
m_table.delete(key);
}
/** Remove all preferences. */
public void removeAll() {
public static void removeAll() {
for (String key : m_table.getKeys()) {
if (!".type".equals(key)) {
remove(key);
@@ -318,7 +322,7 @@ public final class Preferences {
* @param backup the value to return if none exists in the table
* @return either the value in the table, or the backup
*/
public String getString(String key, String backup) {
public static String getString(String key, String backup) {
return m_table.getEntry(key).getString(backup);
}
@@ -330,7 +334,7 @@ public final class Preferences {
* @param backup the value to return if none exists in the table
* @return either the value in the table, or the backup
*/
public int getInt(String key, int backup) {
public static int getInt(String key, int backup) {
return (int) m_table.getEntry(key).getDouble(backup);
}
@@ -342,7 +346,7 @@ public final class Preferences {
* @param backup the value to return if none exists in the table
* @return either the value in the table, or the backup
*/
public double getDouble(String key, double backup) {
public static double getDouble(String key, double backup) {
return m_table.getEntry(key).getDouble(backup);
}
@@ -354,7 +358,7 @@ public final class Preferences {
* @param backup the value to return if none exists in the table
* @return either the value in the table, or the backup
*/
public boolean getBoolean(String key, boolean backup) {
public static boolean getBoolean(String key, boolean backup) {
return m_table.getEntry(key).getBoolean(backup);
}
@@ -366,7 +370,7 @@ public final class Preferences {
* @param backup the value to return if none exists in the table
* @return either the value in the table, or the backup
*/
public float getFloat(String key, float backup) {
public static float getFloat(String key, float backup) {
return (float) m_table.getEntry(key).getDouble(backup);
}
@@ -378,7 +382,7 @@ public final class Preferences {
* @param backup the value to return if none exists in the table
* @return either the value in the table, or the backup
*/
public long getLong(String key, long backup) {
public static long getLong(String key, long backup) {
return (long) m_table.getEntry(key).getDouble(backup);
}
}

View File

@@ -123,8 +123,6 @@ public abstract class RobotBase implements AutoCloseable {
});
}
protected final DriverStation m_ds;
/**
* Constructor for a generic robot program. User code should be placed in the constructor that
* runs before the Autonomous or Operator Control period starts. The constructor will run to
@@ -144,7 +142,6 @@ public abstract class RobotBase implements AutoCloseable {
} else {
inst.startServer();
}
m_ds = DriverStation.getInstance();
inst.getTable("LiveWindow").getSubTable(".status").getEntry("LW Enabled").setBoolean(false);
LiveWindow.setEnabled(false);
@@ -182,7 +179,7 @@ public abstract class RobotBase implements AutoCloseable {
* @return True if the Robot is currently disabled by the field controls.
*/
public boolean isDisabled() {
return m_ds.isDisabled();
return DriverStation.isDisabled();
}
/**
@@ -191,7 +188,7 @@ public abstract class RobotBase implements AutoCloseable {
* @return True if the Robot is currently enabled by the field controls.
*/
public boolean isEnabled() {
return m_ds.isEnabled();
return DriverStation.isEnabled();
}
/**
@@ -200,7 +197,7 @@ public abstract class RobotBase implements AutoCloseable {
* @return True if the robot is currently operating Autonomously.
*/
public boolean isAutonomous() {
return m_ds.isAutonomous();
return DriverStation.isAutonomous();
}
/**
@@ -210,7 +207,7 @@ public abstract class RobotBase implements AutoCloseable {
* @return True if the robot is currently operating autonomously while enabled.
*/
public boolean isAutonomousEnabled() {
return m_ds.isAutonomousEnabled();
return DriverStation.isAutonomousEnabled();
}
/**
@@ -219,7 +216,7 @@ public abstract class RobotBase implements AutoCloseable {
* @return True if the robot is currently operating in Test mode.
*/
public boolean isTest() {
return m_ds.isTest();
return DriverStation.isTest();
}
/**
@@ -229,7 +226,7 @@ public abstract class RobotBase implements AutoCloseable {
* @return True if the robot is currently operating in Tele-Op mode.
*/
public boolean isOperatorControl() {
return m_ds.isOperatorControl();
return DriverStation.isOperatorControl();
}
/**
@@ -239,7 +236,7 @@ public abstract class RobotBase implements AutoCloseable {
* @return True if the robot is currently operating in Tele-Op mode while enabled.
*/
public boolean isOperatorControlEnabled() {
return m_ds.isOperatorControlEnabled();
return DriverStation.isOperatorControlEnabled();
}
/**
@@ -248,7 +245,7 @@ public abstract class RobotBase implements AutoCloseable {
* @return Has new data arrived over the network since the last time this function was called?
*/
public boolean isNewDataAvailable() {
return m_ds.isNewControlData();
return DriverStation.isNewControlData();
}
/** Provide an alternate "main loop" via startCompetition(). */

View File

@@ -7,27 +7,27 @@ package edu.wpi.first.wpilibj;
@SuppressWarnings("MissingJavadocMethod")
public final class RobotState {
public static boolean isDisabled() {
return DriverStation.getInstance().isDisabled();
return DriverStation.isDisabled();
}
public static boolean isEnabled() {
return DriverStation.getInstance().isEnabled();
return DriverStation.isEnabled();
}
public static boolean isEStopped() {
return DriverStation.getInstance().isEStopped();
return DriverStation.isEStopped();
}
public static boolean isOperatorControl() {
return DriverStation.getInstance().isOperatorControl();
return DriverStation.isOperatorControl();
}
public static boolean isAutonomous() {
return DriverStation.getInstance().isAutonomous();
return DriverStation.isAutonomous();
}
public static boolean isTest() {
return DriverStation.getInstance().isTest();
return DriverStation.isTest();
}
private RobotState() {}

View File

@@ -26,7 +26,7 @@ public class Timer {
* @return Time remaining in current match period (auto or teleop) in seconds
*/
public static double getMatchTime() {
return DriverStation.getInstance().getMatchTime();
return DriverStation.getMatchTime();
}
/**

View File

@@ -312,7 +312,7 @@ public final class DriverStationSim {
/** Updates DriverStation data so that new values are visible to the user program. */
public static void notifyNewData() {
DriverStationDataJNI.notifyNewData();
DriverStation.getInstance().waitForData();
DriverStation.waitForData();
}
/**

View File

@@ -44,7 +44,7 @@
*
* {@literal @}Override
* public void robotInit() {
* usbCamera = CameraServer.getInstance().startAutomaticCapture(0);
* usbCamera = CameraServer.startAutomaticCapture(0);
* findTotePipeline = new MyFindTotePipeline();
* findToteThread = new VisionThread(usbCamera, findTotePipeline, this);
* }