create_mtc_device

System Insights

2019-01-07

Creating MTCDevice Class

You can create and MTC Device Class by specifying a Delimited MTConnect Data (DMTCD) file and a devices.XML

DMTCD file and devices XML file - create_mtc_device_from_dmtcd

The usage is straightforward. The user can provide ther path to the Delimited MTConnect Data(DMTCD) file and the devices XML and the package reads the files and packages the data into an easily usable MTCDevice S4 Data Structure.

require(mtconnectR)
## Loading required package: mtconnectR
file_path_dmtcd = "testdata/dataExtraction/test_dmtcd.log"
file_path_xml = "testdata/dataExtraction/test_devices.xml"
device_name = "test_device"
mtc_device = create_mtc_device_from_dmtcd(
  system.file(file_path_dmtcd, package = "mtconnectR"),
  system.file(file_path_xml, package = "mtconnectR"),
  device_name)
## Reading Delimted MTC data...
## 
  |                                                                       
  |                                                                 |   0%
  |                                                                       
  |=                                                                |   2%
  |                                                                       
  |===                                                              |   4%
  |                                                                       
  |====                                                             |   6%
  |                                                                       
  |=====                                                            |   8%
  |                                                                       
  |======                                                           |  10%
  |                                                                       
  |========                                                         |  12%
  |                                                                       
  |=========                                                        |  14%
  |                                                                       
  |==========                                                       |  16%
  |                                                                       
  |============                                                     |  18%
  |                                                                       
  |=============                                                    |  20%
  |                                                                       
  |==============                                                   |  22%
  |                                                                       
  |================                                                 |  24%
  |                                                                       
  |=================                                                |  26%
  |                                                                       
  |==================                                               |  28%
  |                                                                       
  |====================                                             |  30%
  |                                                                       
  |=====================                                            |  32%
  |                                                                       
  |======================                                           |  34%
  |                                                                       
  |=======================                                          |  36%
  |                                                                       
  |=========================                                        |  38%
  |                                                                       
  |==========================                                       |  40%
  |                                                                       
  |===========================                                      |  42%
  |                                                                       
  |=============================                                    |  44%
  |                                                                       
  |==============================                                   |  46%
  |                                                                       
  |===============================                                  |  48%
  |                                                                       
  |================================                                 |  50%
  |                                                                       
  |==================================                               |  52%
  |                                                                       
  |===================================                              |  54%
  |                                                                       
  |====================================                             |  56%
  |                                                                       
  |======================================                           |  58%
  |                                                                       
  |=======================================                          |  60%
  |                                                                       
  |========================================                         |  62%
  |                                                                       
  |==========================================                       |  64%
  |                                                                       
  |===========================================                      |  66%
  |                                                                       
  |============================================                     |  68%
  |                                                                       
  |==============================================                   |  70%
  |                                                                       
  |===============================================                  |  72%
  |                                                                       
  |================================================                 |  74%
  |                                                                       
  |=================================================                |  76%
  |                                                                       
  |===================================================              |  78%
  |                                                                       
  |====================================================             |  80%
  |                                                                       
  |=====================================================            |  82%
  |                                                                       
  |=======================================================          |  84%
  |                                                                       
  |========================================================         |  86%
  |                                                                       
  |=========================================================        |  88%
  |                                                                       
  |==========================================================       |  90%
  |                                                                       
  |============================================================     |  92%
  |                                                                       
  |=============================================================    |  94%
  |                                                                       
  |==============================================================   |  96%
  |                                                                       
  |================================================================ |  98%
  |                                                                       
  |=================================================================| 100%
## 20.48% data contextualized successfuly!

Using the basic convenience functions

A few convenience functions are provided to help the user with the MTC Classes. They are:

getDataItem

This function is used to get a single MTC data item from the MTC device class. If no parameters are provided, the first data item is returned. The user can optionally enter either a character string - in which case the data items whose paths match the character string are returned or one or more indexes. Please note that if the pattern matches more than one data item, a list of MTC Data Items is returned.

