LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

While Loop doesnt stop inside a case structure

Solved!
Go to solution

Hello All,

 

I have a case structure which runs a motor at a certain PWM when my metal detector is not giving a value above the threshold that is in 'False State'. The motor is controlled by a PI controller so a while loop is used inside the false state. When my metal detector goes above threshold i want the 'True State' to execute but that is not happening. the whole program is in a while loop that is basically to keep the metal detector working. How do i make the switch state work.

Regards
Asad Tirmizi
Design Engineer
Institute of Avionics and Aeronautics

" Its never too late to be, what u want to be"
Using LabVIEW 8.2
0 Kudos
Message 1 of 13
(5,995 Views)

If I understand correctly, you have a loop inside a False case of a case structure that gets started, but you then want to stop it and switch to the True case when the condition that controls the case structure in the first place changes. Well, you need to stop the while loop, otherwise LabVIEW cannot go back and read the new value of the state of the line that controls your case structure. How do you stop the while loop.

 

If I did not understand correctly, then ...

 

please

 

 

post

 

 

your

 

 

code.

Message 2 of 13
(5,987 Views)

Thats exactly what is happening, my while loop is not stopping. Please accept my rather low labview knowledge because i was hoping that when the case would shift then the while loop inside the false case would stop aswell. Thanks to you now that it wont. now the problem is how i stop the while loop. i am pasting the VI for better reference. I tried to stop the while loop from the metal detector threshold. when it would cross the threshold a boolean signal would go inside the case structure and then inside the while loop and then stop it. But this seem not to work either. Maybe a look at the program shall help.

Regards
Asad Tirmizi
Design Engineer
Institute of Avionics and Aeronautics

" Its never too late to be, what u want to be"
Using LabVIEW 8.2
0 Kudos
Message 3 of 13
(5,979 Views)

Asad,

 

It is immediately obvious from your VI that you do not understand one of the fundamental behaviors of LabVIEW, dataflow.  The value of the boolean inside the while loop is the value which is present at the tunnel when the while loop starts running.  It is also the value wired to the slector terminal of the case structure. Since you are in the false case the value is false, so the loop runs.  Nothing inside the loop changes that value so the loop will never stop.  The value of the Magnetic sensor will not be read again unitl the outer loop iterates again.  That will not happen until the inner loop stops, which it never will.

 

You will need to do some significant changes to your program to get it to do what you want.  Since I am not sure exactly what it is intended to do, I cannot tell you exactly how to fix it.  However, programs of this type are well suited to a state machine architecture.   Look at the examples which come with LV.

 

Lynn

0 Kudos
Message 4 of 13
(5,972 Views)
Solution
Accepted by topic author Asad_Tirmizi

Once the code is trapped inside the inner while loop, there will never be a change from the boolean wire because the change is outside. All you need is one loop containing a case structure. Run your program with execution highlighting to get a better understanding of dataflow.

Message 5 of 13
(5,969 Views)

I completely agree that i am mixing the fundamentals of dataflow. ive been watching the tutorials on state machines but without much success to the actual working. I would have to agree with a considerable amount of shame that this is actually my shot at the program after watching the state machines tutorials. Anyways to shed more light on the program.

 

My vehicle is following a straight line with a P controller (the false case). while my vehicle is moving the magnetic sensor is searching for magnetic fields. as soon as the magnetic sensor detects the magnetic field. The threshold is crossed and the case is switched. In real world the vehicle will stop, it will swerve around the magnet. this is partially what i want to do.

 

The whole part is that it should swerve around and then follow the same trajectory so as to complete the sector sweep.

 

P.S. i am sorry for my fundamental mistakes in data flow. But thats what i am here for to learn and to get a direction.

Regards
Asad Tirmizi
Design Engineer
Institute of Avionics and Aeronautics

" Its never too late to be, what u want to be"
Using LabVIEW 8.2
0 Kudos
Message 6 of 13
(5,967 Views)

@Altenbach

 

ive tried running it with just one loop. but in that case the motor encoder data doesnot work. The motor encoders are in the 'false case' and they need to be in a while loop to make the Pcontroller work. The whole thing works fine if i remove the while loop and the P controller. but it is imperative to include the P controller to keep the vehicle on the right trajectory

Regards
Asad Tirmizi
Design Engineer
Institute of Avionics and Aeronautics

" Its never too late to be, what u want to be"
Using LabVIEW 8.2
0 Kudos
Message 7 of 13
(5,965 Views)

Asad,

 

If you have not done so, look at the on-line tutorials for LV.  They should give you an introduction to dataflow.

 

Your state machine probably only needs one loop, the outer one.  After you do once the things that the inner loop now does repeatedly, change to the state which reads and tests the magnetic sensors, then come back to the move state or go to a different state.  Rather than getting trapped in a state, exit from it and then return to it immediately if the system is not yet finished with the work of that state.  Your state machine also needs at least one shift register.  The shift register is the means by which the current state tells the system what state will be the next state.

 

Lynn

0 Kudos
Message 8 of 13
(5,959 Views)

Asad,

 

I just noticed your title.  As a Design Engineer, you are surely aware of the value of a good design.  The same is true of software design.  Develop a design for your state machine.  It will list all the states - and each state will generally do only one task.  Create a state transition diagram.  It shows which state comes next after any state and the conditions under which that transition occurs.  For example the Magnet state would have two transitions corresponding to the results of the Greater Than comparison.  Your P controller might be represented by two or more states. Stopping the motor is another state.  Error handling might be another.

 

A good design can lead to good software. Software written without a design is often quite difficult to get working because you do not know exactly what it should be doing at a particular time or, as in your case, data needed to make a decision (magentic sensor data) is not available at the right time or place.

 

Lynn

Message 9 of 13
(5,954 Views)

dear lynn

 

Thanks for the wonderful advice. but pardon my llimited knowledge. Dont you think i would do fine with just two states? One the run state when the vehicle looks for the magnets. and second the swerve arund state when the vehicle moves around the magnet. I just removed the inner while loop to test it again. but it works real bizzare. im working on it make some sense of the data flow and make it work.

 

any ideas if

 

1) If i remove the inner loop. where do i need the shift registers ? and how would they help in changing state from run to swerve and then swerve to run

 

2) What could be the reason of the bizzare motor behaviour when the inner while loop is removed. The p-controller totally loses it. i suppose it is due to the fact that the rotary encoders might not be refreshing properly. Won't the outer loop also refresh the rotarty encoders readers which are in the false loop

Regards
Asad Tirmizi
Design Engineer
Institute of Avionics and Aeronautics

" Its never too late to be, what u want to be"
Using LabVIEW 8.2
0 Kudos
Message 10 of 13
(5,948 Views)