Introduction to Programming

The UberBots use NI LABView to program their robot. If you are interested in learning to program with LABView, please see our intro to LabVIEW and NI's Learning LabVIEW page.


Aspects of Programming:


Structures

Coding is impossible without knowledge of the structures and syntax of the language. Every language has different syntax, but many structures and concepts remain the same. Here are some common structures and their LabVIEW equivalents. For demonstrative purposes, C syntax will be used to show examples as well.


If Statement

An if statement is a way of checking if something is true or not. If the conditional statement is true, then one set of code will be executed; otherwise, a different set of code will be executed. In traditional C code, an if statement looks like this:

if( conditional ){
   statements if true
}else{
   statements if false }

The conditional will evaluate to a boolean expression (either TRUE or FALSE). This will tell which section of code to execute. If the conditional is TRUE, then the statements within the first set of { } will be executed. If the conditional is FALSE, then the statements within the brackets of else will be executed.

In LabVIEW, if statements are called case structures. A boolean value is wired to the input terminal, and there will be two cases: TRUE and FALSE. Put code to be executed in either condition in the corresponding part of the case structure.

More Information
Top of Page

Loops

Loops are a section of code that are repeated again and again until a conditional statements becomes FALSE. There are many different kinds of loops. The two most common are While Loops and For Loops.

Loops in LabVIEW are contained in a structure similar to a case structure. The code inside them will be repeated until the conditional statement returns false.

More Information
Information on Passing Information Between Iterations
Top of Page

While Loops

A While loop is a set of code that repeats until a given boolean is false. This kind of loop can be thought of as a repeating if statement. Every iteration, the loop checks the boolean value. If the value is true, the code will be executed, if the value is false, the loop will be skipped over and the next line of code executed. In traditional C, while loop syntax is as follows:


while( conditional ){ 
statements to be repeated while conditional is true
}

First, the conditional is checked. If that is true, then the statements within the loops brackets will continue to be executed until the conditional is false.

More Information

In LabVIEW, code will be executed until a condition occurs. The loop can be configured to stop on a TRUE or on a FALSE boolean value (the default is to stop on TRUE).

Top of Page

For Loops

The for loop is another type of loop; it's also similar to the while loop. The main difference is that the for loop is based on the number of iterations and it is easier to work with iterations. In traditional C, the for loop syntax is as follows:


for (i = 0; i < 5; i++){
Statements to be repeated five times
}

There are three arguments to the for loop. The first (i = 0) is the initialization. There is a variable (i), and a statement setting it equal to something (in this case zero). Every time this loop executes, the variable i be set to the value of zero. The next arguement is the conditional. This loop will execute as long as the value for i is less than 5. Once that statement is false, the loop will stop. The final argument of the for loop is what will happen upon the loop's completion of an iteration. In this case, one will be added to the value of i.

More Information

In LabVIEW, for loops are different. They are strictly iteration based. The user must wire terminal for the number to times for the loop to execute. As long that is true, the code in the structure will continue to be executed.

Top of Page

Functions

In many programming languages (especially object oriented ones), functions are an integral part of the coding. A function is a single block of code that can be called wherever it's needed to perform its purpose (this is similar to the modules of the OmniPage System). LabVIEW also has the ability to have function-like execution. In LabVIEW, simple make another VI and drag it from the project explorer into any other VI to call it.

Top of Page

Programming Logic

Even though a programmer may know the syntax of a language flawlessly, that person may still have trouble writing effective code if he/she doesn't have correct logic behind it. Knowing how to structure code effectively and efficiently creates much better code overall. Teaching logic is very hard to do; the best way to learn is by studying the language you will be using and observing someone who knows how to use it well. Make sure to ask questions on now only how to do something, but also why something is being done.

Top of Page

Upcoming Events

Events in the next week:

Friday May 29

  • Team Meeting

Connect With Us

Follow us on Twitter! Connect with us on Facebook! Add us to your circles on Google+ Subscribe to us on YouTube!