Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
b-cho opened this issue Feb 20, 2022 · 0 comments
Open

Comments

@b-cho
Copy link
Contributor

b-cho commented Feb 20, 2022

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.

@b-cho b-cho changed the title MotionController.onTarget() is only true when error is exactly zero MotionController.onTarget() is only true when error is <= Double.MIN_VALUE Feb 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant