Distance Sensors
NextDistanceSensor is a lightweight wrapper for a distance sensor that caches the last reading.
Creating a NextDistanceSensor
Section titled “Creating a NextDistanceSensor”// By Lynx Module and I2C bus, recommendedval sensor = NextDistanceSensor(RobotController.controlHub, 0)
// Using your configuration nameval sensor = NextDistanceSensor("distanceSensor")// By Lynx Module and I2C bus, recommendedNextDistanceSensor sensor = new NextDistanceSensor(RobotController.controlHub(), 0);
// Using your configuration nameNextDistanceSensor sensor = new NextDistanceSensor("distanceSensor");update()
Section titled “update()”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()sensor.update();isWithinDistance(threshold, unit)
Section titled “isWithinDistance(threshold, unit)”True if the distance sensor senses an object within threshold, in the given unit.
if (sensor.isWithinDistance(4.0)) { ... } //defaults to CMif (sensor.isWithinDistance(4.0)) { ... } //defaults to CM
