📝 Chapter 2: Your First OpMode

Visual Blocks Examples
Basic LinearOpMode structure
Put initialization blocks here
repeat while opModeIsActive
Put run blocks here
telemetry.update
Blocks Guide

Welcome to Hello Robot

Welcome to Hello Robot!

The first few pages of Hello Robot are an introduction to the programming tools, configuration, and using a gamepad. Ready to jump right into building and programming? Click here to jump to the Blocks Tutorial or here for the OnBot Java Tutorial!

[SUCCESS] The examples and screenshots for this tutorial are completed using a Windows computer, however the Control Hub can be programmed using a Chromebook or a Macbook.

Hello Robot - Choosing Your Path

This tutorial serves as an introduction to the REV Control System, teaching basics of configuration, programming, and utilizing sensors, motors, and servos -- extending beyond the traditional "Hello World" programming exercise.

Two major sections:

  • Part 1: Building a Test Bed using a Control Hub, motor, servo, and touch sensor
  • Part 2: Robot Control for getting a robot moving with a controller and examining sensors/encoders
  • Programming Tools

    Three programming options exist: Blocks (Basic), OnBot Java (Intermediate), and Android Studio (Advanced).

    Blocks Programming Tool

    A drag-and-drop programming tool available directly through the Control Hub, similar to Scratch-based languages used in FIRST LEGO League. It caters to users with minimal programming experience through preset code snippets. Users can view underlying Java syntax using a "Show Java" button.

    OnBot Java

    A text-based programming tool based on a modified version of Java. Suits programmers with basic to advanced Java skills. It provides access to complicated SDK library elements like the hardwareMap class, which remain hidden in Blocks.

    Android Studio

    An advanced IDE for Android app development used by professional developers. Recommended only for users with extensive Java experience, offering enhanced editing and debugging features plus third-party library access. Requires dedicated laptop installation.

    Users select between Blocks or OnBot Java to begin the Hello Robot tutorial.

    Creating an OpMode

    Creating an OpMode - Blocks

    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.

    Instructions

    To start, in the REV Hardware Client, select the "Program and Manage" menu tab. In the upper left-hand corner there is a "Create New OpMode" button, click it.

    Clicking the "Create New OpMode" button will open a new window to name and, if applicable, select a sample template for a program. For this guide use the default "BasicOpMode" sample and name the OpMode HelloRobot_TeleOp.

    Once the OpMode has been named click 'OK' to proceed forward.

    Creating an OpMode will open up the main Blocks programming page. Before moving on to programming, take some time to learn and understand the following key components of Blocks:

    1. Save OpMode - Click this button to save an OpMode to the robot. It is important to save the OpMode any time you stop working on a code, so that progress is not lost. Blocks does not have an autosave feature!

    2. TeleOp/Autonomous - This section of blocks allows users to change between the two types of OpMode: teleop and autonomous.

    3. Categorized Blocks - This section of the screen is where the programming blocks are categorized and accessible. For instance, clicking Logic will open access to programming blocks like if/else statements.

    4. Programming Space - This space is where blocks are added to build programs. Blocks not currently in the use may be dragged off to the side to be clicked back in later or deleted.

    5. Greeting Message - This intro information message may appear when creating a new, empty OpMode. Clicking the ? icon will close this message.

    [DANGER] Remember a configuration needs to be completed first before programming! Some blocks or dropdown menus may be hidden from the side menu until a configuration is made active.

    Opening Java Viewer

    Blocks includes a nifty tool to view how our code would appear if converted to Java. You can click the button on the far right side to open or close this viewer.

    While this feature is designed to aid in the transition between programming platforms, some edits may be required for the Java code to properly compile if added to an OnBot Java OpMode.

    Level Up: OnBot Java versions

    Creating an OpMode (Java)

    Creating an OpMode - OnBot Java

    Creating an OpMode requires selecting a clear and unique name to help locate the program later or communicate with teammates driving the robot.

    Programming follows established naming conventions for variables, classes, and functions. OpModes resemble classes as program-code templates, so their naming convention capitalizes the first letter of every word.

    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 your name, team name, school class period, or similar identifiers. Your OpMode name should not match any created variable name.

    OnBot Java Layout Components

    The REV Hardware Client interface includes five key elements:

    1. Create New OpMode - A plus sign button that opens a window for creating a new OpMode

    2. Project Browser Pane - Displays all Java project files on the Robot Controller

    3. Source Code Editing Pane - The main code editing area

    4. Message Pane - Provides information on code build success or failure and error locations

    5. Build Everything - Builds ALL .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 filename and select "Disable / Comment." OpModes can be reenabled the same way.

    Creating a New OpMode File

    Pre-10.3 Version Settings

    For Hello Robot tutorial, use these settings:

  • 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! The intended configuration file should be active before creating an OpMode using this feature.

    Version 10.3 Settings

    For Hello Robot tutorial in 10.3:

  • File Location: org/firstinspires/ftc/teamcode
  • File Type: Blank OpMode - Linear OpMode
  • File Name: HelloRobot_TeleOp.java
  • OpMode Type: TeleOp
  • Add generated code for configured hardware: on
  • There is a known bug in v10.3 preventing the 'Add generated code for configured hardware' option from working as expected. Hardware mapping code must be manually added to match the Hello Robot tutorial.

    Sample Codes in 10.3

    In the 10.3 version, samples and blank templates are separated for easier navigation. To use sample code, change "File Type" to "Example OpMode," then select the desired sample from the dropdown.

    ← 🚀 Getting Started🔧 Servos →