LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

PID control inside While loop and Case structure

Solved!
Go to solution

Hello Everyone. I'm relatively new to LabVIEW and this forum has been of great help. So thank you all.

 

To make things short, I'm trying to make an extremely simple VI in which I use a Button to Start and stop the PID control of a Laser. This is, because I only need to control the laser until it reaches the setpoint, the Laser then uses an already implemented external feedback control to lock on to the current level 1.5s after the last register update and remains stable. The laser only works with current level % as input, but I want the user to input the desired Power, thus why I added a PID to reach the SP.

 

The controller and gains are now optimized and everything works as it should when implementing it through the main while loop, with a case structure and an ON button. However, I added an extra while loop because I want to implement a simple state machine and want to move to the next state when the while loop ends. For some reason, (which will seem rather obvious to most of you) the second while loop implementation doesn't seem to work.

 

I'm attaching the current working implementation with a simple case structure, the non working VI with two while loops, and a modified General PID Simulator VI to demonstrate what I want to achieve (also working as intended). If the second while loop as an end condition to switch states in a state machine design is not a good idea, please also let me know an alternative. Furthermore, If you spot any mistake, please also let me know.

 

Thanks

Non working>

madvillain97_1-1700483228821.png

 

working

madvillain97_0-1700484153052.png

 

madvillain97_4-1700483342603.png

 

 

 

0 Kudos
Message 1 of 3
(176 Views)
Solution
Accepted by topic author madvillain97

Hi mad,

 


@madvillain97 wrote:

Furthermore, If you spot any mistake, please also let me know.


Why do you need an inner loop to implement a state machine when you already have an outer loop?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 3
(129 Views)

Hi Gerd, thank you for your reply. You are absolutely right. I just assumed it was the case because the controller didn't seem to update, so I figured the state was only running once and not updating the exit condition, but it was rather a communication issue. I made a new state specifically for the control loop and it was more than enough. 

 

I will leave the post up in case it helps anyone with the same goofy mistake.

 

Best.

0 Kudos
Message 3 of 3
(116 Views)