LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Controlling a stepper motor position with timing

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. 

 

0 Kudos
Message 1 of 8
(4,361 Views)

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>   ---'


0 Kudos
Message 2 of 8
(4,260 Views)

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? 

0 Kudos
Message 3 of 8
(4,227 Views)

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/

 

0 Kudos
Message 4 of 8
(4,187 Views)

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

 

 

0 Kudos
Message 5 of 8
(4,115 Views)
Usually you would have an Idle state in which the application sits and waits. The Idle state would have an event structure that is waiting for user input and is pretty much the state that decides when to go to other states. If you want to implement your 2 minute timer in there, you can have a timeout case on the event structure that utilizes an Elapsed Time timer to go to the Stop Motor state.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 6 of 8
(4,108 Views)

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.

0 Kudos
Message 7 of 8
(3,736 Views)
  1. Start a new post, and do not continue a more than 2 years old one
  2. Specify your hardware elements properly, plus interfaces 
  3. Show your code, what have you tried so far 
  4. If you are a beginner in LabVIEW, start to learn using the online tutorials.
Message 8 of 8
(3,733 Views)