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: 

Natural number output node

Hi there,

 

I have been trying to make a program which outputs a number based on the state of my motor.

The way I want to do this is as following:

If the motor turns one way, I want the number to increase by 1 everytime the gear of the motor presses a button

If the motor turns the other way, I want the same number to decrease by 1 everytime the gear of the motor presses a button.

 

The problem I have is that I cannot find a way to program it so that labview only responds 1x, right now when the button is being pressed it continually keeps counting.

Is there an option somewhere to only execute the if loop when a state changes? I have tried with event structures but have not been succesfull.

 

The way I programmed it now seems promising but for some reason the output of my formula node is not a natural number like the inputs, even though i only use the increment function

 

Here is a really short representation of my programme in pseudocode:

 

If Motor=10 and Stepcounter changes from 0 to 1:

   increment number by 1

If Motor=01 and Stepcounter changes from 0 to 1:

   decrement number by 1

 

Thank you for your time and help

Bram

 

0 Kudos
Message 1 of 9
(3,973 Views)

I would suggest to start with some LabVIEW tutorials.

 

  • What do you think would be different of you would remove the "equal TRUE" constructs? Same difference! (see also this long thread!)
  • "index array" is resizable. you only need one instance.
  • Please don't maximise the diagram to the screen. Very annoying.
  • You don't need a formula node. Why is the output a floating point number?
  • Why is your loop spinning millions of times per second consuming all available CPU resources of one CPU core?
  • Why do you show 8 elements of the array, but are only ever using two.
  • How are we supposed to simulate the motor.
  • There is no "if loop". I don't even know what that is.
  • You can use a latch action button to only be true for one iteration.
  • You can use shift registers or feedback node to maintain state.
  • What shoud happen if the motor "is" 11 or 00?
0 Kudos
Message 2 of 9
(3,954 Views)

See if this can give you some ideas.

 

 

Message 3 of 9
(3,940 Views)

The arrays shows 8 elements because the machine that we are making uses 4 motors, now we connect them to the pc via a DAQ and this gives the information to the motors in the form of an array, the first 2 elements of the array would signify the motor 1, the 3 and 4th would be the 2nd motor and so on. The motor can never be 11, because this would be a state where the voltage would be high on both poles. If the motor is 00 it means the motor is receiving no power and thus is off.

 

About the floating point number as output of the formula node, I do not know why LabView puts a orange line there and not a blue one.

0 Kudos
Message 4 of 9
(3,926 Views)

If you are trying to learn LabVIEW, use LabVIEW and forget about Matlab.  The logic that you describe in the Formula Node can easily be rendered as LabVIEW code, as illustrated in the Snippet below (drag this onto a LabVIEW 2015 Block Diagram and it will become executable LabVIEW code).  Note that if you start with a Boolean Plus State, it makes no sense to convert it to a numeric PlusState (0, 1) and then ask "If PlusState == 1" -- much simpler to ask "If Plus State = True".  Also, you should learn about While Loops, Shift Registers, and how a Shift Register can act as a "memory element" to keep track of Position.  [The code on the top is taken from your example, the code on the bottom is a non-Formula way of doing this -- the "else if" clause case is illustrated here].

Position Logic.png 

Bob Schor

Message 5 of 9
(3,888 Views)

(Nearly) the same without case structure(s) and loops:

check.png

(To get the very same result replace the XOR by an OR…)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 9
(3,848 Views)

@GerdW wrote:

(Nearly) the same without case structure(s) and loops:

check.png

(To get the very same result replace the XOR by an OR…)


 

Code is typically easier to read if you would replace the XOR with a "Not Equal". Less nerfy. :D. You should also initialzie the shift regsiter with an integer to make that glaring orange go away. 😄

 

Still, you and Bob are solving a different problem. Where is the array input? The original problem had an array with two elements (givind direction) plus another boolean (from an encoder).

 

0 Kudos
Message 7 of 9
(3,823 Views)

@Kpt.Brambaard wrote:

The motor can never be 11, because this would be a state where the voltage would be high on both poles. If the motor is 00 it means the motor is receiving no power and thus is off.


So 00 IS a valid state, e.g. if a fuse is blown somewhere. That would be very important to detect.

Also 11 cold happen if a moron wired things up. 😄

 

Code should be as smart as possible to handle everything. Don't sweep unexpected states under the rug but proactively handle them, even if their probability is near zero. Murphy's law applies in engineering more than anywhere else! Both of these states should be detected and throw an exception to notify the operator accordingly.

 

There are four valid states:

 

  • Forward
  • Reverse
  • Power loss
  • Wiring error

 

 

0 Kudos
Message 8 of 9
(3,815 Views)

Hi Christian,

 

Where is the array input? The original problem had an array with two elements

I didn't open the VI, I just looked at Bob's snippet…

 

Code is typically easier to read if you would replace the XOR with a "Not Equal". Less nerfy.

I had a lot of boolean logic stuff while apprenticeship (using pneumatic valves :D).

So whenever there is a problem involving boolean logic I think about AND/OR/XOR functions (or LabVIEW's CompoundArithmetic). Using (Un)Equal looks wrong in my eyes…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 9
(3,766 Views)