11# Autonomous
22
3- Creating an autonomous in NextFTC is fairly straightforward. This page will walk
4- you through creating an autonomous. Usage of PedroPathing will not be covered in
5- this page; refer to the [ PedroPathing page ] ( /guide/opmodes/pedropathing ) for
6- details on that .
3+ This page will walk you through creating an autonomous program using NextFTC.
4+ Usage of RoadRunner, Pedro Pathing, or Hermes will not be covered in this guide;
5+ see
6+ the guides for those libraries on the following pages .
77
88This autonomous program will introduce you to some core features of NextFTC such
99as command groups, delays, and running the commands you created in your
@@ -13,7 +13,7 @@ Let's get started!
1313
1414## Step 1: Create your OpMode
1515
16- OpModes in NextFTC will extend the ` NextFTCOpMode ` superclass. Here is the basic
16+ OpModes in NextFTC extend the ` NextFTCOpMode ` superclass. Here is the basic
1717structure for every autonomous OpMode:
1818
1919:::tabs key: code
6060``` java
6161@Autonomous (name = " NextFTC Autonomous Program Java" )
6262public class AutonomousProgram extends NextFTCOpMode {
63- {
63+ public AutonomousProgram () {
6464 addComponents(
6565 new SubsystemComponent (Lift . INSTANCE , Claw . INSTANCE )
6666 );
@@ -76,17 +76,14 @@ and will initialize them accordingly.
7676### A Quick Note on Components
7777
7878Components are NextFTC's approach to making OpModes more modular and
79- customizable. Each component has 10 functions that
80- get run before and after each OpMode function (` onInit ` , ` onWaitForStart ` ,
81- ` onStartButtonPressed ` , ` onUpdate ` , and
82- ` onStop ` ). This means that components are extremely versatile and can be used to
83- accomplish a wide range of
84- functions when they're used in your OpModes.
79+ customizable. Each component has 10 functions that get run before and after each
80+ OpMode function (` onInit ` , ` onWaitForStart ` ,` onStartButtonPressed ` , ` onUpdate ` ,
81+ and` onStop ` ). This means that components are extremely versatile and can be used
82+ to achieve a wide range of functions when they're used in your OpModes.
8583
8684We already have used a component: ` SubsystemComponent ` ! Let's add one more
87- component to our OpMode:
88- ` BulkReadComponent ` . This component automatically adds bulk reading to our
89- OpMode.
85+ component to our OpMode:` BulkReadComponent ` . This component automatically adds
86+ bulk reading to our OpMode.
9087
9188:::tabs key: code
9289
@@ -96,7 +93,7 @@ OpMode.
9693init {
9794 addComponents(
9895 SubsystemComponent (Lift , Claw ),
99- BulkReadComponent ()
96+ BulkReadComponent
10097 )
10198}
10299```
@@ -106,12 +103,10 @@ init {
106103``` java
107104@Autonomous (name = " NextFTC Autonomous Program Java" )
108105public class AutonomousProgram extends NextFTCOpMode {
109-
110- // if you've never seen this before, it's called an instance initialization block, or IIB.
111- {
106+ public AutonomousProgram () {
112107 addComponents(
113108 new SubsystemComponent (Lift . INSTANCE , Claw . INSTANCE ),
114- new BulkReadComponent ()
109+ BulkReadComponent . INSTANCE
115110 );
116111 }
117112}
@@ -122,18 +117,18 @@ public class AutonomousProgram extends NextFTCOpMode {
122117## Step 2: Creating a routine
123118
124119You've already learned how to create individual commands, such as motor and
125- servo movements. Now, it's time to group
126- them together into useful behaviors. This is where ` CommandGroups ` and routines
127- come into play. Before we can create our
128- own, we first need to understand how commands are run behind the scenes.
120+ servo movements. Now, it's time to group them together into useful behaviors.
121+ This is where command groups come into play. Before we can create our own, we
122+ first need to understand how commands are run behind the scenes.
129123
130124The ` CommandManager ` stores an internal list of actively running commands. It
131125goes through each command and calls its
132126` update() ` function every single loop. It also determines which commands to
133127cancel, handles subsystem conflicts, and
134128offers additional functionality as well. The important thing to note is that all
135129commands that are directly stored by
136- the CommandManager run _ simultaneously_ . Knowing that, you may be wondering why
130+ the ` CommandManager ` run _ simultaneously_ . Knowing that, you may be wondering
131+ why
137132` ParallelGroups ` exist, if you can just
138133schedule commands directly. Trust me, we'll get there. Before that, we need to
139134understand what a ` SequentialGroup ` does.
@@ -144,7 +139,7 @@ at once, it schedules the first one, and then waits to schedule the next one
144139until the first has completed, then
145140continues scheduling them one by one until they've all completed. If you think
146141about it a little bit, it may become
147- apparent what a ` ParallelGroup ` is for. If you are using a ` SequentialGroup ` ,
142+ clear what a ` ParallelGroup ` is for. If you are using a ` SequentialGroup ` ,
148143you may have things you want to happen
149144simultaneously _ within_ that group. For example:
150145
@@ -154,10 +149,10 @@ simultaneously _within_ that group. For example:
1541494 . _ Simultaneously_ lower the lift, reset the arm, and drive to a different
155150 location
156151
157- This could only be accomplished using ` ParallelGroups ` in conjunction with
152+ This could only be done using ` ParallelGroups ` in conjunction with
158153` SequentialGroups ` .
159154
160- Now that we know what ` CommandGroups ` do, let's learn how to create them. For
155+ Now that we know what command groups do, let's learn how to create them. For
161156this example, we will create a routine that
162157does the following:
163158
@@ -191,21 +186,9 @@ public Command autonomousRoutine() {
191186
192187:::
193188
194- I've made an empty SequentialGroup here, for demonstration purposes.
195-
196- > [ !CAUTION]
197- > Do not attempt to use empty ` SequentialGroups ` in your code. They will cause
198- > errors that break your OpMode. If you
199- > need a placeholder, use a [
200- ` NullCommand ` ] ( https://nextftc.dev/reference/core/com.rowanmcalpin.nextftc.core.command.utility/-null-command/ ) .
201- >
202- > The above snippet is incomplete and that's why it appears to create an empty
203- ` SequentialGroup ` . That won't work in
204- > practice.
205-
206- As mentioned above, we need to put something in our sequential group in order to
207- avoid errors. In our list, we said the
208- first thing we want to do is raise the lift to the high position. We can add the
189+ However, an empty ` SequentialGroup ` won't do much. Let's add some stuff to it.
190+ In our list, we said the first thing we want to do is raise the lift to the high
191+ position. We can add the
209192` Lift.toHigh ` command into our group
210193very easily:
211194
@@ -265,9 +248,8 @@ public Command autonomousRoutine() {
265248
266249:::
267250
268- Just like with ` SequentialGroups ` , you shouldn't create empty ` ParallelGroups ` .
269- Let's populate it with our
270- ` Lift.toMiddle ` and ` Claw.close ` commands:
251+ Let's populate the ` ParallelGroup ` with our ` Lift.toMiddle ` and ` Claw.close `
252+ commands:
271253
272254:::tabs key: code
273255
@@ -328,7 +310,7 @@ val autonomousRoutine: Command
328310 Lift .toMiddle,
329311 Claw .close
330312 ),
331- Delay (0.5 .sec )
313+ Delay (0.5 .seconds )
332314 )
333315```
334316
@@ -364,7 +346,7 @@ private val autonomousRoutine: Command
364346 Lift .toMiddle,
365347 Claw .close
366348 ),
367- Delay (0.5 .sec ),
349+ Delay (0.5 .seconds ),
368350 ParallelGroup (
369351 Claw .open,
370352 Lift .toLow
@@ -445,7 +427,7 @@ class AutonomousProgram : NextFTCOpMode() {
445427 init {
446428 addComponents(
447429 SubsystemComponent (Lift , Claw ),
448- BulkReadComponent ()
430+ BulkReadComponent
449431 )
450432 }
451433
@@ -456,7 +438,7 @@ class AutonomousProgram : NextFTCOpMode() {
456438 Lift .toMiddle,
457439 Claw .close
458440 ),
459- Delay (0.5 .sec ),
441+ Delay (0.5 .seconds ),
460442 ParallelGroup (
461443 Claw .open,
462444 Lift .toLow
@@ -474,10 +456,10 @@ class AutonomousProgram : NextFTCOpMode() {
474456``` java
475457@Autonomous (name = " NextFTC Autonomous Program Java" )
476458public class AutonomousProgram extends NextFTCOpMode {
477- {
459+ public AutonomousProgram () {
478460 addComponents(
479461 new SubsystemComponent (Lift . INSTANCE , Claw . INSTANCE ),
480- new BulkReadComponent ()
462+ BulkReadComponent . INSTANCE
481463 );
482464 }
483465
0 commit comments