Sensor Data

 

Introduction

The Sensor Data application gives you direct access to data from all of the sensors in the iPhone and iPod Touch. The data can be streamed to your computer using UDP, or the sensor data can be captured, and transferred off the iPhone as a CSV (comma-separated) data file.

iPhone Sensor Introduction

There are different sensors depending upon what model device you have:

·    3D accelerometer - Each iPhone / iPod Touch / iPad has a 3D accelerometer. Returns acceleration in the X, Y, Z axis.

·    3D Gyro – The iPhone 4 has a 3D gyro. The gyro data is integrated with the acceleration data to create Gyro Enhanced Motion data including:

o Euler angles of the device (pitch, roll, and yaw)

o Attitude Quaternion

o Rotation Matrix

o Gravitational component of 3D acceleration

o User acceleration component of 3D acceleration

o Rotation Rate

·    Location data / GPS – Most devices will report some type of location data, but it is likely of limited accuracy unless the device has a GPS. With a GPS, data includes:

o Latitude and longitude

o Course and speed of movement

o Altitude

iPhone Sensor Reported Data and Units

The following data is reported by the app:

·    3D Acceleration

o X, Y, Z in units of g.

o A G is a unit of gravitation force equal to that exerted by the earth’s gravitational field (9.81 m s−2).

o The total acceleration of the device is equal to gravity plus the acceleration the user imparts to the device. These two effects can be separated if you have the 3D gyro sensor.

o 3D Axis of iPhone

 

·    Device attitude - Euler angles (pitch, roll, yaw) – radians

·    Attitude Quaternion – x, y, z, w

§  A quaternion offers a way to parameterize attitude. Mathematically it represents the following unit quaternion: q.x*i + q.y*j + q.z*k + q.w. A unit quaternion represents a rotation of theta radians about the unit vector {x,y,z}, and {q.x, q.y, q.z, q.w} satisfies the following:

1.                         q.x = x * sin(theta / 2)

2.                         q.y = y * sin(theta / 2)

3.                         q.z = z * sin(theta / 2)

4.                         q.w = cos(theta / 2)

·    Attitude rotation matrix – The attitude rotation matrix is a 3x3 matrix ((m11, m12, m13), (m21, m22, m23), (m31, m32, m33)).

·    Gravitational Acceleration – Returns the gravity acceleration vector (x, y, z) expressed in the device’s reference frame – units of g.

·    User acceleration – The acceleration that the user is giving to the device (x, y, z) – units of g.

·    Rotation Rate – Measured by the 3D Gyro sensor – represents a measurement of rotation rate (x, y, z) – units of radians per second.

o The X-axis rotation rate in radians per second. The sign follows the right hand rule: If the right hand is wrapped around the X axis such that the tip of the thumb points toward positive X, a positive rotation is one toward the tips of the other four fingers.

o The Y-axis rotation rate in radians per second. The sign follows the right hand rule: If the right hand is wrapped around the Y axis such that the tip of the thumb points toward positive Y, a positive rotation is one toward the tips of the other four fingers.

o The Z-axis rotation rate in radians per second. The sign follows the right hand rule: If the right hand is wrapped around the Z axis such that the tip of the thumb points toward positive Z, a positive rotation is one toward the tips of the other four fingers.

·    Location – Magnetic and True Heading

o Magnetic Heading - The heading (measured in degrees) relative to magnetic north. 

o True Heading - The heading (measured in degrees) relative to true north.

·    Magnetometer – Some devices include a 3D magnetometer used to provide compass directions. The magnetometer data returns the raw 3D magnetic data measured by the sensor in units of micro-teslas.

o Returned x, y, and z – units microtesla

o Value is normalized to the range of -128 to +128, representing the x,y,z axis deviation from the magnetic field lines being tracked by the device.

·    Position: Latitude, Longitude

o Latitude and longitude are geographical coordinates using the WGS 84 reference frame.

o Units are degrees.

o Latitude - Positive values indicate latitudes north of the equator. Negative values indicate latitudes south of the equator.

o Longitude - The longitude in degrees. Measurements are relative to the zero meridian, with positive values extending east of the meridian and negative values extending west of the meridian.

o Accuracy – Represents the accuracy of a coordinate value in meters.

