RoboRIO

Overview: 
What is the Java language? What is it's history? What are it's attributes? Why do we use it for robotics?
Overview: 
Explore how Java is used to write, produce and deploy programs.
Objectives: 

Understand the basic Java programming process: creating source code, compiling source code and deploying/executing the result.

Content: 

So how do we produce Java programs? Java is a text  based language, so the first step is to write the source code for our Java application using a text editor and save that source text in a file. You can use any editor you wish.

Next that source file is passed to the Java compiler. The compiler reads the Java source and checks for errors and if no errors are found, outputs the appropriate bytecode to a second file for execution.

Normally the next step is to start the Java Virtual Machine on your system and pass it the file of Java bytecode and the JVM runs your program. In the case of robots, this step is two parts. First you download your program file to some robot computer (called deployment) using tools provided in your robot SDK. Then the JVM on the robot is told to execute your program.

The Java compiler and a JVM are installed on your computer when you install the Java SDK. The JVM for your robot is installed as part of your robot platform SDK or may come pre-installed. Note that your robot SDK may have an SDK for your development PC and one for your robot controller.

In the simple case, you are responsible for selecting a text editor to use and figuring out the steps needed to compile and deploy your program to the robot. This sounds simple but in actual practice can be quite complex, particularly deployment. To simplify program development, tools called Integrated Development Environments (IDE) were created. IDEs have a powerful text editor and perform compiling and deployment with the click of a button. IDEs typically understand your installed APIs and SDks and integrate these tools into your editing workspace. IDEs provide a lot of programming support and take care of lot of the messy details.

For the EV3 the IDE we use is Eclipse, for Tetrix the IDE is Android Studio and for the RoboRio the IDE is Visual Studio Code. These tools will be discussed in more detail later.

 

Navigation:

Overview: 
Explore the different execution models supported by Java.
Objectives: 

Understand the differences in the different execution models supported by Java and which models are used in robotics.

Content: 

An aspect of the Java "write once, run anywhere" design, is that Java programs can be run in one of several execution "models" or "contexts". Java programs can be run as "Applications", "Apps", "Applets" or "Servlets".

Application is the term typically used to describe Java programs running locally, standalone on a computer, much like programs on Windows (notepad for example). In this case the Java JVM on the computer is started and passed ('handed') the name of the Java program file. The JVM reads the Java bytecode from the file and executes it. This is how Java programs are executed on PCs. This is also the model that robot programs are run in on the EV3 and RoboRio (FRC). Your robot program is downloaded to the robot computer and the JVM on the robot computer loads and runs your program.

Apps are very similar to Applications but the term is typically used to refer to programs running on mobile devices such as cell phones. Here again your program is run by a JVM on the target device. This is the model that robot programs are run in on Tetrix (FTC) becasuse your robot computer is actually a cell phone. Apps and Applications, while similar in many ways, are different in many ways as well due to the differences in how cell phones operate as compared to PCs.

Applets refer to Java programs downloaded from the internet and executed inside your web browser by a JVM that is typically part of the browser. The idea is that programs could be provided on the fly from the internet and would be separated from your underlying system for security purposes. This model of Java program is rarely used these days but was quite common for many years.

Servlets refer to Java programs written to be executed by a web server to provide functionality to web sites. This model of Java program is still common today in the development of web sites.

 

Navigation:

Overview: 
Explore the architecture of Java.
Objectives: 

Understand the basic architecture and implementation of the Java language.

Content: 

Java is a text based programming language. This means source code is written and stored in a text file and then passed through a compiler which produces the executable program (also called the object code). With C or C++ and other languages, the language and resultant executable program is tailored to a specific operating system or hardware platform. For example, a Windows program written in C will only execute on a Windows device and may or may not run on all variations of Windows or Windows devices. This dependency or customization of languages to specific hardware or operating systems can be a problem in some cases.

