08-03-2015 04:16 PM - edited 08-03-2015 04:17 PM
I want to allow the user to specify a curve like this:
Such that some subVI outputs the value A2 when a time variable is within the range R1, A1 when the time variable is within the range R2, and A3 when the time is within the range R3.
My design looks something like this:
With error checking that looks like this:
My question is, is the array based approach optimal? How else could I tackle this?
Solved! Go to Solution.
08-03-2015 04:49 PM
I fixed some faulty logic and got rid of that concatenating string thingy. This should be much better at error checking, even though it spawns a windows for each individual error.
08-03-2015 09:26 PM
I am not at all sure that I understand what you want. I see three time intervals, R1, R2, and R3 -- I assume it starts at T = 0, and the intervals are contiguous (even though the intervals in the picture are separated by an unspecified amount). I see three values, A1, A2, and A3, and assume A1 goes with interval R1, even though the picture shows A1 going with interval R2.
Can I assume that T starts at 0 (with value A1), and always increases? If so, then the algorithm is much simpler than you developed. However, if my assumptions are not correct, it doesn't make sense to proceed (I'll only muddy the procedings).
BS
08-03-2015 09:35 PM
Okay, sorry for the diagram confusion. I made the labels before thinking about associations. T starts at 0, and the infusion is 0 for some amount of time (or no time at all, the user decides this). Then, at a user specified time, an infusion of some amplitude starts, and stops at another user-specified time. The user can repeat this as many times as they want. Two infusions can't run at the same time (even for just a small amount of time, hence the error checking), can't be less than 0, and the start time must be less than the end time.
Now, I'm implementing this by allowing the user to fill in values into an array, which are then checked. There may be a better way to do this, though. The pics are snippets so you should be able to download the VI directly.
08-03-2015 10:49 PM
Sigh. You still seem to contradict the diagram, which shows R1, R2, R3 as time intervals, which are (by Common Sense) always positive, so you never have to do any error checking on the Arrays, though you could, I suppose, test if the values are all positive, which can be done "all at once" --
BS
08-03-2015 10:52 PM
Sorry for the poor explanations. The array will be user-editable, so they can enter whatever they want. That's why it needs to be checked for validity. Column 1 is amplitude, column 2 is start time of infusion, column 3 is end time. They could enter (-5,4,2), which is invalid, but I have to check for that. That is, unless there's some other way to do this that I'm missing.
08-04-2015 12:25 AM - edited 08-04-2015 12:29 AM
I haven't looked at the code, but there are a couple of things you can change:
08-04-2015 07:21 AM
I think I can summarize the conversation to this point as an answer to the original question (What is the best way ...) -- before starting to write any code, think carefully about what you want to accomplish, and write it down (otherwise known as "Write the Documentation First"). One of the points of a good User Interface is that it doesn't allow users to "make silly mistakes" -- it leads the user "by the hand", restricting the entries to "legal values" and requiring that entries be made in a logical manner.
So if you were going to have a list of Infusions to enter, it makes sense to decide on whether to enter Time Intervals (which are always >0) or Times (which, logically) are always in ascending order. You can (and should) decide which you want (or you could have a control that would let the User decide, but that might be too flexible) and then enforce your "rules".
Suppose you decided on "Intervals" (which seems, to me, to be more User Friendly). After the User has entered the intervals (and you've provided a nice plot of Infusion vs Time), you could allow the User to "split" an Interval, "Remove" an Interval, or "Edit the Infusion" of an Interval, or you could decide to have a simpler "Accept or Start Over" choice -- if you only have a few intervals, the last might be the simplest (and thus the Best) Design Choice.
Spending more time thinking before coding usually pays Big Dividends!
Bob (speaking from Sad Experience) Schor
08-04-2015 09:23 AM
Bob,
As always, your advice has been very helpful. Back to the drawing board!