# Get the first data item in the list
mtc_data_item = getDataItem(mtc_device)
print(mtc_data_item)
## An object of class "MTCDataItem"
## Slot "data":
##                 timestamp value
## 1 2014-07-15 07:04:25.608   100
## 
## Slot "metadata":
## $category
## [1] "SAMPLE"
## 
## $xpath
## [1] "test_device<Device>:Frapidovr<PATH_FEEDRATE-OVERRIDE>"
# Get all the data items with "Xabs" in the name
mtc_data_item = getDataItem(mtc_device, "Xabs")
print(mtc_data_item)
## An object of class "MTCDataItem"
## Slot "data":
##                  timestamp     value
## 1  2014-07-15 07:04:25.608   8.26262
## 2  2014-07-15 07:04:25.788   4.61391
## 3  2014-07-15 07:04:29.983   8.14832
## 4  2014-07-15 07:04:34.210  56.67629
## 5  2014-07-15 07:04:38.526  41.27500
## 6  2014-07-15 07:04:42.862  38.94074
## 7  2014-07-15 07:04:47.049 -19.75612
## 8  2014-07-15 07:04:51.286 -20.20316
## 9  2014-07-15 07:04:55.492 -21.00961
## 10 2014-07-15 07:04:59.729  -1.99644
## 11 2014-07-15 07:05:03.914   1.98247
## 12 2014-07-15 07:05:08.141  29.57195
## 13 2014-07-15 07:05:12.328 -23.00986
## 14 2014-07-15 07:05:16.513 276.65426
## 15 2014-07-15 07:05:20.710  56.94934
## 16 2014-07-15 07:05:24.875  32.88030
## 17 2014-07-15 07:05:29.092 -51.92649
## 
## Slot "metadata":
## $category
## [1] "SAMPLE"
## 
## $xpath
## [1] "test_device<Device>:Xabs<POSITION-ACTUAL>"
# Get the data item with the 5th index
mtc_data_item = getDataItem(mtc_device, 5)
print(mtc_data_item)
## An object of class "MTCDataItem"
## Slot "data":
##                  timestamp     value
## 1  2014-07-15 07:04:25.608 238.02594
## 2  2014-07-15 07:04:25.788 240.46434
## 3  2014-07-15 07:04:29.983 234.98429
## 4  2014-07-15 07:04:34.210 280.67762
## 5  2014-07-15 07:04:38.526 267.71600
## 6  2014-07-15 07:04:42.862 269.86738
## 7  2014-07-15 07:04:47.049 278.72436
## 8  2014-07-15 07:04:51.286 211.29117
## 9  2014-07-15 07:04:55.492 208.65973
## 10 2014-07-15 07:04:59.729 213.84387
## 11 2014-07-15 07:05:03.914 272.26514
## 12 2014-07-15 07:05:08.141 244.55374
## 13 2014-07-15 07:05:12.328 212.84184
## 14 2014-07-15 07:05:16.513 465.69630
## 15 2014-07-15 07:05:20.710 243.04752
## 16 2014-07-15 07:05:24.875 272.85950
## 17 2014-07-15 07:05:29.092 263.14527
## 
## Slot "metadata":
## $category
## [1] "SAMPLE"
## 
## $xpath
## [1] "test_device<Device>:Yabs<POSITION-ACTUAL>"
# Get all data items with path matching the string 'POSITION'
mtc_data_item_list = getDataItem(mtc_device, "POSITION")
print(mtc_data_item)
## An object of class "MTCDataItem"
## Slot "data":
##                  timestamp     value
## 1  2014-07-15 07:04:25.608 238.02594
## 2  2014-07-15 07:04:25.788 240.46434
## 3  2014-07-15 07:04:29.983 234.98429
## 4  2014-07-15 07:04:34.210 280.67762
## 5  2014-07-15 07:04:38.526 267.71600
## 6  2014-07-15 07:04:42.862 269.86738
## 7  2014-07-15 07:04:47.049 278.72436
## 8  2014-07-15 07:04:51.286 211.29117
## 9  2014-07-15 07:04:55.492 208.65973
## 10 2014-07-15 07:04:59.729 213.84387
## 11 2014-07-15 07:05:03.914 272.26514
## 12 2014-07-15 07:05:08.141 244.55374
## 13 2014-07-15 07:05:12.328 212.84184
## 14 2014-07-15 07:05:16.513 465.69630
## 15 2014-07-15 07:05:20.710 243.04752
## 16 2014-07-15 07:05:24.875 272.85950
## 17 2014-07-15 07:05:29.092 263.14527
## 
## Slot "metadata":
## $category
## [1] "SAMPLE"
## 
## $xpath
## [1] "test_device<Device>:Yabs<POSITION-ACTUAL>"

