Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   National Instruments LabVIEW and Data Acquisition (http://www.chiefdelphi.com/forums/forumdisplay.php?f=149)
-   -   State machine in LabVIEW? (http://www.chiefdelphi.com/forums/showthread.php?t=69513)

JBotAlan 08-10-2008 12:27

State machine in LabVIEW?
 
Hey,

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...:D

JBot

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

Joe Ross 08-10-2008 13:06

Re: State machine in LabVIEW?
 
Quote:

Originally Posted by JBotAlan (Post 769243)
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.

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.

Quote:

Originally Posted by JBotAlan (Post 769243)
How are auton and teleop separated in LabVIEW?

See the code team 39 posted for an example: http://forums.usfirst.org/showthread...8186#post18186

Quote:

Originally Posted by JBotAlan (Post 769243)
EDIT: For that matter, how do I regulate a feedback loop to run exactly every X milliseconds?

See this thread on the FIRST forums: http://forums.usfirst.org/showthread.php?t=9906

Joe Hershberger 23-10-2008 00:47

Re: State machine in LabVIEW?
 
Quote:

Originally Posted by JBotAlan (Post 769243)
Hey,
EDIT: For that matter, how do I regulate a feedback loop to run exactly every X milliseconds?

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.

-Joe

JBotAlan 23-10-2008 07:59

Re: State machine in LabVIEW?
 
Thanks for the advice.

Quote:

Originally Posted by Joe Hershberger (Post 771664)
Be warned... When you say exactly, be sure that's what you need.

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!

JBot


All times are GMT -5. The time now is 18:32.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi