LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

While loop inside of event structure only executing properly on second event execution

Hello,

 

I am working with LabVIEW 2010 to control a Newport ESP301 motion controller with an ILS150CC 1-axis stage attached.  The ESP is attached through USB, and I am using a virtual com port to communicate with it.  Everything in the VI seems to be working well enough except for the While loops in Event #1 and #3.  The action that is supposed to take place in these is movement of the stage at a specific velocity and acceleration to a target distance.   The while loop is supposed to compare the actual position to the desired position, and when the quench boolean is true and the desired position is reached or passed, it is supposed to move basically to the hardware limit at a fast velocity.

 

However, I'm having 2 slight problems in making the stage perform as desired.  The first is that there is a slight pause in between the movement and the quenching movement.  This problem is not a huge deal, however, as long as it performs the quenching movement.  I believe it might be hardware limits on the computer that might be causing this, but if there is something wrong with my file I wouldn't be surprised.

 

The second problem is the main reason I am looking for help.  The while loop only seems to function the second time the event command is given.  So, if I decide to "Move Right" (Event 1) a distance of 10 units with the quench boolean "True", it will move right 10 units and stop.  When I "Move Right" a second time, it will move right 10 units, pause for maybe 1 second, and then perform the quenching movement. 

 

What is causing this issue?  I've tried several things to make the command work, but I am very inexperienced with LabVIEW, and I don't know what I've done wrong.   Hopefully, my logic is easy enough to follow and thanks for taking the time to look at this! 

0 Kudos
Message 1 of 4
(2,483 Views)
  • Why is there no while loop around the event structure? Are you using "continuous run" mode?
  • A while loop typically does not belong inside an event structure, especially if it is set to lock the control panel until the event completes.
  • Why are none of your controls connected to anything? Most of these local varaible seem unecessary.
  • You use a combination of mouse down events and weird mechanical actions. Why not "latch action" and "value changed"?

 

0 Kudos
Message 2 of 4
(2,474 Views)

-Yes, I use continuous run mode since I am testing out everything.  

 

-I don't know of any other way to tie that specific loop into only those two commands without making it run for every command.  That doesn't mean it doesn't exist; it just means I am unaware of it because of inexperience. How would I go about fixing this?

 

-The local variables are probably unnecessary.  My advisor suggested it as a fix to a problem that is much like the one I am having now (Inputs only properly functioning on the second event performed), but I've since learned what we were doing wrong.  I will fix that.

 

-I did not know those actions existed.  What would the advantage of using "latch action" and "value changed" as compared to what I am currently using?

 

Thank you for taking the time to respond to my problem!

 

0 Kudos
Message 3 of 4
(2,466 Views)

Run continuous should not be used to control the execution of your program. The code itself should control when and how long it runs. As Chris mentioned you want to avoid long processes in your event structure since this will effectively lock out the UI. Processing within event cases should be very minimal and should occur very quickly. You may want to look at a producer/consumer architecture. This is basically two parallel tasks. The producer would be a while loop with an event structure inside it to handle UI events. When these events occur a message (or messages) would be posted to queue. The second loop would be another while loop which is listening on the queue for messages. When a message arrives it would process the message and perform the task. This type of architecture allows your UI to service user input quickly and avoid what appears to the user as a hung application. If the task you will process takes a long time you may consider breaking it down so that individual steps are smaller tasks. This allows you to inject messages such as your "Emergency Stop" to interrupt the task.



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 Kudos
Message 4 of 4
(2,447 Views)