Elapsed Time - Blocks

Introduction to Elapsed Time

One way to create an autonomous code is to use a timer to define which actions should occur when. Within the SDK actions can be set to a timer by using ElapsedTime.

Timers consist of two main categories: count up and count down. In most applications a timer is considered to be a device that counts down from a specified time interval. For instance, the timer on a phone or a microwave. However, some timers, like stopwatches, count upwards from zero. These types of timers measure the amount of time that has elapsed.

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 case, it is the amount of time elapsed from when the timer is created or reset within the code.

Sections

Goals of Section

Learning the logic needed to use elapsed time for autonomous control.

Basics of Programming with Elapsed Time

Since this section focuses on creating an autonomous program using ElapsedTime it is important to understand where the elapsed time related blocks are located. At the top of the Categorize Blocks section there is a drop down menu for Utilities. The utilities drop down is a list of various utilities in alphabetical order. Towards the bottom of the the list select Time drop down menu. From there you can select Elapsed Time.

Programming with Elapsed Time

Start by creating a new op mode call HelloWorld_ElapsedTime using the BasicOpMode sample.

When creating an op mode a decision needs to be made on whether or not to set it to autonomous mode. For applications under 30 seconds, typically required for competitive game play changing the op mode type to autonomous is recommended. For applications over 30 seconds, setting the code to the autonomous op mode type will limit your autonomous code to 30 seconds of run time. If you plan on exceeding the 30 seconds built into the SDK, keeping the code as a teleoperated op mode type is recommended.

For information on how op modes work please visit the Introduction to Programming section.

For more information on how to change the op mode type check out the Test Bed - Blocks section.

Create a variable named runtime.

For information on creating variables in blocks please revisit the Test Bed - Blocks section.

Use tape to mark the distance from where the robot starts to where you would like it to end up. Try running the code using the following conditions:

  • Press the init button and immediately press play

  • Press the init button, wait 30 seconds and then press play

What difference in behavior did you notice?

As mentioned in previous sections, it can be beneficial to have a telemetry output when testing code. In the following example telemetry is used to output the amount of time that has passed with the timer.

The above code will allow your motor to drive straight for 3 seconds. Additional movements can be added by duplicating the while loop. Right click the while loop block and select duplicate

Full Code Example

Last updated