Creating an OpMode - OnBot
Last updated
Last updated
The time has come to create our first OpMode. We want to make sure to choose a clear and unique name each time we make a program. This will help us to find it again later or to communicate with teammates who may also be driving the robot.
In the programming world, there are common naming conventions that have been established to denote variables, classes, functions, etc. OpModes share some similarities to classes, a program-code-template. Thus the naming convention for OpModes tends to follow the naming convention for classes, which has the first letter of every word is capitalized.
While there are standardized naming conventions in programming, at the end of the day you will want to pick something that makes sense to YOU or your team. This might include having your name, team name, a school class period, or similar in your name.
Your OpMode name should not be the same as a created variable name.
To start, let's take a look at the OnBot Java layout in the REV Hardware Client:
Create New OpMode - The plus sign button opens up a window to create a new OpMode.
Project Browser Pane - This pane shows all the Java project files on the Robot Controller.
Source Code Editing Pane - This is the main code editing area
Message Pane - This pane provides information on the success or failure of code builds, as well as where to check for errors after attemping a build
Build Everything - Builds ALL of the .java files on a Robot Controller.
Selecting to "Build Everything" will attempt to compile ALL your OnBot Java files. Errors may appear for incomplete or test files along with the active file.
To temporarily disable an OpMode, right click the file name and select "Disable / Comment":
OpModes may be reenable the same way!
Select the Create New OpMode button. This will open the New File window.
There are a lot of things we can modify while setting up our OpMode, such as the name, sample in use, and kind of OpMode. For Hello Robot, use the following settings for reference:
File Name: HelloRobot_TeleOp
Sample: BlankLinearOpMode
OpMode Type: TeleOp
Setup for Configured Hardware: on
Setup Code for Configured Hardware is an incredibly useful tool that allows for OnBot to help create the hardwareMap based on the current active configuration!
Your intended configuration file should be active BEFORE creating an OpMode using this feature.
Once the proper settings have been choose, select "OK" to create the OpMode!