CENTERSTAGE My First Autonomous Program

This is a tutorial on creating your first FIRST Tech Challenge (FTC) autonomous program 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.

Prerequisites/Assumptions

This tutorial assumes:

  • a robot with two driving wheels, possibly a basic robot from the FIRST robot building resources page. These are sometimes called pushbots.
  • some way to push pixels around. This robot has a square opening at the front into which a pixel can fit,
  • A webcam is not required for this program,
  • some familiarity with Blocks, possibly a Blocks tutorial.

You can probably follow along even if you’re new to Blocks, however this tutorial doesn’t explain how to program in Blocks.

Plan

This program pushes two preloaded pixels into the backstage area and parks. It is a simple action and easy to program.

The robot will follow the path shown by the green arrows. On the red side the robot moves from tile F4 to F6. On the blue side the robots moves from tile A4 to A6. 

Preload both the yellow and purple pixels in the robot and plan to push them into the backstage area. Parking in the backstage area is worth 5 points, and each pixel in the backstage area is worth 3 points for a total of 11 points.

Game Manual Part 2 Section 4.4.1 Pre-Match indicates robots must start Complete In the starting tile, and must touch the Playing Field Wall. You will probably want the front of the robot aimed backstage, angle the robot just slightly so that only the rear of the robot is touching the wall. You don’t want the robot rubbing against the wall while moving, and don’t want to hit the backdrop either, bumping the backdrop can cause pixels to fall off. Ideally, aim to park on tile F6. That will leave room for your partner to score on the backdrop and/or to park backstage.

The robot needs to back away from the the pixels so that the robot is not in control to actually score the pixels. My robot has a U shaped holder for pushing pixels and that qualifies as Possessing/Controlling a pixel. Therefore we need to backup a small distance to “release” the pixels. If you have a gripper for holding pixels you should release the pixels and then backup.

MyFirstAuto1

1. Start by connecting your laptop to your robot and starting the Block programming tool.

2. Then click on the Create New Op Mode button to create a new Op Mode and set the Op Mode Name to MyFirstAuto1, or whatever you want.

3. Verify that you created the new op mode. You should see your newly created op mode opened for editing in your web browser’s main screen.

4. Change the mode of the Op Mode by selecting the TeleOp drop down and changing it to Autonomous. You can also click the Show Java checkbox and close the window that shows the Java code for these blocks.

5. Select the Repeat while opModeIsActive and delete those blocks. The repeat loop is useful in TeleOp as you want to continuously respond to new commands from the gamepad(s), but in an autonomous program we want to execute a series of commands.

After the repeat loop is deleted:

6. Just like a TeleOp tank drive program, we need to initialize the left drive motor and reverse its direction. This is so when we apply positive power to both motors the wheels on the robot push the robot forward.

7. We want to drive forward by applying power to both wheels, so select a dual motor power block and insert it after the “Put run blocks here” comment. Set both motor power levels to 0.5. This command turns on both motors at the same time. You can set values from 0 to 1, which corresponds to 0 to 100% power. Negative values will turn the motor in reverse. Here we will try 0.5, we don’t want too much power which might cause the wheels to slip and we don’t want the robot to move too slowly either.

8. Now place a Sleep block after the set motor power block. Set the time to 1000 milliseconds, or one second.

9. Next duplicate the motor power block (or create a new one from the left section), and set the motor power levels to zero. Place this block after the Sleep block. All together these block will turn the motors on at half power for one second and then stop.

10. Save your op mode. You should see the message “Save completed successfully.” displayed for a few seconds.

11. Run it and see what happens. The robot should drive forwards for one second and stop.

Not too exciting, but at least the robot is moving

By adjusting the amount of time (or the power level) you can control how far the robot moves. Note: this type of movement is not very accurate and the distance moved will vary depending on your battery level. However, we don’t need to be very precise since the backstage area is relatively large (at least compared to trying to place pixels on the spike marks).

12. Try adjusting the amount of time so that the robot moves up to the back perimeter wall and stops when it touch the back wall. That’s another reason we use 0.5 power level, we don’t want to hit the backwall hard. Do some testing with a fully charged battery and hopefully when the battery is less full the robot will still reach the backstage area. For my robot I needed 3000ms of time.

Your robot may vary depending on what motors you are using and the size of the wheels you are using. You might have higher speed motors than I’m using, If you think you are hitting the backwall too hard, you can reduce the power, maybe from 0.5 to 0.4 or even 0.25.

If you don’t have a field for testing, the robot has to move two tiles to get to the back wall. Each tile is 24 inches. Assuming your robot is set up near the edge of tile F4 then you need to move 48 inches towards the back wall.

13. Finally, let’s back up just a bit to drop off our pixels (but still keep the robot in the backstage area).
Turn both motors on with a power level of -0.3, this will reverse the robot and leave the pixels behind.

14. Sleep for 500ms to back up just a little (maybe six inches) and then set both motors to power level 0 to stop the robot.

Hopefully you will have delivered two pixels into the backstage area and also parked your robot in the backstage area earning your alliance 11 points.

Here’s the completed Blocks program:

Note how I added the “Robot has moved…” comment. It’s good programming to add comments to your programs that explain what’s going on, especially as your autonomous programs get longer as the robot does more actions.

Congratulations on creating your first autonomous program!

Here’s the program in action:

MyFirstAuto1

Next Steps

This particular program has one advantage in that it works for either the Red alliance or the Blue alliance, but it must start from the rear starting positions. 

Your robot should be able to score some points from any of the starting positions. Let’s create a simple autonomous program for the front starting position.

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.