10-01-2013 09:51 AM
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
10-01-2013 10:01 AM - edited 10-01-2013 10:01 AM
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.
10-01-2013 10:18 AM
Or you could use "equal to Zero," in your case meaning "is stopped" and not have to invert anything.
Cameron
10-01-2013 10:26 AM
@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.
10-01-2013 10:36 AM
@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
10-01-2013 11:08 AM
@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. 🙂
10-01-2013 11:45 AM
10-01-2013 01:41 PM - edited 10-01-2013 01:41 PM
@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.
10-01-2013 02:04 PM
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.