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 = 0

  • DOUBLE_TAPPED = 1

  • SHAKEN = 2

  • FALLING = 3

  • UNKNOWN = -1

  • TOP = 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 the

    front 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 front

    hub face)

Functions

acceleration(raw_unfiltered)

Get a tuple containing x, y & z acceleration values as integers.

angular_velocity(raw_unfiltered)

Get a tuple containing x, y & z angular velocity values as integers.

gesture()

Get the gesture recognized.

get_yaw_face()

Get the face of the hub that yaw is relative to.

quaternion()

Get the hub orientation quaternion as a tuple[w: float, x: float, y: float, z: float].

reset_tap_count()

Reset the tap count returned by the tap_count function.

reset_yaw(angle)

Set the yaw angle offset.

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.

stable()

Whether or not the hub is resting flat.

tap_count()

Get the number of taps recognized since the program started or last time motion_sensor.reset_tap_count() was called.

tilt_angles()

Get a tuple containing yaw, pitch, and roll values as integers.

up_face()

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.TAPPED

  • motion_sensor.DOUBLE_TAPPED

  • motion_sensor.SHAKEN

  • motion_sensor.FALLING

  • motion_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 port

  • motion_sensor.FRONT: The SPIKE Prime hub face with the Light Matrix

  • motion_sensor.RIGHT: The right side of the SPIKE Prime hub when facing the front hub face

  • motion_sensor.BOTTOM: The side of the SPIKE Prime hub where the battery is

  • motion_sensor.BACK: The SPIKE Prime hub face where the speaker is

  • motion_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_count function.

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 port

  • motion_sensor.FRONT: The SPIKE Prime hub face with the Light Matrix

  • motion_sensor.RIGHT: The right side of the SPIKE Prime hub when facing the front hub face

  • motion_sensor.BOTTOM: The side of the SPIKE Prime hub where the battery is

  • motion_sensor.BACK: The SPIKE Prime hub face where the speaker is

  • motion_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 port

  • motion_sensor.FRONT: The SPIKE Prime hub face with the Light Matrix

  • motion_sensor.RIGHT: The right side of the SPIKE Prime hub when facing the front hub face

  • motion_sensor.BOTTOM: The side of the SPIKE Prime hub where the battery is

  • motion_sensor.BACK: The SPIKE Prime hub face where the speaker is

  • motion_sensor.LEFT: The left side of the SPIKE Prime hub when facing the front hub face

Return type:

int