キャンセル
次の結果を表示 
次の代わりに検索 
もしかして: 

For loop inside a while loop

解決済み
解決策を見る
Well I have tested the program and it works the I programmed it to be. I have already worked examples on producer consumer. I just cant figure out how to make it run in both direction or change steps while program is running
0 件の賞賛
メッセージ11/28
1,952件の閲覧回数
I tried enclosing the for loop inside a case structure and used a while loop with shift register and created true and false case but what happens the motor runs and when condition changes then it does not do anything and I have to restart the program
0 件の賞賛
メッセージ12/28
1,946件の閲覧回数
Also how can i change the size of the BD to lower pixels just like the way u did
0 件の賞賛
メッセージ13/28
1,941件の閲覧回数

First, don't maximize the window for the block diagram. Once you have it not maximized simply resize it like you would any other window in Windows. Then simply keep your code within those foundries.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 件の賞賛
メッセージ14/28
1,938件の閲覧回数

You have asked a few questions since I last posted. 

 

To change directions (I presume you mean the stepper motor), you just go thorough the array of steps in the opposite direction.  I think that you know that, and that your real question is how to make the program do that. This is one place where a state machine could be very helpful.  If you had a Step state and one of its inputs is Direction, then it could either increment or decrement the array index accordingly.  I would not make any attempt to figure out how to fix your porgram.

 

"I tried enclosing the for loop inside a case structure and used a while loop with shift register..." ????   You probably only need the two loops of a Prodcuer/Consumer Architecture.   The Producer would have the DAQ Assistants and one or two queues to transfer the data.  I cannot tell how much data you get or the relative timing, so it is not clear how many queues are appropriate.  No local variables.  The Consumer would be the state machine which interprets the data and moves the motor.

 

The way I reduced your diagram was by selecting one loop (and sometimes the things connected to it) and then running Clean Up Diagram from the Edit menu.  After doing this with each loop separately, I moved the loops closer together and did some manual fine tuning of the diagram layouts.  It is better if you never let anything get bigger than the boundaries of your screen whle you are creating the VI. Then you do not need to shrink it. Creating subVIs is also helpful, although they should be created fo some logical, functional purpose, not just to shrink code. For example the code to calculate the motor dorive index and array indexing might make a good subVI.  Inputs would be Previous Index and Direction and the output would be the 1D array of booleans that connect to the Digital Write and Coils.

 

The image is reduced to take up less space on the browser.  Actual size of the bounding decoration is 1385x977 pixels.

 

Lynn

Cleaned Step Control4.2.png

0 件の賞賛
メッセージ15/28
1,915件の閲覧回数

Ok I added state machine to my program as you suggested and created a separate que , now the problem Iam experiencing with this stepper control program is that for loop inside the while loop keeps running infinitely and it should stop once it has reached the given steps or N...which in this case is the input to the for loop N. I dont know how to fix this..

0 件の賞賛
メッセージ16/28
1,888件の閲覧回数

I presume you are talking about this for loop?

 

Funny For Loop.png

 

Create a little test VI with just the for loop.  Replace the local with a control.  Put indicators N, i, and the boolean inside the loop.  Add a delay inside the loop. Run it.

 

Hint: "i" starts at zero and increases to N-1.

 

Lynn

0 件の賞賛
メッセージ17/28
1,883件の閲覧回数
No what I meant was the for loop thats inside the case statement and while loop, I created three states, start, clockwise, counterclockwise. In the start case, there is condition statement and when this becomes true then this moves it to next state clockwise and there is a for loop inside a case statement this loop runs the motor clockwise, the n of this for loop is the number of steps the motor would rotate. This loop keeps running infinitely because it is inside the for loop.
0 件の賞賛
メッセージ18/28
1,879件の閲覧回数

I do not understand your question.

 

The state machine consists of a while loop with a state shift register and a case structure containing three state cases: start, counterclockwise, and clockwise.  None of the states has has any kind of infinite loop.  The start state has a state selector and writes all coils off to the Digital Output.  What do you mean by "condition statement"?

 

In both the CW and CCW states you go throught that Rube Goldberg modulus count code in one direction or the other and write the step patterns to the Digital Output with 50 ms delay between steps.  There is nothing which keeps the for loops from running to N and stopping.   About 3.75 seconds in the CCW case and 7.5 seconds in the CW case.

 

Pressing the stop button (if you can find it on that huge front panel) will not do anything until the current state and probably the next state complete. So it could take 15 seconds to stop if you press the stop button just after it is read at the beginning of a CW state and the next state is also a CW state.  Have you waited that long?

 

Have you run this with Execution highlighting turned on?

 

Lynn

0 件の賞賛
メッセージ19/28
1,867件の閲覧回数
Well the selecter VI uses the data from the queue to choose which case to take on. So when the voltage is greater than one it chooses the clockwise case and then the motor keeps running forever and what iam trying to do is whenever clockwise or countetclockwise case is selected the motor should stop right when for loop reaches n-1 without pressing the stop button
0 件の賞賛
メッセージ20/28
1,859件の閲覧回数