Page 36 - MSDN Magazine, April 2018
P. 36
Sensor Hardware
Figure 4 shows the Sensor Kit hardware. What is a sensor? Hardware manufacturers usually refer to sensors as single-purpose measuring devices. In this article, a sensor is an inertial measurement unit (IMU) device powerful enough to take and process data from multiple sensory inputs, store the results and transmit them back to the host or a gateway. The sensor system consists of:
• An IMU capable of providing 9-DOF (degrees of freedom) accelerometer, gyro and magnetometer data at 40-100Hz.
• Bluetooth Low Energy (BLE) or other means of wireless communication.
• Storage adequate for aggregate or raw sensor data.
• Other sensors, such as those for proximity, location, and so forth.
The Data Model and Pipeline
As the saying goes, a journey of a thousand miles begins with the first step. And so we start with in-depth code examples to ingest, transform and prepare the data for later analysis and presentation. We describe two foundational elements here, designing the data structure or “data model,” and designing the pipelining of data from the device to storage, then transforming and presenting the information to the athlete and coach.
Let’s start with the data model. The Sensor Kit has three modes of data aggregation—summary, event level and raw logging:
• Summary data is pre-aggregated data on the sensor. In most retail sensor scenarios, this is a
relatively small payload that’s
transferred with each dataset.
throughput requirements. If you need all the detailed data, the Sensor Kit allows you to enable verbose logging using the SetLogging(true) call.
Connecting to Sensors
Let’s start the description of data pipelining from the sensor itself. Initializing the Sensor Kit is easy, by simply calling the Init method:
SensorKit.Instance.Init();
The Sensor Kit works in both pull and push modes; with pull mode the app needs to explicitly call the Sync method on a sensor, while push mode automatically registers for sensor notification. To enable push updates, you can call SetAutoUpdates(true). To subscribe to sensor updates, use the Subscribe method:
await Task.Run(async () => {
await sensor.Instance.Subscribe(); });
The Sensor Kit consumes data from sensors, provides methods for time synchronization and sends the data to the cloud. Time synchronization is important, especially when athletes can have multiple sensors attached, and the Sensor Kit automatically resolves the timestamp on hardware devices to the time on the host device with the Sensor Kit-enabled app. The method to store data in the cloud is up to the app developer; the library provides a Cosmos DB connector and Azure containers for convenience, as shown in Figure 5.
The Sensor Kit delivers some transformed data events and aggre- gates from the device itself. The following list of item schema describes the taxon-
Figure 4 Sensor Kit Hardware
• Event-level data is triggered by specific events, such as turns, jumps and so forth. Event-level data may have several hundred or thousand records per session. These events are based on pre- defined activity signatures derived from the sensor data. They’re described in more detail in the turn “Detecting Activity Signa- tures from Sensor Data” section.
• Raw logging is best for recording data at high frequency, typically the top frequency the sensor can provide—40-100Hz or more.
Depending on the sample rate of the sensor, aggregation of the raw logging data may be necessary to allow collec- tion of data from the device in near-real time. In broader consumer mass mar- ket scenarios, producing, storing and transmitting so much granular data can be excessive, so we defined a stan- dard mode in the Sensor Kit to transmit slightly aggregated data to reduce data
Figure 5 The Sensor Kit Library in Visual Studio
omy of these data elements:
• SensorItem: Single-sensor data item; items can be of any dura-
tion or granularity
• SensorTurnData: Aggregated
data for turns
• SensorAirData: Aggregated data
for jumps
• SensorSummaryData: Summary
data aggregated per sensor
• SensorRawData: High-frequency
raw data (for example, 100Hz)
• UserData*: User-level information
(optional, app specific)
• TeamData*: Team-level data for teams
of athletes (optional, app specific)
Storing Sensor Data
in Cosmos DB
Of course, there are many options when it comes to loading data into the cloud. Cosmos DB is great for IoT and telemetry data, as shown in Figure 6, and provides multiple APIs for loading and querying data, as well as scalability and global distribution.
30 msdn magazine
Machine Learning