PID kills safety thread

I just got finished putting in PID VI’s into a loop in the periodic tasks VI. I am feeding the PID with global variables so that PID can be used in autonomous as well as teleop.

When I enable, I get a string of error messages that tell me that my code isn’t running fast enough and that the RobotDrive VI is not being updated enough! I need to use PID because the robot doesn’t drive straight. I figured that the closed-loopedness of PID would alleviate these problems, not add to them!

Simplified: How do I make PID work so that the wheels are driven at the speeds they should be and make the safety thread happy as well.

It’s most likely how you’ve structured your code, rather than the PID calculations.

The warnings are going to be based on how often you update your Arcade/Tank/Holo drive. PID shouldn’t be slowing that down.

Where do you call Arcade/Tank/Holo drive and how often?

I am calling the tank drive VI from the periodic loops in the same loop as the PID code. It’s being called as fast as the loop will run (I think the cRIO is 40mips)!

You can measure your loop time with a utility vi that NI (Greg) included with the Framework.

From the project explorer window open up the Support Code folder and drag the Elapsed into your Periodic Tasks loop.

Now if you Run from Robot Main you can open up the Elapsed Times front panel and watch the number of milliseconds each loop takes.
Anything greater than 100 ms is trouble.

I’ll try that, I also get the ‘not running fast enough’ error when I attempt to engage my follow-a-line-on-demand code in the teleop loop. It basically works as a giant state machine and no, its not just a copy of the default code. This loop I know runs several hundred times a second though.

Make sure that you aren’t using any while loops in your code, these can delay the update of PWM outputs, therefore cause a watchdog error. (The Periodic loop itself doesn’t count)

If I can’t use a while loop, what should I do to make my code repeat?! I need the PID updated every 25ms by my calculations for safe operation. Should I move the moterdrive VI out of the PID loop?

Don’t use loops in Teleop. It gets called repeatedly and rapidly by the project framework, and it needs to finish quickly in order to keep from holding up the communication processes.

Loops are perfectly reasonable, expected, and indeed necessary in the Periodic Tasks vi.