motion_sensor

Hub's motion sensor

Example

var hub = serviceSPIKE.PrimeHub();
var motion_sensor = hub.motion_sensor;
// do something with motion_sensor

Methods

static was_gesture(gesture) → {boolean}

Sees whether a gesture has occurred since the last time was_gesture() was used or since the beginning of the program (for the first use).

Parameters:
Name Type Description
gesture string
Returns:
boolean -

true if the gesture was made, false otherwise

static wait_for_new_gesture(callback)

Executes callback when a new gesture happens

Parameters:
Name Type Description
callback function

A callback of which argument is name of the gesture

Example
motion_sensor.wait_for_new_gesture( function ( newGesture ) {
     if ( newGesture == 'tapped') {
            console.log("SPIKE was tapped")
     }
     else if ( newGesture == 'doubletapped') {
            console.log("SPIKE was doubletapped")
     }
     else if ( newGesture == 'shaken') {
            console.log("SPIKE was shaken")
     }
     else if ( newGesture == 'freefall') {
            console.log("SPIKE was freefall")
     }
})

static wait_for_new_orientation(callback)

Executes callback when the orientation of the Hub changes or when function was first called

Parameters:
Name Type Description
callback function

A callback whose signature is name of the orientation

Example
motion_sensor.wait_for_new_orientation( function ( newOrientation ) {
       if (newOrientation == "up") {
             console.log("orientation is up");
       }
       else if (newOrientation == "down") {
             console.log("orientation is down");
       }
       else if (newOrientation == "front") {
             console.log("orientation is front");
       }
       else if (newOrientation == "back") {
             console.log("orientation is back");
       }
       else if (newOrientation == "leftSide") {
             console.log("orientation is leftSide");
       }
       else if (newOrientation == "rightSide") {
             console.log("orientation is rightSide");
       }
})

static get_yaw_angle() → {integer}

“Yaw” is the rotation around the front-back (vertical) axis.

Returns:
integer -

yaw angle

static get_pitch_angle() → {integer}

“Pitch” the is rotation around the left-right (transverse) axis.

Returns:
integer -

pitch angle

static get_roll_angle() → {integer}

“Roll” the is rotation around the front-back (longitudinal) axis.

Returns:
integer -

roll angle

static get_yaw_acceleration() → {integer}

Gets the acceleration of the SPIKE's yaw axis

Returns:
integer -

acceleration

static get_pitch_acceleration() → {integer}

Gets the acceleration of the SPIKE's pitch axis

Returns:
integer -

acceleration

static get_roll_acceleration() → {integer}

Gets the acceleration of the SPIKE's roll axis

Returns:
integer -

acceleration

static get_gesture() → {string}

Retrieves the most recently detected gesture.

Returns:
string -

the name of gesture

static get_orientation() → {string}

Retrieves the most recently detected orientation Note: Hub does not detect orientation of when it was connected

Returns:
string -

the name of orientation