knitr::opts_chunk$set(echo = TRUE, fig.align = "center")
Modern smartphones include a lot of sensors, e.g. for gravity or linear acceleration. Some apps provide the data collected from these sensors. One famous android app is "HyperIMU" (IMU: Inertial measurement unit). There are other apps available, but HyperIMU has some advantages:
The R-package HypeRIMU provides some handy functions to visualise sensor data. Different streaming protocolls are supported (a local .csv file and TCP).
Until now two different methods to read the sensor data are supported: TCP and a local file.
The TCP protocol is also supported. Using this method needs to know your IP address to sumbit in the smartphone app, see HIMUServer.
data <- execute_TCP(port = 5555)
The recommended way to read the data is to save the records on your smartphone and submit them locally to your PC as a .csv file. The advantage from this method is the appropriation of sensor names.
The following code shows an example of using a local file. The file can be imported via the function
execute_file(). If your data provide a
TRUE for the argument
timestamp. The functions tries to guess if a timestamp is available even when you set the
timestamp argument wrong.
When a timestamp is available in the file, the function changes the UNIX format to as POSIXct format.
library(HypeRIMU) library(magrittr) data <- system.file('extdata', 'short_y_impulse.csv', package = 'HypeRIMU') %>% execute_file()
HypeRIMU provides a function to extract some specific sensor data, see next code.
When a sumbitted
sensorName is not available in the
data, an error message is printed.
MPL_Accelerometer <- get_specificSensor(data, sensorName = "MPL_Accelerometer") MPL_Linear_Acceleration <- get_specificSensor(data, sensorName = "MPL_Linear_Acceleration")
Visulasing the data is one of the main advantages of this R-package. With some extra libraries a nice plot can be created in just a few lines. NOTE: It is recommended to use data with a timestamp.
library(ggplot2) library(reshape2) library(scales) melt(MPL_Linear_Acceleration, id.vars = "Timestamp", variable.name = "Sensor") %>% ggplot(aes(x = Timestamp, y = value, color = Sensor)) + geom_line() + theme(axis.text.x = element_text(angle = 45, hjust = 1)) + scale_x_datetime(labels = date_format("%H:%M:%S", tz = Sys.timezone()))
melt(MPL_Accelerometer, id.vars = "Timestamp", variable.name = "Sensor") %>% ggplot(aes(x = Timestamp, y = value, color = Sensor)) + geom_line() + theme(axis.text.x = element_text(angle = 45, hjust = 1)) + scale_x_datetime(labels = date_format("%H:%M:%S", tz = Sys.timezone()))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.