Javadoc - ftc8380/coding-guide GitHub Wiki

There's obviously a lot more to FTC than making a motor spin when you press the Dpad! Let's look at how to read the documentation, so you can figure out the syntax for anything and everything FIRST has to offer.

A first look

You can find the documentation by searching up "FTC Javadoc" and clicking the first or second link. When you get there, you'll find something that looks like FTC Javadoc homepage

It's slightly intimidating. But if you're going to be a successful programmer, you'll need to read documentation like a pro, so let me show you a few pointers.

Example: trigger pull

Let's solve an example problem:

if( /* right trigger pulled */) {

}

Ugh! I just don't know what to put! How do you even read the triggers? Let's see if Javadoc can help us.

Finding a class

See that sidebar labeled "All Classes"? It is pretty much just what it says it is: a list of every class. If you know the exact class you need, great! We don't, so let's scroll until we spot something that can help us:

Scrolling to Gamepad

The Gamepad class seems to be promising. Let's click on it and have a look:

Class info

Description of Gamepad class

Okay. That looks like some info written by the people at FIRST, and it seems rather helpful. It tells us that triggers are floats, and are 0 when they aren't being pulled. Let's keep scrolling...

Field Summary

We'll eventually land on a section called Field Summary in clear italic text, and it's starting to list some buttons and such. Ooh, look!

Right trigger

This tells us that we the Gamepad class has a field called right_trigger which is a float.

Using information

We access fields with a period like objectName.fieldName we can just...

if(gamepad1.right_trigger) { // WRONG

Not quite. Remember, it says that the trigger value is a float, not a boolean. You can't just ask whether a number is true or not, that doesn't make any sense! So let's change our code:

if(gamepad1.right_trigger > 0.5) {

There we go. By comparing the trigger value to 0.5, we have a complete boolean statement that can be either true or false - we're checking if the trigger is being pulled at 0.5 or harder. Problem solved!

Example: Servo position

Let's try using Javadoc to help us with this:

@Override
public void init() {
    myServo = hardwareMap.get(Servo.class, "my_servo");
    // Set servo position to max but idk how to do that
}

Finding a class

Now that we know that our servo is an instance of the Servo class, we can find it right in the sidebar, and click its name to open the Servo page.

Class info

Servo class info

Field Summary

We notice some helpful fields that show that minimum and maximum position of our servo, but that's not useful to setting its position. Let's look further...

Method Summary

Below Field Summary is Method Summary, which shows the methods available for the class. Look through the list of methods and lo and behold...

Servo.getPosition()

Servo.setPosition() takes in a double between 0 and 1 and returns... nothing. That's what a void function is.

Using information

We call an object's method with objectName.methodName(/* parameters */); so let's go ahead and do that.

myServo.setPosition(1.0);

Notice that we're taking everything into account:

  • respect void function by not storing its output in a variable
  • giving it a double, as it is supposed to accept
  • giving it a double between 0 and 1, as directed by FIRST