Trajectory

This API enables the user to estimate the trajectory of the mobile device.

The Trajectory estimates spatial motion of the mobile device over time. When the device moves, the Trajectory event fires and returns the device's linear acceleration, velocity, and position. It is designed to measure short range motion within an arm's length. Special care is taken to correct for drift due to bias and noise in the signal.

Trajectory relies on the device's Accelerometer sensor and derived Orientation.

Example

var trajectory = new MotionStack.Trajectory({
  frame: "world",
  nonCausal: true,
  closed: false
});

trajectory.start(function (e) {
  console.log(e.position.x);

  if (e.position.x > 10) {
    trajectory.stop();
  }
});

Constructor

new MotionStack.Trajectory([options])

Create a new Trajectory instance object.

Argument Type Description
options Object Options to pass in for the new Trajectory instance (optional)

  • frame {String}
  • Reports the data relative to the specified coordinate system. Refer to the coordinates frame page for more details.

    • "device" Reference frame fixed to the device.
    • "world" Reference frame fixed to the Earths gravity.
    • "user" Reference frame fixed to the user. It is a combination of device-frame and world-frame and assumes the user is holding the device in portrait mode in-front of them.


    Default: "world"

  • nonCausal {Boolean}
  • Apply a non-causal bias correction to remove drift incurred by the accelerometer. The correction is applied after one full motion is completed. A motion is considered complete once the device is determined to be stationary. The bias-correction guarantees that the final velocity after each motion is zero. The corrected data is returned in addition to the uncorrected data.


    Default: true

  • closed {Boolean}
  • If the first and last "corrected" points are near each other, then adjust the "corrected" data to create a closed path.


    Default: false

var trajectory = new MotionStack.Trajectory({
  frame: "world",
  nonCausal: true,
  closed: false
});

Instance Methods

start(callback, [context])

Start receiving trajectory updates.

Argument Type Description
callback Function Callback function that receives an object as an argument

  • function(e)
  • e.acceleration.x, e.acceleration.y, e.acceleration.z
    {Number}
    Axial components of linear acceleration in the frame specified in the constructor (m/s2).
  • e.velocity.x, e.velocity.y, e.velocity.z
    {Number}
    Axial components of linear velocity (integrated acceleration) in the frame specified in the constructor (m/s).
  • e.position.x, e.position.y, e.position.z
    {Number}
    Axial components of linear position (integrated velocity) in the frame specified in the constructor (m).
  • e.mode {String}
    Indicates the type of motion.
    • "resting" The external forces are small enough to consider the device stationary. The returned velocity is the zero vector and the position is stationary.
    • "moving" The external forces are great enough to consider the device in-motion and motion is estimated without bias correction.
    • "corrected" In-motion data with the applied non-causal bias correction. The correction is applied to all "moving" mode data between the the last "resting" modes, and is output in one batch. This is reported if options.nonCausal is set to true.
  • e.interval {Number}
    The time in milliseconds between consecutive readings.
  • e.timeStamp {Number}
    The time in milliseconds when the data is collected.
context Object Context in which to invoke the callback (optional).
trajectory.start(function(e) {
  console.log(e.position.x);
});

stop()

Stop trajectory updates.

trajectory.stop();

pause()

Pauses trajectory updates and resets the velocity to zero. Every time pause() is called, the trajectory instance toggles between ignoring and registering motion events.

trajectory.start(function () {/*do something*/}); // register motion
trajectory.pause(); // motion is ignored
trajectory.pause(); // motion is being registered again

set(position, timeStamp)

Sets the position with the given timeStamp and fires one trajectory event. Estimates for acceleration and velocity are set to zero and interval is undefined.

Argument Type Description
position Object The position coordinates in meters to set. position.x, position.y, position.z
timeStamp Number The time in milliseconds to set.
trajectory.set({ x: 0, y: 0, z: 0 }, Date.now());

Source

src/interfaces/Trajectory.js