PIDF (2020) questions

We are starting to work with PIDs on our robot, and though we are using Neos for the shooter (so we will use the built-in PID), ultimately, we want to use Odometry for the drivetrain. So, I began with simple PIDF and KInematics to try to understand how these pieces fit together and ran into two questions about the 2020 implementation of the PID algorithm. One is specific to robotpy, the other is not.

  1. How do we implement the feedforward variable? I tried to import edu.wpi.first.wpilibj.controller.SimpleMotorFeedforward; (which is what the Java docs use) in python by doing…
$py
>>>from wpilib.controller import SimpleMotorFeedforward

…but got a library not found error. I think I am using the most recent version of pyfrc because the Ramsete Controller imports fine. The new PID controller no longer supports kF on construction. Is there something else we should use?

  1. How do we “clamp” the outputs? We could use a simple if / then statement, or map, but I am wondering if there is a built-in function I am missing.

~Mr. R^2

If you do dir(wpilib.controller) you’ll see a SimpleMotorFeedforwardMeters and a SimpleMotorFeedforwardFeet.

1 Like

I was missing the Feet or Meters. Also, that command is really helpful. Thanks.

SimpleMotorFeedforward seems bizarre to have separate classes for distance units, given that said units cancel out in the calculations… (not to mention that people usually don’t measure the distance flywheels spin in metres)

1 Like

For clamping there’s a clamp method on WPIlib’s MathUtil, not sure about PY buts it’s in java.

We don’t have a clamp function in our libraries, but you can very easily write one:

def clamp(value: float, bottom: float, top: float) -> float:
    return max(bottom, min(value, top))
1 Like

Thank you. That is a good idea. I guess that would function differently than map which keeps the relationship. I find it odd that Wpi took those pieces out. Especially the latter for people who have little experience with PID. A robot can run rampant easily with a poorly tuned system. It does not take much.
Edit: not that I am above that mistake mind you. It seems we learn it every year in one form or another. At least now we know to begin with the wheels off the ground :slight_smile:

Thanks for the clarification, never used the Python libraries. Sorry for any confusion OP!

1 Like

It’s largely because RobotPy is based on the C++ libraries now, so we only expose what C++ has unless someone goes out of their way to write it in Python.

1 Like