Merge "Adds missing Javadocs and @Overrides annotations to the PIDController in Java"

This commit is contained in:
Thomas Clark (WPI)
2014-07-29 07:25:34 -07:00
committed by Gerrit Code Review

View File

@@ -6,7 +6,6 @@
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
import edu.wpi.first.wpilibj.parsing.IUtility;
import edu.wpi.first.wpilibj.tables.ITable;
@@ -62,7 +61,8 @@ public class PIDController implements IUtility, LiveWindowSendable, Controller {
percentage = value;
}
public boolean onTarget() {
@Override
public boolean onTarget() {
return (Math.abs(getError()) < percentage / 100
* (m_maximumInput - m_minimumInput));
}
@@ -75,20 +75,22 @@ public class PIDController implements IUtility, LiveWindowSendable, Controller {
this.value = value;
}
public boolean onTarget() {
@Override
public boolean onTarget() {
return Math.abs(getError()) < value;
}
}
public class NullTolerance implements Tolerance {
public boolean onTarget() {
@Override
public boolean onTarget() {
throw new RuntimeException("No tolerance value set when using PIDController.onTarget()");
}
}
private class PIDTask implements Runnable {
private PIDController m_controller;
private final PIDController m_controller;
public PIDTask(PIDController controller) {
if (controller == null) {
@@ -97,7 +99,8 @@ public class PIDController implements IUtility, LiveWindowSendable, Controller {
m_controller = controller;
}
public void run() {
@Override
public void run() {
while (!m_controller.m_freed) {
m_controller.calculate();
Timer.delay(m_controller.m_period);
@@ -145,12 +148,13 @@ public class PIDController implements IUtility, LiveWindowSendable, Controller {
/**
* Allocate a PID object with the given constants for P, I, D and period
* @param Kp
* @param Ki
* @param Kd
* @param source
* @param output
* @param period
* @param Kp the proportional coefficient
* @param Ki the integral coefficient
* @param Kd the derivative coefficient
* @param source the PIDSource object that is used to get values
* @param output the PIDOutput object that is set to the output percentage
* @param period the loop time for doing calculations. This particularly effects calculations of the
* integral and differential terms. The default is 50ms.
*/
public PIDController(double Kp, double Ki, double Kd,
PIDSource source, PIDOutput output,
@@ -176,6 +180,7 @@ public class PIDController implements IUtility, LiveWindowSendable, Controller {
* @param Kp the proportional coefficient
* @param Ki the integral coefficient
* @param Kd the derivative coefficient
* @param Kf the feed forward term
* @param source The PIDSource object that is used to get values
* @param output The PIDOutput object that is set to the output percentage
*/
@@ -440,7 +445,8 @@ public class PIDController implements IUtility, LiveWindowSendable, Controller {
* @param percent error which is tolerable
* @deprecated Use {@link #setPercentTolerance(double) or {@link #setAbsoluteTolerance(double)} instead.
*/
public synchronized void setTolerance(double percent) {
@Deprecated
public synchronized void setTolerance(double percent) {
m_tolerance = new PercentageTolerance(percent);
}
@@ -475,7 +481,8 @@ public class PIDController implements IUtility, LiveWindowSendable, Controller {
/**
* Begin running the PIDController
*/
public synchronized void enable() {
@Override
public synchronized void enable() {
m_enabled = true;
if (table != null) {
@@ -486,7 +493,8 @@ public class PIDController implements IUtility, LiveWindowSendable, Controller {
/**
* Stop running the PIDController, this sets the output to zero before stopping.
*/
public synchronized void disable() {
@Override
public synchronized void disable() {
m_pidOutput.pidWrite(0);
m_enabled = false;
@@ -512,12 +520,14 @@ public class PIDController implements IUtility, LiveWindowSendable, Controller {
m_result = 0;
}
public String getSmartDashboardType() {
@Override
public String getSmartDashboardType() {
return "PIDController";
}
private ITableListener listener = new ITableListener() {
public void valueChanged(ITable table, String key, Object value, boolean isNew) {
private final ITableListener listener = new ITableListener() {
@Override
public void valueChanged(ITable table, String key, Object value, boolean isNew) {
if (key.equals("p") || key.equals("i") || key.equals("d") || key.equals("f")) {
if (m_P != table.getNumber("p", 0.0) || m_I != table.getNumber("i", 0.0) ||
m_D != table.getNumber("d", 0.0) || m_F != table.getNumber("f", 0.0))
@@ -537,7 +547,8 @@ public class PIDController implements IUtility, LiveWindowSendable, Controller {
}
};
private ITable table;
public void initTable(ITable table) {
@Override
public void initTable(ITable table) {
if(this.table!=null)
this.table.removeTableListener(listener);
this.table = table;
@@ -555,26 +566,30 @@ public class PIDController implements IUtility, LiveWindowSendable, Controller {
/**
* {@inheritDoc}
*/
public ITable getTable() {
@Override
public ITable getTable() {
return table;
}
/**
* {@inheritDoc}
*/
public void updateTable() {
@Override
public void updateTable() {
}
/**
* {@inheritDoc}
*/
public void startLiveWindowMode() {
@Override
public void startLiveWindowMode() {
disable();
}
/**
* {@inheritDoc}
*/
public void stopLiveWindowMode() {
@Override
public void stopLiveWindowMode() {
}
}