PID While Loop

I have put a PID into my code for autonomous. The PID is inside of a while loop, how would I stop the loop once the PID reaches it’s set point? We are using labview for programming.

Posting your code would make it easier to help or at least a picture of the area you are talking about.

Normally you do not stop a PID that is running the motor for RPM. That is the purpose of the PID to get the motor to the proper RPM and them maintain it.

Unless we know what you are doing in your code it would be difficult to tell you how to do what you are trying to accomplish.

Tim

Here ya go





Why do you have the PID in the other loop? From what I see you are using it to turn. If this is true once you get the PID to turn your robot it should go to close to zero on the output if you set it up correctly. If you put it in the same loop you could use an “In Range?” vi to make your robot quit turning if your PID has some residual output. If you put this in a second loop things get more difficult.

The other thing I see is that you are trying to feed values from one loop to the other with tunnels. That is not the way LabVIEW works. If you want to get a values into the bottom loop you will have to use a local variable or some pther method to do that. THe distance will not go to the bottom loop this way.

I’ll try putting the Pid in the other loop. What is being done is we have made an algorithm to find out how far back or forward we need to move to be in line with the lower goal. The PID is to have the robot move to the proper setpoint.

So a few problems here.

A while loop with no time constraint is asking for trouble. It’ll eat up your CPU resources running as fast as possible while not maintaining a constant delta time between calls. That will make it untunable since the dT between calls is never the same. That’s my biggest :ahh:

If you want to terminate a separate running while loop, you can use Notifiers. Definitely look at some example code in the LabVIEW help. If you use Obtain Notifier in code that you call often, you need to call Release Notifier, or else it will eat up all your RAM over time. Ask me how I know…

But, as aeastet, you typically want to keep your PID running at all times. Perhaps put it in a while loop in Period Tasks that runs every 50ms? You can share the set-point using global variables or notifiers.

It looks like you want to share data constantly between the two loops by running wires between them. That’s not how LabVIEW works – a loop doesn’t produce an output until it has finished running. You need to put everything in the same loop, or you can share data using variables (local or global) or queues or some other mechanism.