Fix some errors mevan/live-pidtuning
authorEvanYap <evanyap.14@gmail.com>
Sat, 4 Feb 2017 22:25:38 +0000 (14:25 -0800)
committerEvanYap <evanyap.14@gmail.com>
Sat, 4 Feb 2017 22:25:38 +0000 (14:25 -0800)
1  2 
src/org/usfirst/frc/team3501/robot/utils/PIDController.java

index 2e40d7a514f0176ba9dd1bad50c368ff004670dc,c6ab0fb7b14d632bd987714b890525c025273221..5077fc084bc5fbce81d6ed78614b5ad285aceef1
@@@ -175,85 -169,4 +175,83 @@@ public class PIDController implements L
  
      return this.doneCycleCount >= this.minDoneCycleCount;
    }
-         || key.equals(Constants.DriveTrain.D_VAL)
-         || key.equals(Constants.DriveTrain.MOTOR_VAL)) {
 +
 +  private final ITableListener m_listener = (table, key, value, isNew) -> {
 +    if (key.equals(Constants.DriveTrain.P_VAL)
 +        || key.equals(Constants.DriveTrain.I_VAL)
-             table.getNumber(Constants.DriveTrain.D_VAL, 0.0),
-             table.getNumber(Constants.DriveTrain.MOTOR_VAL, 0.0));
++        || key.equals(Constants.DriveTrain.D_VAL)) {
 +      if (getP() != table.getNumber(Constants.DriveTrain.P_VAL, 0.0)
 +          || getP() != table.getNumber(Constants.DriveTrain.I_VAL, 0.0)
 +          || getD() != table.getNumber(Constants.DriveTrain.D_VAL, 0.0)) {
 +        setConstants(table.getNumber(Constants.DriveTrain.P_VAL, 0.0),
 +            table.getNumber(Constants.DriveTrain.I_VAL, 0.0),
++            table.getNumber(Constants.DriveTrain.D_VAL, 0.0));
 +      }
 +    } else if (key.equals(Constants.DriveTrain.SETPOINT)) {
 +      if (getSetpoint() != (Double) value) {
 +        setSetPoint((Double) value);
 +      }
 +    }
 +  };
 +
 +  @Override
 +  public void initTable(ITable table) {
 +
 +    if (this.table != null) {
 +      table.removeTableListener(m_listener);
 +    }
 +    this.table = table;
 +    if (table != null) {
 +      table.putNumber(Constants.DriveTrain.P_VAL, getP());
 +      table.putNumber(Constants.DriveTrain.I_VAL, getI());
 +      table.putNumber(Constants.DriveTrain.D_VAL, getD());
 +      table.putNumber(Constants.DriveTrain.SETPOINT, getSetpoint());
 +      table.addTableListener(m_listener, false);
 +    }
 +
 +  }
 +
 +  private double getP() {
 +    return this.pConst;
 +  }
 +
 +  private double getI() {
 +    return this.iConst;
 +  }
 +
 +  private double getD() {
 +    return this.dConst;
 +  }
 +
 +  private double getSetpoint() {
 +    return this.setPoint;
 +  }
 +
 +  @Override
 +  public ITable getTable() {
 +    // TODO Auto-generated method stub
 +    return null;
 +  }
 +
 +  @Override
 +  public String getSmartDashboardType() {
 +    return "Drive Controller";
 +  }
 +
 +  @Override
 +  public void updateTable() {
 +
 +  }
 +
 +  @Override
 +  public void startLiveWindowMode() {
 +    // TODO Auto-generated method stub
 +
 +  }
 +
 +  @Override
 +  public void stopLiveWindowMode() {
 +    // TODO Auto-generated method stub
 +
 +  }
  }