summary

Displays a quick summary of the MTC Object with the following

  • Path to each data item
  • Number of Records
  • Start and End times
  • Type of data item (device, sample)
print(summary(mtc_device))
##    Length     Class      Mode 
##         1 MTCDevice        S4
print(summary(mtc_data_item))
##      Length       Class        Mode 
##           1 MTCDataItem          S4

getData

If the user wants to get all the data from an MTC Object into a data.frame for further analysis, they can use the getData method. It converts all the time series data into a data.frame object.

# Get Data from a MTC Device Class
mtc_device_data = getData(mtc_device)
print(mtc_device_data)
##                                           data_item_name
## 1  test_device<Device>:Frapidovr<PATH_FEEDRATE-OVERRIDE>
## 2       test_device<Device>:Sovr<SPINDLE_SPEED-OVERRIDE>
## 3              test_device<Device>:Xabs<POSITION-ACTUAL>
## 4              test_device<Device>:Xabs<POSITION-ACTUAL>
## 5              test_device<Device>:Xabs<POSITION-ACTUAL>
## 6              test_device<Device>:Xabs<POSITION-ACTUAL>
## 7              test_device<Device>:Xabs<POSITION-ACTUAL>
## 8              test_device<Device>:Xabs<POSITION-ACTUAL>
## 9              test_device<Device>:Xabs<POSITION-ACTUAL>
## 10             test_device<Device>:Xabs<POSITION-ACTUAL>
## 11             test_device<Device>:Xabs<POSITION-ACTUAL>
## 12             test_device<Device>:Xabs<POSITION-ACTUAL>
## 13             test_device<Device>:Xabs<POSITION-ACTUAL>
## 14             test_device<Device>:Xabs<POSITION-ACTUAL>
## 15             test_device<Device>:Xabs<POSITION-ACTUAL>
## 16             test_device<Device>:Xabs<POSITION-ACTUAL>
## 17             test_device<Device>:Xabs<POSITION-ACTUAL>
## 18             test_device<Device>:Xabs<POSITION-ACTUAL>
## 19             test_device<Device>:Xabs<POSITION-ACTUAL>
## 20                       test_device<Device>:Xload<LOAD>
## 21                       test_device<Device>:Xload<LOAD>
## 22                       test_device<Device>:Xload<LOAD>
## 23                       test_device<Device>:Xload<LOAD>
## 24                       test_device<Device>:Xload<LOAD>
## 25                       test_device<Device>:Xload<LOAD>
## 26                       test_device<Device>:Xload<LOAD>
## 27                       test_device<Device>:Xload<LOAD>
## 28             test_device<Device>:Yabs<POSITION-ACTUAL>
## 29             test_device<Device>:Yabs<POSITION-ACTUAL>
## 30             test_device<Device>:Yabs<POSITION-ACTUAL>
## 31             test_device<Device>:Yabs<POSITION-ACTUAL>
## 32             test_device<Device>:Yabs<POSITION-ACTUAL>
## 33             test_device<Device>:Yabs<POSITION-ACTUAL>
## 34             test_device<Device>:Yabs<POSITION-ACTUAL>
## 35             test_device<Device>:Yabs<POSITION-ACTUAL>
## 36             test_device<Device>:Yabs<POSITION-ACTUAL>
## 37             test_device<Device>:Yabs<POSITION-ACTUAL>
## 38             test_device<Device>:Yabs<POSITION-ACTUAL>
## 39             test_device<Device>:Yabs<POSITION-ACTUAL>
## 40             test_device<Device>:Yabs<POSITION-ACTUAL>
## 41             test_device<Device>:Yabs<POSITION-ACTUAL>
## 42             test_device<Device>:Yabs<POSITION-ACTUAL>
## 43             test_device<Device>:Yabs<POSITION-ACTUAL>
## 44             test_device<Device>:Yabs<POSITION-ACTUAL>
## 45                       test_device<Device>:Yload<LOAD>
## 46                       test_device<Device>:Yload<LOAD>
## 47                       test_device<Device>:Yload<LOAD>
## 48                       test_device<Device>:Yload<LOAD>
## 49                       test_device<Device>:Yload<LOAD>
## 50                       test_device<Device>:Yload<LOAD>
## 51                       test_device<Device>:Yload<LOAD>
##                  timestamp     value
## 1  2014-07-15 07:04:25.608 100.00000
## 2  2014-07-15 07:04:25.608 100.00000
## 3  2014-07-15 07:04:25.608   8.26262
## 4  2014-07-15 07:04:25.788   4.61391
## 5  2014-07-15 07:04:29.983   8.14832
## 6  2014-07-15 07:04:34.210  56.67629
## 7  2014-07-15 07:04:38.526  41.27500
## 8  2014-07-15 07:04:42.862  38.94074
## 9  2014-07-15 07:04:47.049 -19.75612
## 10 2014-07-15 07:04:51.286 -20.20316
## 11 2014-07-15 07:04:55.492 -21.00961
## 12 2014-07-15 07:04:59.729  -1.99644
## 13 2014-07-15 07:05:03.914   1.98247
## 14 2014-07-15 07:05:08.141  29.57195
## 15 2014-07-15 07:05:12.328 -23.00986
## 16 2014-07-15 07:05:16.513 276.65426
## 17 2014-07-15 07:05:20.710  56.94934
## 18 2014-07-15 07:05:24.875  32.88030
## 19 2014-07-15 07:05:29.092 -51.92649
## 20 2014-07-15 07:04:25.608  -8.00000
## 21 2014-07-15 07:04:29.983  -2.00000
## 22 2014-07-15 07:04:47.049  10.00000
## 23 2014-07-15 07:04:51.286  -1.00000
## 24 2014-07-15 07:05:03.914  -9.00000
## 25 2014-07-15 07:05:08.141 -17.00000
## 26 2014-07-15 07:05:12.328   6.00000
## 27 2014-07-15 07:05:20.710  -1.00000
## 28 2014-07-15 07:04:25.608 238.02594
## 29 2014-07-15 07:04:25.788 240.46434
## 30 2014-07-15 07:04:29.983 234.98429
## 31 2014-07-15 07:04:34.210 280.67762
## 32 2014-07-15 07:04:38.526 267.71600
## 33 2014-07-15 07:04:42.862 269.86738
## 34 2014-07-15 07:04:47.049 278.72436
## 35 2014-07-15 07:04:51.286 211.29117
## 36 2014-07-15 07:04:55.492 208.65973
## 37 2014-07-15 07:04:59.729 213.84387
## 38 2014-07-15 07:05:03.914 272.26514
## 39 2014-07-15 07:05:08.141 244.55374
## 40 2014-07-15 07:05:12.328 212.84184
## 41 2014-07-15 07:05:16.513 465.69630
## 42 2014-07-15 07:05:20.710 243.04752
## 43 2014-07-15 07:05:24.875 272.85950
## 44 2014-07-15 07:05:29.092 263.14527
## 45 2014-07-15 07:04:25.608 -29.00000
## 46 2014-07-15 07:04:38.526 -24.00000
## 47 2014-07-15 07:04:47.049 -34.00000
## 48 2014-07-15 07:04:51.286 -25.00000
## 49 2014-07-15 07:05:12.328 -20.00000
## 50 2014-07-15 07:05:16.513 -29.00000
## 51 2014-07-15 07:05:29.092 -24.00000
# Get Data from a MTC Data item Class
mtc_data_item_data = getData(mtc_data_item)
print(mtc_data_item_data)
##                  timestamp     value
## 1  2014-07-15 07:04:25.608 238.02594
## 2  2014-07-15 07:04:25.788 240.46434
## 3  2014-07-15 07:04:29.983 234.98429
## 4  2014-07-15 07:04:34.210 280.67762
## 5  2014-07-15 07:04:38.526 267.71600
## 6  2014-07-15 07:04:42.862 269.86738
## 7  2014-07-15 07:04:47.049 278.72436
## 8  2014-07-15 07:04:51.286 211.29117
## 9  2014-07-15 07:04:55.492 208.65973
## 10 2014-07-15 07:04:59.729 213.84387
## 11 2014-07-15 07:05:03.914 272.26514
## 12 2014-07-15 07:05:08.141 244.55374
## 13 2014-07-15 07:05:12.328 212.84184
## 14 2014-07-15 07:05:16.513 465.69630
## 15 2014-07-15 07:05:20.710 243.04752
## 16 2014-07-15 07:05:24.875 272.85950
## 17 2014-07-15 07:05:29.092 263.14527

