Learner

Introduction

This lesson is the first in the "off ramp" unit for RoboRio programmers. This unit contains a detailed exploration of writing Java programs for the RoboRio. Don't forget to complete the rest of the Java curriculum starting with Unit 12.

We have been learning a lot about the Java programming language. Now its time to explore how we actually write, compile and deploy Java programs for the RoboRio (FRC) robotics control system.

Introduction

This lesson is the first in the "off ramp" unit for Tetrix programmers. This unit contains a detailed exploration of writing Java programs for the Tetrix control system. Don't forget to complete the rest of the Java curriculum starting with Unit 12.

We have been learning a lot about the Java programming language. Now its time to explore how we actually write, compile and deploy Java programs for the Tetrix (FTC) robotics control system.

leJOS Example Programs

leJOS provides a set of example programs you can download and install into Eclipse. The examples show how to do a number of things with the leJOS API and are valuable to have available to look at. These examples cover advanced topics and techniques so you should work through the exercises in this unit before looking at these examples.

You can download the examples here. Select the file leJOS_EV3_0.9.1-beta_samples.zip.

Hello World on the EV3

Now its time to try your first Java program on the EV3. Start Eclipse on your PC. When Eclipse is ready, select New on the File menu. Slide your cursor over to the item list and select Project (not Java Project).

Installing Eclipse

If you do not already have a working Eclipse IDE, you should download Eclipse here. The recommended package of Eclipse is the Eclipse IDE for Java Developers. Install the 32 or 64 bit version matching the bitness of your PC. Eclipse requires Java Run Time (JRE) 8 (1.8) in 32 or 64 bit form matching the bitness of Eclipse. Download here if you do not already have it. 

Installing leJOS

There are three main steps to installing leJOS. The first two steps are installing the Java and leJOS SDKs on your PC. The third step is creating the leJOS memory card that goes in the EV3. This three part installation process for Windows (Mac users see below) is documented on the leJOS web site here. Open the link and follow the instructions, after reading the following three notes:

Introduction

This lesson is the first in the "off ramp" unit for EV3 programmers. This unit contains a detailed exploration of writing Java programs for the EV3. Don't forget to complete Unit 8 and the rest of the Java curriculum starting with Unit 12.

We have been learning a lot about the Java programming language. Now its time to explore how we actually write, compile and deploy Java programs for the EV3 (FLL) robotics control system.

Packages and Imports in Detail

A real project, even robotics projects, can end up having many classes. You will likely need to use classes in libraries provided by FIRST or others. Finding the classes you need, controlling access to them and naming conflicts between your classes and library classes would be a problem. You may also want to organize a group of your classes into a library that can be reused with other projects or other robotics teams. Packages give us a way to group together related classes in a unique naming scheme and reference them from other classes.

More on Objects

Now we are going to look at some aspects of using objects in your code.

Constructors

Objects have special kind of method called a constructor. A constructor is an optional method that is called when a new instance of an object is created with the new keyword. Constructors are used to initialize the fields of the new object instance. A constructor looks like a method except that it has no return data type (including void) and has the same name as the class. A constructor can have a parameter list and a class can have more than one constructor by varying the parameter list.

Pages