Pid working differently at different distances

We tuned our pid to 10 ft and it seemed accurate. But when running it for 5 feet it was not accurate at all. Any ideas?

We’re definitely going to need more information… Is your code posted anywhere? Also, how inaccurate is it? If it’s only off by an inch or two, “meh”. If it’s off by 3 feet, “yowzah”

PID is not a great solution for drivetrain trajectories, assuming you’re doing a position PID and just setting the target to 10’ or 5’. If you have any I term at all, it’s going to to wind up a lot over 10’ versus 5’, which probably means you’re either overshooting 10’ or undershooting 5’. It’s probably too late to implement, but depending on your motor controller solution, Talon Motion Magic could work, or Jaci’s Pathfinder both would work very well.

If not, you could try ramping your position instead of making one giant step. The basic idea would be to start with a target of 0, then add a small amount to it every loop until you get to 10’. That would require different (tighter/faster) tuning parameters, but it’s going to be much more repeatable over different distances, especially if you don’t change the ramp rate/speed.

Hi, Cloverbots!

Are you using the I term?

First, other posters in this thread have pointed out the problem with PID control in drivetrain control, and that is the I term. Since the I term is proportional the sum of error of all previous samples, where “error” in this case means the distance between your current sensor location and your setpoint, it stands to reason that the further away from the target you started, and the longer it takes you to get to your setpoint, the bigger the I term will be. This is not desirable in drivetrain control.

Most drivetrain position feedback control I’ve seen has used PD control, eliminating the I term completely. This allows you to control the robot’s drivetrain position using only (relatively) current information. PD control can be pretty accurate; I’m not an expert in feedback control tuning, but I can say that my teams have had success with the following drivetrain tuning instructions:

1.) Tune using just P control. Set kP to a reasonable value, and keep kI and kD at zero. Test multiple distances. Tune the P control so that the robot slightly overshoots and then corrects itself.
2.) Introduce a non-zero D constant, keeping kI at zero. If the robot still overshoots, increase kD until it doesn’t overshoot anymore, again testing different distances. If the robot starts oscillating or behaving erratically (stop-go-stop-go) before it has even reached the setpoint, decrease kD.
3.) There is no third step. Your PD control is tuned! Maybe verify that the control repeatably gets you to within a small tolerance of the setpoint. This year, my team has been able to get it to within an inch or so most of the time.

Good luck this year, and I hope to see you at the Pacific Northwest Championship!

Yes! That was our issue. All the documentation we were finding was telling us to do P, then add in I, and it was causing us to way overshoot. So, a with the gracious professionalism of FIRST, we were told to just do P, then D and it worked marvelous.

We are now starting to tune the PID on our gyro and having problems, but P with D isn’t working quite as well as it did on the drive train. Any ideas?