Tetrix

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:

Overview: 
Explore how programming languages make computers work and how we use those languages.
Objectives: 

Understand lower and higher levels of programming instructions. Understand compilers, compiling, linking and deployment.

Content: 

At the hardware level, computers understand one language, called machine language (also called object code). This is the set of instructions supported by the computer's processor hardware and is specific to each type of processor. This object code language is numeric in nature and expressed in binary, which is a numeric coding made up of only 1s and 0s (base 2). It is very tedious to program in binary, so higher level languages were created to make it easier to create programs. In a higher level language, you use syntax that is English like and easier to understand to express what you want the computer to do. It is the job of the higher level language to translate those written instructions into binary object code for the computer to execute. In fact, when a program file is created by a higher level language it will contain only the binary instructions for the computer, not your source code.

Typically, the programmer writes instructions in the selected higher level language, Java in our case, and these instructions or source code are stored in text form in a file. This source file is then passed to a program called a compiler which translates the source language to object code in binary form and writes that to another file called the program. An example is an .exe file on Windows. There may be an additional step called linking which is the process of combining the programmers instructions with libraries of instructions created by someone else. Sometimes the program file may be sent to another computer for execution. This is called deploying.

When the program is run by the computer, the computers operating system opens the program file, reads and executes the binary instructions it finds.

The exact steps and processes taken by each language to convert source code into an executable program may vary but will always follow this general set of steps. The process of translating from source code to a computer-usable program is called compilation or compiling. It is important to note that compilation is a one-time packaging of a certain set of source code into a program file. If the source code is modified by the programmer after compilation, the previously compiled program file will represent the same set of source code that existed at the time of compilation. In order to use whatever changes are made in the source code, the program must be recompiled.

 

Navigation:

Overview: 
Explore what programming languages are and how we use them.
Objectives: 

Gain an understand what a programming language is. Understand the difference between text based and visual languages.

Content: 

When we are programming, that is creating a program for a computer to execute, we will use a programming language. Like English or Spanish, a programming language is a written way to communicate with someone (or something). Computer languages allow you to encode the operations you wish to have the computer perform with a syntax (language) that is much easier for you to understand than the numeric language (binary) that computers understand. There are many text based languages such as Basic, C, C++, C#, Java, JavaScript, Python and many more. Each language was created for various reasons to serve varied populations of programmers. In this course we will be studying the Java programming language.

Here is the Wikipedia description of a programming language.

When we say a language is text based, we mean that the language is expressed in written statements, which are typically entered into a text file and then processed for execution by the computer. Text based languages in general provide more capability in expressing what you want the computer to do at the price of being more complex to learn and use.

Note that there are also many visual programming tools (might be a stretch to call them languages) that seek to simplify programming by allowing the user to assemble programs by manipulating pictures instead of text. Such tools have visual objects that map to functions the computer can perform and programs are created by arranging such objects on a visual workspace. Generally such tools sacrifice some amount of capability for simplicity of learning and ease of use.

Navigation:

Overview: 
Explore what it means to program and why we do it.
Objectives: 

Understand at a high level what programming is and what it means to "program".

Content: 

When used in the context of computers, programming generally means the process of creating the instructions that a computer will follow in solving a particular problem or completing some task. The product of programming is a "program", which is a package of instructions that can be executed by a computer. A program typically directs the computer to accept input of some type and produce output of some type. Programs are at the heart of all computing and are what you are using when you play games, edit documents, make calls on your phone, interact with web sites or make robots move.

Here is the Wikipedia description of programming.

A video describing programming.

Navigation:

Customization Description: 
Overview: 

This course is intended to introduce the Java programming language to students using the EV3 (FLL), Tetrix (FTC) and RoboRio (FRC) robotics platforms. For EV3, the course moves the student away from block based robot programming to using a text based programming language. For Tetrix and RoboRio, the course will provide more instruction in Java itself, which is missing in existing materials. The course will teach a basic competency in Java with a focus on robotics applications. Robot construction will not be covered in any depth as it is assumed the student will have or acquire hardware building skills separately. The course is targeted to beginners and there are no prerequisites.

Get started using this course by clicking the first Unit and then the first Lesson. The Lesson content will be displayed and next/previous lesson buttons will appear at the bottom of each lesson making it easy to move between adjacent lessons.

Education Level: 
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: 
Explore what it means to program and why we do it.
Objectives: 

Understand at a high level what programming is and what it means to "program".

Content: 

When used in the context of computers, programming generally means the process of creating the instructions that a computer will follow in solving a particular problem or completing some task. The product of programming is a "program", which is a package of instructions that can be executed by a computer. A program typically directs the computer to accept input of some type and produce output of some type. Programs are at the heart of all computing and are what you are using when you play games, edit documents, make calls on your phone, interact with web sites or make robots move.

