Lesson: 6 Week FIRST Tech Challenge Workshop Start Programming

Examine the details of using Android Studio to create OpMode classes.

Understand how to use Android Studio to create OpMode classes, compile them and download them to the robot controller phone.


Now its time to get more familiar with OnBot or Android Studio and writing OpModes. Note that all of the code samples in this curriculum will work in either OnBot or AS.

If you are using OnBot, you will be connecting to the controller phone via WiFi Direct right away, no USB cable needed. You interact with OnBot using a web browser (Chrome recommended) from a PC, a tablet or a Chrome book. The web browser is the only software tool you need to have installed on your development device. Once you connect to OnBot with a browser, a simplified interactive development environment is displayed (like a web site) in the browser. This IDE is being served by the controller phone. In this IDE you create Java source files and edit code in these files in a manner similar to Android Studio. Once you have written a program, you click a button to compile your program and it becomes available on the controller phone (and visible on the driver station phone) immediately. There is no deployment step as with AS.

Here are several video tutorials (simple, detailed) and a text tutorial (start with section 9) discussing OnBot in more detail. You will need to view at least the first tutorial in order to learn how to connect your development PC to the controller phone, start OnBot and then how to enter and run Java code.

Note: You should download any code written in OnBot to your development device to make sure your code is not lost if something happens to the controller phone.

If you are using Android Studio, Watch this video on writing OpModes.

Remember, each time we change an OpMode's source code, we must recompile and download the newly updated robot controller app to the controller phone. Compiling in Android Studio will take care of the download as long as your PC is connected to the controller phone with a USB cable or via WiFi. We will start using the cable and graduate to WiFi.

The first time you connect your controller phone to your PC with a USB cable, the phone should install the USB driver needed for AS to communicate with your phone. If this driver install is unsuccessful, disconnect and reconnect the phone. Once install is complete the phone should now be visible to AS.

Also, the first time you connect the controller phone to your PC, the phone will prompt you accept the RSA Security Key presented by your PC to the phone. Set the option to always accept the RSA Key from this PC and click Ok.

Note: It is possible to use both AS and OnBot at the same time. However, if any class has the same name in AS as one created in OnBot, the OnBot class will be used. Also, any shared classes used by OnBot classes must exist in the OnBot file list in order to compile.