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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Circular Numeric Control

Hello,

 

I set a numeric control with a min of 0 and a max of 23. I want to make it so that if you try to go above 23 the numeric control goes back to 0 and vice versa, if it goes below 0 i goes to 23. Basically I want this to work in a circular type of motion.

 

Maybe there is a better more elegant way to do this, with an array for example.

 

Thanks!

0 Kudos
Message 1 of 8
(1,638 Views)

Are you aware of what is sometimes called the "mod" operator?  "a mod b" means "the remainder when you divide a by b" (b must be non-zero, and is generally positive, with the remainder also usually positive).

     23 mod 5 = 3 (23 / 5 = 4, remainder 3)

    -23 mod 5 = 2 (-23 / 5 = -5, remainder 2)

 

Have you looked at the Numeric features that come with LabVIEW?  Look at the function called "Remainder and Quotient", and get the answer to your question (I'll leave the details to you -- you should be able to figure it out for yourself, even without the hints in the first paragraph).

 

Bob Schor

0 Kudos
Message 2 of 8
(1,631 Views)

I am aware of the "Quotient and Remainder" function, it was one of the first options/ideas I had when I started working in this project but I didn't like the fact that it wasn't "intuitive" in the control side as the values would be outside the range (see picture attached).

 

I would prefer if the values weren't outside the range (0-23) on the control side, and I was wondering if there is a different method like changing a property node value of the control for example since that's what I used to set the Min and Max.

0 Kudos
Message 3 of 8
(1,601 Views)

One of the reasons the Unofficial Forum Rules and Guidelines stress that it helps to post code rather than pictures (and is a topic I've been known to stress, as well) is that it helps us to understand what you really are talking about!

 

I think I understand, now, what you want.  See if this is correct:  You'd like a Control that has the following properties:

  • It looks like a "normal Integer Control", with increment and decrement buttons.
  • It behaves as a "restricted range" Control, say taking on values from 0 .. 23.
  • It also has the property that it is "circular" -- incrementing from 23 gives you 0, decrementing from 0 gives you 23, and entering (manually) any number gives you "number mod 24".

Is this correct?  I've designed a number of these controls.  Do you know about Event Loops, and the Value Changed property for controls?  This lets you (almost instantly) "trap" when a Control has been modified (by a Front Panel interaction, typically) and lets you "post-modify" it, say by always replacing it with "value mod 24".

 

Bob Schor

 

P.S. -- go read those Unofficial Rules, and thank Hooovahh for posting them.

Message 4 of 8
(1,582 Views)
  1. If you want a circular numeric control, use a knob, dial, or gauge where the scale is 0..23 and the scale is set to cover 360 degrees.
  2. If you want a plain numeric control, do the quotient and remainder and write back the remainder via a local variable whenever the value changes. (Here the VI needs to be running for the control to work properly, of course)
  3. Create an Xcontrol that implements your desired functionality (This will even work correctly in edit mode)
  4. Create an enum with 24 items. This will automatically roll over. (This assumes the values are integers)

As you can see, you have plenty of options! Is the control an integer or floating point?

 


@ht210 wrote:

Maybe there is a better more elegant way to do this, with an array for example.


Can you explain why you think an "array" would help? That seems to be completely unrelated to the question.

0 Kudos
Message 5 of 8
(1,564 Views)

@ht210 wrote:

I would prefer if the values weren't outside the range (0-23) on the control side, and I was wondering if there is a different method like changing a property node value of the control for example since that's what I used to set the Min and Max.


If you use the Q&R method, you don't even need to define the min&max. Don't overcomplicate things!

 

Here's a simple example:

 

altenbach_0-1610211066216.png

 

Message 6 of 8
(1,557 Views)

Yes, this is exactly what I want to do. Sorry for not posting code, I thought it wasn't necessary as what I wanted to achieve was pretty straight forward.

 

Doing an event structure and having the event structure "re-assign" or overwrite the value once it goes outside the allowable range sounds like a good idea, ill give this a shot. Is the "Value Changed" property for controls the same as the Value property node?

 

@altenbach:

The snippet really helped out a lot! And regarding the array, I was thinking that maybe by cycling through the elements of an array I could achieve what I wanted to.

0 Kudos
Message 7 of 8
(1,520 Views)

@ht210 wrote:

Doing an event structure and having the event structure "re-assign" or overwrite the value once it goes outside the allowable range sounds like a good idea, ill give this a shot. Is the "Value Changed" property for controls the same as the Value property node?

 


You can place my code inside an event case with no changes.

 

Watch your terminology!

 

  • A "value changed" is an event type for a control, not a property
  • A value property node can be used like a local variable, except that a local variable is much more efficient. Property nodes carry much more baggage under the hood, so stay with the local variable here.
  • I did not post a "snippet", just an image. The term snippet has a special meaning in LabVIEW.

@ht210 wrote:

The snippet really helped out a lot! And regarding the array, I was thinking that maybe by cycling through the elements of an array I could achieve what I wanted to.


An array has nothing to do with this problem. You can cycle through the index, getting array elements in sequence and wrapping to the other side when the end is reached.

 

For example, the following code would cycle through all elements of an array forever.

 

altenbach_0-1610402037751.png

 

 

 

Message 8 of 8
(1,518 Views)