WPILibC++ 2023.4.3-108-ge5452e3
Shuffleboard.h
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 <string_view>
8
12
13namespace frc {
14
15class ShuffleboardTab;
16
17/**
18 * The Shuffleboard class provides a mechanism with which data can be added and
19 * laid out in the Shuffleboard dashboard application from a robot program. Tabs
20 * and layouts can be specified, as well as choosing which widgets to display
21 * with and setting properties of these widgets; for example, programmers can
22 * specify a specific {@code boolean} value to be displayed with a toggle button
23 * instead of the default colored box, or set custom colors for that box.
24 *
25 * For example, displaying a boolean entry with a toggle button:
26 * <pre>{@code
27 * NetworkTableEntry myBoolean = Shuffleboard.getTab("Example Tab")
28 * .add("My Boolean", false)
29 * .withWidget("Toggle Button")
30 * .getEntry();
31 * }</pre>
32 *
33 * Changing the colors of the boolean box:
34 * <pre>{@code
35 * NetworkTableEntry myBoolean = Shuffleboard.getTab("Example Tab")
36 * .add("My Boolean", false)
37 * .withWidget("Boolean Box")
38 * .withProperties(Map.of("colorWhenTrue", "green", "colorWhenFalse",
39 * "maroon")) .getEntry();
40 * }</pre>
41 *
42 * Specifying a parent layout. Note that the layout type must <i>always</i> be
43 * specified, even if the layout has already been generated by a previously
44 * defined entry.
45 * <pre>{@code
46 * NetworkTableEntry myBoolean = Shuffleboard.getTab("Example Tab")
47 * .getLayout("List", "Example List")
48 * .add("My Boolean", false)
49 * .withWidget("Toggle Button")
50 * .getEntry();
51 * }</pre>
52 * </p>
53 *
54 * Teams are encouraged to set up shuffleboard layouts at the start of the robot
55 * program.
56 */
57class Shuffleboard final {
58 public:
59 /**
60 * The name of the base NetworkTable into which all Shuffleboard data will be
61 * added.
62 */
63 static constexpr const char* kBaseTableName = "/Shuffleboard";
64
65 /**
66 * Updates all the values in Shuffleboard. Iterative and timed robots are
67 * pre-configured to call this method in the main robot loop; teams using
68 * custom robot base classes, or subclass SampleRobot, should make sure to
69 * call this repeatedly to keep data on the dashboard up to date.
70 */
71 static void Update();
72
73 /**
74 * Gets the Shuffleboard tab with the given title, creating it if it does not
75 * already exist.
76 *
77 * @param title the title of the tab
78 * @return the tab with the given title
79 */
81
82 /**
83 * Selects the tab in the dashboard with the given index in the range
84 * [0..n-1], where <i>n</i> is the number of tabs in the dashboard at the time
85 * this method is called.
86 *
87 * @param index the index of the tab to select
88 */
89 static void SelectTab(int index);
90
91 /**
92 * Selects the tab in the dashboard with the given title.
93 *
94 * @param title the title of the tab to select
95 */
96 static void SelectTab(std::string_view title);
97
98 /**
99 * Enables user control of widgets containing actuators: motor controllers,
100 * relays, etc. This should only be used when the robot is in test mode.
101 * IterativeRobotBase and SampleRobot are both configured to call this method
102 * when entering test mode; most users should not need to use this method
103 * directly.
104 */
106
107 /**
108 * Disables user control of widgets containing actuators. For safety reasons,
109 * actuators should only be controlled while in test mode. IterativeRobotBase
110 * and SampleRobot are both configured to call this method when exiting in
111 * test mode; most users should not need to use this method directly.
112 */
114
115 /**
116 * Starts data recording on the dashboard. Has no effect if recording is
117 * already in progress.
118 */
119 static void StartRecording();
120
121 /**
122 * Stops data recording on the dashboard. Has no effect if no recording is in
123 * progress.
124 */
125 static void StopRecording();
126
127 /**
128 * Sets the file name format for new recording files to use. If recording is
129 * in progress when this method is called, it will continue to use the same
130 * file. New recordings will use the format.
131 *
132 * <p>To avoid recording files overwriting each other, make sure to use unique
133 * recording file names. File name formats accept templates for inserting the
134 * date and time when the recording started with the {@code ${date}} and
135 * {@code ${time}} templates, respectively. For example, the default format is
136 * {@code "recording-${time}"} and recording files created with it will have
137 * names like {@code "recording-2018.01.15.sbr"}. Users are
138 * <strong>strongly</strong> recommended to use the {@code ${time}} template
139 * to ensure unique file names.
140 * </p>
141 *
142 * @param format the format for the
143 */
145
146 /**
147 * Clears the custom name format for recording files. New recordings will use
148 * the default format.
149 *
150 * @see SetRecordingFileNameFormat(std::string_view)
151 */
153
154 /**
155 * Notifies Shuffleboard of an event. Events can range from as trivial as a
156 * change in a command state to as critical as a total power loss or component
157 * failure. If Shuffleboard is recording, the event will also be recorded.
158 *
159 * <p>If {@code name} is {@code null} or empty, no event will be sent and an
160 * error will be printed to the driver station.
161 *
162 * @param name the name of the event
163 * @param description a description of the event
164 * @param importance the importance of the event
165 */
167 std::string_view description,
168 ShuffleboardEventImportance importance);
169
170 /**
171 * Notifies Shuffleboard of an event. Events can range from as trivial as a
172 * change in a command state to as critical as a total power loss or component
173 * failure. If Shuffleboard is recording, the event will also be recorded.
174 *
175 * <p>If {@code name} is {@code null} or empty, no event will be sent and an
176 * error will be printed to the driver station.
177 *
178 * @param name the name of the event
179 * @param importance the importance of the event
180 */
182 ShuffleboardEventImportance importance);
183
184 private:
185 static detail::ShuffleboardInstance& GetInstance();
186 static detail::RecordingController& GetRecordingController();
187
188 // TODO usage reporting
189
190 Shuffleboard() = default;
191};
192
193} // namespace frc
194
195// Make use of references returned by member functions usable
The Shuffleboard class provides a mechanism with which data can be added and laid out in the Shuffleb...
Definition: Shuffleboard.h:57
static void StartRecording()
Starts data recording on the dashboard.
static constexpr const char * kBaseTableName
The name of the base NetworkTable into which all Shuffleboard data will be added.
Definition: Shuffleboard.h:63
static void StopRecording()
Stops data recording on the dashboard.
static void SetRecordingFileNameFormat(std::string_view format)
Sets the file name format for new recording files to use.
static void SelectTab(int index)
Selects the tab in the dashboard with the given index in the range [0..n-1], where n is the number of...
static ShuffleboardTab & GetTab(std::string_view title)
Gets the Shuffleboard tab with the given title, creating it if it does not already exist.
static void AddEventMarker(std::string_view name, std::string_view description, ShuffleboardEventImportance importance)
Notifies Shuffleboard of an event.
static void SelectTab(std::string_view title)
Selects the tab in the dashboard with the given title.
static void EnableActuatorWidgets()
Enables user control of widgets containing actuators: motor controllers, relays, etc.
static void AddEventMarker(std::string_view name, ShuffleboardEventImportance importance)
Notifies Shuffleboard of an event.
static void DisableActuatorWidgets()
Disables user control of widgets containing actuators.
static void ClearRecordingFileNameFormat()
Clears the custom name format for recording files.
static void Update()
Updates all the values in Shuffleboard.
Represents a tab in the Shuffleboard dashboard.
Definition: ShuffleboardTab.h:26
Definition: RecordingController.h:21
Definition: ShuffleboardInstance.h:15
basic_string_view< char > string_view
Definition: core.h:520
Definition: AprilTagPoseEstimator.h:15
ShuffleboardEventImportance
Definition: ShuffleboardEventImportance.h:15
auto format(wformat_string< T... > fmt, T &&... args) -> std::wstring
Definition: xchar.h:87