> For the complete documentation index, see [llms.txt](https://docs.revrobotics.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.revrobotics.com/ftc-kickoff-concepts/home/programming-teleop-and-auto/programming-auto.md).

# Programming - Auto

The autonomous program for the 2026-27 Starter Bot has the robot move forward from the starting location then launch the preloaded Pollen into the Hive. An optional delay is available so that the robot can either start on the high end of the Hive or wait until after your alliance partner launches their preloads and shifts the goal on the other side!

## Auto Initialization&#x20;

<figure><img src="https://268621232-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MHCAE012xNfg1h3SM9v%2Fuploads%2FAOMomHb0bh9VpVXWA8A7%2Fimage.png?alt=media&amp;token=54ab1aac-47bb-4d80-83fb-e3239c4f1e37" alt=""><figcaption><p>Initialization for the Auto OpMode</p></figcaption></figure>

During initialization, the robot will complete a few tasks in preparation for "Play" being pressed. Similarly to the TeleOp code, one of the drivetrain motors must be reversed and the flywheel motor told to use the encoder.&#x20;

The `targetVelocity` variable is set to the same as in TeleOp, but another variable is created here. The autoTimer sets up our ElapsedTime timer that we will be using during the auto period!

### What is ElapsedTime?

What do you think of when you think of a timer? A stopwatch? Your phone? Maybe the timer on a microwave or oven? Timers commonly consist of two main categories: **count up** and **count down**. You can think about the differences of these two by a comparison like keeping track of how fast a runner did a 100m dash vs. needing to know how much longer our food should cook.

**ElapsedTime** is a count up timer. Registering the amount of time elapsed from the start of a set event, like the starting of a stopwatch. In this situation, it is the amount of time passed from when the timer is created or reset within the code.

{% hint style="success" %}
For more information on ElapsedTime, check out the [Hello Robot - Blocks tutorial](https://docs.revrobotics.com/duo-control/hello-robot-blocks/part-3/elapsed-time)!
{% endhint %}

## Optional Delay

At the very start of the auto OpMode, after "Play" is pressed, the pollenServo will move to it's 1 position if not already there.

<figure><img src="https://268621232-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MHCAE012xNfg1h3SM9v%2Fuploads%2FEk6kifCS5MxQ3j3C2q6Q%2Fimage.png?alt=media&amp;token=5f51c4b3-8c53-4dc7-a84c-74df4444cb8d" alt=""><figcaption><p>Reset the servo to be up</p></figcaption></figure>

Then there is a disabled block in the sample code.

<figure><img src="https://268621232-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MHCAE012xNfg1h3SM9v%2Fuploads%2FHvmNceP5Q18rZoEBjiVQ%2Fimage.png?alt=media&amp;token=798f409b-9ac2-4dfd-83df-6cb433bd8473" alt=""><figcaption><p>Sleep Block to add a delay to the start of the program</p></figcaption></figure>

This sleep call is available to force the OpMode to wait before beginning the code proper. During this time we don't want the robot to do anything so we'll tell it to sleep for 10 seconds then begin.&#x20;

If your team's strategy is to wait on the low side of the Hive, with the intention of launching your preloads after your alliance partner has gone and shifted the Hive up, then enable this block! Be sure to check how long the sleep period should be to make sure there is enough time to execute the full auto.&#x20;

{% hint style="info" %}
Blocks can be enabled/disabled by right clicking, then selecting the option as seen here:

![](https://268621232-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MHCAE012xNfg1h3SM9v%2Fuploads%2F1VVvGS5sQ8hGKI7Ps0PM%2Fimage.png?alt=media\&token=9ee6020c-51fe-4b96-ad16-8b3ee81f669e)
{% endhint %}

## Driving Forward

The timer used for ElapsedTime begins as soon as the OpMode is initialized. Since it's hard to plan for how long it's been running, we'll first simply reset the timer before using it.&#x20;

<figure><img src="https://268621232-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MHCAE012xNfg1h3SM9v%2Fuploads%2FWt0bEkiF9xn4UyeYl1HC%2Fimage.png?alt=media&amp;token=d7a37791-064c-4640-a694-14923bd032f6" alt=""><figcaption><p>Resetting the autoTimer</p></figcaption></figure>

Next, we have a loop for the robot to move for 0.7 seconds to reposition from the wall.

<figure><img src="https://268621232-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MHCAE012xNfg1h3SM9v%2Fuploads%2FBizFDyB0xScGcmQFZ1p7%2Fimage.png?alt=media&amp;token=5a59d62b-aa9f-4de9-a0b9-3901fae49c89" alt=""><figcaption><p>Code for backing up for 0.7 seconds</p></figcaption></figure>

How long the robot needs to move may vary per robot build. Be sure to test this and make adjustments for your final design!

### Loop Controls

Looking more closely at the loop, there are two checks. The loop while continue so long as BOTH are true. A check for if `opModeIsActive`, meaning if the "Play" has been pressed, should always be used with loops to ensure the OpMode executes properly and safely disables when needed!

<figure><img src="https://268621232-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MHCAE012xNfg1h3SM9v%2Fuploads%2FzCEC5tXMEgi11BAKSClh%2Fimage.png?alt=media&amp;token=55d2df1c-29d4-4e04-9fe6-8c874b8894ff" alt=""><figcaption><p>Checks for the loop</p></figcaption></figure>

The other check looks at if the autoTimer is still less than or equal to 0.7 seconds. Remember we just restarted the timer so it'll be at 0 when entering the loop!

### Stopping

During the loop, the robot will send -0.25 power to the drivetrain motors to move slowly away. Since the recommended orientation for starting is the robot sitting with the front side (intake) to the wall, the robot must back up or use negative power.&#x20;

<figure><img src="https://268621232-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MHCAE012xNfg1h3SM9v%2Fuploads%2FREX8jM8aGHkLy6YNrZqx%2Fimage.png?alt=media&amp;token=f51ffbfa-5baa-4b0d-a71f-3f51f3ab8b43" alt=""><figcaption><p>Motor power for reversing then coming to a stop</p></figcaption></figure>

After the 0.7 seconds is over, the motors are told to go to 0 power to prevent any extra movement. At this point the robot is in place and ready to launch!

## Flywheel Auto Sequence

Before our next loop begins, we'll reset our timer again so it starts from 0 and is easier to make adjustments to the program.&#x20;

<figure><img src="https://268621232-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MHCAE012xNfg1h3SM9v%2Fuploads%2Fn3TOlxfctOFH4319s8hk%2Fimage.png?alt=media&amp;token=13628a15-eabe-40a7-9dae-324db1548fe8" alt=""><figcaption><p>Resetting the autoTimer</p></figcaption></figure>

Similar to the driving portion of the code, the loop will continue while the OpMode is active AND the timer is less than or equal to 15 seconds. Make sure to test this amount of time and adjusted it based on your robot and strategy!

<figure><img src="https://268621232-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MHCAE012xNfg1h3SM9v%2Fuploads%2FIYAlQRCIFyjbfOi4iuVO%2Fimage.png?alt=media&amp;token=9d6fbd6b-ad4e-4151-a230-180d35d6748f" alt=""><figcaption><p>Checks for the second loop</p></figcaption></figure>

### Launching Pollen

Once the loop begins, the flywheel will turn on to get up to velocity.

<figure><img src="https://268621232-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MHCAE012xNfg1h3SM9v%2Fuploads%2F7ASNLJvOLcVAywTp8NYB%2Fimage.png?alt=media&amp;token=8a4da92d-79ef-4035-bc55-f25e73ebad96" alt=""><figcaption><p>Activating the flywheel to spin to velocity</p></figcaption></figure>

Before feeding in game pieces, the robot will check if the flywheel's velocity is within a specified range of the `targetVelocity`, similar to the TeleOp code.&#x20;

The range is larger than when running the TeleOp program, but it's recommended to do some testing with your final robot to adjust this range appropriately!

<figure><img src="https://268621232-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MHCAE012xNfg1h3SM9v%2Fuploads%2FEripJAXOZgFETizwPZyD%2Fimage.png?alt=media&amp;token=eafb10a6-9320-4364-9398-3f21d232b745" alt=""><figcaption><p>Check for if the flywheel velocity is within a specified range</p></figcaption></figure>

If the velocity is within range, then the servo feeder AND intake will begin moving game pieces into the flywheel shoot to be launched.

<figure><img src="https://268621232-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MHCAE012xNfg1h3SM9v%2Fuploads%2FF1vNAGAbfuBbsBGtm2v1%2Fimage.png?alt=media&amp;token=7a37ee19-d014-4c55-8390-b8fa7d9afc5c" alt=""><figcaption><p>Activating the servo and intake motor if true</p></figcaption></figure>

If the velocity is out of range, the servo feeder and intake will turn off. This may cause what appears to be "stuttering" or "rubberbanding" while the flywheel stabilizes to the correct velocity.&#x20;

<figure><img src="https://268621232-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MHCAE012xNfg1h3SM9v%2Fuploads%2FwOTmLn9oeH95gFnvSLKj%2Fimage.png?alt=media&amp;token=691188e3-7428-4531-a68b-d972187ddc00" alt=""><figcaption><p>Turning off the servo and motor if false</p></figcaption></figure>

Once the 15 seconds for the flywheel portion of the code ends the program will stop!
