Skip to content

Distance Sensors

NextDistanceSensor is a lightweight wrapper for a distance sensor that caches the last reading.

// By Lynx Module and I2C bus, recommended
val sensor = NextDistanceSensor(RobotController.controlHub, 0)
// Using your configuration name
val sensor = NextDistanceSensor("distanceSensor")

Reads the distance at that moment and refreshes the cache. Call this once per loop, before reading anything. It’s recommended to put this in your periodic for your Mechanism.

sensor.update()

True if the distance sensor senses an object within threshold, in the given unit.

if (sensor.isWithinDistance(4.0)) { ... } //defaults to CM