MotionSensor
Package: Libraries.Robots.Spike · Inherits from: Libraries.Language.Object
The motion sensor is a function of the SPIKE Hub which allows for the detection of movements, orientaion, and environmental interactions.
Example Code
use Libraries.Robots.Spike.MotionSensor
MotionSensor ms
integer taps = ms:GetTapCount()
Variables
integer FALLINGinteger LEFT: The face with the USB charging portinteger SHAKENinteger BOTTOM: The right side of the hub when facing the front faceinteger FRONT: The face with the Light Matrixinteger RIGHT: The side of the hub where the speaker isinteger DOUBLE_TAPPEDinteger TOP: The face with the Light Matrixinteger UNKOWNinteger BACK: The side of the hub where the battery isinteger TAPPED
Actions
ChangeYawOffset(integer angle)
Changes the Hub's yaw angle offset to the angle specified.
Parameters
angleinteger: The angle to set as the Hub's yaw offset
Example
use Libraries.Robots.Spike.MotionSensor
MotionSensor ms
ms:ChangeYawOffset(30)
GetAcceleration(boolean raw_data)
Returns the acceleration in all 3 directions in units of mili G (1/1000 G)
Parameters
raw_databoolean: A boolean value which determines if the function will return the acceleration as raw unfiltered data (true) or not (false)
Returns
Libraries.Containers.Array<integer>: An Array
Example
use Libraries.Robots.Spike.MotionSensor
use Libraries.Containers.Array
MotionSensor ms
Array<integer> acceleration
acceleration = ms:GetAcceleration(false)
GetAngularVelocity(boolean raw_data)
Returns the angular velocity in all 3 directions in units of decidegrees per second
Parameters
raw_databoolean: A boolean value which determines if the function will return the angular velocity as raw unfiltered data (true) or not (false)
Returns
Libraries.Containers.Array<integer>: An Array
Example
use Libraries.Robots.Spike.MotionSensor
use Libraries.Containers.Array
MotionSensor ms
Array<integer> angular_velocity
angular_velocity = ms:GetAngularVelocity(false)
GetCurrentUpFace()
Returns the hub face that is currently facing up.
Returns
integer: An integer for the Hub face which is currently facing up, which
corresponds to one of the constants in the MotionSensor class (TOP, FRONT, RIGHT, BOTTOM, BACK, LEFT)
Example
use Libraries.Robots.Spike.MotionSensor
MotionSensor ms
integer up_face = ms:GetCurrentUpFace()
GetGesture()
Retrieves the recognized gesture from 1 of 5 possible values listed as constants in the MotionSensor class (TAPPED, DOUBLE_TAPPED, SHAKEN, FALLING, UNKNOWN)
Returns
integer: The recognized gesture from 1 of 5 possible values listed as constants in the
MotionSensor class (TAPPED, DOUBLE_TAPPED, SHAKEN, FALLING, UNKNOWN)
Example
use Libraries.Robots.Spike.MotionSensor
MotionSensor ms
integer gesture = ms:GetGesture()
GetQuaternion()
Used to get the hub's orientation quaternion
Returns
Libraries.Containers.Array<number>: An Array
Example
use Libraries.Robots.Spike.MotionSensor
use Libraries.Containers.Array
MotionSensor ms
Array<number> quaternion
quaternion = ms:GetQuaternion()
GetTapCount()
Retrieves the amount of taps recognized since the last time ResetTapCount() was called.
Returns
integer: An integer stating the amount of taps detected since the count
was last reset.
Example
use Libraries.Robots.Spike.MotionSensor
MotionSensor ms
integer taps = ms:GetTapCount()
GetTiltAngles()
Retrieves the angle in all 3 axes of the current orientation of the SPIKE Hub.
Returns
Libraries.Containers.Array<integer>: An Array
Example
use Libraries.Robots.Spike.MotionSensor
use Libraries.Containers.Array
Array<integer> angles
MotionSensor ms
angles = ms:GetTiltAngles()
GetYawFace()
Retrieves the face of the hub that yaw is relative to from 1 of 6 possible faces listed as constants in the MotionSensor class (TOP, FRONT, RIGHT, BOTTOM, BACK, LEFT)
Returns
integer: The recognized yaw_face from 1 of possible faces listed as constants in the
MotionSensor class (TOP, FRONT, RIGHT, BOTTOM, BACK, LEFT)
Example
use Libraries.Robots.Spike.MotionSensor
MotionSensor ms
integer yaw_face = ms:GetYawFace()
IsHubStable()
Checks if the hub is in stable, returns true if it is, false if it's not.
Returns
boolean: A boolean value that returns true if the hub is stable, and
false if it isn't.
Example
use Libraries.Robots.Spike.MotionSensor
MotionSensor ms
if ms:IsHubStable()
// The Hub is stable!
else
// The Hub isn't stable
end
ResetTapCount()
Resets the Hub's tap counter to 0
Example
use Libraries.Robots.Spike.MotionSensor
MotionSensor ms
ms:ResetTapCount()
SetYawFace(integer upface)
Sets the face of the hub that yaw is relative to from 1 of 6 possible faces listed as constants in the MotionSensor class (TOP, FRONT, RIGHT, BOTTOM, BACK, LEFT)
Parameters
upfaceinteger: The desired yaw face from 1 of possible faces listed as constants in the MotionSensor class (TOP, FRONT, RIGHT, BOTTOM, BACK, LEFT)
Returns
boolean: A boolean
Example
use Libraries.Robots.Spike.MotionSensor
MotionSensor ms
boolean yaw_face_set = ms:SetYawFace(ms:FRONT)