State machine in LabVIEW?


So I have been wondering…

I want to help students write in LabVIEW next year, but I really don’t know it all that well myself yet.

First off, last year I had, in C, a state machine for autonomous. It was an integer paired up with a giant switch/case; there were states for “moving forward”, “turning left”, “short segment moving forward”, etc. It worked well. But it only worked well because there was a round robin method of execution–the arm control code got executed (feedback loops for the arm joints), the drivetrain control code got executed (feedback loops for the two crab drive mechanisms), and any other support code got called, once a loop. Now that we have LabVIEW, how do I implement a similar setup?

I have seen a Case statement for LabVIEW, but does that exclude any other code that might need to be executing? I need my feedback loops in one spot, executing all the time. How are auton and teleop separated in LabVIEW?

I am trying to write up something that will at least take user controls as input (instead of encoders and sensors) and output to “motors”–indicators.

Is there a better method to learn LabVIEW?

Thanks for your help…now that I am back to being a n00b…:smiley:


EDIT: For that matter, how do I regulate a feedback loop to run exactly every X milliseconds?

Labview is inherently parallel. If you want your feedback loops to run all the time, put them outside the case statement. If it depends on something from inside the case statement, run a wire from inside the case statement to your feedback loops outside.

See the code team 39 posted for an example:

See this thread on the FIRST forums:

Be warned… When you say exactly, be sure that’s what you need. If you use a timed loop to do everything, you will have lots of problems. It’s not like there is a turbo button on the controller and making everything on the controller high priority will keep the CPU from being lazy. Consider the timed loop to be a timer interrupt service routine. Only put the things in it that NEED to be exact… and it had better be a small amount of code.

For the general case, a simple “Wait Until Next ms Multiple” VI will do the trick. It takes into account the time that the code in the loop takes to execute and should give you a consistent loop rate.


Thanks for the advice.

I am beginning to understand how LabView works. It seems like there would be a way to configure the cRio to sample every x milliseconds, and that time-critical part of the code would be isolated from my user code. If that’s the case, there’s not much use in using a timed loop; if I write it correctly, the data flow of each sample coming in should do that.

I wish things weren’t so fuzzy. Working on a beta team would have been so exciting!