28
Sep
10

FRC LabVIEW Programming – more basics

LabVIEW is a Graphical Programming Language. As a programming language it has a lot of the constructs as text based languages but also has a lot of features that make it easier to use. It also has things to keep in mind when you’re programming.

First thing to remember is that LabVIEW is a data flow language. What that means is that a block has to have all its connected data inputs ready before it executes. Also, there is no guarantee of order of execution of the blocks unless they are wired from one to another. In the example below, block 1 will not put out its output until the two inputs are both ready. Also, with block 2 and block 3, there is no way to tell for sure which block will execute first.

The main way to sequence blocks is to use the error wires to sequence the blocks as shown below.

Above, since all of the inputs have to be at the block before it executes, since the output of block 2 goes to block 3, this will force block 2 to execute before block 3.
Another important item that you need to be aware of is that Loops are threads. What that means is that each loop executes independent of each other and executes at the same time…as far as you’re concerned. An excellent use of this feature for your FRC Code is one loop waiting for a button to be pushed to kick while another loop is taking Joystick inputs to drive the robot. The two loops below both run at the same time and would see no difference in execution. One thing to remember is to put “wait” blocks in the loops. Without the wait blocks other loops may not have any time to execute because one is taking up all the processor time. In the example below, without the wait block in the loop with the button read all that would be going on is the processor waiting on buttons the joystick. The loop with the joystick read would only run occasionally and you would see a lot of sluggishness in the movement of the Robot.

Another important construct in any programming language is the state machine. The state machine allows the robot to do one step, once complete, do the next, then do the next, etc. This is great for the autonomous mode where you want to do a sequence of steps. Such as move forward, stop, kick, move forward again, etc.

The pictures below show a simplistic state machine example with 3 states and an idle state (state 0). In the Begin block (in robot main) you would initialize the State Number.vi with a 1. Then once you start executing the loop the state machine is in it would execute the case #1. Of course you would actually need to do something where below I just say to do something. It may be drive the motors forward for a certain amount of time. The true/false case inside the state case should have the output of something with the output of false if not complete and true if the operation is complete. Once the operation is complete a 2 would be output and put into the state number.vi.

Once the state number is 2 then the state case 2 would be executed. Notice the true/false case shown in the picture below shows the false case. What this shows is that if the operation not complete (i.e. a false is output) the state case number stays at 2. And again, once whatever operation is complete and a true is fed into the true/false case, the case number would be changed to 3 (not shown below).

Once the state case is 3, again some actions are performed. Since 3 is the last case we have, once the operation is completed a 0 is put into the state number.

In this case we do nothing else we would just stay in case 0. In this case there is no way to move to another case without re-starting.

Now that I’ve talked about LabVIEW and some concepts of programming, next week, I’m going to go back and talk about some LabVIEW navigation and short cuts that are helpful.

Advertisements

0 Responses to “FRC LabVIEW Programming – more basics”



  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s


%d bloggers like this: