RobotAutoDriveByTime_Blocks Sample Program

There’s no Blocks sample program in the SDK for moving the robot based on time. There is a Java sample program for time-based movement so let’s make a Blocks copy of that program.

This is a tutorial on creating FIRST Tech Challenge (FTC) autonomous programs for the CENTERSTAGE game.

Visit the FTC docs page on Creating Op Modes in Blocks if you need help getting started and to create your first driver controlled program.

This OpMode illustrates the concept of driving a path based on time.

The code assumes that you do NOT have encoders on the motors, otherwise you would use: RobotAutoDriveByEncoder.

The desired path in this example is:

  • Drive forward for 3 seconds
  • Spin right for 1.3 seconds
  • Drive Backward for 1 Second

The code is written in a simple form with no optimizations. However, there are several ways that this type of sequence could be streamlined.


This tutorial assumes you’ve got some familiarity with Blocks and that you have a robot configuration in your driver station. Ideally you’ve completed a Blocks tutorial. This tutorial doesn’t explain how to program in blocks.

This tutorial assumes you have a robot with two driving wheels, normally referred to as a tank drive or pushbot drive.

A webcam is not required for this program.


The RobotAutoDriveByTime_Blocks program is a not a long program. We’re not going to create it step by step. Instead, please copy the .blk file from the Pushbot GitHub repository and then I’ll explain how the program works.

Right click and select Download on GitHub file RobotAutoDriveByTime_Blocks.blk.

You can then connect to your robot and ‘upload’ the file to your robot, give the program the name RobotAutoDriveByTime_Blocks. Open this program in Blocks.

The first step in this program is to initialize variables and set one of the motors to reverse direction. We also create a runtime variable and initialize it as an ElapsedTime object. Applying positive power to the motors will drive forward, and negative power will drive backwards.

To make the robot move, we turn both motors on and then reset our runtime variable which starts a timer. The robot will start moving when the motor Power is set non-zero. We then have a repeat while loop where we test if the OpMode is still active and the ElapsedTime of the runtime variable is less than 3 second. Inside the loop, we display the current step and elapsed time.

In order to spin the robot we can apply positive power to one wheel and negative power to the other. You could turn instead by applying positive power to one wheel and zero power to the other wheel.

In step 3 we backup by applying negative power to both motors.

Finally, in order to stop the motors spinning, we apply zero power to both motors.

Here’s a YouTube video showing the robot running this program.

You should save the program and try running it. The robot should drive forward for 3 second, spin to the right, and then back up.

Next Steps

Try using these functions to move around the field. Instead of spinning, try setting one motor to zero and compare spinning to turning.

Then you could use this program to park backstage in the CENTERSTAGE game.

Check out the other Blocks sample programs:

Blocks Sample Programs

Getting Help

It is often possible to use Google (or other search engine) to get help or solve problems. There are lots of resources online. If you’re still stuck you can ask for help here.