Learner

Exercise: Using Library Classes

Many times we write code that will be repeated in a single project or code that is repeated in different projects. An example of this is the code to read the touch sensor in the DriveCircle project. This code would be repeated in every project that uses a touch sensor. It can be useful to put utility code, that is code that be used in several places or several projects into separate classes that can be called upon whereever needed. Another benefit is if we need to change how we handle the touch sensor.

Exercise: Using Multiple Threads

If you have not read the lesson on multi-threading in the Advanced Topics unit, do so before continuing.

Exercise: Using Logging

We are now going to take a look at logging (also called tracing) as a tool to debug our robot programs. Logging is recording useful information from the robot program to a disk file on the EV3 controller. You can then download that file to your PC and examine it. It can be very useful to record information while your robot is running during a match so you can look at it afterwards and see what took place. If you have not read the general lesson on Logging, you should do that now.

EV3 Control Center

The EV3 Control Center is installed with the leJOS SDK on your development PC. The Control Center is a powerful tool that allows you to view and control many aspects of the EV3 controller. With the EV3 connected to your PC, you can start the Control Center from the leJOS pull down menu on the Eclipse tool bar. You can also start Control Center by clicking on this file:

C:\Program Files\leJOS EV3\bin\ev3control.bat

You might want to create a desktop shortcut for that file as you will probably use Control Center often.

Deploying Code over WiFi or Bluetooth

So far we have been deploying code to the EV3 over a USB cable connecting the EV3 to the development PC. This works fine but is tedious, time consuming and may mean moving the robot closer to the PC. A much better way to do development is to connect the EV3 and PC over WiFi (wireless network) or Bluetooth (wireless peer-to-peer).

Exercise: Using Logging

We are now going to take a look at logging (also called tracing) as a tool to debug our robot programs. Logging is recording useful information from our robot program to a disk file on the EV3 controller. We can then download that file to the development PC and examine it. It can be very useful to record information while your robot is running during a match so you can look at it afterwards and see what took place.

Multi-Threading

An executing Java program is called a Process. That process executes your instructions (program) sequentially following the path you created when you wrote your program. This single path is called a thread. As such, your program is only doing one activity (Java statement) at a time and working on one task (your programs list of statements) at a time. For most situations, this works fine. But there are times when you would like to have your program doing more than one thing at time.

Files and File Input/output

Writing data to and reading data from disk files is a common activity for Java programs in many situations. However, file input/output (I/O) is rarely used in the programs created for robots on the platforms we are working with. As such, and given that file I/O is a large and complex topic, it is not going to be covered here. For those who are interested, here are some resources where you can learn more:

Data Conversion (Casting)

Java provides the ability to convert from one data type to another within a set of rules. Some conversions are made automatically and some you have to explicitly request.

Here is a discussion of converting between primitive data types.

Here is a discussion of converting between reference (object) data types.

Deploying Code over WiFi

If you are using OnBot, you can skip this lesson. AS users, read on!

As you have no doubt learned, deploying code with a USB cable is time consuming and means taking the controller phone off the robot. When you are developing actual robot code, you will be doing this a lot. There is a better way.

You can deploy your code over a WiFi network instead of using a cable. This is much quicker and leaves the controller phone on the robot. Here are the instructions on how to do it using WiFi Direct.

Pages