Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Accelerometer and Gyroscope

Similar presentations


Presentation on theme: "The Accelerometer and Gyroscope"— Presentation transcript:

1 The Accelerometer and Gyroscope
Mobile Device Components The Accelerometer and Gyroscope

2 Agenda Mobile Device Attitude Properties Accelerometer Gyroscope
Unity 3D Accelerometer Unity 3D Gyroscope

3 Mobile Axis Orientation
A mobile device will use an internal Attitude Measurement and Orientation System The orientation data can then be used by apps to respond accordingly to changes in the orientation of the device. Orientation data is typically used in the contexts of 3D environments such as games and 2D scenarios. The devices Gyroscope is typically involved in providing the orientation data of the mobile device See the respective API’s for more information on the available methods.

4 Orientation Properties
The 3D orientation of a mobile device is described by three properties: Pitch Roll Yaw

5 3D Device Coordinate axes for X, Y, Z
3D Coordinate Axis Y axis Z axis X axis 3D Device Coordinate axes for X, Y, Z

6 Rotation about the X axis is called ‘Pitch’

7 Rotation about the Y axis is called ‘Roll’

8 Rotation about the Z axis is called ‘YAW’

9 Retrieving Gyroscope Values
// global variables to store gyro data public float pitchValue = 0.0f; public float rollValue = 0.0f; public float yawValue = 0.0f; void Start () { // enable the Gyroscope Input.gyro.enabled = true; }

10 Assigning Gyroscope Values
// Unity stores the values of pitch, roll and yaw in // x, y, and z respectively Void Update () { pitchValue = Input.gyro.rotationRateUnbiased.x;  rollValue  = Input.gyro.rotationRateUnbiased.y; yawValue  = Input.gyro.rotationRateUnbiased.z;  } //see the API for the various methods

11 Application of Accelerometer Values
// simple application of accelerometer data public class AccelerometerInput : MonoBehaviour  {     void Update ()      {     transform.Translate(Input.acceleration.x, 0, -Input.acceleration.z);     } } // attach script to a game object to control linear movement in x and z

12 Retrieving Accelerometer Values
// global variables to store accelerometer data public float xValue = 0.0f; public float yValue = 0.0f; public float zValue = 0.0f;

13 Retrieving Accelerometer Values
// store the accelerometer values associated with // x , y, and z as a Vector3 object (force and magnitude) Vector3 accelerator = Input.acceleration; Void Update () { // basic retrieval of Vector3 values in x, y, and z xValue = accelerator.x; yValue = accelerator.y; zValue = accelerator.z; } // would usually required more computation

14 Summary Mobile devices feature a gyroscope and an accelerometer
The gyroscope maintains information on the device’s rotational orientation The x , y and z axis rotational orientation are referred to a pitch, roll and yaw respectively The rotational values for each axis represent radians per second The accelerometer measures acceleration force applied to the device on x, y and z axes and gravitational force g, both in m/s2 Depending on the scenario, apps may require one set of device data or both


Download ppt "The Accelerometer and Gyroscope"

Similar presentations


Ads by Google