Skip to content

Checkables

cezarmathe edited this page Mar 4, 2019 · 2 revisions

Checkable is an interface for checking the status of different components. The source code can be found here.

How to use

Any class(or anonymous class) that has a method Boolean check() is considered a Checkable, and it's status can be checked by calling check().

CheckableGroup

You can group multiple Checkables in a CheckableGroup which implements the Checkable interface(aka you can pass it as a Checkable) and returns the evaluation of it's items. For this to work, you need to use a CheckableLogicalOperation, which can be AND(&&) or OR(||).

Examples

The main example is the DrivetrainEncoderCheckable which checks whether each motor has reached it's destination or not.

For this, we implement first a MotorEncoderCheckable that checks whether a single motor reached it's destination.

Then, we add all the items like this:

// those Checkables must be MotorEncoderCheckables
public DrivetrainCheckableGroup(Checkable a, Checkable b, Checkable c, Checkable d) {
    items.add(new Pair<>(a, Operation.AND)); // we want to return true only if
    items.add(new Pair<>(b, Operation.AND)); // each motor reached it's destination
    items.add(new Pair<>(c, Operation.AND));
    items.add(new Pair<>(d, Operation.AND));
}
Clone this wiki locally