LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Running two stepper motors at the same time from one port

Solved!
Go to solution

Ok, sorry for the confusion. Here's my latest vi. What I am doing is running tension and torsion at the same time, but the steps are independent of one another. I have a linear ball screw that's attached to one motor and controller. The ball screw moves a platform back and forth. The the other motor (with attached controller) and is mounted on top of this platform, therefore making it possible to do tension and torsion simulataneously. There are not necessarily an equal amount of steps for torsion and tension, and each step does not necessarily take the same amount of time, i.e. Step 1 in tension could run a lot longer than step 1 for torsion. The very first step of tension and torsion are sent at the same time however because I need the tests to begin at the same time. I do not need to wait until both tension and torsion have completed before moving onto the next step, and I do not need a time delay built into LV because it is already built into the command sent to the motor. Here is the logical flow of what I want to do:

 

1. Have the user input all the steps for both tension and torsion, and have LV store them in two arrays. (I have another program for this.)

2. When the user presses "Start Testing" (or something like that), have the first step from both the tension and torsion array execute. 

3. Wait for a response from one of the motors before sending the next command.

        3a. If it is 66, then I know that the tension motor has completed the given command, and I would like to write the next tension command and send it to its controller/motor. 

        3b. If it is 67, then I know that the torsion motor has completed the given command, and I would like to write the next torsion command and send it to its controller/motor.

4. Repeat step 3 until both the tension and torsion array are empty, i.e. worked through all the requested steps. 

5. Stop test. 

 

Right now, I am having problems with step 2, but I've attached what I've worked out so far. 

 

Thanks!

0 Kudos
Message 11 of 20
(1,127 Views)
I'm still having problems running both motors at the same time. My tension motor will take do the steps I give it, but the tension motor doesn't move at all.
0 Kudos
Message 12 of 20
(1,119 Views)
Solution
Accepted by topic author manchmal3

Based on your descriptions, I came up with this producer/consumer architecture.  I have no way of testing it to be sure it works with out bugs.

 

It has a producer loop that reads the serial port.  It enqueues new write commands when necessary.  It has a consumer loop that takes the write commands and writes them out to the serial port.

 

If the producer loop detects the special response (66 or 67) and there are more commands in the particular command array, it takes the next item in the array and enqueues it.  Since this code was the same for both controllers, I broke it into a subVI.  At the beginning of the program, it sees both the write queue with the first command from each array using the same subVI's.

 

The producer loop runs as long as the stop button has NOT been pressed, or there are more commands in the tension array, or in the torsion array.  Once the producer loop stops, it enqueues a "KillLoop" string.  This special string tells the consumer loop to stop and kill the queue once it has finished all its commands.

 

EDIT:  You may need to include special error handling to clear a timeout error.  If you read 50 bytes and don't get that many, you'll get a timeout error.  But you still want the following code to run if your special responses are present.  You may also need to modify your timeout values also in these cases.

Message Edited by Ravens Fan on 06-09-2009 09:10 PM
Download All
Message 13 of 20
(1,115 Views)
I think we've made this too complicated; perhaps I never should have suggested a queue.  Starting from your description of what you're trying to accomplish, rather than from your previous code, I wrote a new VI that I think does what you need (or will with minor modifications).  It maintains an array of tension commands and and array of torsion commands.  Each time it sends a command over the serial port it removes that command from the array.  When the code receives the appropriate signal that a command has finished it sets a shift register to true, indicating that the code should send the next command for that motor on the next loop iteration.  When both command arrays are empty the code stops.
Download All
Message 14 of 20
(1,101 Views)

Hi nathand,

 

Do you think you could post those programs in 8.5 instead of 8.6? My lab hasn't upgraded yet. 

 

Thanks.

0 Kudos
Message 15 of 20
(1,095 Views)
Oops, sorry about that.  Here you go.
Download All
0 Kudos
Message 16 of 20
(1,093 Views)

I ran both of the suggested programs on the device. The one from Ravans Fan would only run the first step in tension. Torsion never executed. The one from nathand acted a little bit confusingly: I tried once with two commands each for tension and torsion. Both commands ran in tension, neither in torsion. I then tried three commands in tension and no commands in torsion. All three ran in tension. When I tried three commands in tension with one command in torsion though, the first and third command ran in tension. The one in torsion did not run. The sub vi in both of the programs sent back this error: -1073807339, which is "Timeout expired before operation completed.".

 

Any thoughts on what I need to change? Ravens Fan, I am looking into what you said about the timeout errors. 

 

Thanks

0 Kudos
Message 17 of 20
(1,081 Views)
I don't think this will completely solve the problem, but try running my version after replacing the error wire shift registers with tunnels (right click on the shift register and click replace with tunnels).  I suspect that the first timeout error is preventing any further commands from being sent.
0 Kudos
Message 18 of 20
(1,074 Views)

manchmal3 wrote:

 

Any thoughts on what I need to change? Ravens Fan, I am looking into what you said about the timeout errors. 

 

Thanks


I think that could definitely be it.  It occurred to me after I posted the example but before my edit time ran out on the message.  I remember seeing a VI called "clear specific error", but I don't remember if it is built into LabVIEW, or if it was OpenG, or some other homegrown, or LV Basics lesson VI.  Something like that would be helpful.  It would be hard to program, just look at the error code on the error wire and clear it if it matches -1073807339.  It would make a good subVI itself.

0 Kudos
Message 19 of 20
(1,067 Views)
There are a few things still to work out, but the code worked! Thanks for all the help.
0 Kudos
Message 20 of 20
(1,047 Views)