LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Active and deactivate control

Hello,

I am trying to input 'motion distance'  and 'motion velocity' for a motor using control. Since the motion time is fixed, konwing one of these two parameters will also know the other.  Therefore,  I plan to give user an option, either input distance or velocity.

So, I want to use radio check for distance and velocity mode. If distance mode is checked, the numerical control for distance is activated  and  the control for velocity is deactivated (in gray color). On the other hand, if the velocity mode is checked, the control for velocity is activated but the one for distanced is inactive.

Anyone can give me hint  to implement this? I don't want to  use loop structure to continuously check  the  status to save CPU resource. 

Thanks a lot for suggestion.

-Dejun
0 Kudos
Message 1 of 12
(3,861 Views)

Use an Event structure (Structures->Event Structure), create an event for Radio Buttons Value Change. In the event, wire your radio buttons icon  to a case structure. In the case structure, have a "0" and a "2" numeric constants, wire them outside the case stucture to two "Disabled" property nodes (right click on numeric control on block diagram, go to Create->Property Node->Disabled), each correspodning to the motor parameters you can set. You want a 0 going to the property node if you want it enabled, a 2 if you want it disabled and grayed out.

Michael

Message 2 of 12
(3,851 Views)


@Dejun wrote:
I am trying to input 'motion distance'  and 'motion velocity' for a motor using control. Since the motion time is fixed, konwing one of these two parameters will also know the other.  Therefore,  I plan to give user an option, either input distance or velocity.

It is not necessary to force the user to choose first what he wants to change, grey out things and complicate the user interface.

All you need is two controls, one for distance and one for velocity and the user is allowed to change either one of them at any time! However, changing one will update the value of the other (e.g. via local variable) such that the math is consistent. Attached is a simple example. Modify as needed. 🙂

 

Message Edited by altenbach on 09-25-2007 09:22 AM

Message 3 of 12
(3,845 Views)
Thanks a lot for replies.

Both methods use loop structure, which is what I want to avoid in my code. I don't want to use loop structure for such a trivial function in order to save CPU resource for more important functions.

So, I plan to give up using two controls and let use just input velocity.
0 Kudos
Message 4 of 12
(3,819 Views)


@Dejun wrote:
Both methods use loop structure, which is what I want to avoid in my code.

My loop is event driven and does NOT use any CPU resources unless one of the values changes. Even then, the CPU use is insignificant in the greater scheme of things. 🙂

You could waste or save way more CPU by programming the main tasks more or less efficiently. So Focus on that! 🙂

Message 5 of 12
(3,815 Views)
Altenbach, thank you very much for your very nice code.

Your code is event driven loop, that means user have to change the value of at least one control (clicking 'stop' is inevitable) to finish and exit this event loop, then proceed to other code parts.

Fpr my situation, the distance and velocity controls are just two among more than 10 controls on the program panel, so sometimes user do not need to change the default values of these two controls. I mean, sometimes user can just skip these two parameters and proceed to next step.

Using event-driven loop, user has to change at least one value and click 'stop' button.....
0 Kudos
Message 6 of 12
(3,812 Views)

That is still no problem.

For example, you can place this event structure inside your own big loop and make the event structure transparent by adding an empty timeout case with small (or even zero) timeout.

Message 7 of 12
(3,809 Views)
Can you give more details about  "make the event structure transparent"?

Sorry I only ever used simple event structure. A example VI code is greatly appreciated.

Message Edited by Dejun on 09-25-2007 11:59 PM

0 Kudos
Message 8 of 12
(3,805 Views)

The beauty of LabVIEW is the fact that things can happen in parallel and simultaneously. Here's a parallel loop containing an event structure that only spins when needed to keep the two controls consistent and uses near zero CPU. The main loop can spin at any rate you want and can contain other controls.

See if it all makes sense to you. 🙂

 

 

 

 

 

Message 9 of 12
(3,801 Views)
Thanks a lot Altenbach, your really nice code is just what I need!!!

One question: what's the purpose of input -1 to the shift register in the loop for event?  Never timeout?

Message Edited by Dejun on 09-26-2007 12:08 AM

0 Kudos
Message 10 of 12
(3,798 Views)