FTC Help Menu

This website will generate all the code snippets you will need to get off the ground fast!

This help page has interactive snippets that you can change on the fly and copy into your file for easy use, as well as many explanations on how to use different features.

Opmodes

Opmodes are the way that you can make code appear on the robot. They are defined the same way as normal classes, but with a few extras. They follow a simple template that goes like this:

public class OpModeName extends OperationMode implements TeleOperation {
	@Override
	public void contruct() { 
		
	} 
	
	@Override
	public void run() {
	
	}
}	
Opmode Name:


There are two functions there: construct and run. construct is run once at the beginning before the opMode starts, and run is run periodically after it starts. It is important that you don't keep any long loops in the run function or you may cause an error to occur.

To make an autonomous routine, swap the TeleOperation at the top to AutonomousOperation.

OpModes has a special varieable, environment, that allows for you to run special functions, set special variables, and add additional features.

Hardware

Hardware is the way that you can interact with the robot's physical features. Hardware is the term for things like motors, gamepads, servos, and sensors.

Hardware devices can be interacted with using the HardwareGetter class. Note that some hardware must be initialized before it can be used.

Hardware uses a system which I call "Requests". Requests have a two-part system. First, a request must actually be created, then you can call that request. Requests can be used in any part of the script, and some advantages will be explained later.

Motors

Motors are automatically ready for you, you just need to know what port its attached to.

There are 2 main paramaters for a motor which can all be changed: They are power and the operation type. See more about operation types below. To change a motor's power, use the following command.
Devices.motor0.setPower(1.0); // Set the power of the motor

Motor Port:


Motor Power:


To change a motor's operation type, use the following command.
Devices.motor0.setOperation(OperationType); // Set the operation type of the motor

Motor Port:


Operation Type:


Operation Types

There are three big operation types: POWER, ENCODER_POWER, and ENCODER_DISTANCE.

POWER accepts a value between -1 and 1, and will set the motor to that value. This is the most useful.

ENCODER_POWER accepts a value between -1 and 1, and will set the motor to that value, but will also adjust it to keep the speed of the robot consistent. It does this by using a device called an "encoder".

ENCODER_DISTANCE accepts any value and will drive the motor to that many "counts", which are a small fraction of one revolution. To find out how what the input should be for this, use this sample formula:
counts_per_inch = (counts_per_rev * gear_ratio) / (wheel_diameter * PI)

Counts per inch: The amount of counts that the encoder to do to get the robot to move 1 inch. If you multiply this value by any distance (in inches), then you will get the number of encoder counts needed to move the robot that distance.

Counts per rev: The amount of counts that the encoder has per revolution of the motor internally. For most motors this is 1440, but you can look this information up online for the motor if you need to.

Gear Ratio: The ratio of the gears in between the motor and the wheel. You can see this information on the gearbox attatched to the motor, if there is no external gearbox, assume that this is 1.

Wheel Diameter: The diameter (in inches) of the wheel that the motor is attached to.

Gamepads

If you just scrolled past the long section about motors and thought "You know what.... this hurts my brain!", then great, because it took me two hours to write.

But do not fear, because gamepads are pretty simple.
They work on the same request system as motors, but require fewer inputs, and are initialized for you!

To interact with a gamepad, you need to know a few things:

First, you need to know which gamepad you want to use. You can choose between two, which are called "gamepad1" and "gamepad2".

Second, you need to know which type of gamepad you want to use, which are either Xbox style, which have A B X Y as the labels on the four buttons on the front of the controller, or PlayStation style, which have the weird shapes as labels on the four buttons on the front of the controller.

Third, you need to know which button you want to use. There are quite a lot, so here is a list of them.
GENERIC BUTTONS
     dpadUp
     dpadDown
     dpadLeft
     dpadRight
     leftStickSutton
     rightStickButton
     leftBumper
     rightBumper

GENERIC AXES
     leftTrigger
     rightTrigger
     leftStickX
     leftStickY
     rightStickX
     rightStickY

