NextColorDistanceSensor
class NextColorDistanceSensor(colorInitializer: () -> NormalizedColorSensor, distanceInitializer: () -> DistanceSensor? = null)
Combines a color sensor and an optional distance sensor into one class. Call update each loop to read the hardware. Use isColor to check against a dev.nextftc.hardware.sensors.colors.ColorProfile.
Example:
val green = ColorProfile(
space = ColorSpace.HSV,
color = NextColor.HSV(160f, 0.8f, 0.7f),
tolerance = NextColor.HSV(15f, 0.3f, 1f),
)
override fun periodic() {
sensor.update()
if (sensor.isWithinDistance(4.0) && sensor.isColor(green)) { ... }
}Content copied to clipboard
Use debug in telemetry to calibrate dev.nextftc.hardware.sensors.colors.ColorProfiles.
Author
28shettr
Parameters
colorInitializer
Lazily resolves the backing NormalizedColorSensor.
distanceInitializer
Optional lazy distance sensor.
Constructors
Link copied to clipboard
constructor(colorInitializer: () -> NormalizedColorSensor, distanceInitializer: () -> DistanceSensor? = null)
Functions
Link copied to clipboard
Single-line telemetry string showing current HSV and distance. Useful for calibrating ColorProfiles.
Link copied to clipboard
Returns the last cached distance converted to the requested unit.
Link copied to clipboard
True if the cached color reading matches profile.
Link copied to clipboard
fun isColorWithinDistance(profile: ColorProfile, threshold: Double, unit: DistanceUnit = DistanceUnit.CM): Boolean
Link copied to clipboard