Skip to content

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

@b-cho

Description

@b-cho

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions