INTO THE DEEP My First Autonomous Program

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

INTO THE DEEP Program Tutorials

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 samples around. This robot has a square opening at the front into which a sample can fit.
  • A webcam is not required for this program.
  • The robot is assumed to have an active config file with motor names “left_drive” and “right_drive”. Adjust the motor names in the program if you’ve configured the motors with different names. Sample programs for two wheel robots will use left_drive and right_drive so may be easier to rename them in the config.
  • 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

Have the robot drive forward a short distance and stop. This is a program can be used from four starting positions. At the back of the field it will drive into the observation zone and park in order to score 3 points. At the front of the field the robot can push a sample into the net zone to score two points.

The robot will follow the paths shown by the green arrows depending on which location it starts from.

Competition Manual Section 11.3 Pre-Match rule G303 indicates robots must start touching the Field wall and not be in the net zone or observation zone. You will want the front of the robot aimed towards the zone but 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.

Samples only need to be “IN” the net zone, so it’s ok of the robot is touching a sample. We can push the sample in and stop.

DeepAuto1

1. Start by connecting your laptop to your robot and starting the Block programming tool. Assuming you’ve connected your driver station to the robot, you can look at the Program and Manage page on your driver station. That will show you the network password for the robot and the IP address. The default password for a control hub is “password” and the IP address to use to connect to the robot is http://192.168.43.1:8080.

2. Then click on the Create New Op Mode button to create a new Op Mode and set the Op Mode Name to DeepAuto1, or whatever you want. Also select the Sample RobotAutoDriveByTime.

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. Check that the mode of the Op Mode says Autonomous, it’s beside the OpMode Name. You can also click the Show Java checkbox and close the window that shows the Java code for these blocks. The Java code can be interesting to look at, but it just takes up screen space if you don’t know Java.

5. Click the Save OpMode button in the upper left of the screen. Then try running this program from the driver station, you’ll need some floor space for this, maybe eight feet long. The robot should drive forward, do a turn, and then back up a little bit. If the robot initially spins instead of going forward, check each the motor Direction and adjust them so that when positive power is sent to the motors the wheels spin forward. See instructions for that below.

Let’s have a look at the RobotAutoDriveByTime program. Click it to see the full program.

This program illustrates a common feature of autonomous programs which is that they are composed of a number of steps. We also commonly refer to the movement of the robot as a path. The path for this robot is to drive forward, turn, back up and then stop moving for a total of four steps. It’s important to know the path of your autonomous programs so you can coordinate with you alliance partner before a match. If this robot has other mechanisms we could add additional steps to this program to activate them.

Let’s look more closely at this program. The top of the program is where we initialize variables and get the robot ready to run. This happens when the user presses the INIT button on the driver station.

  • Set a runtime variable to an ElapsedTime block, we’ll use this to display on the driver station how long our program has been running.
  • Set a FORWARD_SPEED variable for the power level to apply to the motors to drive forward.
  • Set a TURN_SPEED variable for the motor power level to use when turning.

6. Let change the FORWARD_SPEED to 0.4 instead of 0.6. We’re not going far so we don’t need to go too fast.

  • Finally, we set a Direction for each motor. See the comments and adjust directions if needed. It’s a good idea to insert lots of Comments (the blue blocks), not to describe what is obvious (like setting a variable), but why. In this case, describing why we need one motor reversed.

Next there’s some Telemetry to provide feedback to the driver station that the initialization step is complete. Then there is a waitForStart block which waits for the START button to be pressed.

We finally get to the main part of the program. The if opModeIsActive just checks that the user hasn’t pressed the STOP/ABORT button during initialization. The rest of the program then runs in a linear fashion as a series of steps. The first step drives forward for 3 seconds.

  • The first part of step1 is to set the Power of both motors to the FORWARD_SPEED value
  • The the runtime elapsed timer is reset. This starts or restarts the runtime timer.
  • Then we start a repeat loop which check if the opModeIsActive block indicates the user has not pressed the stop button on the driver station, and that the elapsed runtime is less than 3 seconds. In most loops that take some time you should check if the driver has pressed the stop button. If your long running AUTO program got bumped off course you might want to stop it before it incurred penalties say by driving into the opposing alliance area.
  • The content of this loop is to use Telemetry to report which step we are on and the elapsed time.

7. Let’s change the elapsed time for Step 1 to one second.

  • It’s possible to move the robot around the field using a combination of motor power levels and time. More time or more power will cause the robot to move faster or longer. You can keep the time the same and add or subtract power, or keep the power the same and add or subtract time. If you need fine control of time you can select Milliseconds instead of Seconds for the ElapsedTime block.
  • One second at power level 0.4 is enough to move this robot into the net or observation zone assuming it starts adjacent to the zone.

6. For our first program, we just need two steps, a simple path of driving forward a short distance and stopping. Scroll down the Blocks program and start deleting all the blocks in Step 2 and Step 3. Stop when you get to the comment for Step 4.

7. Step 4 is very simple, it sets the power for both motors to zero.

  • Finally there is some Telemetry to let us know the program is done.
  • The sleep command just ensures that the Telemetry message will get displayed for one second before the program end.

8. 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.

Parking in the Observation Zone. 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 as we just need to stop anywhere in the zone.

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 don’t have a field for testing, the robot only has to move a foot or so for this program.

Here’s the completed program.

I also adjust the comment that hides under the ? symbol at the start of the program. 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!

The program can also push a sample into the net zone, here’s what that looks like:

DeepAuto1 Scoring a Sample

Next Steps

This particular program has one advantage in that it works from any starting position. The main problem is that it doesn’t score many points.

Let’s create a second autonomous program that will push a sample into the net zone and park in the observation zone.

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.

You can also check out last year’s tutorials on creating autonomous programs for CENTERSTAGE. This page creates a similar movement program by adding to an empty opMode.