001// Copyright (c) FIRST and other WPILib contributors.
002// Open Source Software; you can modify and/or share it under the terms of
003// the WPILib BSD license file in the root directory of this project.
004
005package org.wpilib.driverstation;
006
007import org.wpilib.driverstation.internal.DriverStationBackend;
008import org.wpilib.hardware.hal.RobotMode;
009import org.wpilib.util.Color;
010
011/** Provides access to robot state information from the Driver Station. */
012public final class RobotState {
013  private RobotState() {}
014
015  /**
016   * Gets a value indicating whether the Driver Station requires the robot to be enabled.
017   *
018   * @return True if the robot is enabled, false otherwise.
019   */
020  public static boolean isEnabled() {
021    return DriverStationBackend.isEnabled();
022  }
023
024  /**
025   * Gets a value indicating whether the Driver Station requires the robot to be disabled.
026   *
027   * @return True if the robot should be disabled, false otherwise.
028   */
029  public static boolean isDisabled() {
030    return DriverStationBackend.isDisabled();
031  }
032
033  /**
034   * Gets a value indicating whether the Robot is e-stopped.
035   *
036   * @return True if the robot is e-stopped, false otherwise.
037   */
038  public static boolean isEStopped() {
039    return DriverStationBackend.isEStopped();
040  }
041
042  /**
043   * Gets the current robot mode.
044   *
045   * <p>Note that this does not indicate whether the robot is enabled or disabled.
046   *
047   * @return robot mode
048   */
049  public static RobotMode getRobotMode() {
050    return DriverStationBackend.getRobotMode();
051  }
052
053  /**
054   * Gets a value indicating whether the Driver Station requires the robot to be running in
055   * autonomous mode.
056   *
057   * @return True if autonomous mode should be enabled, false otherwise.
058   */
059  public static boolean isAutonomous() {
060    return DriverStationBackend.isAutonomous();
061  }
062
063  /**
064   * Gets a value indicating whether the Driver Station requires the robot to be running in
065   * autonomous mode and enabled.
066   *
067   * @return True if autonomous should be set and the robot should be enabled.
068   */
069  public static boolean isAutonomousEnabled() {
070    return DriverStationBackend.isAutonomousEnabled();
071  }
072
073  /**
074   * Gets a value indicating whether the Driver Station requires the robot to be running in
075   * operator-controlled mode.
076   *
077   * @return True if operator-controlled mode should be enabled, false otherwise.
078   */
079  public static boolean isTeleop() {
080    return DriverStationBackend.isTeleop();
081  }
082
083  /**
084   * Gets a value indicating whether the Driver Station requires the robot to be running in
085   * operator-controller mode and enabled.
086   *
087   * @return True if operator-controlled mode should be set and the robot should be enabled.
088   */
089  public static boolean isTeleopEnabled() {
090    return DriverStationBackend.isTeleopEnabled();
091  }
092
093  /**
094   * Gets a value indicating whether the Driver Station requires the robot to be running in Utility
095   * mode.
096   *
097   * @return True if utility mode should be enabled, false otherwise.
098   */
099  public static boolean isUtility() {
100    return DriverStationBackend.isUtility();
101  }
102
103  /**
104   * Gets a value indicating whether the Driver Station requires the robot to be running in Utility
105   * mode and enabled.
106   *
107   * @return True if utility mode should be set and the robot should be enabled.
108   */
109  public static boolean isUtilityEnabled() {
110    return DriverStationBackend.isUtilityEnabled();
111  }
112
113  /**
114   * Adds an operating mode option. It's necessary to call publishOpModes() to make the added modes
115   * visible to the driver station.
116   *
117   * @param mode robot mode
118   * @param name name of the operating mode
119   * @param group group of the operating mode
120   * @param description description of the operating mode
121   * @param textColor text color, or null for default
122   * @param backgroundColor background color, or null for default
123   * @return unique ID used to later identify the operating mode
124   * @throws IllegalArgumentException if name is empty or an operating mode with the same robot mode
125   *     and name already exists
126   */
127  public static long addOpMode(
128      RobotMode mode,
129      String name,
130      String group,
131      String description,
132      Color textColor,
133      Color backgroundColor) {
134    return DriverStationBackend.addOpMode(
135        mode, name, group, description, textColor, backgroundColor);
136  }
137
138  /**
139   * Adds an operating mode option. It's necessary to call publishOpModes() to make the added modes
140   * visible to the driver station.
141   *
142   * @param mode robot mode
143   * @param name name of the operating mode
144   * @param group group of the operating mode
145   * @param description description of the operating mode
146   * @return unique ID used to later identify the operating mode
147   * @throws IllegalArgumentException if name is empty or an operating mode with the same name
148   *     already exists
149   */
150  public static long addOpMode(RobotMode mode, String name, String group, String description) {
151    return DriverStationBackend.addOpMode(mode, name, group, description);
152  }
153
154  /**
155   * Adds an operating mode option. It's necessary to call publishOpModes() to make the added modes
156   * visible to the driver station.
157   *
158   * @param mode robot mode
159   * @param name name of the operating mode
160   * @param group group of the operating mode
161   * @return unique ID used to later identify the operating mode
162   * @throws IllegalArgumentException if name is empty or an operating mode with the same name
163   *     already exists
164   */
165  public static long addOpMode(RobotMode mode, String name, String group) {
166    return DriverStationBackend.addOpMode(mode, name, group);
167  }
168
169  /**
170   * Adds an operating mode option. It's necessary to call publishOpModes() to make the added modes
171   * visible to the driver station.
172   *
173   * @param mode robot mode
174   * @param name name of the operating mode
175   * @return unique ID used to later identify the operating mode
176   * @throws IllegalArgumentException if name is empty or an operating mode with the same name
177   *     already exists
178   */
179  public static long addOpMode(RobotMode mode, String name) {
180    return DriverStationBackend.addOpMode(mode, name);
181  }
182
183  /**
184   * Removes an operating mode option. It's necessary to call publishOpModes() to make the removed
185   * mode no longer visible to the driver station.
186   *
187   * @param mode robot mode
188   * @param name name of the operating mode
189   * @return unique ID for the opmode, or 0 if not found
190   */
191  public static long removeOpMode(RobotMode mode, String name) {
192    return DriverStationBackend.removeOpMode(mode, name);
193  }
194
195  /** Publishes the operating mode options to the driver station. */
196  public static void publishOpModes() {
197    DriverStationBackend.publishOpModes();
198  }
199
200  /** Clears all operating mode options and publishes an empty list to the driver station. */
201  public static void clearOpModes() {
202    DriverStationBackend.clearOpModes();
203  }
204
205  /**
206   * Gets the operating mode selected on the driver station. Note this does not mean the robot is
207   * enabled; use isEnabled() for that. In a match, this will indicate the operating mode selected
208   * for auto before the match starts (i.e., while the robot is disabled in auto mode); after the
209   * auto period ends, this will change to reflect the operating mode selected for teleop.
210   *
211   * @return the unique ID provided by the addOpMode() function; may return 0 or a unique ID not
212   *     added, so callers should be prepared to handle that case
213   */
214  public static long getOpModeId() {
215    return DriverStationBackend.getOpModeId();
216  }
217
218  /**
219   * Gets the operating mode selected on the driver station. Note this does not mean the robot is
220   * enabled; use isEnabled() for that. In a match, this will indicate the operating mode selected
221   * for auto before the match starts (i.e., while the robot is disabled in auto mode); after the
222   * auto period ends, this will change to reflect the operating mode selected for teleop.
223   *
224   * @return Operating mode string; may return a string not in the list of options, so callers
225   *     should be prepared to handle that case
226   */
227  public static String getOpMode() {
228    return DriverStationBackend.getOpMode();
229  }
230
231  /**
232   * Check to see if the selected operating mode is a particular value. Note this does not mean the
233   * robot is enabled; use isEnabled() for that.
234   *
235   * @param id operating mode unique ID
236   * @return True if that mode is the current mode
237   */
238  public static boolean isOpMode(long id) {
239    return DriverStationBackend.isOpMode(id);
240  }
241
242  /**
243   * Check to see if the selected operating mode is a particular value. Note this does not mean the
244   * robot is enabled; use isEnabled() for that.
245   *
246   * @param mode operating mode
247   * @return True if that mode is the current mode
248   */
249  public static boolean isOpMode(String mode) {
250    return DriverStationBackend.isOpMode(mode);
251  }
252
253  /**
254   * Gets a value indicating whether the Driver Station is attached.
255   *
256   * @return True if Driver Station is attached, false otherwise.
257   */
258  public static boolean isDSAttached() {
259    return DriverStationBackend.isDSAttached();
260  }
261
262  /**
263   * Gets if the driver station attached to a Field Management System.
264   *
265   * @return true if the robot is competing on a field being controlled by a Field Management System
266   */
267  public static boolean isFMSAttached() {
268    return DriverStationBackend.isFMSAttached();
269  }
270}