1
0
mirror of https://github.com/undera/pylgbst.git synced 2020-11-18 19:37:26 -08:00
Andrey Pokhilko 32eecac1a6
Make v1.0, based on official docs (#27)
* It's HUB ID

* Rename file

* Working with official doc

* Some progress

* AttachedIO msg

* device action impl

* some better device alert impl

* restructuring

* Some port commands handled

* Some command feedback waiting

* Some more request-reply things

* Some more request-reply things

* Reworked msg classes

* Getting back to UTs

* Getting back to UTs

* Facing sync lock problems

* Facing sync lock problems

* Testing it

* Covering more with tests

* handle actions

* Hub class is almost covered

* done coverage for Hub

* done coverage for MoveHub

* Button is tested

* remove debug server from examples

* Current and voltage tested

* color sensor basic test

* cover tilt sensor

* motor sensor tested

* constant motor

* motor is tested

* hold_speed impl for motor

* motor commands recorded

* some cleanup

* some cleanup

* some cleanup

* debug

* debug

* FIX a bug

* acc/dec profiles figured out

* UT motor ops

* UT motor ops

* Get rid of weird piggyback

* fix UT

* Fix encoding?

* fix test mb

* More robust

* Checked demo works

* cosmetics

* cosmetics

* Maybe better test

* fetching and decoding some device caps

* describing devs

* describing devs works

* Applying modes we've learned

* Simple and extensible dev attach

* Reworking peripherals based on modes

* Applying modes we've learned

* implemented getting sensor data

* fixed port subscribe

* Added led out cmds on vision sensor

* Worked on color-distance sensor

* Introduce some locking for consistency

* Improved it all

* Travis flags

* improve

* improve

* improve docs
2019-05-30 17:02:50 +03:00

1.8 KiB

Color & Distance Sensor

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, use callback(color, distance) where distance is float value in inches
  • COLOR_ONLY - use callback(color)
  • DISTANCE_INCHES - use callback(color) measures distance in integer inches count
  • COUNT_2INCH - use callback(count) - it counts crossing distance ~2 inches in front of sensor
  • DISTANCE_HOW_CLOSE - use callback(value) - value of 0 to 255 for 30 inches, larger with closer distance
  • DISTANCE_SUBINCH_HOW_CLOSE - use callback(value) - value of 0 to 255 for 1 inch, larger with closer distance
  • LUMINOSITY - use callback(luminosity) where luminosity is float value from 0 to 1
  • OFF1 and OFF2 - seems to turn sensor LED and notifications off
  • STREAM_3_VALUES - use callback(val1, val2, val3), sends some values correlating to distance, not well understood at the moment