Java seeks to solve this problem by allowing Java source code to be written and compiled for one virtual hardware/operating system platform. The Java compiler outputs a generic object code called bytecode, which is not specific to any platform. This bytecode is then executed by a Java Virtual Machine (JVM), which is an interface between bytecode and each different platform. The JVM is specific to each platform and translates the generic bytecode of a Java program to the native object code of the target platform for execution. This allows a program compiled from a single Java source file to be run on systems other than the system on which it was compiled.

The processors (controller) on your robots use the Linux operating system and have a JVM already installed on them (this is done when installing your robotics SDK). Your Java robot programs are run by that JVM on Linux even though they were written on Windows.

The final piece of Java is the Java Class Library. This is pre-built library of utility functions that facilitate building programs and also provide generic access to the features of the target platform. This library (API) is provided as part of the Java SDK. We will discuss the JCL in more detail later.

In addition, each robot platform SDK will provide a library that provides access (API) to the specific components and capabilities of the robot hardware.

When it comes to installing Java on your PC and your robot there some terms to understand. The Java Runtime Environment or JRE, is installed when all you want to do is run Java programs developed by someone else. If you want to develop Java programs, you need the Java Deveopment Kit or JDK. The JDK contains the JRE so you typically don't need both but its ok and not uncommon for both the JDK and JRE to get installed on a PC. You can have multiple JREs or JDKs of different versions installed and use them for different purposes. For robotics you install the JDK on your development machine and the JRE will be installed on your robot controller. Actual installation of these Java packages will be covered in a later lesson.

 

Navigation:

Overview: 
Explore the history and nature of Java.
Objectives: 

Understand the history and basic architecture of Java.

Content: 

Java is a general purpose programming language developed in the mid 1990s by Sun Microsystems. Java is now owned by Oracle Corp. Java is a text based, object oriented, class based programming language (we will learn what these terms mean later). In addition to the language itself, Java is designed to allow a program to be written once on a selected hardware and operating system platform and then executed on different hardware and operating system platforms through the use of virtual machine technology. This means the language and the programs generated from that language are not platform (hardware/operating system) dependent. An example is writing Java robot programs on a Windows PC but executing the resulting programs on Linux based robot controllers. This idea is called "write once, run anywhere".

Here is the Wikipedia discussion of Java.

Note that Java is not the same thing as JavaScript. While these two programming languages share ideas and have similar syntax they are definitely different in their purpose, design and implementation.

 

Navigation:

Overview: 
What is computer programming? Why do we do it? How does programming apply to robots? In this unit we will explore these questions and set the stage for the following units.
Overview: 
Questions and exercises to test your understanding of Unit 1 concepts.
Content: 

1. Draw a picture/diagram showing the flow of steps from a programming idea all the way to running code.

2. What is the difference between source code and binary object code?

3. What does an API do for us?

4. What is the difference between an SDK and API?

Navigation:

Overview: 
Explore the programming term SDK (Software Development Kit).
Objectives: 

Understand what an SDK is and how it is used.

Content: 

An SDK, or Software Development Kit, is a package of all of the software tools needed to develop programs for a particular computer or hardware platform. To write programs for specific computers or robotics platforms you need an API library (as described in the previous lesson), deployment scripts (which help compilation on certain platforms), possibly compilers (to allow for the compilation of the code) or IDE plug-ins (similar to extensions to a web browser). All of these items are needed to produce programs for a specific platform. Software vendors or providers (such as FIRST) typically gather all of the components you need to program the target platform into an easily installable package called an SDK.

To develop Java programs, you will need to install the Java SDK. We will cover that in detail later.

For robotics, each hardware (and software) platform has its own SDK. We will explore the details of these SDKs later. For now, just know that for whatever platform you are working with, you will need to download the specific required SDK and install it on your programming computer to get started programming robots.

Here is the Wikipedia discussion of an SDK.

An SDK is typically used in conjunction with an IDE or Interactive Development Environment. An IDE is a software tool used to write programs. Think of it as Windows NotePad on steroids. An IDE has many features and capabilities to make developing programs easier and faster. You will write your robot programs using an IDE. The IDE used with the EV3 and FRC robots is called Eclipse. There are two IDEs available for Tetrix robots, OnBot Java or Android Studio. Will will discuss these IDEs in detail in a later lesson.

 

