LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

local variable and control & simulation loop, variable updates

Hi,

 

I am using local variable in my discrete system( creating a while loop ouside the control & simulation loop, as shown in the attachment). I use the  control & simulation loop to simulate my state space model and set output(k) as local variable and use it in the while loop.

 

I am trying to do following: excute the state space model at instant k and send the output(k) to while loop, by some logic part, I get the decision from this while loop, and finally feed the decision back to the orginal control & simulation loop.

 

My problem is, I don't know how to get these variables update properly. For example, in my program, when I run it first time, it shows bad result, however, when I run it a second time, it shows the favorable result(as in the attachment). That result is extremely weird. It seems there is something left in the memory after first running.

 

I tried to do following: assign different processors to these two loops so they can run parallel; and try to add some offset to the while loop (because it seems that the simulation loop is more demanding). However, my problem is not solved. Does anyone know where did I go wrong? Appreciate any kind help.

0 Kudos
Message 1 of 6
(3,326 Views)

You would probably be best served using something like a producer/consumer loop.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 2 of 6
(3,289 Views)

Classic race condition.  That's why we scream to avoid using local variables.

 

Why can't you just put everything into a single loop?


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 3 of 6
(3,272 Views)

@crossrulz wrote:

Classic race condition.  That's why we scream to avoid using local variables.

 

Why can't you just put everything into a single loop?



Hi, 

 

I tried to put them in a for loop to avoid local variable. But I have problem using the waveform chart to display the result as in the simulation loop. I have an output array of 8 elements, I want them to be displayed as 8 curves with the same time horizon as time evolves. Any suggestion about that?

0 Kudos
Message 4 of 6
(3,264 Views)

You just can't put the chart terminal in the simulation loop?  I'm not familiar with the simulation loop, but that doesn't sound right.  Otherwise I would suggest using a queue to pass the output data to another loop (Producer/Consumer).


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 5 of 6
(3,256 Views)

@crossrulz wrote:

You just can't put the chart terminal in the simulation loop?  I'm not familiar with the simulation loop, but that doesn't sound right.  Otherwise I would suggest using a queue to pass the output data to another loop (Producer/Consumer).


Hi, I think there is some misunderstanding. I meant in the for loop, how to display the 8 different curves(the output array has 8 elements) with the same time horizon? 

 

 

0 Kudos
Message 6 of 6
(3,251 Views)