Go to Post Einstein 2015 was just a tryout for FIRST's next warehouse forklift operator. - Jay O'Donnell [more]
Home
Go Back   Chief Delphi > FIRST > General Forum
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
Prev Previous Post   Next Post Next
  #4   Spotlight this post!  
Unread 06-02-2013, 09:15
apalrd's Avatar
apalrd apalrd is offline
More Torque!
AKA: Andrew Palardy (Most people call me Palardy)
VRC #3333
Team Role: College Student
 
Join Date: Mar 2009
Rookie Year: 2009
Location: Auburn Hills, MI
Posts: 1,347
apalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond repute
Re: Using Timers in Labview

The right way to do this in LabVIEW is with a state machine.

A state machine basically works like this:
-You store the state of the machine as an integer number or enum
-Every loop, you run code conditionally based on the current state, and evaluate if you should change to another state
--If you decide to change, then you set the new number or enum of the state
--If you don't want to change, then you set the same number as the currents tate
-We will also keep a loop counter which we will use to decide to transition.

In LV, you would implement this as a shift register or feedback node, integer number, and case structure. The number has to be integer, not float, with a blue wire.

You would then define each state, and assign it a number. Alternatively, you can use an enum, and define each state both a number and a name. The result is the same, since an enum can act like a number when you want it to. It looks like your states are:
-idle
-fire_open
-fire_close
-reload_wait
-reload_run
and they always run in that order.

I would then create a feedback node or shift register for a loop counter, and case structure with a panel for each of the 5 states.

Most of the cases will look similar, and basically do this:
-Add 1 to the loop counter
-Check if the loop counter is >= a threshold
--If yes, increment the state number and set the loop counter to zero
--Else leave the state number and loop counter the same.
-For the highest state, you will have to set state to 0 instead of increment it
-For the idle state, you will not use a timer, but the push of a button to increment the state number and reset the loop counter.

What's cool about state machines is you can modify the code in each state to create fairly complex transitions between any states, just by setting the state number correctly.


I'll post a VI of it later. This can go anywhere in the code without blocking, and can be interrupted by overriding the state (the flat sequence can't easily be interrupted).
__________________
Kettering University - Computer Engineering
Kettering Motorsports
Williams International - Commercial Engines - Controls and Accessories
FRC 33 - The Killer Bees - 2009-2012 Student, 2013-2014 Advisor
VEX IQ 3333 - The Bumble Bees - 2014+ Mentor

"Sometimes, the elegant implementation is a function. Not a method. Not a class. Not a framework. Just a function." ~ John Carmack
Reply With Quote
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


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

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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