Tetrix

Overview: 
Explore the general ideas behind programming and how it applies to robots.
Objectives: 

Understand the general idea of what the programming activity is, how we do it and how a program is the result. Understand how these ideas apply to a robot.

Content: 

Simply put, a program is a set of instructions that describe the actions we want a computer to take to reach the desired output (result) from a set of input(s). That set of actions, taken as a whole, is also called an algorithm. The instructions to making a peanut butter and jelly sandwich qualify as an algorithm:

Take two slices of bread
Open jelly jar
Open peanut butter jar
Spread jelly on one side of one slice
Spread peanut butter on one side of the other slice
Place the two slices together so that the covered faces touch

Keep in mind that just like regular instructions, a program is written sequentially, and will run sequentially. In this silly example, I am assuming some pre-built instructions are in place that provide the small details of how you open a jar of peanut butter, and that you should use a knife when doing the action of “spreading”. This is a good example of the fact that we will not have to give every tiny instruction at the lowest level, but will be able to use some pre-built functions that are provided by the programming language or a robotics support library (these functions would be an API).

While the particular statements or program design we might use will vary with each language, generally the steps to achieve the output are the same. We can express these steps in English using normal language to define the steps and create an initial design for a program, without worrying about how a specific programming platform wants us to express a particular instruction. In effect, we write a program in English. This is called using pseudo code, that is, a made up computer language.

For example, lets say we want a robot to drive in a square pattern, for 3 seconds on each side. We could write this program in pseudo code as follows:

drive.forward
wait.3seconds
drive.stop
turn.right.90degrees
drive.forward
wait.3seconds
drive.stop
turn.right.90degrees
drive.forward
wait.3seconds
drive.stop
turn.right.90degrees
drive.forward
wait.3seconds
drive.stop

Notice that we just made up this "language", but it does express the idea of what the program has tell the robot to do to achieve the desired result. The function that we need in order to move forward may not be exactly “drive.forward”, but writing this pseudo code gave us a framework to think about what we are doing without worrying about the specifics of the language.

Lets do another example. Lets say we want a robot to drive forward until it hits an obstacle, using a touch sensor to detect the obstacle. When we contact an obstacle we want to back up a bit and stop. The touch sensor is on the front of the robot.

drive.forward
label:keepdriving
if touchsensor.istouching
    drive.stop
    drive.backward
    wait.1second
    drive.stop
otherwise
    go to keepdriving
end of question

We can use pseudo code to think through how we can produce the desired result of the program and design the steps or algorithm needed to achieve the result. Then we can use that pseudo code to as a guide to write the actual program in a real programming language.

Note that block or visual programming tools are based on this idea of designing programs in simplified terms and then these tools write the actual program for you.

Another powerful tool you can use to design a program is a Flowchart. We are not going discuss them here but flowcharts are very useful in designing algorithms to solve problems. You can create flowcharts online at draw.io.

There other techniques and tools available to help in program design but once the algorithm is designed, you will express those steps in an actual programming language to create your program.

As an exercise, write the pseudocode instructions to get from your classroom to your school's front office. What are the functions in the API that you used to write your pseudocode?

 

Navigation:

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:

Pages