You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Add TimedRobot explanation for autonomous choosers
Resolves#1736 by creating separate sections for TimedRobot and Command-Based Robots.
* Fix duplicate titles
Copy file name to clipboardExpand all lines: source/docs/software/dashboards/smartdashboard/choosing-an-autonomous-program-from-smartdashboard.rst
+74-8Lines changed: 74 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,12 +3,78 @@ Choosing an Autonomous Program
3
3
4
4
Often teams have more than one autonomous program, either for competitive reasons or for testing new software. Programs often vary by adding things like time delays, different strategies, etc. The methods to choose the strategy to run usually involves switches, joystick buttons, knobs or other hardware based inputs.
5
5
6
-
With the SmartDashboard you can simply display a widget on the screen to choose the autonomous program that you would like to run. And with command based programs, that program is encapsulated in one of several commands. This article shows how to select an autonomous program with only a few lines of code and a nice looking user interface.
6
+
With the SmartDashboard you can simply display a widget on the screen to choose the autonomous program that you would like to run. And with command based programs, that program is encapsulated in one of several commands. This article shows how to select an autonomous program with only a few lines of code and a nice looking user interface, with examples for both TimedRobot and Command-Based Robots.
7
+
8
+
TimedRobot
9
+
----------
10
+
11
+
.. note:: The code snippets shown below are part of the TimedRobot template (`Java <https://github.com/wpilibsuite/allwpilib/tree/main/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/timed>`__, `C++ <https://github.com/wpilibsuite/allwpilib/tree/main/wpilibcExamples/src/main/cpp/templates/timed>`__):
12
+
13
+
Creating SendableChooser Object
14
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15
+
16
+
In ``Robot.java`` / ``Robot.h``, create a variable to hold a reference to a ``SendableChooser`` object. Two or more auto modes can be added by creating strings to send to the chooser. Using the ``SendableChooser``, one can choose between them. In this example, ``Default`` and ``My Auto`` are shown as options. You will also need a variable to store which auto has been chosen, ``m_autoSelected``.
The chooser allows you to pick from a list of defined elements, in this case the strings we defined above. In ``robotInit``, add your options created as strings above using ``setDefaultOption`` or ``addOption``. ``setDefaultOption`` will be the one selected by default when the dashboard starts. The ``putData`` function will push it to the dashboard on your driver station computer.
Now, in ``autonomousInit`` and ``autonomousPeriodic``, you can use the ``m_autoSelected`` variable to read which option was chosen, and change what happens during the autonomous period.
.. note:: The code snippets shown below are part of the HatchbotTraditional example project (`Java <https://github.com/wpilibsuite/allwpilib/tree/main/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/hatchbottraditional>`__, `C++ <https://github.com/wpilibsuite/allwpilib/tree/main/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional>`__):
9
75
10
76
Creating the SendableChooser Object
11
-
-----------------------------------
77
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12
78
13
79
In ``RobotContainer``, create a variable to hold a reference to a ``SendableChooser`` object. Two or more commands can be created and stored in new variables. Using the ``SendableChooser``, one can choose between them. In this example, ``SimpleAuto`` and ``ComplexAuto`` are shown as options.
14
80
@@ -20,14 +86,14 @@ In ``RobotContainer``, create a variable to hold a reference to a ``SendableChoo
Imagine that you have two autonomous programs to choose between and they are encapsulated in commands ``SimpleAuto`` and ``ComplexAuto``. To choose between them:
33
99
@@ -54,7 +120,7 @@ In ``RobotContainer``, create a ``SendableChooser`` object and add instances of
54
120
frc::SmartDashboard::PutData(&m_chooser);
55
121
56
122
Starting an Autonomous Command
57
-
------------------------------
123
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
58
124
59
125
In ``Robot.java``, when the autonomous period starts, the ``SendableChooser`` object is polled to get the selected command and that command must be scheduled.
60
126
@@ -81,7 +147,7 @@ In ``Robot.java``, when the autonomous period starts, the ``SendableChooser`` ob
81
147
:lines: 37-44
82
148
83
149
Running the Scheduler during Autonomous
84
-
---------------------------------------
150
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
85
151
86
152
In ``Robot.java``, this will run the scheduler every driver station update period (about every 20ms) and cause the selected autonomous command to run.
87
153
@@ -106,7 +172,7 @@ In ``Robot.java``, this will run the scheduler every driver station update perio
106
172
:lineno-start: 20
107
173
108
174
Canceling the Autonomous Command
109
-
---------------------------------
175
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
110
176
111
177
In ``Robot.java``, when the teleop period begins, the autonomous command will be canceled.
112
178
@@ -127,7 +193,7 @@ In ``Robot.java``, when the teleop period begins, the autonomous command will be
0 commit comments