·    Course and Speed

o Course – The direction in which the device is traveling – units of degrees. Course values are measured in degrees starting at due north and continuing clockwise around the compass. Thus, north is 0 degrees, east is 90 degrees, south is 180 degrees, and so on. Course values may not be available on all devices. A negative value indicates that the direction is invalid.

o Speed - The instantaneous speed of the device in meters per second. This value reflects the instantaneous speed of the device in the direction of its current heading. A negative value indicates an invalid speed. Because the actual speed can change many times between the delivery of subsequent location events, you should use this property for informational purposes only.

·    Altitude - The altitude measured in meters. Positive values indicate altitudes above sea level.

Modes of Operation

There are two primary modes of operation:

·          Capture (Capture Tab) – Allows you to capture the sensor data and store it on the internal Flash filesystem of the device. The Library tab allows you to view and manage the collected data. The app creates an internal web server that allows you to use an external web browser from another computer to download the stored data files to another computer. These files are downloaded as CSV (comma separated) data values. This data is then easily used for data analysis and importing into spreadsheets for further analysis.

·          Streaming (Streaming Tab) – Creates a real-time UDP stream of sensor values from the device to an external computer for real-time data collection.

 

Config Tab

Data Capture Config - Allows you to specify what data is collected and reported. Data that is not available on your device will be grayed out and not selectable.

 

Sample Count allows you to specify a maximum number of samples that are collected. 0 means unlimited (meaning manually turned off). Sample Count is valid for both Capture and Streaming modes.

 

Streaming Data Configuration – Specifies the network streaming configuration for the Streaming Mode.

·    Mode – Select Unicast or Broadcast. By default it uses broadcast mode, which means that all devices in the same broadcast domain will receive the packets.

·    Address – Don’t change for broadcast. For Unicast, allows you to specify the IP address to which the UDP data is sent.

·    Port – Specifies the IP port for the UDP packets.

 

Capture Mode

Allows you to capture the sensor data and store it on the internal Flash filesystem of the device. The Library tab allows you to view and manage the collected data. The app creates an internal web server that allows you to use an external web browser from another computer to download the stored data files to another computer. These files are downloaded as CSV (comma separated) data values. This data is then easily used for data analysis and importing into spreadsheets for further analysis.

·    You need to have an active wifi connection between the computer and the device. The data transfer does not work over 3G.

·    URL: The URL to enter in the external computer web browser to access the data library. Use the entire URL including the :54388 port specifier.

·    Freq: Specifies the rate at which the data is collected (1-100 Hz).

·    Sampling – Turn On to start capturing, Turn Off to stop capturing. Sampling will also stop if the maximum Sample Count (Config Tab) has been reached.

·    Samples – Provides count of samples that have been collected in the latest run.

·    Filename – The generated filename that this data store is in within the data library.

 

Streaming Mode

 

Allows you to real-time stream the sensor data with UDP packets to another computer.

Control:

·    Freq: Specifies the rate at which the data is collected (1-100 Hz)

·    Enable Streaming – Turn On to start streaming, Turn Off to stop streaming. Streaming will also stop if the maximum Sample Count (Config Tab) has been reached.

·    Samples – Provides count of samples that have been collected in the latest run.

 

You will need to run a server-side program to collect and store the UDP packets with the sensor data data. A sample Python program is available here.

 

 

Example Experimental Projects:

Following are some example experimental uses that are appropriate for a science fair project or a physics lab project.

 

Note: Obviously be careful in using your iPhone/iTouch as an acceleration data collection device for experiments. Do not subject it to impact or unusual / significant forces.

 

·    Use the iPhone/iTouch as the bob of a pendulum, collecting the acceleration data from the pendulum.

·    Use the iPhone/iTouch on a “sled” down a ramp, collecting the acceleration data from the pendulum.

·    Measure motions of elevators.

·    Measure motions of roller coasters.

·    Measure motions during sky diving.

·    Measure motions during driving.

 

Capture Mode – Library

·    Clicking the Library tab allows you to manage the captured data files.

·    Clicking Delete will delete an individual capture file. Be careful, it won’t ask you to confirm the delete.

·    Clicking on the filename will display the data in an HTML table.