Navigation:

Overview: 
Explore the programming term API.
Objectives: 

Understand what an API is and how they are used in programming.

Content: 

Simply put, an API or Application Programming Interface, is a library of pre-written computer programs that simplify the use of software or hardware features. When you look at a robot, there is a lot of low level programming needed to operate motors, read sensors, control valves, all at the binary level. There has to be different low level code for each different hardware component. For instance, two different models of motor may require different types of voltage input in order to properly move. It would be very tedious, error prone and time consuming if you had to write all of that low level code as well as the higher level instructions to perform the overall function of your robot.

To solve this problem, other programmers have written all of that low level code and provided it to you in the form of Java Object Libraries. You use these library objects in your program to handle all of the low level tasks for you, allowing you control the robot hardware at a much higher level. So rather than understanding all of the nuances and technical issues in controlling motor voltages, you can simply create a motor object (from the object library) and call the motor.SetSpeed() function to make the motor turn at your desired speed. The motor API is written so that you do not need to understand the specifics of how particular models of motors or servos (or other hardware) vary in their voltage level, but instead can focus on the actions you want the robot to complete. It is important to note, however, that sometimes the small differences in how hardware behaves at the low level (as controlled by the API), can result in surprising, undesired, or otherwise unexpected results when the robot is running.

There are many functions and many devices available for each robot platform and the object library has many objects representing all of the features of the robot hardware. Taken together, all of these library objects are called an API. For the EV3, the API is called the leJOS API. For the Tetrix, the API is called the FTC SDK. On the RoboRio, the API is called the WpiLib.

The term API may also be used for subsets of the overall API. For instance the WpiLib, which is a large API, has a subset of objects dealing with robot vision named the Vision API.

Here is the Wikipedia discussion of an API.

Navigation:

Overview: 
Explore how programming languages are used with robots.
Objectives: 

Understand how programming and programming languages apply to robots.

Content: 

In the simple view, robots are mechanical devices controlled by embedded computers. Robots typically employ sensors, to obtain input about their environment and motors or other actuators that allow the robot to act in or alter that same environment. A necessary component of any robot will be a computer (also called a controller) which is running a program that takes the available input and translates it to an appropriate output. In a robot, output typically is physical action: moving a servo, spinning a motor, etc.

A computer in a robot is different than other computers in that the robot computer has hardware extensions that allow the computer to receive input from various hardware devices (like cameras, joysticks, encoders, touch sensors) and to control hardware devices (such as motors, servos, valves). A program on a PC is typically only looking at input from a keyboard or mouse (for instance) and deciding on an output which might be displaying characters on a screen. A program on a robot is typically looking at input from a joystick or environment sensor and deciding on a physical output, which might be setting a motor speed or opening a valve. The computer interacts with external hardware devices through reading or writing data to a port (or channel) which represents the actual physical connection (plugs and wires) between the controller computer and an external hardware device.

Typically any action a robot takes is the result of the instructions in the program running on the robot's controller responding to external stimuli. In order for a robot to complete its intended function, a programmer had to study the robots intended function and its physical (hardware) design and write the source code that maps all possible inputs to the appropriate outputs, enabling the robot to perform the intended function. A robot cannot function without a program to tell it what to do.

Normally when you program a computer, you will write your program and compile it on the same type of computer on which your program will execute. For instance, when developing for Windows, you will do your programming on a Windows computer and run the resulting program on a Windows computer. Programming robots is different because you will typically develop your program on a different computer than it will be executed on. For your robotics work you will most likely develop your program on a Windows PC and then transfer the program file to a robot's controller (deploying). When you run your robot program on the EV3, Tetrix or RoboRio platform, your program is actually running on a form of Linux. It is good to keep this concept in mind when programming robots, but the Java language has specific features that minimize this as a concern. We will discuss this a bit later.

 

Navigation:

Pages