Here is the Wikipedia description of programming.

A video describing programming.

Navigation:

Customization Description: 
Overview: 

This course is intended to introduce the Java programming language to students using the EV3 (FLL), Tetrix (FTC) and RoboRio (FRC) robotics platforms. For EV3, the course moves the student away from block based robot programming to using a text based programming language. For Tetrix and RoboRio, the course will provide more instruction in Java itself, which is missing in existing materials. The course will teach a basic competency in Java with a focus on robotics applications. Robot construction will not be covered in any depth as it is assumed the student will have or acquire hardware building skills separately. The course is targeted to beginners and there are no prerequisites.

Get started using this course by clicking the first Unit and then the first Lesson. The Lesson content will be displayed and next/previous lesson buttons will appear at the bottom of each lesson making it easy to move between adjacent lessons.

Education Level: 
Overview: 
Learn about Interfaces which are definitions of the fields and methods implementing classes must expose.
Objectives: 

Understand Interfaces and be able to use them when appropriate.

Content: 

Just as a class is a description of an object, an Interface is a description of a class. An Interface defines the fields (variables) and methods that a class must provide (public access) to users of the class. The Interface does not define how a class derives the value of a field or the result of a method, only that a class that implements an Interface must expose that Interface's fields and methods. As such, the Interface defines a public facing API that the class must provide. Interfaces are also called Contracts, in that the Interface defines a contract or agreement (in terms of the fields and methods exposed) between a class and users of that class. Classes may extend only one (parent) class but classes may implement any number of interfaces.

One power of Interfaces is that any class that implements an Interface can be used where ever that Interface is defined as a required data type. This concept is best explained by an example.

A simplifed view of the PIDController class in the FRC library shows a constructor that takes two classes as input, a PIDSource object and a PIDOutput object. PIDSource and PIDOutput are both Interfaces. Digressing for a moment, a simplified PIDController needs two things to perform its function. An input or process control value that will be used by the PIDController to compute an output value, which must be sent to some other class for action. Now in many cases the input value will come from an encoder (counts) and the output value will go to a motor (power). You could define the PIDController class constructor as Public PIDController(Encoder enc, Motor motor). There are two problems with this. First, the PIDController class and the Encoder and Motor classes have not agreed on how data will pass between the Encoder and PIDController class and how data will pass between the PIDController and Motor class. The second issue is that the PIDController as defined will only work with Encoders and Motors. What if we wanted to use some other classes as the input and output objects? Interfaces solve both of these problems.

The simplified PIDController class constructor actually looks like this: Public PIDController(PIDSource source, PIDOutput output). PIDSource and PIDOutput are Interfaces and they define what fields and methods are required for any class that wants to act as a PID source or PID output object. These Interfaces define the contract between the PIDController class and any class wanting to act as a PID source data provider or a PID output data consumer. The example Interfaces look like this:

A class implementing the PIDSource Interface must provide a method defined as double pidGet(). That method must return the current input value to be used by the PIDController. Since any class passed into the PIDController constructor for input must implement the PIDSource Interface, the PIDController now knows what method to call on the source object reference variable to get the input value. For instance, the Encoder class implements PIDSource and as such must provide the method pidGet() along with its other methods. When pidGet() is called, the Encoder returns the current tick count. So an Encoder object can be passed to the PIDController constructor. But so can any other class that implements PIDSource. A class implementing the PIDSource Interface would look like this:

Any class that implements PIDOuput must provide the pidWrite(double value) method. That method when called, will take the passed value and perform some action with it. The PIDController knows that any class implementing PIDOutput will have  the pidWrite() method and so it knows how to send the output value it has calculated from the input, by calling the pidWrite method on the output object reference variable. A class implementing the PIDOutput Interface would look like this:

For instance, the Motor class implements PIDOutput and provides the pidWrite(double value) method and sets it's motor power from the value. So a Motor object can be passed to the PIDController constructor as an output object. But so can any other class that implements PIDOutput.

A simplified PIDController class would look like this:

An example of using these classes:

The key here is that the single implementation of the PIDController class can handle both the custom source and output classes as well as the standard encoder and motor classes.

Classes can implement more than one Interface along with any other fields or methods they wish. Interfaces are very powerful and allow a class expecting an Interface (like PIDController) to work with any number of other classes that implement that Interface.

Note that Interfaces only define the expected fields and methods to be exposed by the implementing class. The actual implementation (code) is contained in the class implementing the Interface.

Like many things in Java (and other languages), this is a basic introduction to Interfaces. There is a lot more to Interfaces which you can read about here. Here is a video on interfaces. This lesson should be enough to understand Interfaces and use them in your robot code.

 

Navigation:

Pages