View Single Post
  #6   Spotlight this post!  
Unread 14-02-2016, 14:53
DGoldDragon28's Avatar
DGoldDragon28 DGoldDragon28 is offline
Programmer
FRC #1719 (The Umbrella Corporation)
Team Role: Programmer
 
Join Date: Jan 2016
Rookie Year: 2015
Location: Baltimore, MD
Posts: 10
DGoldDragon28 is an unknown quantity at this point
Re: DriveTrain TankDrive Control

I actually advise writing your own PID. It's fairly simple. You just adjust your constants, which are arbitrary anyway, to account for the fact that the motors are -1 to 1. You may also want to limit the output to avoid faults.

Code:
private static final double KP = xx;
private static final double KI = xx;
private static final double KD = xx;
private static final double MAX_INTEGRAL_ERROR = xx;
private double integral = 0.0D;
private double pasterr;

public double motorPID(double encoderval, double desiredval) {
    double error = desiredval - encoderval
    if(error > MAX_INTEGRAL_ERROR) integral = 0.0D;
    else integral += error;
    double derivative = error - pasterr;
    pasterr = error;
    double out = KP * error + KI * integral + KD * derivative;
    out = Math.min(Math.max(out, -1.0D), 1.0D);
    return out;
}
You may want to put your constants on the SmartDashboard instead in order to tune the PID, or make other adjustments such as smoothing the data with an EWMA, but this is the basic idea. And I don't trust the wpilib PID, it doesn't act predictably in my experience.
Reply With Quote