EZ-Robotics / EZ-Template

Simple plug-and-play PROS template that handles drive base functions for VEX robots.
https://ez-robotics.github.io/EZ-Template/
Mozilla Public License 2.0
73 stars 31 forks source link

Derivative Kick #99

Closed ssejrog closed 4 months ago

ssejrog commented 6 months ago

Expected Behavior

PID targets can be changed and the robot will switch to following the new target.

Actual Behavior

The robot follows a new target, but 1 iteration after the target has changed there is derivative kick.

This can be solved by getting the derivative of the input sensor value instead of error.

ssejrog commented 4 months ago

Fixing this removes a (probably only used by me) strange behavior where you can set target and compute the PID with a current of 0. I do this in some of my code that's EZ-Template based, here and here.

To keep this functionality, a new function was added to PID called .compute_error(). You pass error and current into this, and it'll compute PID ignoring target. current is only used for derivative calculation.