Chapter 3. creating and modifying programs

After you build your robot, the next thing the robot needs is a program. For example, a program can make the EXPLOR3R drive forward and then steer left or right.

In this chapter, you’ll learn how to create and edit programs using the EV3 software. While you can create programs for your robots without a computer using On Brick Programming, such programs are limited and won’t let you access many of the features of the EV3 brick. (You’ll find an introduction to On Brick Programming in Appendix B.)

First, you’ll create and download a small program to your robot. To create the program, take the following steps:

  1. Connect the robot to the computer using the USB cable that came with your set (see Figure 3-1) and make sure the EV3 brick is turned on. (You’ll have to connect the robot to the computer each time you want to download a program to it.)

  2. Launch the EV3 software by double-clicking the LEGO MINDSTORMS EV3 Home Edition shortcut on your desktop. Once the software loads, you should see the lobby, where you’ll create new programs and open existing ones.

  3. Open a new programming project by clicking the + symbol, as shown in Figure 3-2.

  4. Choose a Move Steering block and place it as shown in Figure 3-3. Remember that a program is basically a list of instructions for actions that the robot should perform. This block is an instruction that makes the robot move forward.

  5. Now click the Download and Run button (see Figure 3-4). Your computer should download this simple program to your robot, and your robot should start moving forward. To download and run this program again, simply click this button again.

If your robot moves forward a short distance, you’ve created your first program. Congratulations!

Okay, your robot moved, but how did you do that? In the following sections, I’ll explore various parts of the EV3 software to help you better understand how to create and edit basic programs before you move on to create more complex ones.

Your screen should look like Figure 3-5 after running your program. I’ll discuss each of the marked sections in turn.

Your EV3 programs consist of programming blocks. Each block instructs the robot to do something different, such as move forward or make a sound. You find blocks on the Programming Palette (see Figure 3-6).

There are several categories of blocks, each of which is found behind one of the colored tabs. You’ll learn to use Action blocks (green), Flow blocks (orange), and My Blocks (light blue) in Chapter 4 and Chapter 5. You’ll learn to use Flow blocks to control sensors in Part II of this book.

Sensor blocks (yellow) and Data Operations blocks (red) are discussed in Part V, and you’ll meet some of the Advanced blocks (dark blue) throughout this book.

Use the Hardware Page to transfer your programs to the EV3 brick, to view the status of the EV3 and any connected devices, and to configure the connection between the EV3 and your computer. Click the toggle on the left to expand the Hardware Page, as shown in Figure 3-9. (I’ll introduce you to many of its features throughout this book.)

When you build a robot, you’ll often want to create more than one program for it. While each program makes your robot behave differently, it makes sense to keep related programs together in a project. You’ll now see how to manage a project file and the programs contained in it using the sections marked in Figure 3-10.

When you made your first program earlier, you actually created a new project file with one empty program in it, as shown in Figure 3-11. To add another empty program to the current project, click the + sign labeled Add program, as shown in the figure.

To change the name of a program, double-click its tab and enter a new name. (For example, I renamed the first program in Figure 3-12 DriveForward.) To change the name of a project, you have to create a new project based on the current one by clicking File > Save Project As and choosing a new name.

Be sure to choose descriptive names for your projects and programs so you can easily find them on the EV3 brick.

When you click Download or Download and Run, the complete project should be transferred to the EV3 brick, as shown in Figure 3-13. In the File Navigation tab on the EV3 brick, you should find one folder for each project, containing all of its programs as well as any files used in the project, such as images or sounds. You start a program by selecting it and clicking the Center button.

(If you inserted a microSD card into the EV3 brick, you should see a folder called SD_Card on the File Navigation tab, and you should find the MyFirstProject folder inside it.)

Clicking the tool icon to the left of the program tabs in the EV3 software opens the Project Properties page (see Figure 3-14). Here you can add information about your project (give it a description, a representative photo, or even a video) and share it with others.

The Project Properties page lists all of the files in your project, including programs and sounds. To reopen a closed program in your project, just double-click its name. To delete a program from your project, select it and click Delete.

Use the toolbar (see Figure 3-15) to open and save programs from your project, undo or redo changes to your program, and navigate around your program.

When the Select tool button on the toolbar is blue, as shown in Figure 3-15, you should be able to use your mouse to place, move, and configure programming blocks on the Programming Canvas. You move around the Canvas using the arrow keys on your keyboard. You’ll use the Select tool most of the time.

If you select the Pan tool, the mouse should move the Canvas. This is especially useful when you make large programs that don’t fit on your computer screen. To navigate to a specific part of a program, select the Pan tool, click in the Programming Canvas, and drag the Canvas around by moving the mouse while holding the left mouse button. (Holding ALT while the Select tool is activated has the same effect.)

To get a better overview of a large program, Zoom out to fit more blocks on your screen. Click Zoom in or Zoom reset to return to normal view.

The Content Editor on the right side of the screen (see Figure 3-19) is where you can add further information about your project, such as descriptions of how your program works or of how to build your robot, whether for your own use or to make it easy for others to rebuild a shared robot. You can add text and images to present your project to others much as you would in a slide presentation editor.

Usually, you’ll want to hide the Content Editor to free up space on your screen.

Once you’ve gained some experience in building and programming EV3 robots, you can build the 5 robots, such as EV3RSTORM, that you’ll find in the lobby. You can also try some of the 12 bonus models found on the More Robots tab. I designed the RAC3 TRUCK, shown in Figure 3-20.

In this chapter, you’ve learned the basics of working with the EV3 programming software. You should now know how to create, edit, and save projects and programs, as well as how to transfer programs to the EV3 brick.

In Chapter 4, we’ll take on some serious programming challenges!