Java

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:

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. Provide Examples.
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:

Pages