ElapsedTime Setup
Programming with ElapsedTime
Start by creating a new OpMode called HelloRobot_ElapsedTime using the BlankLinearOpMode sample similar to what we used in Part 1.

Selecting the features discussed above will allow you to start with the following code. Remember that if "Setup Code for Configured Hardware" is selected the OpMode will try to generate a hardwareMap based on the active configuration. This example uses the same Hello Robot config file we originally created!
Setting up the Basics
To prepare to use ElapsedTime, a variable and an instance of ElapsedTime needs to be created. To do this the following line is needed:
In this case we are named our variable runtime.
The above line performs two actions:
A ElapsedTime variable called runtime is created. Once it is created and defined as an ElapsedTime variable, it can hold the relevant time information and data.
The other part of the line,
runtime = new ElapsedTime();, creates an instance of the ElapsedTime timer object and assigns it to our new runtime variable.
Add this line to the OpMode with the other private variables:
Next we can go ahead and add the basic movement for our motors. For this example, we will set both motors to a power of 1:
Lastly, we need to make sure our right motor's direction is reversed during initialization:
Last updated
Was this helpful?

