LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do you compare continuously collected data?

Solved!
Go to solution

Hi Lynn,

 

OK, your suggestion about the 3 case structures was wonderful.  It solved a whole bunch of problems for me.  Now, I am back to a question of logic, or sequence, not sure which.  I eliminated the shift registers since I don't need them now.  So, now I have 3 case structures (True and False cases only), just as you drew in your diagram, inside the WHILE loop.  The WHILE loop measures a voltage, and then sends it to the 3 case structures, and only one of the case structures can be TRUE.  The TRUE case executes a simple calculation and outputs a command to change the speed of my mechanical system based on the measured voltage.

 

Consider that I have a LOW value, a HIGH value, and the range of values in between HIGH and LOW, is the MID RANGE.

 

In the LOW case, the output command generated by this case causes a slight decrease in speed of my mechanical system, which registers as an INCREASE in the measured voltage, due to the feedback sensor we are using. 

 

decreasing speed = increasing measured voltage

increasing speed = decreasing measured voltage

 

higher measured voltage = higher speed command

lower measured voltage = lower speed command

 

measured voltage within MID RANGE = NO CHANGE IN SPEED COMMAND

 

 

When the WHILE loop repeats, it sees a higher voltage than before, and it issues a higher speed command, which then brings the mechanical system back to the original slower speed where it started before the first WHILE loop execution.  In other words, an oscillation sets in. 

 

What I would like is for this (LOW) TRUE case structure to increase the speed several times before the WHILE loop measures the voltage again.  I would like the CASE structure to execute until the voltage measurement exceeds the LOW case structure, making it FALSE, and then the MID-RANGE case structure would be TRUE.  Likewise, I structure the calculation in the HIGH case structure to be the opposite of the LOW case, so, that it also moves in the direction of the MID range.

 

So, for example, in the HIGH case, what I am hoping is that I can write my calculation/speed command so that it takes the measured value from the WHILE loop, and then adjusts (increases) speed to decrease the voltage in the direction of the MID RANGE.  However, if it simply goes back to the WHILE loop, it will issue a new command that will decrease the speed, and the oscillation is underway.  I would prefer that the calculation in the case structure repeat itself and incrementally increase the speed (to decrease the voltage) until it reaches the MID-RANGE.  The calculation is written such that it increases (or decreases) the speed by a fixed % of the current speed, i.e. SPEED =  SPEED + 0.2*SPEED, will increase the speed by 20%.  I would like it to keep adding 20% and 20% and 20% until it reaches the MID RANGE.  The calculation in the MID RANGE does not change the speed; it holds the speed constant, which is what we want to achieve. 

 

But, if I put a WHILE loop inside the case structure so that it repeats 20% + 20% + 20%, the WHILE loop never exits the case structure to return to the larger WHILE loop.  It stays trapped in the one case structure because the voltage measurement in the outer WHILE loop has no way to be executed again.

 

Is there a way that I can make the calculation and speed command in the HIGH (or LOW) case structure repeat itself several times, changing the speed command by 20% with each cycle, until the measured voltage reaches the MID RANGE?  Right now, the case structure only executes once, and then the system oscillates with subsequent iterations of the WHILE loop.

 

Thanks!

 

 

 

 

0 Kudos
Message 21 of 26
(826 Views)

I am not sure I followed all the details of your description.

 

It sounds as though your control system could be a state machine.  Since state machines in LV are usually implemented as a while loop containing a case structure, you are already started in the right direction.  You could have a Too High state, a Too Low state, and a Just Right state.  Of course several other states for initialization, shutdown, and other things would also be included.  In the Too Low state it would issue the command to reduce the speed.  Then it would check the voltage again and return to the Too Low state if still low and do this as often as necessary until the signal reaches the mid range when it goes to the Just Right state.

 

You may need to adjust the size of the speed changes or the time between issuing a speed command and reading the result, depending on the parameters of your mechanical and sensing system.  This is the same tuning process you would need for any feedback control system.

 

Lynn

0 Kudos
Message 22 of 26
(820 Views)

Thanks a lot, Lynn. I apologize for the excessive detail.  The system is fairly complicated, and I had a hard time describing it to be easy to understand.  I happened to watch the tutorial on state machines the other night, so, I will watch that again and see if I can figure out how to apply it to my system.

 

Perhaps my underlying question from previous post can be answered this way.  Is it possible to put a WHILE loop inside a CASE?  If so, how do you exit the WHILE loop and the case?

0 Kudos
Message 23 of 26
(816 Views)

Yes, you can put while loops inside case structures.  Making sure that they terminate is the issue.

 

The advantage of the state machine in a situation like this is that you only have one loop.  Rather than staying in some inner loop until the condition is met (during which time the program will not respond to user inputs such as Halt!), it enters one case for a brief time, performing a simple task, and then leaves that case.  If the task is not complete, it returns immediately to the same case, except when some higher priority command has been received.

 

Lynn

0 Kudos
Message 24 of 26
(809 Views)

Hi Lynn,

 

I am creating a state machine, because, I think it may work for me.  If you look at the attached picture, is this allowed?  And, will it just keep executing the MID RANGE ad nauseum?  I want the state machine program to move from LOW to MID and from HIGH to MID, and once it is in MID, to stay there, i.e. to move from MID to MID.

 

What do you think of the attachment?

0 Kudos
Message 25 of 26
(797 Views)

You do not show any output, but I am presuming that you will be using the output from the Select as the output and that it will be returned via a shift register as the next state.  For that situation what you have show will stay in the MID state forever.

 

Now, how does the program get out of that state to quit?  State machines, especially those which interact with hardware, will usually have initialization and shutdown states as well as the "operational" states.  Do you have a mechanism not shown which can alter the next state based on user inputs, errors, or other conditions?

 

Lynn

0 Kudos
Message 26 of 26
(789 Views)