Android Studio Tutorial
Android Studio Tutorial
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual |3
Revision History
Revision Date Description
1.0 09/27/2017 Initial Release
2.0 08/08/2019 Control Hub Update
Contents
Contents ............................................................................................................................................................ 3
1. Introduction................................................................................................................................................. 6
1.1. What is FIRST® Tech Challenge? ........................................................................................................ 6
2. Gracious Professionalism® ......................................................................................................................... 6
3. Introduction to Android Studio .................................................................................................................... 7
4. The FTC Control System ............................................................................................................................ 7
4.1. About the FIRST Tech Challenge ........................................................................................................ 7
4.2. Autonomous vs. Driver-Controlled ....................................................................................................... 8
4.3. Point-to-Point Control System ............................................................................................................. 8
4.4. REV Robotics Expansion Hub ............................................................................................................. 9
4.5. REV Robotics Control Hub ................................................................................................................ 10
4.6. What's an Op Mode? ......................................................................................................................... 10
5. Required Materials ................................................................................................................................... 11
6. Using Your Android Device....................................................................................................................... 17
6.1. Unlocking Your Screen ...................................................................................................................... 18
6.2. Navigating in Android ........................................................................................................................ 19
6.3. Displaying Available Apps on your Android Phone ............................................................................ 21
6.3.1. Android Marshmallow Users ....................................................................................................... 21
6.3.2. Android Nougat Users ................................................................................................................ 21
7. Configuring Your Android Devices ............................................................................................................ 22
7.1. What Needs to Be Configured for My Control System? ..................................................................... 22
7.1.1. Control Hub Users ...................................................................................................................... 22
7.1.2. Users with Two Android Smartphones ........................................................................................ 23
7.2. Renaming Your Smartphones ........................................................................................................... 23
7.3. Installing the FTC Apps ..................................................................................................................... 31
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
4 | FIRST® Tech Challenge Android Studio Manual
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual |5
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
6 | FIRST® Tech Challenge Android Studio Manual
1. Introduction
2. Gracious Professionalism®
Gracious Professionalism® is a way of doing things that encourages high-quality work, emphasizes the
value of others, and respects individuals and the community.
Watch Dr. Woodie Flowers explain Gracious Professionalism in this short video.
Learn more about the roles of volunteers on our Volunteer Resources page, “Volunteer Role Description”.
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual |7
This tutorial will take you step-by-step through the process of configuring, programming, and operating your
Control System. This tutorial uses Android Studio to help you get started programming your robot.
Android Studio is an advanced integrated development environment for creating Android apps. This tool is the
same tool that professional Android app developers use. Android Studio is only recommended for advanced
users who have extensive Java programming experience.
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
8 | FIRST® Tech Challenge Android Studio Manual
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual |9
One Android device is mounted onto the robot and is called the Robot Controller. The Robot Controller acts as
the “brains” of the robot. It does all of the thinking for the robot and tells the robot what to do. It consists of an
Android device running an FTC Robot Controller app. There are two hardware options currently being used:
REV Robotics Expansion Hub or the REV Robotics Control Hub.
A second Android device sits with the team drivers and has one or two gamepads connected. This second
device is known as the Driver Station. The Driver Station is sort of like a remote control that you might use to
control your television. The Driver Station allows a team to communicate remotely (using a secure, wireless
connection) to the Robot Controller and to issue commands to the Robot Controller. The Driver Station
consists of an Android device running an FTC Driver Station app.
The Expansion Hub is also connected to a 12V battery which is used to power the Expansion Hub, the motors,
the servos and sensors. If an Android smartphone is used as the Robot Controller, then the smartphone will
have its own independent battery. If a REV Robotics Control Hub is used as the Robot Controller, then the
Control Hub will use the main 12V battery to power its internal Android device.
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
10 | FIRST® Tech Challenge Android Studio Manual
The Control Hub, which has its built-in Android device connected directly to the Expansion Hub using an
internal serial bus, eliminates the need for an external USB connection between the Android Robot Controller
and the I/O module.
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 11
score a game element (such as a ball) into a goal autonomously during a match. Teams write “op modes”
(which stand for “operational modes”) to specify the behavior for their robot.
Op modes are computer programs that are used to customize the behavior of a competition robot. The Robot
Controller can execute a selected op mode to perform certain tasks during a match.
Teams who are participating in the FIRST Tech Challenge have a variety of programming tools that they can
use to create their own op modes. Teams can use a visual ("drag and drop") programming tool called the FTC
Blocks Programming Tool to create their op modes. Teams can also use a text-based Java tool known as the
FTC OnBot Java Programming Tool or Google's Android Studio integrated development environment (also
known as an "IDE") to create their op modes.
5. Required Materials
This wiki contains tutorials that demonstrate how to configure, program, and operate the FTC control system.
In order to complete the tutorials, you will need to have the following materials available:
Or...
Or...
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
12 | FIRST® Tech Challenge Android Studio Manual
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 13
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
14 | FIRST® Tech Challenge Android Studio Manual
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 15
Or...
FIRST-approved* 12V Battery (such as
Tetrix W39057 or REV Robotics REV-
31-1302).
*For a list of FIRST-approved 12V batteries, refer to the current FTC Game Manual Part 1, rule
<RE03>.
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
16 | FIRST® Tech Challenge Android Studio Manual
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 17
Before you get started with your control system, it is helpful if you familiarize yourself with the basic operation
of your Android device.
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
18 | FIRST® Tech Challenge Android Studio Manual
Depending on your security settings, you might be challenged for a pass code or PIN number. Use the touch
screen to enter in the pass code or PIN value and tap on the check mark to log into the device.
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 19
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
20 | FIRST® Tech Challenge Android Studio Manual
At the bottom of the screen there should be some buttons that you can use to navigate the screens on your
Android device.
The leftmost button (see image above) is the "Back" button. You can use this button to return to the previous
screen on your Android device.
The center button is the "Home" button. Pressing this button should take you back to the home or opening
screen of your Android device.
The rightmost button is the "Recent Apps" button. If you click on this button it will display the apps that were
recently run and are dormant in the background. You can close a recent app by tapping the "X" button on the
app's listing.
Note that some Android smartphones have an auto-hide feature which automatically hides the bottom
navigation buttons. If your smartphone has this feature, you might need to swipe up from the bottom of the
screen to display the navigation buttons.
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 21
There should be another row of buttons visible above the "Back", "Home" and "Recent Apps" buttons. In the
center of this row of buttons is a button that has an array of dots or squares.
Tapping on this button will launch the Android App Drawer. The App Drawer displays a list of all of the apps
that are available on your Android device. You can scroll through the App Drawer screens to find and launch
an app.
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
22 | FIRST® Tech Challenge Android Studio Manual
Teams who are using a Control Hub with the integrated Robot Controller will only need to configure a single
smartphone for use as a Driver Station. The process is as follows:
• Rename the smartphone to "<TEAM NUMBER>-DS" (where <TEAM NUMBER> is replaced by your
team number).
• Install the Driver Station app onto the Driver Station phone.
• Put your phone into Airplane Mode (with the WiFi radio still on).
• Pair (i.e., wirelessly connect) the Driver Station to the Control Hub.
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 23
IMPORTANT NOTE: Eventually the Control Hub will need be renamed so that its name complies with Game
Manual rule< RS01>, but for now we will use the Control Hub with its default name. You can learn how to
manage a Control Hub (and modify its name, password, etc.) in this tutorial.
Teams who have two smartphones and are not using a Control Hub will need to configure one smartphone for
use as a Robot Controller and a second smartphone for use as a Driver Station. The process is as follows,
• Rename one smartphone to "<TEAM NUMBER>-RC" (replace <TEAM NUMBER> with your team
number).
• Install the Robot Controller app onto the Robot Controller phone.
• Rename a second smartphone to "<TEAM NUMBER>-DS" (where <TEAM NUMBER> is replaced by
your team number).
• Install the Driver Station app onto the Driver Station phone.
• Put your phones into Airplane Mode (with the WiFi radios still on).
• Pair (i.e., wirelessly connect) the Driver Station to the Robot Controller.
The official rules of the FIRST Tech Challenge (see <RS01>) require that you change the Wi-Fi name of your
smartphones to include your team number and “-RC” if the phone is a Robot Controller or “-DS” if it is a Driver
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
24 | FIRST® Tech Challenge Android Studio Manual
Station. A team can insert an additional dash and a letter (“A”, “B”, “C”, etc.) if the team has more than one set
of Android phones.
If, for example, a team has a team number of 9999 and the team has multiple sets of phones, the team might
decide to name one phone “9999-C-RC” for the Robot Controller and the other phone “9999-C-DS” for the
Driver Station. The “-C” indicates that these devices belong to the third set of phones for this team.
NOTE: it will take an estimated 5 minutes per phone to complete this task.
Step Image
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 25
Step Image
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
26 | FIRST® Tech Challenge Android Studio Manual
Step Image
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 27
Step Image
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
28 | FIRST® Tech Challenge Android Studio Manual
Step Image
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 29
Step Image
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
30 | FIRST® Tech Challenge Android Studio Manual
Step Image
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 31
Step Image
The FTC apps are available to download for free from the Google Play store. You will need to have your
Android phones connected to a Wi-Fi network that has Internet access before you can access the Google Play
store. You will also need a Google account to be able to download the apps from the Google Play store.
It is also possible to "side-load" the FTC Android Apps onto the Robot Controller and Driver Station phones.
The GitHub repository contains the release versions of the Android apps:
https://github.com/ftctechnh/ftc_app/tree/master/doc/apk
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
32 | FIRST® Tech Challenge Android Studio Manual
However, this section of the wiki does not include instructions on how to side-load the apps. It only explains
how to use Google Play to install the FTC apps.
NOTE: it will take an estimated 7.5 minutes per phone to complete this task.
Step Image
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 33
Step Image
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
34 | FIRST® Tech Challenge Android Studio Manual
Step Image
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 35
Step Image
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
36 | FIRST® Tech Challenge Android Studio Manual
Step Image
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 37
Step Image
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
38 | FIRST® Tech Challenge Android Studio Manual
Step Image
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 39
Step Image
For the FIRST Tech Challenge competitions, it is important that you place your Robot Controller and Driver
Station phones into Airplane mode but keep their Wi-Fi radios turned on. This is important because you do not
want any of the cellular telephone functions to be enabled during a match. The cellular telephone functions
could disrupt the function of the robot during a match.
NOTE: it will take an estimated 2.5 minutes per phone to complete this task. Also note that the screens
displayed on your Android devices might differ slightly from the images contained in this wiki.
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
40 | FIRST® Tech Challenge Android Studio Manual
Step Image
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 41
Step Image
The REV Robotics Control Hub should come with the Robot Controller app pre-installed. Once you have
successfully installed the FTC Driver Station on an Android phone, you will want to establish a secure wireless
connection between the Control Hub and the Driver Station. This connection will allow your Driver Station
phone to select op modes on your Robot Controller and send gamepad input to these programs. Likewise, it
will allow your op modes running on your Robot Controller to send telemetry data to your Driver Station phone
where it can be displayed for your drivers. The process to connect the two devices is known as “pairing.”
NOTE: the Control Hub does not have its own internal battery. Before you can connect a Driver Station to the
Control Hub, you must connect the Control Hub to a 12V battery.
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
42 | FIRST® Tech Challenge Android Studio Manual
Also note that it will take an estimated 10 minutes to complete this task.
Step Image
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 43
Step Image
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
44 | FIRST® Tech Challenge Android Studio Manual
Step Image
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 45
Step Image
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
46 | FIRST® Tech Challenge Android Studio Manual
Step Image
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 47
Step Image
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
48 | FIRST® Tech Challenge Android Studio Manual
Step Image
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 49
Step Image
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
50 | FIRST® Tech Challenge Android Studio Manual
Step Image
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 51
Step Image
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
52 | FIRST® Tech Challenge Android Studio Manual
Step Image
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 53
Step Image
Important Note: If your Driver Station was previously paired to a Control Hub, and you currently would like to
connect to an Android smartphone Robot Controller, then before attempting to pair to the Robot Controller, you
should forget the Wi-Fi network for the previous Control Hub (using the Android Wifi Settings screen on the
Driver Station) and then power cycle the Driver Station phone. If the previous Control Hub is powered on and if
you haven't forgotten this network, then the Driver Station might try and connect to the Control Hub and might
be unable to connect to the Robot Controller smartphone.
Once you have successfully installed the FTC apps onto your Android phones, you will want to establish a
secure wireless connection between the two devices. This connection will allow your Driver Station phone to
select op modes on your Robot Controller phone and send gamepad input to these programs. Likewise, it will
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
54 | FIRST® Tech Challenge Android Studio Manual
allow your op modes running on your Robot Controller phone to send telemetry data to your Driver Station
phone where it can be displayed for your drivers. The process to connect the two phones is known as “pairing.”
This section explains how to connect a motor, a servo, and some sensors to your REV Robotics Control Hub
or REV Robotics Expansion Hub. While the Control Hub differs from the Expansion Hub because of its built in
Android device, the layout of the external motor, servo, and sensor ports are identical for the Control Hub and
Expansion Hub.
The images in this section use an Expansion Hub to demonstrate how to connect the devices. The process,
however, is identical for a Control Hub.
When the instructions in this section use the word "Hub", they are referring to a Control Hub or Expansion Hub.
1. If your 12V battery has a Tamiya style connector, connect the Tamiya to XT30 adapter cable to the
matching end of the switch cable.
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 55
Important Note: Do not connect the 12V battery to the Tamiya adapter yet. We will connect the battery
during a later step.
2. Connect the other end of the switch cable to a matching XT30 port on the Hub.
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
56 | FIRST® Tech Challenge Android Studio Manual
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 57
5. Turn on the switch and verify that the Hub is drawing power from the battery. Note that the Hub’s LED
should be illuminated (notice the blue LED in upper right-hand corner of the Hub in the image below).
6. Turn off the switch and verify that the Hub is off. Note that the Hub’s LED should not be illuminated.
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
58 | FIRST® Tech Challenge Android Studio Manual
For the examples in this wiki, FIRST recommends that the user build a simple rig to secure the motor in place
and prevent it from moving about during the test runs. The image above shows a Tetrix motor installed in a rig
built with a Tetrix motor mount and some Tetrix C-channels. A gear was mounted on the motor shaft to make it
easier for the user to see the rotation of the shaft.
Note that it will take an estimated 2.5 minutes to complete this task.
1. Connect the Anderson Powerpole end of the motor’s power cable to the Powerpole end of the Anderson
to JST VH adapter cable.
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 59
2. Connect the other end of the Anderson to JST VH adapter cable into the motor port labeled “0” on the
Hub.
Note that it will take an estimated 2.5 minutes to complete this task.
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
60 | FIRST® Tech Challenge Android Studio Manual
1. Connect the servo cable to the servo port labeled “0” on the Hub. Note that the ground pin is on the left
side of the servo port.
2. Verify that the black ground wire of the servo cable matches the ground pin of the servo port (which is
aligned on the left side of the port).
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 61
Note: that it will take an estimated 2.5 minutes to complete this task.
1. Connect the one end of the 4-pin JST PH cable to the REV Robotics Color-Distance sensor.
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
62 | FIRST® Tech Challenge Android Studio Manual
2. Plug the other end of the 4-pin JST PH cable to the I2C port labeled “0” on the Hub.
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 63
Note that in the case of the REV Robotics Touch Sensor, the device has a connector port for a 4-pin sensor
cable. However, the device only needs to connect to one of the two available digital I/O pins. For the REV
Robotics Touch Sensor, the second digital I/O pin in the port is the one that gets connected when a standard
REV Robotics 4-pin JST PH cable is used. For the “0-1” port, it is the pin labeled “1” that gets connected
through the 4-pin cable. Similarly, for the “2-3” port, it is the pin labeled “3” that gets connected through the 4-
pin cable.
Note that it will take an estimated 2.5 minutes to complete this task.
1. Connect the one end of the 4-pin JST PH cable to the REV Robotics Touch sensor.
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
64 | FIRST® Tech Challenge Android Studio Manual
2. Plug the other end of the 4-pin JST PH cable to digital I/O port labeled “0-1” on the Hub.
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 65
Before you can communicate with the motor, servo and sensors that are connected to the Control Hub or
Expansion Hub, you first must create a configuration file on your Robot Controller, so that the Robot Controller
will know what hardware is available on the Control Hub's or Expansion Hub's external ports.
If you are using an Android smartphone as a Robot Controller, you must physically connect the Robot
Controller smartphone to the Expansion Hub using a USB cable and an On-The-Go (OTG) adapter. Also, you
should verify that the Driver Station is currently paired to the Robot Controller.
2. Plug the Type B Mini end of the USB cable into the USB mini port on the Expansion Hub.
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
66 | FIRST® Tech Challenge Android Studio Manual
3. Plug the Type A end of the USB cable into the OTG adapter.
4. Verify that your Robot Controller smartphone is powered on and unlocked. Plug in the USB Micro OTG
adapter into the OTG port of the Robot Controller phone.
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 67
Note that when the OTG adapter is plugged into the smartphone, the phone will detect the presence of the
Expansion Hub and launch the Robot Controller app.
5. The first time you connect the Robot Controller smartphone to the Expansion Hub, the Android operating
system should prompt you to ask if it is OK to associate the newly detected USB device (which is the Expansion
Hub) with the FTC Robot Controller app.
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
68 | FIRST® Tech Challenge Android Studio Manual
Important Information!
You might be prompted multiple times to associate the USB hardware with the FTC Robot Controller. Whenever
you are prompted by your phone with this message, you should always select the “Use by default for this USB
device” option and hit the “OK” button to associate the USB device with the FTC Robot Controller app.
If you fail to make this association, then the Robot Controller app might not reliably connect to this Expansion
Hub the next time you turn your system on.
If you are using a Control Hub, you do not need to make any additional connections. You simply need to make
sure that the Control Hub is powered on and paired to the Driver Station.
Although the configuration file needs to reside on the Robot Controller, for this tutorial we will use the Driver
Station app to create the configuration file remotely. The Driver Station can be used to create a configuration
file for a Control Hub or for an Android smartphone Robot Controller.
Creating a Configuration File on the Robot Controller using the Driver Station
1. Touch the three vertical dots in the upper right hand corner of the Driver Station app. This will launch a pop-
up menu.
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 69
Creating a Configuration File on the Robot Controller using the Driver Station
2. Select Configure Robot from the pop up menu to display the Configuration screen.
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
70 | FIRST® Tech Challenge Android Studio Manual
Creating a Configuration File on the Robot Controller using the Driver Station
3. If your Robot Controller does not have any existing configuration files, the screen will display a message
indicating that you need to create a file before proceeding.
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 71
Creating a Configuration File on the Robot Controller using the Driver Station
Hit the New button to create a new configuration file for your Robot Controller.
4. When the new configuration screen appears, the Robot Controller app will do a scan of the serial bus to see
what devices are connected to the Robot Controller.
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
72 | FIRST® Tech Challenge Android Studio Manual
Creating a Configuration File on the Robot Controller using the Driver Station
It will display the devices that it found in a list underneath the words “USB Devices in configuration.” You should
see an entry that says something like “Expansion Hub Portal 1” in the list.
Your Expansion Hub is listed as a Portal because it is directly connected to the Robot Controller phone through
the USB cable or in the case of the Control Hub through the internal serial bus.
If you do not see your Expansion Hub Portal listed and you are using a smartphone as a Robot Controller,
check the wired connections to make sure they are secure and then press the Scan button one or two times
more to see if the smartphone detects the device on a re-scan of the USB bus.
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 73
Creating a Configuration File on the Robot Controller using the Driver Station
5. Touch the Portal listing (“Expansion Hub Portal 1” in this example) to display what Expansion Hubs are
connected through this Portal.
Since we only have a single Expansion Hub connected, we should only see a single Expansion Hub configured
(“Expansion Hub 2” in this example).
6. Touch the Expansion Hub listing (“Expansion Hub 2” in this example) to display the Input/Output ports for that
device.
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
74 | FIRST® Tech Challenge Android Studio Manual
Creating a Configuration File on the Robot Controller using the Driver Station
The screen should change and list all the motor, servo and sensor ports that are available on the selected
Expansion Hub.
Now that you've created a file, you will need to add a DC Motor to the configuration file.
Important Note: At this point, although you have created your configuration file, you have not yet saved its
contents to the Robot Controller. You will save the configuration file in a later step.
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 75
Configuring a DC Motor
1. Touch the word Motors on the screen to display the Motor Configuration screen.
2. Since we installed our motor onto port #0 of the Expansion Hub, use the dropdown control for port 0 to select
the motor type (Tetrix Motor for this example).
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
76 | FIRST® Tech Challenge Android Studio Manual
Configuring a DC Motor
3. Use the touch screen keypad to specify a name for your motor (“motorTest” in this example).
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 77
Configuring a DC Motor
4. Press the Done button to complete the motor configuration. The app should return to the previous screen.
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
78 | FIRST® Tech Challenge Android Studio Manual
Configuring a DC Motor
You will also want to add a servo to the configuration file. In this example, you are using a standard 180-
degree servo.
Configuring a Servo
1. Touch on the word Servos on the screen to display the Servo Configuration screen.
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 79
Configuring a Servo
2. Use the dropdown control to select “Servo” as the servo type for port #0.
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
80 | FIRST® Tech Challenge Android Studio Manual
Configuring a Servo
3. Use the touch pad to specify the name of the servo (“servoTest” for this example) for port #0.
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 81
Configuring a Servo
4. Press the Done button to complete the servo configuration. The app should return to the previous screen.
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
82 | FIRST® Tech Challenge Android Studio Manual
Configuring a Servo
The REV Robotics Color Distance Sensor is an I2C sensor. It actually combines two sensor functions into a
single device. It is a color sensor, that can determine the color of an object. It is also a distance or range
sensor, that can be used to measure short range distances. Note that in this tutorial, the word "distance" is
used interchangeably with the word "range".
1. Touch the words I2C Bus 0 on the screen to launch the I2C configuration screen for this I2C bus.
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 83
The Expansion Hub has four independent I2C buses, labeled “0” through “3”. In this example, since you
connected the Color Sensor to the port labeled “0”, it resides on I2C Bus 0.
2. Look at the I2C Bus 0 screen. There should already be a sensor configured for this bus. The Expansion Hub
has its own built-in inertial measurement unit (IMU) sensor. This sensor can be used to determine the
orientation of a robot, as well as measure the accelerations on a robot.
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
84 | FIRST® Tech Challenge Android Studio Manual
The built-in IMU is internally connected to I2C Bus 0 on each Expansion Hub. Whenever you configure an
Expansion Hub using the Robot Controller, the app automatically configures the IMU for I2C Bus 0. You will
need to add another I2C device for this bus to be able to configure the color sensor.
3. Press the Add button to add another I2C device to this bus.
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 85
4. Select “REV Color/Range Sensor” from the dropdown selector for this new device. Use the touchscreen
keyboard to name this device “sensorColorRange”.
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
86 | FIRST® Tech Challenge Android Studio Manual
5. Press the Done button to complete the I2C sensor configuration. The app should return to the previous
screen.
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 87
The REV Robotics Touch Sensor is a digital sensor. An Op Mode can query the Touch Sensor to see if its
button is being pressed or not.
1. Touch the words Digital Devices on the screen to launch the Digital I/O configuration screen.
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
88 | FIRST® Tech Challenge Android Studio Manual
2. Use the touch screen to add a “REV Touch Sensor” for port #1 and name the device “testTouch”.
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 89
Notice that we are configuring the Touch Sensor on port #1 instead of port #0. This is because when the REV
Robotics Touch Sensor is connected to a digital port using a standard 4-wire JST sensor cable, it is the second
digital pin that is connected. The first pin remains disconnected.
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
90 | FIRST® Tech Challenge Android Studio Manual
Once you have configured your hardware, you must save the information to the configuration file. If you do not
save this information, it will be lost and the robot controller will be unable to communicate with your hardware.
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 91
2. Press the Done button again to return to the highest level in the configuration screens.
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
92 | FIRST® Tech Challenge Android Studio Manual
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 93
4. When prompted, specify a configuration file name using the touchscreen’s keypad (use “TestConfig” for this
example).
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
94 | FIRST® Tech Challenge Android Studio Manual
5. Press the OK button to save your configuration information using that file name.
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 95
6. After the configuration file has been saved, touch the Android back-arrow button to return to the main screen
of the app.
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
96 | FIRST® Tech Challenge Android Studio Manual
7. Verify that the configuration file is the active configuration file on the main Driver Station screen.
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 97
http://developer.android.com/sdk/index.html
Android Studio is available on the Windows, MacOS, and Linux operating systems.
http://developer.android.com/sdk/index.html#Requirements
https://developer.android.com/studio/index.html
Click on the green “DOWNLOAD ANDROID STUDIO” button to start the download process.
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
98 | FIRST® Tech Challenge Android Studio Manual
Accept the license terms and then push the blue “DOWNLOAD ANDROID STUDIO” button on the Android
Developer webpage to download the software.
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 99
Once the setup package has downloaded, launch the application and follow the on-screen instructions to install
Android Studio.
11.1. Introduction
If you are an Android Studio user, one of the most important steps to take is to disable Android Studio
Instant Run. Instant Run is a feature that is designed to streamline the development process by reducing the
time to apply code changes to your app. Unfortunately, Instant Run is limited in function and when used with
the FIRST Tech Challenge Android Studio project folder, can cause severe and difficult-to-troubleshoot
problems.
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
100 | FIRST® Tech Challenge Android Studio Manual
On the left hand side of the Settings window, there should be a category called "Build, Execution,
Deployment". Within this category, click on the "Instant Run" subcategory to display the Instant Run settings for
your Android Studio installation. By default, Instant Run is enabled when you first install Android Studio.
Uncheck the "Enable Instant Run to hot swap code/resource changes on deploy (default enabled)" option and
then click on the "OK" button to disable Instant Run.
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 101
https://developer.android.com/studio/run/index.html#disable-ir
https://github.com/
For the 2019-2020 season and beyond, each new FIRST Tech Challenge season has its own unique public
GitHub repository.
The current season's public repository can be found at the following address:
https://github.com/FIRST-Tech-Challenge/SkyStone
Important Note for Advanced GitHub Users: This tutorial assumes that the user is a novice with respect to
using GitHub and the git version control software. If you are a GitHub power user, you can use git to clone a
local copy of the current season's public GitHub repository. This document, however, does not explain how to
use git to access the repository. It provides instructions on downloading the repository as a .ZIP file instead.
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
102 | FIRST® Tech Challenge Android Studio Manual
From the main repository web page, click on the “releases” link to jump to the Releases page for the
repository. The Releases page should list the available software releases for the repository. The latest release
should be displayed near the top of the page.
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 103
Each software release should include an Assets section that you can use to download the software that you
will need to program your robot. Note that you might have to click on the triangular symbol to expand this
Assets section.
Click on the Source code (zip) link to download the compressed Android Studio project folder.
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
104 | FIRST® Tech Challenge Android Studio Manual
Before you can import the FTC project into Android Studio, you must first extract the contents of the archived
project file. For Windows users, right mouse click on the file and select “Extract All” from the pop up menu.
Windows should prompt you to select a destination for the extracted project folder. The dialog that appears
should look similar to the one show in the figure below.
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 105
Highlight the suggested name for the destination folder (in the figure above, the suggested name is “SkyStone-
5.0”) and change the destination folder name into something more user friendly. In this example, we will
change the name of the destination folder to “mycopy”.
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
106 | FIRST® Tech Challenge Android Studio Manual
After you have renamed the destination folder, extract the contents of the archive to the folder. After the
extraction process is complete, verify that the project folder was successfully extracted to its target destination.
Once you have successfully extracted the contents of the archived file, you are ready to import the FTC project
into Android Studio.
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 107
Android Studio should prompt you to select the project folder that you would like to import. Use the file browser
in the pop up dialog box to locate and then select the folder that you extracted in an section of this document.
Make sure you select the extracted project folder (and not the .ZIP file which might have a similar name to the
extracted folder). Hit the “OK” button to import the selected project into Android Studio.
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
108 | FIRST® Tech Challenge Android Studio Manual
In the figure above the project folder called “SkyStone-5.0” is selected to be imported into Android Studio. It
might take Android Studio several minutes to import the project. Once the project has been successfully
imported, the screen should look similar to the one depicted in the image below.
After you have configured your Android phone, you will also have to make sure that your phone is in developer
mode before you will be able to install apps onto the phone using the tools that are included with Android
Studio.
Important Note for Control Hub Users: The Control Hub has Developer Options automatically enabled from
the factory, so you do NOT need to do this step for your Control Hub.
The Android Developer website contains information on how to enable Developer Options onto your phone. If
you visit the following link and read the section entitled “Enabling On-device Developer Options” you will see
that you can enable Developer Options on you Android phone by going to Settings->About phone on the
phone, and then tapping the Build number seven times.
https://developer.android.com/studio/run/device.html#device-developer-options
In order to be able to use the Android Studio tools to install apps onto your phone, you will need to make sure
that the Developer Options and USB debugging are enabled for both of your phones.
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 109
When you first connect a phone to your computer with Android Studio running, the phone might prompt you if it
is OK to allow the computer to have USB debugging access to the phone. If this happens, make sure that you
check the “Always allow from this computer” option and hit the OK button to allow USB debugging.
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
110 | FIRST® Tech Challenge Android Studio Manual
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 111
When you create your classes and op modes, you will to create them in the org.firstinspires.ftc.teamcode
package that resides in the TeamCode module. This package is reserved for your use within the FTC Android
Studio project folder.
http://ftctechnh.github.io/ftc_app/doc/javadoc/index.html
Check the "Add unambiguous imports on the fly" so that Android Studio will automatically add the required
import statements for classes that you would like to use in your op mode.
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
112 | FIRST® Tech Challenge Android Studio Manual
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 113
@Disabled
and comment out this line to enable the op mode and allow it to be run on the Robot Controller:
//@Disabled
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
114 | FIRST® Tech Challenge Android Studio Manual
Press the OK button to create the new class. The source code for the new class should appear in the editing
pane of the Android Studio user interface.
Modify the main portion of your op mode so that it looks like the following code (note that the package
definition and some import statements have been omitted in the following source code):
@TeleOp
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 115
@Override
public void runOpMode() {
imu = hardwareMap.get(Gyroscope.class, "imu");
motorTest = hardwareMap.get(DcMotor.class, "motorTest");
digitalTouch = hardwareMap.get(DigitalChannel.class, "digitalTouch");
sensorColorRange = hardwareMap.get(DistanceSensor.class, "sensorColorRange");
servoTest = hardwareMap.get(Servo.class, "servoTest");
telemetry.addData("Status", "Initialized");
telemetry.update();
// Wait for the game to start (driver presses PLAY)
waitForStart();
}
}
}
We will use this source code as the framework for your first op mode. Note that Android Studio automatically
saves your source code as you are editing it.
Congratulations! You've written an op mode. It does not do much, but we will modify it to make it more useful.
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
116 | FIRST® Tech Challenge Android Studio Manual
If you think about an op mode as a list of instructions for the robot, this set of instructions that you created will
be executed by the robot whenever a team member selects the op mode called “MyFIRSTJavaOpMode” from
the list of available op modes for this Robot Controller.
Let’s look at the structure of your newly created op mode. Here’s a copy of the op mode text (minus some
comments, the package definition, and some import package statements):
@TeleOp
@Override
public void runOpMode() {
imu = hardwareMap.get(Gyroscope.class, "imu");
motorTest = hardwareMap.get(DcMotor.class, "motorTest");
digitalTouch = hardwareMap.get(DigitalChannel.class, "digitalTouch");
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 117
telemetry.addData("Status", "Initialized");
telemetry.update();
// Wait for the game to start (driver presses PLAY)
waitForStart();
}
}
}
At the start of the op mode there is an annotation that occurs before the class definition. This annotation states
that this is a tele-operated (i.e., driver controlled) op mode:
@TeleOp
If you wanted to change this op mode to an autonomous op mode, you would replace the “@TeleOp” with an
“@Autonomous” annotation instead.
You can see from the sample code that an op mode is defined as a Java class. In this example, the op mode
name is called “MyFIRSTJavaOpMode” and it inherits characteristics from the LinearOpMode class.
@Override
public void runOpMode() {
At the start of the runOpMode method, the op mode uses an object named hardwareMap to get references to
the hardware devices that are listed in the Robot Controller’s configuration file:
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
118 | FIRST® Tech Challenge Android Studio Manual
Note that when you attempt to retrieve a reference to a specific device in your op mode, the name that you
specify as the second argument of the HardwareMap.get method must match the name used to define the
device in your configuration file. For example, if you created a configuration file that had a DC motor named
“motorTest”, then you must use this same name (it is case sensitive) to retrieve this motor from the
hardwareMap object. If the names do not match, the op mode will throw an exception indicating that it cannot
find the device.
In the next few statements of the example, the op mode prompts the user to push the start button to continue.
It uses another object that is available in the runOpMode method. This object is called telemetry and the op
mode uses the addData method to add a message to be sent to the Driver Station. The op mode then calls the
update method to send the message to the Driver Station. Then it calls the waitForStart method, to wait until
the user pushes the start button on the driver station to begin the op mode run.
telemetry.addData("Status", "Initialized");
telemetry.update();
// Wait for the game to start (driver presses PLAY)
waitForStart();
Note that all linear op modes should have a waitForStart statement to ensure that the robot will not begin
executing the op mode until the driver pushes the start button.
After a start command has been received, the op mode enters a while loop and keeps iterating in this loop until
the op mode is no longer active (i.e., until the user pushes the stop button on the Driver Station):
}
As the op mode iterates in the while loop, it will continue to send telemetry messages with the index of “Status”
and the message of “Running” to be displayed on the Driver Station.
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 119
Or, if you are using a Control Hub, verify that the Control Hub is powered by a freshly charged 12V battery, and
that it is connected to your laptop through its USB Type C port. Note that the Control Hub should automatically
have USB debugging permission enabled.
When using the Control Hub, please make sure you use the Type C port (and not the USB Mini port) to
connect the Control Hub to your development laptop.
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
120 | FIRST® Tech Challenge Android Studio Manual
Look towards the top of the Android Studio user interface and find the little green Play or Run button (which is
represented by a green triangle) next to the words “Team Code”. Press this green button to build the Robot
Controller app and to install it onto your phone.
Android Studio should prompt you to select a target device to install the Robot Controller app. Your screen
might look something like the image shown below.
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 121
Make sure that you select the correct target device. In the figure above the Motorola phone is selected as the
target device. Hit OK to build the APK file and install it on the target device.
Note: If you previously installed a copy of the FTC Robot Controller app from the Google Play store, the
installation of your newly built app will fail the first time you attempt to install it. This is because Android Studio
detects that the app that you just build has a different digital signature than the official version of the FTC
Robot Controller app that was installed from Google Play.
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
122 | FIRST® Tech Challenge Android Studio Manual
If this happens, Android Studio will prompt you if it's OK to uninstall the previous (official) version of the app
from your device and replace it with the updated version of the app. Select "OK" to uninstall the previous
version and to replace it with your newly created Robot Controller App (see image above).
If the installation was successful, the Robot Controller app should be launched on the target Android device. If
you are using an Android phone as your Robot Controller, you should see the main Robot Controller app
screen displayed on the phone.
Although the Control Hub lacks a built in screen, if you are Control Hub user, you can verify that the app was
installed onto your Control Hub properly by looking at your Driver Station. If the Driver Station indicates that it
is successfully connected to the Control Hub (after momentarily disconnecting while the update was occurring)
then the app was successfully updated.
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 123
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
124 | FIRST® Tech Challenge Android Studio Manual
The op mode will execute the statements in the runOpMode method up to the waitForStart statement. It will
then wait until you press the start button (which is represented by the triangular shaped symbol) to continue.
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 125
Once you press the start button, the op mode will continue to iterate and send the “Status: Running” message
to the Driver Station. To stop the op mode, press the square-shaped stop button.
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
126 | FIRST® Tech Challenge Android Studio Manual
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 127
}
If you look at the code that was added, you will see that we defined a new variable called target power before
we enter the while loop.
double tgtPower = 0;
At the start of the while loop we set the variable tgtPower equal to the negative value of the gamepad1’s left
joystick:
tgtPower = -this.gamepad1.left_stick_y;
The object gamepad1 is available for you to access in the runOpMode method. It represents the state of
gamepad #1 on your Driver Station. Note that for the F310 gamepads that are used during the competition, the
Y value of a joystick ranges from -1, when a joystick is in its topmost position, to +1, when a joystick is in its
bottommost position. In the example code above, you negate the left_stick_y value so that pushing the left
joystick forward will result in a positive power being applied to the motor. Note that in this example, the notion
of forwards and backwards for the motor is arbitrary. However, the concept of negating the joystick y value can
be very useful in practice.
The next set of statements sets the power of motorTest to the value represented by the variable tgtPower. The
values for target power and actual motor power are then added to the set of data that will be sent via the
telemetry mechanism to the Driver Station.
tgtPower = -this.gamepad1.left_stick_y;
motorTest.setPower(tgtPower);
telemetry.addData("Target Power", tgtPower);
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
128 | FIRST® Tech Challenge Android Studio Manual
Before you connect your gamepad to the phone, verify that the switch on the bottom of the gamepad is set to
the “X” (i.e., the "Xbox" mode) position.
Connect the gamepad to the Driver Station using the Micro USB OTG adapter cable.
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 129
Your example op mode is looking for input from the gamepad designated as the user or driver #1. Press the
Start button and the A button simultaneously on the Logictech F310 controller to designate your gamepad as
user #1. Note that pushing the Start button and the B button simultaneously would designate the gamepad as
user #2.
If you successfully designated the gamepad to be user #1, you should see a little gamepad icon above the text
“User 1” in the upper right hand corner of the Driver Station Screen. Whenever there is activity on gamepad #1,
the little icon should be highlighted in green. If the icon is missing or if it does not highlight in green when you
use your gamepad, then there is a problem with the connection to the gamepad.
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
130 | FIRST® Tech Challenge Android Studio Manual
If you configured your gamepad properly, then the left joystick should control the motion of the motor. As you
run your op mode, be careful and make sure you do not get anything caught in the turning motor. Note that the
User #1 gamepad icon should highlight green each time you move the joystick. Also note that the target power
and actual motor power values should be displayed in the telemetry area on the Driver Station.
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 131
In this section, you will modify your op mode to control a servo motor with the buttons of the gamepad.
In the figure below, “standard scale” 180-degree servo is shown. This type of servo is popular with hobbyists
and with FIRST Tech Challenge teams. This servo motor can rotate its shaft through a range of 180 degrees.
Using an electronic module known as a servo controller you can write an op mode that will move a servo motor
to a specific position. Once the motor reaches this target position, it will hold the position, even if external
forces are applied to the shaft of the servo.
Servo motors are useful when you want to do precise movements (for example, sweep an area with a sensor
to look for a target or move the control surfaces on a remotely controlled airplane).
With a typical servo, you can specify a target position for the servo. The servo will turn its motor shaft to move
to the target position, and then maintain that position, even if moderate forces are applied to try and disturb its
position.
For the FIRST Tech Challenge control system, you can specify a target position that ranges from 0 to 1 for a
servo. A target position of 0 corresponds to zero degrees of rotation and a target position of 1 corresponds to
180 degrees of rotation for a typical servo motor.
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
132 | FIRST® Tech Challenge Android Studio Manual
In this example, you will use the colored buttons on the right side of the F310 controller to control the position
of the servo. Initially, the op mode will move the servo to the midway position (90 degrees of its 180-degree
range). Pushing the yellow “Y” button will move the servo to the zero-degree position. Pushing the blue “X”
button or the red “B” button will move the servo to the 90-degree position. Pushing the green “A” button will
move the servo to the 180-degree position.
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 133
}
This added code will check to see if any of the colored buttons on the F310 gamepad are pressed. If the Y
button is pressed, it will move the servo to the 0-degree position. If either the X button or B button is pressed, it
will move the servo to the 90-degree position. If the A button is pressed, it will move the servo to the 180-
degree position. The op mode will also send telemetry data on the servo position to the Driver Station.
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
134 | FIRST® Tech Challenge Android Studio Manual
After you have modified your op mode, you can build it and then run it. Verify that gamepad #1 is still
configured and then use the colored buttons to move the position of the servo.
The Color-Range sensor uses reflected light to determine the distance from the sensor to the target object. It
can be used to measure close distances (up 5” or more) with reasonable accuracy. Note that at the time this
document was most recently edited, the REV Color-Range sensor saturates around 2” (5cm). This means that
for distances less than or equal to 2”, the sensor returns a measured distance equal to 2” or so.
Modify your op mode to add a telemetry statement that will send the distance information (in centimeters) to
the Driver Station.
Revision 1: 08/08/2019
FIRST® Tech Challenge Androd Studio Manual | 135
The Expansion Hub digital ports contain two digital pins per port. When you use a 4-wire JST cable to connect
a REV Robotics Touch sensor to an Expansion Hub digital port, the Touch Sensor is wired to the second of the
two digital pins within the port. The first digital pin of the 4-wire cable remains disconnected.
For example, if you connect a Touch Sensor to the “0,1” digital port of the Expansion Hub, the Touch Sensor
will be connected to the second pin (labeled “1”) of the port. The first pin (labeled “0”) will stay disconnected.
Modify the code in your op mode that occurs before the waitForStart command to set the digital channel for
input mode.
telemetry.addData("Status", "Initialized");
telemetry.update();
// Wait for the game to start (driver presses PLAY)
waitForStart();
Also, modify the code in your while loop to add an if-else statement that checks the state of the digital input
channel. If the channel is LOW (false), the touch sensor button is pressed and being pulled LOW to ground.
Otherwise, the touch sensor button is not pressed.
// is button pressed?
if (digitalTouch.getState() == false) {
// button is pressed.
telemetry.addData("Button", "PRESSED");
} else {
// button is not pressed.
telemetry.addData("Button", "NOT PRESSED");
}
telemetry.addData("Status", "Running");
telemetry.update();
Build and install the updated Robot Controller app, then reinitialize and restart your op mode. The op mode
should now display the state of the button (“PRESSED” or “NOT PRESSED”).
Gracious Professionalism® - “Doing your best work while treating others with respect and kindness - It’s what makes FIRST, first.”
136 | FIRST® Tech Challenge Android Studio Manual
Volunteers that apply for a specific volunteer role will receive an email from FTCTrainingSupport@firstinspires.org
with their username and password to the forum. You will receive access to the forum thread specific to your role.
FIRST Websites
FIRST homepage – www.firstinspires.org
FIRST Tech Challenge Page – For everything FIRST Tech Challenge.
Feedback
We strive to create support materials that are the best they can be. If you have feedback about this manual, please email
firsttechchallenge@firstinspires.org. Thank you!
Revision 1: 08/08/2019