LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Stop the application when the desired variable is reached

Solved!
Go to solution

Ok, now it seems to work (the linear motor is moving and stopping with the desired velocity and I implemented the stop stage as you suggested). Now the problem is the following: when I stop the program, I want the motor to return in the initial position (that we can say to be set as position 0), but if I stop the motor when it moves forward, it stops completely extended, while if I stop it when it moves backward, it reaches the initial position. How can I tell the motor to always stop at the initial position? 

Thank you!

0 Kudos
Message 11 of 15
(378 Views)

Hi luna,

 


@luna30 wrote:

Now the problem is the following: when I stop the program, I want the motor to return in the initial position (that we can say to be set as position 0), but if I stop the motor when it moves forward, it stops completely extended, while if I stop it when it moves backward, it reaches the initial position. How can I tell the motor to always stop at the initial position? 


I guess you need to set the correct movement direction, too.

(You should know your motor driver hardware better than I do!)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 12 of 15
(373 Views)

Hello, Luna.

 

     I apologize for not carefully reading the earlier posts, and showing you a nice piece of code that runs on a PC with a multi-function USB DAQ device providing the pulse trains for the Stepper motor.  I also missed that you were using a linear motor.

 

Do you have "limit switches" that close when the linear motor is "fully homed" and "fully extended"?  [Note that, ideally, you'll place the switches so that they close when the carriage is "close" (like 1 mm) from either end].  If you have such a switch, you can (and should) program the following Algorithm when initializing the system:

  1. Call the fully-retracted position "All In", and the fully-extended position "All Out".  I'll use these names for the two switches that get activated when "All In" or "All Out".
  2. If "All In" is High (so the motor is fully retracted), start it moving slowly (step at 10 to 100 Hz) until All In goes Low.  You can call this Position 1 or 0 (you choose the convention).
  3. Figure out how many steps you'd need to take to get near the "All Out" position.  Move the motor that many steps to bring you near the "All Out" switch.  Ensure it is still Low.  
  4. Move slowly out, incrementing the step count, until All Out goes High.  This is the "Fully Extended" position, This is "Pmax", the maximum Pulse position, the number of steps between "All In" and "All Out".  Knowing the current position P between 0 and Pmax, to get to PNew you step Pnew - Pmax, where a positive difference means "step out" that many pulses.

With this simple design, after determining P0 (the All In position, which I define as the zero position for the linear movement) and Pmax (the number of steps to get to the maximum position for the linear movement), it is easy to move to Pnew, someplace between P0 and Pmax.  So to leave the actuator at 0 when it is at some partially-extended position Pend, simply move it -Pend (backwards towards P0) steps.  You can move it "quickly" until you get close (if you want), and then more slowly, but since stepper motors "count", and Counter-Timers also count just as accurately, there's no special reason (other than noise or vibration) not to simply move at whatever (constant) rate "makes sense to you" (like noise or vibration) until you hit 0 (exactly).

 

Bob Schor

0 Kudos
Message 13 of 15
(348 Views)

Hi Bob, 

Thank you for you help. I have limit switches in the linear motor but I'm working with MyRIO and not with DAQ. 

I am not so experienced with LabVIEW so I wouldn't really know how to implement this. Can you give me an example?
Thank you

0 Kudos
Message 14 of 15
(313 Views)

Oh, dear.  You "are not so experienced with LabVIEW", but are working with myRIO, which means you are not working with LabVIEW, but with LabVIEW Real-Time, which has some subtle differences.  One is that when it is running on the myRIO, there is no User Interface -- the Front Panel is only for passing arguments in and out of the VI.  LabVIEW Real-Time, while is it running in the myRIO, does not allow you to enter values, push Buttons, or plot a Graph -- you need the Host code, running in the PC, to do that.  Plus you need a mechanism to communicate between the PC and the Target (myRIO) -- I prefer Network Streams.  You should probably have a few uears experience with single-processor (i.e. LabVIEW running on the PC) LabVIEW code, using DAQ hardware (powered by DAQmx, of course) before substituting a RIO (with its own hardware, but now you need to write, using LabVIEW Real-Time and yet another processor, the myRIO's FPGA what you can either program yourself or use pre-written functions that are part of the myRIO Software Toolkit to do some of the work for you.

 

It's really my fault.  You started at the beginning you were using a myRIO, but I got caught up in the notion you were using something like a Stepper motor, which I've recently been driving with a USB-6212 and LabVIEW 2019, using DAQmx (and the "programming" coded in the hardware inside the 6212, rather than my having to write the code in the FPGA of a myRIO, much easier.

 

So since (belatedly) I now realize you are developing a LabVIEW Real-Time Project, you really need to gather all the VIs, TypeDev, and other code elements in this LabVIEW RT Project into a single Windows Folder on your PC (with a little luck, you've already done this), then right-click the Project Folder (which now contains the .lvproj Project declaration, all of the VIs, TypeDefs, Globals, etc. that are part of this "Project") and choose "Send to", "Compresses (zipped) Folder", then attach the Ziipped Folder as an attachment.  This lets us see all of the code, so we can begin to tell you how to get the "button push" (which has to be in the Host) to the "sfarting" and "stopping" of the Target code (which, apparently, has to be in the myRIO).

 

Bob Schor 

 

 

0 Kudos
Message 15 of 15
(270 Views)