12-22-2017 03:11 AM
Suppose x and y are two controls on front panel
Constraint: P<= x+y <= Q
How to program such that user cannot avoid this constraint.
12-22-2017 04:08 AM
Hi gkartik
Use an Event Structure to detect changes of x and y, then evaluate against P and Q and action based on that.
I have chosen to reset the value of x to 0 to show where the action would go but your requirements on how to modify x and y when x+y is outside of your P & Q limits would replace that.
Steve
12-22-2017 08:18 AM
It depends a bit on what you want to do. I'm going to assume P and Q are fixed, and just for the sake of argument, I'm going to assume that all the quantities are integer (as there are issues involving coercing Floats). I'll express the constraint as [P, Q], the interval from P to Q, including P and Q.
So suppose you have controls X and Y, and have initialized them such that X+Y is in [P, Q]. If you want to constrain X and Y in this way, I would create an indicator with the message "X+Y must lie in the interval [P, Q]" (you'd put the values for P and Q in this message, of course).
Now you want two Event Cases, with almost the same code in each. The Value Changed case for X uses the In Range and Coerce function (on the Comparison Palette), with P, X+Y, and Q as the inputs, and then set X to the Output - Y. You want to set this up to include both upper and lower bounds in the comparison. The code for Y is similar, except Y = Output - X. Do you see how this works? In the X case, X+Y is coerced to be in [P, Q], so to get the (coerced) value of X, we just subtract Y from "coerced X+Y".
Bob Schor
12-22-2017 10:04 AM
It's likely to be better code to stick with the single event case. Watch for both value changes.
Instead of that silly OR logic, replace with two case structures: one for over and one for under. Handle the appropriate logic.
Quick, clean, all of the logic in one place.
12-22-2017 11:23 AM
There are many ways to handle the restriction.
Which option do you want?
Another option would be to use two controls that are a transform of the current x and y, e.g.
Control A (defined as x+y and restricted with fixed boundaries.)
Control B (defined as x-y and not restricted in any way)
You could even create an xcontrol.