RobotCasserole1736 / CasseroleLib

Common Libraries used year-to-year for FRC robot code
MIT License
6 stars 1 forks source link

Implement CasserolePID #6

Closed gerth2 closed 8 years ago

gerth2 commented 8 years ago

WIPlib has a decent PID library, but we've seen some spurious issues with it. I also take issue with how they did their feed-forward programming. Also, it's got many features we don't use. Although some would consider it overhead, I believe it is a worthwhile exercise to go through and write our own.

Basic Requirements: Software must implement a PID Algortihm. Interfacing should be same as wpilib: users will instantiate a superclass of the CasserolePID class and override specific functions for getting the PID input, and using its output. The class should operate by spawning a separate thread in the background to do the actual PID math, gather PID inputs, and set the output. Run at a 10ms rate for now (hardcoded).

There are actually six terms to calculate, described below.

For robustness, the PID algorithm should implement a simple watchdog: Periodic thread should Increment a counter variable every time it runs. A separate method should reset the counter back to zero ("wack" watchdog). This method must be called at regular intervals by the control loop. When it is called, before it resets the watchdog counter, it should check if it's already zero. Under the assumption the PID loop is called faster than the control loop, it should never stick at zero. If it's actually zero, we can surmise the PID loop is no longer running, and should take some user-defined actions.... So just return something nonzero from the method to indicate a problem.

Terminology - Desired = current value of the setpoint Actual = current value read in from the system (sensors) Error = Actual - Desired

Class should support the following methods:

setP()

setDSource()

setSetpoint()

start() - Kick off the PID background thread stop() - kill the background thread if running resetI() - reset the integrator back to zero

checkAndWackWatchdog() - should check if watchdog counter is zero. Return -1 if counter is still zero to indicate an issue. If counter is non-zero, reset it back to zero and return 0.

gerth2 commented 8 years ago

Tested bro. Called it done even thought there might be more to do but whateves. Moving on with my life.