02-20-2014 04:24 PM
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.
02-21-2014 01:47 AM
You would probably be best served using something like a producer/consumer loop.
02-21-2014 09:38 AM
Classic race condition. That's why we scream to avoid using local variables.
Why can't you just put everything into a single loop?
02-21-2014 09:48 AM - edited 02-21-2014 09:49 AM
@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?
02-21-2014 10:30 AM
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).
02-21-2014 10:40 AM
@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?