RoboticsTeam4904 / standard

Command Based Git Submodule
BSD 3-Clause "New" or "Revised" License
11 stars 3 forks source link

`MotionController.onTarget()` is only true when error is `<= Double.MIN_VALUE` #276

Open b-cho opened 2 years ago

b-cho commented 2 years ago

In MotionController.java:

public abstract class MotionController implements Subsystem {
    protected DoubleConsumer output;
    protected final PIDSensor sensor;
    protected double setpoint;
    protected double absoluteTolerance;
    ......

    public MotionController(PIDSensor sensor, DoubleConsumer output) {
        this.sensor = sensor;
        setOutput(output);
        enable = false;
        overridden = false;
        absoluteTolerance = Double.MIN_VALUE; // Nonzero to avoid floating point errors
        ......
    }

     /**
     * True if the error in the motion controller is less than the tolerance of the
     * motion controller.
     *
     * @return
     */
    public boolean onTarget() {
        return Math.abs(getError()) <= absoluteTolerance;
    }
    ......
}

the onTarget() method only returns true IF our error (offset from the target point) is less than or equal to absoluteTolerance = Double.MIN_VALUE, which will never happen. absoluteTolerance needs to be increased to a reasonably small decimal value or tuned based on the required tolerance of each individual subsystem.