# Navigating Blocks

{% hint style="info" %}
This section pairs with Unit 1, Lesson 6 from the Intro to Robotics V2 curriculum.
{% endhint %}

**Blocks** is a visual programming language designed to be new programmer friendly by helping to streamline parts of the process and cut down the risk of common syntax errors. While it appears similar to other visual languages, such as Scratch or Blockly, it is designed specifically for use with the DUO Control System.

## Accessing Blocks

While connected to a powered Control Hub via USB, open the REV Hardware Client. Select the Control Hub to be programmed then the **Program and Manage** menu.

<figure><img src="https://3023198990-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FnKoHwxC0Q1NBpLowZUmu%2Fuploads%2Fp5f2pg8Zz9lh4X3MYZtF%2Fimage.png?alt=media&#x26;token=b7691e90-a13e-4807-9cd7-60239bb93fd6" alt=""><figcaption></figcaption></figure>

The options for Blocks and OnBot Java should appear at the top alongside the manage option.

<figure><img src="https://3023198990-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FnKoHwxC0Q1NBpLowZUmu%2Fuploads%2FnXwyA1JyObjXagDCuTcB%2Fimage.png?alt=media&#x26;token=1b6899aa-daab-462a-8d50-bd86a5cc9441" alt=""><figcaption></figcaption></figure>

Select Blocks. Let's take a look at the landing page below:

<figure><img src="https://3023198990-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FnKoHwxC0Q1NBpLowZUmu%2Fuploads%2F1TIJbSGGYJlieypiefGN%2Funknown.png?alt=media&#x26;token=be99147a-05e4-4c46-b819-b5930e9bce2e" alt=""><figcaption></figcaption></figure>

1. Create a new OpMode
2. Upload an OpMode
3. Download all saved OpModes
4. All currently saved OpModes and information
5. Enable/[Disable OpModes](#user-content-fn-1)[^1]

## Deleting, Renaming, and Downloading OpModes

While on the home screen, existing OpModes can be modified or downloaded. Downloading a copy of an important OpMode is recommended to help prevent a project being lost in the event of accidental deletion, change, or equipment failure. Blocks DOES NOT autosave.

<figure><img src="https://3023198990-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FnKoHwxC0Q1NBpLowZUmu%2Fuploads%2Fp6NMPj5vJLlqZphc0zvr%2Funknown.png?alt=media&#x26;token=08e248a4-2f9a-4885-84e7-eef7131d0d71" alt=""><figcaption></figcaption></figure>

Select the checkbox beside the OpMode you would like to modify first. Then you can select what you would like to do, such as download, delete, rename, or copy.

## Creating a New OpMode

To create a brand new OpMode, select **Create New OpMode**.

<figure><img src="https://3023198990-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FnKoHwxC0Q1NBpLowZUmu%2Fuploads%2F1X3jvYviKwaMhPow96wl%2Fimage.png?alt=media&#x26;token=a12c55b1-b66a-4d86-9f18-9640d2ef7f44" alt=""><figcaption></figcaption></figure>

This will open the menu to name the OpMode and select a sample program. For now the sample should remain **BasicOpMode** as this will give us an easy to work with foundation to get started.

<figure><img src="https://3023198990-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FnKoHwxC0Q1NBpLowZUmu%2Fuploads%2F9iNCdrqJiuQYugosnpGQ%2Fimage.png?alt=media&#x26;token=651fa55d-a27e-4581-b3aa-a822e46f16fe" alt=""><figcaption></figcaption></figure>

The name of our OpMode should be easily recognizable and give some indication of what it's used for. When working with a class, it may be helpful to include student or group names in the OpMode to aid with grading later.

This first OpMode we will use for a couple activities in this training section so we can name it **myFirstOpMode**.&#x20;

<figure><img src="https://3023198990-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FnKoHwxC0Q1NBpLowZUmu%2Fuploads%2FEBgRctKjpQPKXQ4uT1cO%2Fimage.png?alt=media&#x26;token=2da4fc76-2be8-4054-a87f-18121a3b536b" alt=""><figcaption></figcaption></figure>

Once we click OK, Blocks will fully open.&#x20;

## Navigating Blocks

Let's take a tour of the Blocks user interface.

<figure><img src="https://3023198990-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FnKoHwxC0Q1NBpLowZUmu%2Fuploads%2Fl76DbQ6k91HuWype5Wbu%2Fimage.png?alt=media&#x26;token=87751449-7d53-4928-ba3c-622e412e00b9" alt=""><figcaption></figcaption></figure>

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.

#### OnBot Java Editor

The OnBot Java editor will open as well on the righthand side. Click the checkbox to close this for extra space in the programming area.

<figure><img src="https://3023198990-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FnKoHwxC0Q1NBpLowZUmu%2Fuploads%2FMmnR611yHtp8v6wr7DM5%2Fimage.png?alt=media&#x26;token=454e52dd-58a7-44f5-9dd6-0cdee8f0f324" alt=""><figcaption></figcaption></figure>

In the next section, we'll take a closer look at the different categories of Blocks available. Remember if the correct configuration is not active, some Blocks may be hidden, such as those for motors and sensors.

<figure><img src="https://3023198990-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FnKoHwxC0Q1NBpLowZUmu%2Fuploads%2FuQJmtQU81LdRpAwX7NvC%2Fimage.png?alt=media&#x26;token=45348fc4-ce8c-4cfd-b1fc-6a4df57021b6" alt=""><figcaption></figcaption></figure>

[^1]: Disabled OpModes will not appear on the Driver Hub. This can help reduce clutter for groups with several programs.
