Implement PID Source

Hello again,
Now that we are getting vision and gyros working, we are beginning to delve into PID. We understand PID well conceptually, but besides the specific speed controller types (velocity/ distance), we have not implemented any.

We want to use WPILIB’s implementation but are stuck on source control. We have pigeons (and eventually vision targeting) that we want to use as the source, but it is not a pidsource object (like the navx).

I have read through some of the threads on creating a pidsource, but most are in C++ which We do not understand as well as java and python.

How can we take a variable, and turn it into a PID source? We want to start with the Pigeon (Yaw), but I envision we will want a different controller for the vision targeting as well.

The first thing we are trying to do is turn to an angle. We can use the NAVX code to make that work, but we do not currently have a NavX, and the Navx AHRS is already a wpilib PID Source.

Thanks again for all of the answers thus far.

Also, if this would be easier with the new version of the library, that would be helpful to know as well.

In RobotPy, a pidSource can just be a no-args function. For pigeon, I think I used lambda: self.pigeon.getYawPitchRoll()[0]… hopefully you get the idea.

1 Like

Thanks, that was exactly what I needed. It makes it easy and will easily be transferable to other contexts.