mirror of
https://github.com/undera/pylgbst.git
synced 2020-11-18 19:37:26 -08:00
* 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
1.3 KiB
1.3 KiB
Tilt Sensor
There are several modes to subscribe to sensor, providing 2-axis, 3-axis and bump detect data.
An example:
from pylgbst.hub import MoveHub, TiltSensor
import time
def callback(pitch, roll, yaw):
print("Pitch: %s / Roll: %s / Yaw: %s" % (pitch, roll, yaw))
hub = MoveHub()
hub.tilt_sensor.subscribe(callback, mode=TiltSensor.MODE_3AXIS_SIMPLE)
time.sleep(60) # turn MoveHub block in different ways
hub.tilt_sensor.unsubscribe(callback)
TiltSensor
sensor mode constants:
MODE_2AXIS_SIMPLE
- usecallback(state)
for 2-axis simple state detectMODE_2AXIS_FULL
- usecallback(roll, pitch)
for 2-axis roll&pitch degree valuesMODE_3AXIS_SIMPLE
- usecallback(state)
for 3-axis simple state detectMODE_3AXIS_FULL
- usecallback(roll, pitch)
for 2-axis roll&pitch degree valuesMODE_BUMP_COUNT
- usecallback(count)
to detect bumps
There are tilt sensor constants for "simple" states, for 2-axis mode their names are also available through TiltSensor.DUO_STATES
:
DUO_HORIZ
- "HORIZONTAL"DUO_DOWN
- "DOWN"DUO_LEFT
- "LEFT"DUO_RIGHT
- "RIGHT"DUO_UP
- "UP"
For 3-axis simple mode map name is TiltSensor.TRI_STATES
with values:
TRI_BACK
- "BACK"TRI_UP
- "UP"TRI_DOWN
- "DOWN"TRI_LEFT
- "LEFT"TRI_RIGHT
- "RIGHT"TRI_FRONT
- "FRONT"