hub.motion_sensor¶
The motion_sensor module includes functions to interact with the
internal motion sensor (gyroscope) in a SPIKE hub.
To use the motion_sensor module, add the following import statement to
your project:
from hub import motion_sensor
All functions in the module should be called inside the
motion_sensor module as a prefix like so:
motion_sensor.up_face()
The following constants are defined:
TAPPED= 0DOUBLE_TAPPED= 1SHAKEN= 2FALLING= 3UNKNOWN= -1TOP= 0 (the SPIKE Prime hub face with the Light Matrix)FRONT= 1 (the SPIKE Prime hub face where the speaker is)RIGHT= 2 (the right side of the SPIKE Prime hub when facing thefront hub face)
BOTTOM= 3 (the side of the SPIKE Prime hub where the battery is)BACK= 4 (the SPIKE Prime hub face with the USB charging port)LEFT= 5 (the left side of the SPIKE Prime hub when facing the fronthub face)
Functions
|
Get a tuple containing x, y & z acceleration values as integers. |
|
Get a tuple containing x, y & z angular velocity values as integers. |
|
Get the gesture recognized. |
Get the face of the hub that yaw is relative to. |
|
Get the hub orientation quaternion as a tuple[w: float, x: float, y: float, z: float]. |
|
Reset the tap count returned by the |
|
|
Set the yaw angle offset. |
|
Set what hub face is used as the yaw face.If you put the hub on a flat surface with this face pointing up, when you rotate the hub only the yaw will update. |
|
Whether or not the hub is resting flat. |
Get the number of taps recognized since the program started or last time |
|
Get a tuple containing yaw, pitch, and roll values as integers. |
|
|
Get the Hub face that is currently facing up. |
- hub.motion_sensor.acceleration(raw_unfiltered)¶
Get a tuple containing x, y & z acceleration values as integers. The values are milli G, so 1 / 1000 G.
- Parameters:
raw_unfiltered (bool) – If we want the data back raw and unfiltered
- Return type:
tuple
- hub.motion_sensor.angular_velocity(raw_unfiltered)¶
Get a tuple containing x, y & z angular velocity values as integers. The values are decidegrees per second.
- Parameters:
raw_unfiltered (bool) – If we want the data back raw and unfiltered
- Return type:
tuple
- hub.motion_sensor.gesture()¶
Get the gesture recognized. Possible values are:
motion_sensor.TAPPEDmotion_sensor.DOUBLE_TAPPEDmotion_sensor.SHAKENmotion_sensor.FALLINGmotion_sensor.UNKNOWN
- Return type:
int
- hub.motion_sensor.get_yaw_face()¶
Get the face of the hub that yaw is relative to. If you put the hub on a flat surface with the face returned pointing up, when you rotate the hub only the yaw will update. Possible return values are:
motion_sensor.TOP: The SPIKE Prime hub face with the USB charging portmotion_sensor.FRONT: The SPIKE Prime hub face with the Light Matrixmotion_sensor.RIGHT: The right side of the SPIKE Prime hub when facing the front hub facemotion_sensor.BOTTOM: The side of the SPIKE Prime hub where the battery ismotion_sensor.BACK: The SPIKE Prime hub face where the speaker ismotion_sensor.LEFT: The left side of the SPIKE Prime hub when facing the front hub face
- Return type:
int
- hub.motion_sensor.quaternion()¶
Get the hub orientation quaternion as a tuple[w: float, x: float, y: float, z: float].
- Return type:
tuple
- hub.motion_sensor.reset_tap_count()¶
Reset the tap count returned by the
tap_countfunction.- Return type:
None
- hub.motion_sensor.reset_yaw(angle)¶
Set the yaw angle offset. The angle set will be the new yaw value.
- Return type:
None
- Parameters:
angle (int)
- hub.motion_sensor.set_yaw_face(up)¶
Set what hub face is used as the yaw face.If you put the hub on a flat surface with this face pointing up, when you rotate the hub only the yaw will update.
- Parameters:
up (int) –
The hub face that should be set as the upwards facing hub face. Possible values are:
motion_sensor.TOP: The SPIKE Prime hub face with the USB charging portmotion_sensor.FRONT: The SPIKE Prime hub face with the Light Matrixmotion_sensor.RIGHT: The right side of the SPIKE Prime hub when facing the front hub facemotion_sensor.BOTTOM: The side of the SPIKE Prime hub where the battery ismotion_sensor.BACK: The SPIKE Prime hub face where the speaker ismotion_sensor.LEFT: The left side of the SPIKE Prime hub when facing the front hub face
- Return type:
bool
- hub.motion_sensor.stable()¶
Whether or not the hub is resting flat.
- Return type:
bool
- hub.motion_sensor.tap_count()¶
Get the number of taps recognized since the program started or last time
motion_sensor.reset_tap_count()was called.- Return type:
int
- hub.motion_sensor.tilt_angles()¶
Get a tuple containing yaw, pitch, and roll values as integers. Values are in decidegrees (tenths of a degree). Values range from -1795 to 1800. Negative values indicate clockwise rotation from zero, positives indicate counter-clockwise rotation.
- Return type:
tuple
- hub.motion_sensor.up_face()¶
Get the Hub face that is currently facing up. Possible values are:
motion_sensor.TOP: The SPIKE Prime hub face with the USB charging portmotion_sensor.FRONT: The SPIKE Prime hub face with the Light Matrixmotion_sensor.RIGHT: The right side of the SPIKE Prime hub when facing the front hub facemotion_sensor.BOTTOM: The side of the SPIKE Prime hub where the battery ismotion_sensor.BACK: The SPIKE Prime hub face where the speaker ismotion_sensor.LEFT: The left side of the SPIKE Prime hub when facing the front hub face
- Return type:
int