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.
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.
07-09-2015 04:26 PM
Hello,
I am trying to write a VI that will continuously cycle a stepper motor that is connected to a linear actuator. I would like to be able to command it to move the linear actuator 2 inches, retract it to 0 inches, and loop this profile so that it will continue to move without user interation (aka. not having to have a person click the button to execute profile everytime it completed those moves.) I have figured out how to program it to move the desired length however it will not continuously loop even through the code is placed in a timed loop. Here is a .png file of the block diagram (I have also attached it):
I am using LabVIEW 2014 along with the SoftMotion module, Real-Time Module, and a cRIO-9073 chassis. I have exhausted all of my ideas; therefore, any help on how to loop or continuously repeat this profile would be greatly appreciated. Thank You!
Solved! Go to Solution.
07-09-2015 04:30 PM
If you attached real code instead of just a picture, we could try it (maybe putting in our own dummy functions) and be much more helpful. Plus my eyes aren't good enough to see the details ...
Bob Schor
07-09-2015 05:04 PM
07-09-2015 05:06 PM
I recommend creating an indicator to check the error on the output of the timed loop.
07-09-2015 05:09 PM
Function blocks can be tricky to get working properly. I would recommend looking at the SoftMotion property/invoke node examples instead of using function blocks. I think there is a state machine example that you should be able to easily modify to suit your needs.
The 'execute' input on function blocks is rising edge sensitive. So what is happening is when the user clicks the "execute" control, the first function block will start. When the motor completes that move, it will assert the 'done' boolean and this will cause the second function block to execute (because it will see a rising edge on its 'execute' input). What you want to happen is when the second function blocks finishes, you get a rising edge on the 'execute' input of the first function block so that it starts again. You should be able to do this with a shift register and some boolean logic.
Thanks,
07-09-2015 09:14 PM
Sorry, my bad. I tried copying the attachment to a Block Diagram, and it didn't expand. I must have overlooked the picture (that is obviously a snippet) in the post.
Here's a question -- why is this in a Timed Loop? If you just want it to repeat, wouldn't a While loop (for a For loop if you want it to do it N times) work?
BS
07-09-2015 11:13 PM
A while loop would work just as well as a timed loop. However, I wouldn't recommend a For loop. The motion function blocks (and maybe all function blocks) are designed to be timed loop safe because they never block. On a rising edge of the 'execute' input, the function block will issue a start move command and then immediately return. The next iteration of the loop the function block will just reflect the status of the move on the 'done' output (unless it sees a rising edge on 'execute', in which case it will start another move). What this means is that you don't know how many loop iterations will occur before the move is done, and therefore it would be difficult to know how many iterations to run the For loop.
In general, I wouldn't recommend using motion function blocks unless you have to use them in a time critical loop. Using function blocks can be nice, but they aren't very LabVIEWy and so I hesitate to recommend them. I see nothing in your snippet that suggests you need to use function blocks. so I would ditch them in favor of using motion property/invoke nodes in a state machine.
07-10-2015 09:31 AM - edited 07-10-2015 09:33 AM
Thank you all for your help and suggestions!
I found the Axis Line State Machine example and it works; however, I could not modify it to loop the profile.
I took the suggestion of applying the boolean logic to my code. I added a shift register and wired the 'done' output to the shift register. Then I added the 'or' boolean operation and wired it to the shift register and the execute button. I wired the output of the 'or' operation to the execute slot in the first function block.
The trick to have it loop is to change the mechanical action of the 'execute' button from 'Switch When Pressed' to 'Latch When Pressed'. The VI will now loop the position commands.
07-10-2015 09:42 AM
You should mark Paul's message #5 as the solution to your problem rather than your own message since he is the one who gave you the idea on how to solve it.