01-30-2014 10:34 AM
Is there any way to move live data from inside a for loop to outside of the case structure in real time? I would like to graph data from a case structure in real time outside of the case structure. It would ideally include the information from the true case and then the wait period as a "0" for the false case. Attached is a simplified version of the VI i am working on. I have tried local variables but they will only read the first element the for loop puts out every T/F cycle. Any idea's are welcomed including complete change of structure to the VI.
Thanks!
Solved! Go to Solution.
01-30-2014 10:44 AM - edited 01-30-2014 10:49 AM
Your code makes no sense whatsoever. In your FOR loop you create an array with a single element, then try to index it out again. Why the detour? None of that code is needed. Also, the code outside the case structure executes only once in parallel to the FOR loop, so sharing data across will not really update anything. Also, your scalar indicator is not needed. Simply right-click the chart...visible iterms...digital display.
To share data between independent code segments, you would use queues or local variables, for example, but it seems that your current problems are much deeper. I would suggest you start with some tutorials about dataflow.
Please tell us exaclty what the code is supposed to do. There are probably much better solutions to all this.
01-30-2014 10:47 AM
The quick answer that comes to mind is to use a queue. You would want to put the reading of the queue and the writing to the chart in another While loop.
01-30-2014 11:05 AM - edited 01-30-2014 11:06 AM
@kspink wrote:
Is there any way to move live data from inside a for loop to outside of the case structure in real time? I would like to graph data from a case structure in real time outside of the case structure. It would ideally include the information from the true case and then the wait period as a "0" for the false case. Attached is a simplified version of the VI i am working on. I have tried local variables but they will only read the first element the for loop puts out every T/F cycle. Any idea's are welcomed including complete change of structure to the VI.
Charts often only make sense if they are updated at a constant interval, else you cannot label the x-axis as time.
The correct way here would be to spin the while loop at 10ms and use the case structure to either output zero or real data, depending on the state. The terminal of the chart belongs after the loop. Flip the boolean acording to the required state transition, and not with every while iteration.
01-30-2014 11:12 AM
Dividing by one and getting the remainder is not necessary either. That's always 0.
01-30-2014 11:17 AM
Here is one possible solution. Modify as needed.
01-30-2014 12:31 PM
Sorry the simplified version might have caused more problems. What I would like to do is create a program that will pump a linear actuator to act as a mock heart beat.
What I am currently doing is taking a .txt and using the "read from measurement file" and turning it into dynamic data. This is done outside the main while loop.
Inside the while loop is is a case structure wired to a not function connected to a shift register.
In the true case I use a for loop and convert the dynamic using a local variable and create an array by indexing the data with the iteration and quotient and remainder function. Within the for loop there is a wave chart, this graphs the data within the for loop.
In the false case there is only a wait until function. This is pauses the the graph.
Overall all I want to do is create an array (a .txt file mimicking the rate of ejection volume of the heart) that can output to a linear actuator. I want to be able to change the frequency of the curve (mock heart rate) And the duration of the phase (which includes a rest period)
01-30-2014 12:41 PM
Why read the same file 103 times? Just read it all at once. Then get the array of data out of it. You can then pass that array into your loops with wires and tunnels. You can index off any value you need from there.
01-30-2014 12:49 PM - edited 01-30-2014 12:53 PM
You still should program this as a simple state machine without inner loops (look at my earlier example for some ideas).
There are still plenty of very questionable constructs.
There are race conditions, because there is no guarantee that the "systolic" terminal is written before the corresponding local variable is read in the FOR loop. Why not just wire acrosss, eliminating the terminal and local variable? Why are you reading the same file 103 times? (We cannot tell how the reading is configured, so please attach the actual VI instead). Why are you dividing by 102 instead of 103? The last read is never seen! Since you never exceed the number anyway, you could just autoindex the dynamic array at the loop border and eliminate all of the useless index math..
Please attach the actual VI. Thanks!
01-30-2014 12:56 PM
@crossrulz wrote:
Why read the same file 103 times? Just read it all at once.
The read can be configured to read fixed size segments so this might not be the same. No way to tell without seeing the actual code.