From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
11-30-2018 01:23 PM
Hello,
Im new to labview and currently stuck on one task. I hope you can help me.
I try to build a VI where one has just two numerical inputs, one button and potentially a display for the resulting array on the front panel.
The first time one presses the button an array with one row and two columns with the two values respectively is created.
Everytime you press the button another row with other values you is added - as often as you want.
My idea was an event structure where one can add a row to an already existing Array. I got it working. But Im not getting the part where I have to make it recursive and run it without and pre-existing array.
Im very grateful for every help. Thanks
Solved! Go to Solution.
11-30-2018 01:29 PM
You have the right idea with an event structure. You want to combine an event structure, a While loop, and preferrably a case structure to create a State Machine. Your array can be stored in a Shift Register from iteration to iteration and appended to within a specific case or just within the event structure.
The Simple State Machine template that ships with LabVIEW is really the best way for new developers to get familiar with LabVIEW while utilizing a semi-scalable architecture.
Here's a broad example of how a state machine works:
Each of the states can tell the application to go to any state they want. Want to reinitialize? Go to the Init state again. Want to end the program? Go to the Exit state. Want each state to trigger another (like a sequence)? Have DoThing1 output DoThing2, which outputs DoThing3, which outputs Idle.
Cheers
--------, Unofficial Forum Rules and Guidelines ,--------
'--- >The shortest distance between two nodes is a straight wire> ---'
11-30-2018 01:36 PM - edited 11-30-2018 01:37 PM
@James.M wrote:
You have the right idea with an event structure. You want to combine an event structure, a While loop, and preferrably a case structure to create a State Machine. Your array can be stored in a Shift Register from iteration to iteration and appended to within a specific case or just within the event structure.
Here's an old example that you can modify for your purpose. (originally posted here)
(you could also use a feedback node instead of a shift register)
11-30-2018 01:44 PM
@Godeko wrote:
But Im not getting the part where I have to make it recursive and run it without and pre-existing array.
Make what recursive? Adding items into an array one at a time does not need recursion. Is this a homework assignment? Can you state the problem more clearly or show the homework assignment, if it is indeed homework?
11-30-2018 02:09 PM
In your subVI, you would use an uninitialized shift register (or better a globally initialized feedback node) and assignment the scalar input and array output to the connector pane
11-30-2018 05:18 PM
Sounds like you need to learn about Shift Registers. Why don't you attach some LabVIEW code (so that we don't do all of your Homework for you). It seems to me that you are describing an "iterative", not a "recursive", problem (though "tail recursion" and "iteration" do look very similar).
Bob Schor
12-01-2018 06:59 AM
Thank you very much guys. It will take me some time getting used to the shift registers, but this tool opens many more possibilities.
I got stuck on the idea of recursive functions that I didn't see this option.
@altenbach wrote:
@James.M wrote:
You have the right idea with an event structure. You want to combine an event structure, a While loop, and preferrably a case structure to create a State Machine. Your array can be stored in a Shift Register from iteration to iteration and appended to within a specific case or just within the event structure.
Here's an old example that you can modify for your purpose. (originally posted here)
(you could also use a feedback node instead of a shift register)
Ive modified the example and got it working after a while.
Thanks!
12-01-2018 12:02 PM
Seems to work. Good!
Some points:
12-07-2018 06:56 AM
@altenbach wrote:
Seems to work. Good!
Some points:
- Please do not maximize the front panel and diagram window to the screen. That's extremely annoying because you can only look at one thing at any given time. You probably need room to also see the help window occasionally. Nobody wants to stare at a gigantic diagram that is 90% whitespace.
- A good rule is to place the terminal of latch action booleans inside their respective event. This way you can verify that the event actually fired. Especially important with more complicated code. (If the terminal is not in the dataflow and read, it would not reset to false)
- You might want to initialize your shift register with an empty 2D array constant. Currently, the shift register clears when the stop event executes, but if you would abort the VI, the shift register contents content are retained until the VI leaves memory.
- Typically you would rename the label and boolean text to something reasonable. "Start Button" and "Start" are not descriptive of the current functionality.
- Since the array can grow without bounds, I would show the vertical scrollbar of it.
Thank you very much. At the moment its quit messy as I just try to get it working in any way, but I will keep it in mind for the final product as its going to be used my external users.
I have one more question or problem which came up working with the new array mechanic.
I need to give a small explanation on my project to understand it.
My project is programing and setting up a galvo system, where one can basically set up a angle of the galvos = output voltage of the DAQ.
As I already stated, this system has to be useable by other scientists which dont have any clue about the program.
What I want is that one can set different voltage values (first column) and times (second column). The output switches the voltages for the respective times. When it reached the last value it starts over again.
I got it working with a simple array one can modify (see voltageswap NI forum.vi), but I want it to feel more intuitiv. Thats why I wanted this function I asked my initial question for.
I tried to implement the solution I linked in my last post, but the problem is now that:
You can see it in the file voltageswap add NI forum.vi
The second while loop with the voltage analog input is just there to link the output to the input and check if everything is alright (which aperently isnt as already stated).
Im using a USB-6002 DAQ but that shouldnt be the problem.
I probably didnt understand the event and while-loop mechanics right and would be really happy if one can give a clue on what is wrong.
Thank you!
12-07-2018 07:11 AM - edited 12-07-2018 07:12 AM
Hi Godeko,
I tried to implement the solution I linked in my last post, but the problem is now that:
THINK DATAFLOW!
The FOR loop will restart as soon as the While loop starts the next iteration.
The While loop will start the next iteration as soon as all its included functions are finished.
The event loop is finished as soon as you press the Start button - as you configured it…
On your VI:
Why don't you use AutoCleanup?
Why do you index those array values in a very complicated way?