XBOX-ONLY BUTTONS
     a
     b
     x
     y
     back
     start
     guide

PLAYSTATION-ONLY BUTTONS
     circle
     cross
     square
     triangle
     share
     options
     touchpad
     touchpadFinger1
     touchpadFinger2
     ps

PLAYSTATION-ONLY AXES
     touchpadFinger1X
     touchpadFinger1Y
     touchpadFinger2X
     touchpadFinger2Y
     
Note that some of those buttons, are axes, rather than buttons. Axes will return a value between -1 and 1, with the exception of the touchpad of the playstation controller, which we never use. Buttons will return a boolean value. To use the gamepad, look at the code snippet below:
Devices.controller1.getDpadUp();

Gamepad Name:


Gamepad button:

Emulator

The emulator can be used almost identically to opmodes, just a little bit differently. First you need to use a different folder to put them in. The folders highlighted green in Android Studio contain data for the emulator. To create them is exactly the same.

public class OpModeName extends EmulatedOpMode implements TeleOperation {
	@Override
	public void contruct() {

	}

	@Override
	public void run() {

	}
}	
Opmode Name:


When you have it open, there should be a little green play button next to the class name. Click it and it will run the emulator.

There are no differences except for a few extra functions.

First are the setTimeUntilAbort and getTimeUntilAbort functions. They are used to set the time until the emulator will stop running.

Second is the setGamepadValues function, which allows you to change the values of the emulated gamepad. This can be used to test what different gamepad inputs will do.

Wireless Communication

Sometimes, you might want to connect to the robot wirelessly to connect to ADB, view the Dashboard, push code to the bot, etc.
This is possible in 2 ways:

REV Hardware Client

The REV Hardware Client is useful for management of hardware. If you don't have it already—and you run Windows—you should install it even if you don't plan to use its wireless functions so you can still manage hardware. It is necessary for at least one computer to have this installed because the Control Hub's operating system and firmware must be updated every season.

With that out of the way, using the REV Hardware Client to connect to the robot wirelessly is simple.

  1. Connect to the Control Hub's wifi network.
  2. Open the client. Wait a few seconds for the Control Hub to appear in the client. If it does not, reboot your computer. The client has connection issues sometimes.
  3. You are now connected! In Android Studio or IntelliJ IDEA Ultimate, you can use Logcat via the ADB connection to view robot logs, interact with the filesystem, and install code. You can also access the FTC Dashboard via 192.168.43.1:8080/dash and the robot management portal, blocks, etc. via 192.168.43.1:8080 or through the Program and Manage tab in the REV Hardware Client.

Connecting to the Internet and the Robot

You may have noticed that you can't access the internet using the REV Hardware Client to wirelessly communicate with the robot as you're on the robot's wifi network. There are two ways to solve this.

If you're on Windows, you can use two network adapters to connect to the internet and the robot at the same time by following this method:
  1. Connect a second network adapter to your computer. We have some in the robotics room in the hardware box near the whiteboard and the window outside. They're in a box labeled something similar to "Wifi Adapters".
  2. Open Settings.
  3. Go to your wifi settings and connect the second adapter to the robot's wifi network.
  4. View the adapter's properties to see its private IP address. Alternatively, you can open Command Prompt, execute ipconfig, and view the IP of the default gateway for the second adapter.
  5. Open PowerShell as an administrator.
  6. Paste the following command into PowerShell:
    route -p ADD 192.168.43.0 MASK 255.255.255.0 192.168.1.X METRIC 1
    Make sure to replace 192.168.1.X with the private IP address you just found.
  7. Reboot your computer.
  8. Now, as long as the network adapter's IP doesn't change, you will be able to access the internet while connected to the robot. Just make sure your main wifi adapter inside your computer is connected to a real wifi network that can access the internet and the second adapter is connected to the robot. If the adapter's IP changes, you can re-run the PowerShell command with the new IP address. You will still need to use the REV Hardware Client using this method.