WPILibC++ 2027.0.0-alpha-5
Loading...
Searching...
No Matches
RobotState.hpp
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <cstdint>
8#include <string>
9#include <string_view>
10
12
13namespace wpi {
14
16
17/**
18 * Provides access to robot state information from the Driver Station.
19 */
20class RobotState final {
21 public:
22 RobotState() = delete;
23
24 /**
25 * Check if the DS has enabled the robot.
26 *
27 * @return True if the robot is enabled and the DS is connected
28 */
32
33 /**
34 * Check if the robot is disabled.
35 *
36 * @return True if the robot is explicitly disabled or the DS is not connected
37 */
41
42 /**
43 * Check if the robot is e-stopped.
44 *
45 * @return True if the robot is e-stopped
46 */
50
51 /**
52 * Gets the current robot mode.
53 *
54 * Note that this does not indicate whether the robot is enabled or disabled.
55 *
56 * @return robot mode
57 */
61
62 /**
63 * Check if the DS is commanding autonomous mode.
64 *
65 * @return True if the robot is being commanded to be in autonomous mode
66 */
70
71 /**
72 * Check if the DS is commanding autonomous mode and if it has enabled the
73 * robot.
74 *
75 * @return True if the robot is being commanded to be in autonomous mode and
76 * enabled.
77 */
81
82 /**
83 * Check if the DS is commanding teleop mode.
84 *
85 * @return True if the robot is being commanded to be in teleop mode
86 */
90
91 /**
92 * Check if the DS is commanding teleop mode and if it has enabled the robot.
93 *
94 * @return True if the robot is being commanded to be in teleop mode and
95 * enabled.
96 */
100
101 /**
102 * Check if the DS is commanding utility mode.
103 *
104 * @return True if the robot is being commanded to be in utility mode
105 */
109
110 /**
111 * Check if the DS is commanding Utility mode and if it has enabled the robot.
112 *
113 * @return True if the robot is being commanded to be in Utility mode and
114 * enabled.
115 */
119
120 /**
121 * Adds an operating mode option. It's necessary to call PublishOpModes() to
122 * make the added modes visible to the driver station.
123 *
124 * @param mode robot mode
125 * @param name name of the operating mode
126 * @param group group of the operating mode
127 * @param description description of the operating mode
128 * @param textColor text color
129 * @param backgroundColor background color
130 * @return unique ID used to later identify the operating mode; if a blank
131 * name is passed, 0 is returned; identical names for the same robot
132 * mode result in a 0 return value
133 */
134 static int64_t AddOpMode(RobotMode mode, std::string_view name,
135 std::string_view group, std::string_view description,
136 const wpi::util::Color& textColor,
137 const wpi::util::Color& backgroundColor) {
139 mode, name, group, description, textColor, backgroundColor);
140 }
141
142 /**
143 * Adds an operating mode option. It's necessary to call PublishOpModes() to
144 * make the added modes visible to the driver station.
145 *
146 * @param mode robot mode
147 * @param name name of the operating mode
148 * @param group group of the operating mode
149 * @param description description of the operating mode
150 * @return unique ID used to later identify the operating mode; if a blank
151 * name is passed, 0 is returned; identical names for the same robot
152 * mode result in a 0 return value
153 */
154 static int64_t AddOpMode(RobotMode mode, std::string_view name,
155 std::string_view group = {},
156 std::string_view description = {}) {
158 description);
159 }
160
161 /**
162 * Removes an operating mode option. It's necessary to call PublishOpModes()
163 * to make the removed mode no longer visible to the driver station.
164 *
165 * @param mode robot mode
166 * @param name name of the operating mode
167 * @return unique ID for the opmode, or 0 if not found
168 */
169 static int64_t RemoveOpMode(RobotMode mode, std::string_view name) {
171 }
172
173 /**
174 * Publishes the operating mode options to the driver station.
175 */
179
180 /**
181 * Clears all operating mode options and publishes an empty list to the driver
182 * station.
183 */
187
188 /**
189 * Gets the operating mode selected on the driver station. Note this does not
190 * mean the robot is enabled; use IsEnabled() for that. In a match, this will
191 * indicate the operating mode selected for auto before the match starts
192 * (i.e., while the robot is disabled in auto mode); after the auto period
193 * ends, this will change to reflect the operating mode selected for teleop.
194 *
195 * @return the unique ID provided by the AddOpMode() function; may return 0 or
196 * a unique ID not added, so callers should be prepared to handle that case
197 */
198 static int64_t GetOpModeId() {
200 }
201
202 /**
203 * Gets the operating mode selected on the driver station. Note this does not
204 * mean the robot is enabled; use IsEnabled() for that. In a match, this will
205 * indicate the operating mode selected for auto before the match starts
206 * (i.e., while the robot is disabled in auto mode); after the auto period
207 * ends, this will change to reflect the operating mode selected for teleop.
208 *
209 * @return Operating mode string; may return a string not in the list of
210 * options, so callers should be prepared to handle that case
211 */
212 static std::string GetOpMode() {
214 }
215
216 /**
217 * Check to see if the selected operating mode is a particular value. Note
218 * this does not mean the robot is enabled; use IsEnabled() for that.
219 *
220 * @param id operating mode unique ID
221 * @return True if that mode is the current mode
222 */
223 static bool IsOpMode(int64_t id) {
225 }
226
227 /**
228 * Check to see if the selected operating mode is a particular value. Note
229 * this does not mean the robot is enabled; use IsEnabled() for that.
230 *
231 * @param mode operating mode
232 * @return True if that mode is the current mode
233 */
234 static bool IsOpMode(std::string_view mode) {
236 }
237
238 /**
239 * Check if the DS is attached.
240 *
241 * @return True if the DS is connected to the robot
242 */
246
247 /**
248 * Is the driver station attached to a Field Management System?
249 *
250 * @return True if the robot is competing on a field being controlled by a
251 * Field Management System
252 */
256};
257
258} // namespace wpi
@ name
Definition base.h:690
static bool IsOpMode(int64_t id)
Check to see if the selected operating mode is a particular value.
Definition RobotState.hpp:223
static bool IsAutonomousEnabled()
Check if the DS is commanding autonomous mode and if it has enabled the robot.
Definition RobotState.hpp:78
RobotState()=delete
static bool IsEnabled()
Check if the DS has enabled the robot.
Definition RobotState.hpp:29
static int64_t AddOpMode(RobotMode mode, std::string_view name, std::string_view group, std::string_view description, const wpi::util::Color &textColor, const wpi::util::Color &backgroundColor)
Adds an operating mode option.
Definition RobotState.hpp:134
static int64_t RemoveOpMode(RobotMode mode, std::string_view name)
Removes an operating mode option.
Definition RobotState.hpp:169
static void PublishOpModes()
Publishes the operating mode options to the driver station.
Definition RobotState.hpp:176
static bool IsTeleop()
Check if the DS is commanding teleop mode.
Definition RobotState.hpp:87
static bool IsUtilityEnabled()
Check if the DS is commanding Utility mode and if it has enabled the robot.
Definition RobotState.hpp:116
static bool IsDSAttached()
Check if the DS is attached.
Definition RobotState.hpp:243
static int64_t GetOpModeId()
Gets the operating mode selected on the driver station.
Definition RobotState.hpp:198
static bool IsEStopped()
Check if the robot is e-stopped.
Definition RobotState.hpp:47
static bool IsFMSAttached()
Is the driver station attached to a Field Management System?
Definition RobotState.hpp:253
static bool IsTeleopEnabled()
Check if the DS is commanding teleop mode and if it has enabled the robot.
Definition RobotState.hpp:97
static bool IsOpMode(std::string_view mode)
Check to see if the selected operating mode is a particular value.
Definition RobotState.hpp:234
static void ClearOpModes()
Clears all operating mode options and publishes an empty list to the driver station.
Definition RobotState.hpp:184
static int64_t AddOpMode(RobotMode mode, std::string_view name, std::string_view group={}, std::string_view description={})
Adds an operating mode option.
Definition RobotState.hpp:154
static bool IsDisabled()
Check if the robot is disabled.
Definition RobotState.hpp:38
static RobotMode GetRobotMode()
Gets the current robot mode.
Definition RobotState.hpp:58
static std::string GetOpMode()
Gets the operating mode selected on the driver station.
Definition RobotState.hpp:212
static bool IsAutonomous()
Check if the DS is commanding autonomous mode.
Definition RobotState.hpp:67
static bool IsUtility()
Check if the DS is commanding utility mode.
Definition RobotState.hpp:106
static bool IsDisabled()
Check if the robot is disabled.
Definition DriverStationBackend.hpp:253
static RobotMode GetRobotMode()
Gets the current robot mode.
Definition DriverStationBackend.hpp:270
static bool IsEStopped()
Check if the robot is e-stopped.
Definition DriverStationBackend.hpp:260
static bool IsAutonomous()
Check if the DS is commanding autonomous mode.
Definition DriverStationBackend.hpp:277
static bool IsTeleop()
Check if the DS is commanding teleop mode.
Definition DriverStationBackend.hpp:295
static int64_t AddOpMode(RobotMode mode, std::string_view name, std::string_view group, std::string_view description, const wpi::util::Color &textColor, const wpi::util::Color &backgroundColor)
Adds an operating mode option.
static bool IsUtility()
Check if the DS is commanding utility mode.
Definition DriverStationBackend.hpp:310
static bool IsTeleopEnabled()
Check if the DS is commanding teleop mode and if it has enabled the robot.
Definition DriverStationBackend.hpp:303
static bool IsEnabled()
Check if the DS has enabled the robot.
Definition DriverStationBackend.hpp:243
static int64_t GetOpModeId()
Gets the operating mode selected on the driver station.
static int64_t RemoveOpMode(RobotMode mode, std::string_view name)
Removes an operating mode option.
static bool IsUtilityEnabled()
Check if the DS is commanding Utility mode and if it has enabled the robot.
Definition DriverStationBackend.hpp:318
static std::string GetOpMode()
Gets the operating mode selected on the driver station.
static void ClearOpModes()
Clears all operating mode options and publishes an empty list to the driver station.
static bool IsOpMode(int64_t id)
Check to see if the selected operating mode is a particular value.
Definition DriverStationBackend.hpp:421
static bool IsFMSAttached()
Is the driver station attached to a Field Management System?
Definition DriverStationBackend.hpp:445
static bool IsAutonomousEnabled()
Check if the DS is commanding autonomous mode and if it has enabled the robot.
Definition DriverStationBackend.hpp:286
static void PublishOpModes()
Publishes the operating mode options to the driver station.
static bool IsDSAttached()
Check if the DS is attached.
Definition DriverStationBackend.hpp:437
Represents colors that can be used with Addressable LEDs.
Definition Color.hpp:42
RobotMode
The overall robot mode (not including enabled state).
Definition DriverStationTypes.hpp:15
Definition CvSource.hpp:15