07-09-2015 05:31 PM
Hey guys.
I am trying to build a motion controlled data acquisition unit and I am in way over my head. I am new to LabVIEW so bear with me.
For starters I am using the NI USB-6212 with LabVIEW 2014 and a 200 steps/rev stepper motor.
The VI I am using is attached. I am able to use it as written successfully to turn the motor but I am having trouble modifying it to do anything remotely like what I need.
Essentially I want my VI to do the following:
-User presses a button on the front screen
-VI pauses for X seconds
-Motor turns for 1 rev (200 steps)
-Pause again for X seconds
-Repeat for X times
-Return to the starting position
-Break/ stop
Eventually I need to add in the motion of a linear actuator and data logging into the pauses of the stepper motor but I figure this is a good place to start.
Any help at all will be greatly appreciated.
07-10-2015 08:56 AM - edited 07-10-2015 08:56 AM
You have a good start, getting the instrument to do what you want is the hardest part and it sounds like you've figured that out.
From the steps you listed, it sounds like you want to use a State Machine architecture. You can follow that link to see how that would function and LabVIEW also ships with a Simple State Machine template you could start from. Now, you have a whole bunch of parallel While loops that you don't need because all of that can go in the same loop. All of your pre-loop code would go in the "Initialize" state of your state machine and the post-loop code can all go in the "Exit" state. Read through that tutorial and check out LabVIEW's shipped template and you'll see what I'm talking about.
You have some loops just continuously writing the boolean output values. You don't need to do this over and over. You can just write True and leave it until you want to write False. With the state machine, you could have a state that writes the value and essentially just trigger that state when you want to switch.
Cheers
--------, Unofficial Forum Rules and Guidelines ,--------
'--- >The shortest distance between two nodes is a straight wire> ---'
07-10-2015 03:51 PM
Thanks for the help. I have created the state machine and got it working by itself but I can't figure out the timing piece. I changed up the parallel while loops and turned into a for loop that runs once. Inside a put a delay so the motor will run for two seconds before breaking out of the loop (which it does). But since the case structure is inside a while loop, that two second clock keeps being called. ---
-How can I get it to run only once?
-And looking ahead, how can I go from one case to the next with timing instead of a button push?
07-13-2015 06:20 AM
You should learn more about state machines, what you created is not a proper one! Beside, never write values to an indicator via local variable (position string control). Use wire to set its value!
First make a clear flowchart about the states and transitions you need.
After this flowchart is made, you can start to build up a state machine properly, with typedefinied enums and case structure. You should have a "wait" and a "check for GUI" state too. You have to create a resettable timer subVI too. Have a look at the many examples...
http://www.ni.com/white-paper/3024/en/
07-27-2015 12:11 PM
I am trying to implement the suggested changes and I am still having difficulty. I broke down my state machine into actions rather than physical states and will control which action to perform with internal logic rather than writing a state for each physical state. Which is a better way to set up my cases?
Init
Home/record data
Start motor
Stop motor
Wait two seconds (this is how long I want the motor to run)
Return motor to zero (starting positon)
or can it be simplifed to
Init
Home/record data
Move motor for two seconds
Return motor to starting position
I am trying the first option because it was recommended in an earlier thread. The problem I am currently having is I can't figure out if or how to pass a currently running task from one case to another. If I initialize my motor in the first case, how do I start it in another and stop it in another?
Thanks
07-27-2015 12:28 PM
Cheers
--------, Unofficial Forum Rules and Guidelines ,--------
'--- >The shortest distance between two nodes is a straight wire> ---'
01-04-2017 11:56 PM
Hello, I am working with stepper motor which should be stopeed at particular position according to number of steps. I am using labview 2010 to control it. I am new to this area, so if any one can guide further to make design of it. I will really be thankful for that.
01-05-2017 12:06 AM