Lesson: Start Programming

Overview: 
Examine the details of using OnBot or Android Studio to create OpMode classes.
Objectives: 

Understand how to use OnBot or Android Studio to create OpMode classes, compile and download (AS only) them to the robot controller phone.

Content: 

Now its time to get more familiar with OnBot or Android Studio and writing OpModes. 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 device via WiFi 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 device. 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 device (and visible on the driver station phone) immediately. There is no deployment step as with AS. Each time you change your code, you must click the button to recompile in order for your changes to be incorporated into the controller app.

Here are several video tutorials (simple, detailed) and a text tutorial discussing OnBot in more detail. When using a cell phone as the controller device, you should 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. The quick summary of using OnBot is to open the 3 dot menu on the controller phone and select Program and Manage. Here you will see the name of the WiFi Direct network being published by the phone. On your development PC, this name should appear in the list of available WiFi connections (may take a few second after starting controller app). Connect to this network. The phone also shows the password that Windows will ask for. Check the automatically connect box to avoid having to enter the password again. Once connected, browse to http://192.168.49.1:8080 and OnBot will appear.

When using the Control Hub, connect your development PC to the WiFi name of the Control Hub using the password you configured in the Control Hub in the earlier lesson. Check the automatically connect box to avoid having to enter the password again. Once connected, browse to http://192.168.43.1:8080 and OnBot will appear. Note the IP address is different that the address used with the cell phone.

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 device. Compiling in Android Studio will take care of the download as long as your PC is connected to the controller device with a USB cable or via WiFi. We will start using the cable and graduate to WiFi.

The first time you connect your controller device to your PC with a USB cable, the device should install the USB driver needed for AS to communicate with your device. If this driver install is unsuccessful, disconnect and reconnect the device. Once the install is complete the device should now be visible to AS. Driver install requires an internet connection and on Windows versions after 7, the install may take several minutes to complete. Driver installs will not complete on metered connections. Controller device will appear as a media player (MTP) in the Devices and Printers control panel applet.

As of this writing, the Control Hub USB driver install fails on Windows 7. In this case, download this file and extract. Run DriverInstall.exe. When it is finished, reconnect the Control Hub to the PC. The hub USB driver install should now complete.

Also, the first time you connect a 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 but not recommended. If you do use both IDEs, if any class has the same name in both IDEs, an error will be generated, and on controller restart, the first class on the phone will be automatically renamed to resolve the name collision. Also, any shared classes used by OnBot classes must exist in the OnBot file list in order to compile.

 

Navigation: