LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

linear motion control program

I have a cart which is pulled back and forth along a short length of straight track by a motor turning a Ball screw.  The motor controller is controlled with FieldPoint relays.  I get my position info from a potentiometer coupled to the end of the track, so that when the screw turns, the pot turns, giving me a change in voltage across my pot.  I have written a simple control program which works fine in manual mode (i.e. I press a button for left or right), but is not behaving in automatic mode.  Auto mode should move the cart to the right until the pot voltage, read by a FieldPoint AI module, reads 15V or less; then it should stop, wait for 3 seconds, and continue down the track until pot reads 13V, then stop.
The problem seems to be that when the program goes from the main loop to the loop containing the Write to FP Relay subVI to start or stop the cart, it can no longer see the Read FP AI signal which is in the main loop.  How do I keep my FieldPoint Read subVI in the main loop always updating, even when I go into this nested loop to control the Write for the FP-Relay?

The program, written in LV  8 is attached.  I'm sure there is some general programming principle I am ignoring.  Any help is appreciated.
0 Kudos
Message 1 of 11
(3,928 Views)

Sounds like a case for a producer-consumer loop.

http://zone.ni.com/devzone/conceptd.nsf/webmain/C54BADADD8BBDE4286256C5200533B80

 

The producer loop will always read the FP IO. The consumer loop will decide what to do with the FP data that it receives from the queue.

0 Kudos
Message 2 of 11
(3,919 Views)
Thanks unclebump.  This looks like what I need.  I'll play around with it until I grok.
0 Kudos
Message 3 of 11
(3,911 Views)
as unclebump suggested, I used a producer consumer loop to control my cart (goes left or right on track).  The producer loop keeps track of the potentiometer voltage which corresponds to the cart position, while the consumer loop decides what to do based on this voltage.  This works well when I move to just one positon then stop.  I would like,however, to have the cart move right, then pause, then move right again, etc.  When I use a sequence structure in my consumer loop, the cart behaves badly.  Could anyone suggest a better way to use the Producer/Consumer method for programming a sequence of events?
0 Kudos
Message 4 of 11
(3,892 Views)

The best way to do this is to use a Producer/Consumer with User Defined Events and passing a variant/enum cluster through the ques. This gives you two additional features that the plain producer/consumer does not have.   1. You can pass a command as well as data from the producer to the consumer. The enum itself is the command, and the consumer can use a case structure to see what command is being sent. From this information, the variant should be able to be changed to relevent data based upon the case.   2. The user defined events allows the consumer loop to speak to the producer loop. If you have some sort of sequence, you can have the consumer send the command for the next sequence.

This type of architecure is the most advanced and most useful one there is IMHO.  If you need an example or a template of sorts, let me know.

 

Tyler H.

National Instruments

0 Kudos
Message 5 of 11
(3,875 Views)

Tyler H

I would love to see a real example.  This issue has been a thorn in my side for a while now and it's time I learned to do it right.  Thanks.

Telemaque
0 Kudos
Message 6 of 11
(3,872 Views)
Here is an example that I made for you. If you use Highlight Execution you can see how the producer/consumer can communicate seamlessly. I would suggest however with all the clustered Enums/Variants, that you create a TypeDef for updating them. The example itself allows the producer to send a double, the consumer to get the info, then the consumer sends a message to the producer, which the producer responds by a pop up dialog.  This may sound contrived, but just give it a try and I think you will agree that this by far the best type of architecture.
 
Tyler H.
National Instruments
0 Kudos
Message 7 of 11
(3,858 Views)
Thanks Tyler,
 
Could you make that a 7.0 format please.
0 Kudos
Message 8 of 11
(3,853 Views)
Thanks Tyler H.  I think that I will be able to adapt this to my application...and learn a few things along the way.

Telemaque
0 Kudos
Message 9 of 11
(3,840 Views)

Here is the 7.0 version. Enjoy!!

Tyler H.

0 Kudos
Message 10 of 11
(3,826 Views)