LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Breaking a while loop using number

Hello everyone,

I am programming a stepper motor using LabView. One of the tasks of the code is to check if the motion of the motor has been completed. When I query the command I get either a 1:motion is going on, 0 motion has completed. Now I get this number as a number, ie blue wire. How can I use this number to exit my while loop? Essentially this number is a boolean so it would be great to use.

 

Thanks for the help

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

I suppose you could compare it to NOT zero where a 0 gives a false and anything else (a 1, in other words) is true, then invert the results to stop your loop on a 0.

 

It might seem a bit of extra code to have a value and invert it, but sometimes I am guessing the query is "Are you moving?" T/F and I want to preserve that logic.  If the query were "Am I stopped?" instead, I would reverse the logic and then you wouldn't have to invert the results.  This is strictly my preference, though.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 2 of 9
(3,010 Views)

Or you could use "equal to Zero," in your case meaning "is stopped" and not have to invert anything.

 

Cameron

 

To err is human, but to really foul it up requires a computer.
The optimist believes we are in the best of all possible worlds - the pessimist fears this is true.
Profanity is the one language all programmers know best.
An expert is someone who has made all the possible mistakes.

To learn something about LabVIEW at no extra cost, work the online LabVIEW tutorial(s):

LabVIEW Unit 1 - Getting Started</ a>
Learn to Use LabVIEW with MyDAQ</ a>
0 Kudos
Message 3 of 9
(2,999 Views)

@camerond wrote:

Or you could use "equal to Zero," in your case meaning "is stopped" and not have to invert anything.

 

Cameron

 


See my original post on why I had suggested what I did.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 4 of 9
(2,995 Views)

@billko wrote:

@camerond wrote:

Or you could use "equal to Zero," in your case meaning "is stopped" and not have to invert anything.

 

Cameron

 


See my original post on why I had suggested what I did.


Yep, but I inferred from the original question, "One of the tasks of the code is to check if the motion of the motor has been completed." that he might be looking at it the other way. No matter. I just thought that if the OP were a beginner, he also might not know that both functions existed. No criticism of your method, I've done things that way, too.

 

No hard feelings? Next time you're up my way, I'll get you a cup of SB coffee (or other, if you have a different preference).

 

Cameron

 

 

To err is human, but to really foul it up requires a computer.
The optimist believes we are in the best of all possible worlds - the pessimist fears this is true.
Profanity is the one language all programmers know best.
An expert is someone who has made all the possible mistakes.

To learn something about LabVIEW at no extra cost, work the online LabVIEW tutorial(s):

LabVIEW Unit 1 - Getting Started</ a>
Learn to Use LabVIEW with MyDAQ</ a>
0 Kudos
Message 5 of 9
(2,990 Views)

@camerond wrote:

@billko wrote:

@camerond wrote:

Or you could use "equal to Zero," in your case meaning "is stopped" and not have to invert anything.

 

Cameron

 


See my original post on why I had suggested what I did.


Yep, but I inferred from the original question, "One of the tasks of the code is to check if the motion of the motor has been completed." that he might be looking at it the other way. No matter. I just thought that if the OP were a beginner, he also might not know that both functions existed. No criticism of your method, I've done things that way, too.

 

No hard feelings? Next time you're up my way, I'll get you a cup of SB coffee (or other, if you have a different preference).

 

Cameron

 

 


Never hard feelings.  I was in a hurry so my post ended up seeming terse, when it was actually just kind of abrupt.  I actually concur with you that probably the best thing was to mention the most strightforward way first, followed by the option.  🙂

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 6 of 9
(2,979 Views)
No matter what, you never need to invert. Just change the loop condition from "stop if true" to "continue if true". 😉

(Of course if you need to combine several conditions, e.g. also a manual stop button, some logics are easier)
0 Kudos
Message 7 of 9
(2,961 Views)

@altenbach wrote:
No matter what, you never need to invert. Just change the loop condition from "stop if true" to "continue if true". 😉

<snip>

I try to stay away from that because I can get totally confused.  I don't know why, because it should be just as easy to figure out as the other way 'round, but my brain freaks when it sees the circular arrow.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 8 of 9
(2,942 Views)

Thanks for the help guys,

I went ahead and did X not equal to 0, to return true and wired that into my while loop and set it to continue if true.

Message 9 of 9
(2,928 Views)