merge

One common use case for a user doing exploratory analysis is to see how the different data items interact with each other. The long format using getData method is not ideal for this. For this case, we can use the merge function to put all the data into a single time series by merging the data items.

Also, the user can conveniently specify the pattern over which to merge or the indices to merge like case of the getData method. For Example `merge(x, “abc”)’ will merge all the objects that have the the string “abc” in their name to one data frame. If no pattern is provided then all the data items are merged into one.

# merge all the objects that have the string 'POSIT' into one data frame
print(merge(mtc_device, "POSIT"))
##                  timestamp test_device<Device>:Xabs<POSITION-ACTUAL>
## 1  2014-07-15 07:04:25.608                                   8.26262
## 2  2014-07-15 07:04:25.788                                   4.61391
## 3  2014-07-15 07:04:29.983                                   8.14832
## 4  2014-07-15 07:04:34.210                                  56.67629
## 5  2014-07-15 07:04:38.526                                  41.27500
## 6  2014-07-15 07:04:42.862                                  38.94074
## 7  2014-07-15 07:04:47.049                                 -19.75612
## 8  2014-07-15 07:04:51.286                                 -20.20316
## 9  2014-07-15 07:04:55.492                                 -21.00961
## 10 2014-07-15 07:04:59.729                                  -1.99644
## 11 2014-07-15 07:05:03.914                                   1.98247
## 12 2014-07-15 07:05:08.141                                  29.57195
## 13 2014-07-15 07:05:12.328                                 -23.00986
## 14 2014-07-15 07:05:16.513                                 276.65426
## 15 2014-07-15 07:05:20.710                                  56.94934
## 16 2014-07-15 07:05:24.875                                  32.88030
## 17 2014-07-15 07:05:29.092                                 -51.92649
##    test_device<Device>:Yabs<POSITION-ACTUAL>
## 1                                  238.02594
## 2                                  240.46434
## 3                                  234.98429
## 4                                  280.67762
## 5                                  267.71600
## 6                                  269.86738
## 7                                  278.72436
## 8                                  211.29117
## 9                                  208.65973
## 10                                 213.84387
## 11                                 272.26514
## 12                                 244.55374
## 13                                 212.84184
## 14                                 465.69630
## 15                                 243.04752
## 16                                 272.85950
## 17                                 263.14527
# merge data items with indices 3:5 into a data.frame
print(merge(mtc_device, 3:5))
##                  timestamp test_device<Device>:Xabs<POSITION-ACTUAL>
## 1  2014-07-15 07:04:25.608                                   8.26262
## 2  2014-07-15 07:04:25.788                                   4.61391
## 3  2014-07-15 07:04:29.983                                   8.14832
## 4  2014-07-15 07:04:34.210                                  56.67629
## 5  2014-07-15 07:04:38.526                                  41.27500
## 6  2014-07-15 07:04:42.862                                  38.94074
## 7  2014-07-15 07:04:47.049                                 -19.75612
## 8  2014-07-15 07:04:51.286                                 -20.20316
## 9  2014-07-15 07:04:55.492                                 -21.00961
## 10 2014-07-15 07:04:59.729                                  -1.99644
## 11 2014-07-15 07:05:03.914                                   1.98247
## 12 2014-07-15 07:05:08.141                                  29.57195
## 13 2014-07-15 07:05:12.328                                 -23.00986
## 14 2014-07-15 07:05:16.513                                 276.65426
## 15 2014-07-15 07:05:20.710                                  56.94934
## 16 2014-07-15 07:05:24.875                                  32.88030
## 17 2014-07-15 07:05:29.092                                 -51.92649
##    test_device<Device>:Xload<LOAD>
## 1                               -8
## 2                               -8
## 3                               -2
## 4                               -2
## 5                               -2
## 6                               -2
## 7                               10
## 8                               -1
## 9                               -1
## 10                              -1
## 11                              -9
## 12                             -17
## 13                               6
## 14                               6
## 15                              -1
## 16                              -1
## 17                              -1
##    test_device<Device>:Yabs<POSITION-ACTUAL>
## 1                                  238.02594
## 2                                  240.46434
## 3                                  234.98429
## 4                                  280.67762
## 5                                  267.71600
## 6                                  269.86738
## 7                                  278.72436
## 8                                  211.29117
## 9                                  208.65973
## 10                                 213.84387
## 11                                 272.26514
## 12                                 244.55374
## 13                                 212.84184
## 14                                 465.69630
## 15                                 243.04752
## 16                                 272.85950
## 17                                 263.14527
# merge all the data items
merged_mtc_device = (merge(mtc_device))

# renaming column names to make it more readable
names(merged_mtc_device) = stringr::str_replace(names(merged_mtc_device), "test_device<Device>:", "")
print(merged_mtc_device)
##                  timestamp Frapidovr<PATH_FEEDRATE-OVERRIDE>
## 1  2014-07-15 07:04:25.608                               100
## 2  2014-07-15 07:04:25.788                               100
## 3  2014-07-15 07:04:29.983                               100
## 4  2014-07-15 07:04:34.210                               100
## 5  2014-07-15 07:04:38.526                               100
## 6  2014-07-15 07:04:42.862                               100
## 7  2014-07-15 07:04:47.049                               100
## 8  2014-07-15 07:04:51.286                               100
## 9  2014-07-15 07:04:55.492                               100
## 10 2014-07-15 07:04:59.729                               100
## 11 2014-07-15 07:05:03.914                               100
## 12 2014-07-15 07:05:08.141                               100
## 13 2014-07-15 07:05:12.328                               100
## 14 2014-07-15 07:05:16.513                               100
## 15 2014-07-15 07:05:20.710                               100
## 16 2014-07-15 07:05:24.875                               100
## 17 2014-07-15 07:05:29.092                               100
##    Sovr<SPINDLE_SPEED-OVERRIDE> Xabs<POSITION-ACTUAL> Xload<LOAD>
## 1                           100               8.26262          -8
## 2                           100               4.61391          -8
## 3                           100               8.14832          -2
## 4                           100              56.67629          -2
## 5                           100              41.27500          -2
## 6                           100              38.94074          -2
## 7                           100             -19.75612          10
## 8                           100             -20.20316          -1
## 9                           100             -21.00961          -1
## 10                          100              -1.99644          -1
## 11                          100               1.98247          -9
## 12                          100              29.57195         -17
## 13                          100             -23.00986           6
## 14                          100             276.65426           6
## 15                          100              56.94934          -1
## 16                          100              32.88030          -1
## 17                          100             -51.92649          -1
##    Yabs<POSITION-ACTUAL> Yload<LOAD>
## 1              238.02594         -29
## 2              240.46434         -29
## 3              234.98429         -29
## 4              280.67762         -29
## 5              267.71600         -24
## 6              269.86738         -24
## 7              278.72436         -34
## 8              211.29117         -25
## 9              208.65973         -25
## 10             213.84387         -25
## 11             272.26514         -25
## 12             244.55374         -25
## 13             212.84184         -20
## 14             465.69630         -29
## 15             243.04752         -29
## 16             272.85950         -29
## 17             263.14527         -24