Sensor has number of different modes to subscribe.
Colors that are detected are part of COLORS
map (see LED section). Only several colors are possible to detect: BLACK
, BLUE
, CYAN
, YELLOW
, RED
, WHITE
. Sensor does its best to detect best color, but only works when sample is very close to sensor.
Distance works in range of 0-10 inches, with ability to measure last inch in higher detail.
Simple example of subscribing to sensor:
from pylgbst.hub import MoveHub, VisionSensor
import time
def callback(clr, distance):
print("Color: %s / Distance: %s" % (clr, distance))
hub = MoveHub()
hub.vision_sensor.subscribe(callback, mode=VisionSensor.COLOR_DISTANCE_FLOAT)
time.sleep(60) # play with sensor while it waits
hub.vision_sensor.unsubscribe(callback)
Subscription mode constants in class ColorDistanceSensor
are:
COLOR_DISTANCE_FLOAT
- default mode, usecallback(color, distance)
wheredistance
is float value in inchesCOLOR_ONLY
- usecallback(color)
DISTANCE_INCHES
- usecallback(color)
measures distance in integer inches countCOUNT_2INCH
- usecallback(count)
- it counts crossing distance ~2 inches in front of sensorDISTANCE_HOW_CLOSE
- usecallback(value)
- value of 0 to 255 for 30 inches, larger with closer distanceDISTANCE_SUBINCH_HOW_CLOSE
- usecallback(value)
- value of 0 to 255 for 1 inch, larger with closer distanceLUMINOSITY
- usecallback(luminosity)
whereluminosity
is float value from 0 to 1OFF1
andOFF2
- seems to turn sensor LED and notifications offSTREAM_3_VALUES
- usecallback(val1, val2, val3)
, sends some values correlating to distance, not well understood at the moment