getHardware

protected fun <T : HardwareDevice> getHardware(name: String, device: Class<T>, onSuccess: Consumer<T> = Consumer { }): T?

Convenience method for reading the device from the hardwareMap without having to check for exceptions. This method can be passed a Runnable to run if the device is successfully configured, useful for setting up directions or other configurations that will only run if the device was successfully found.

Every failed device name with this method is saved to Storage.memory().hardwareErrors, which can be accessed during the lifetime of the OpMode. These errors will also be reported to telemetry.

Parameters

name

name of device saved in the configuration file

device

the class of the item to configure, extending HardwareDevice (DcMotorEx.class, ServoImplEx.class, etc.)

onSuccess

a Runnable to run if the device is successfully configured, useful for setting up motor configs without having to check for null explicitly.