aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHongmei Gou2019-06-03 09:25:26 -0500
committerHongmei Gou2019-06-03 09:25:26 -0500
commit832c4021de19998c7e47e94e1868943c9a145489 (patch)
treed32de21c7a73463b760e20aa0fa10903944c1cf3
parentb1f2a6fc7f38db24b0daa6d972c796a2536e050a (diff)
parentac8b1cea16e17e56294b8db149f5bee1718fb702 (diff)
downloadpdm-anomaly-detection-832c4021de19998c7e47e94e1868943c9a145489.tar.gz
pdm-anomaly-detection-832c4021de19998c7e47e94e1868943c9a145489.tar.xz
pdm-anomaly-detection-832c4021de19998c7e47e94e1868943c9a145489.zip
Merge pull request #3 in PROCESSOR-SDK/pdm-anomaly-detection from pdm-demo-bringup to master
* commit 'ac8b1cea16e17e56294b8db149f5bee1718fb702': Update LICENSE and add copyright header in the source files Qt related files: restore copyright header psensors.cpp: rename generic name of /tmp/myfifo to /tmp/pdmfifo main.cpp: detach the thread before returning from main() Code cleanup: add comments and utilize header files Add comments for QML entries Qt display: by default show the images for the motor setup, call flow, and system model Makefile.build: install the binary without renaming Add Makefile.build to enable building the demo in PLSDK installer Naming replacement: oscilloscope is changed to pdm-anomaly-detection
-rw-r--r--LICENSE77
-rw-r--r--Makefile.build41
-rw-r--r--datasource.cpp61
-rw-r--r--datasource.h61
-rw-r--r--lstm_infer.cpp33
-rw-r--r--lstm_infer.h40
-rw-r--r--main.cpp120
-rw-r--r--motor-pdm.cpp228
-rw-r--r--motor_pdm.cpp285
-rw-r--r--motor_pdm.h45
-rw-r--r--motor_pdm_loc.h66
-rw-r--r--oscilloscope.pro28
-rw-r--r--pdm-anomaly-detection.pro42
-rw-r--r--psensors.cpp275
-rw-r--r--psensors.h42
-rw-r--r--qml/oscilloscope/ControlPanel.qml17
-rw-r--r--qml/oscilloscope/MultiButton.qml40
-rw-r--r--qml/oscilloscope/PdmView.qml74
-rw-r--r--qml/oscilloscope/ScopeView.qml81
-rw-r--r--qml/oscilloscope/main.qml142
-rw-r--r--qml/pdm-anomaly-detection/ControlPanel.qml80
-rw-r--r--qml/pdm-anomaly-detection/MultiButton.qml101
-rw-r--r--qml/pdm-anomaly-detection/PdmView.qml141
-rw-r--r--qml/pdm-anomaly-detection/ScopeView.qml148
-rw-r--r--qml/pdm-anomaly-detection/anomaly-detection.png (renamed from qml/oscilloscope/anomaly-detection.png)bin23510 -> 23510 bytes
-rw-r--r--qml/pdm-anomaly-detection/main.qml214
-rw-r--r--qml/pdm-anomaly-detection/motor-drive.png (renamed from qml/oscilloscope/motor-drive.png)bin231705 -> 231705 bytes
-rw-r--r--qml/pdm-anomaly-detection/system-model.png (renamed from qml/oscilloscope/system-model.png)bin61284 -> 61284 bytes
-rw-r--r--qml/pdm-anomaly-detection/ti-logo.png (renamed from qml/oscilloscope/ti-logo.png)bin19964 -> 19964 bytes
-rw-r--r--resources.qrc18
30 files changed, 1746 insertions, 754 deletions
diff --git a/LICENSE b/LICENSE
index f6cb9de..6a9305a 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,3 +1,33 @@
1Copyright (c) 2019, Texas Instruments Incorporated
2All rights reserved.
3
4Redistribution and use in source and binary forms, with or without
5modification, are permitted provided that the following conditions
6are met:
7
8 Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10
11 Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in the
13 documentation and/or other materials provided with the distribution.
14
15 Neither the name of Texas Instruments Incorporated nor the names of
16 its contributors may be used to endorse or promote products derived
17 from this software without specific prior written permission.
18
19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
29EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
1Copyright (c) 2016 Robert W. Rose 31Copyright (c) 2016 Robert W. Rose
2 32
3Permission is hereby granted, free of charge, to any person obtaining a copy 33Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -17,3 +47,50 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 47LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 48OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19SOFTWARE. 49SOFTWARE.
50
51
52Copyright 2009 Shawn Stevenson
53
54Permission is hereby granted, free of charge, to any person obtaining a copy
55of this software and associated documentation files (the "Software"), to deal
56in the Software without restriction, including without limitation the rights
57to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
58copies of the Software, and to permit persons to whom the Software is
59furnished to do so, subject to the following conditions:
60
61The above copyright notice and this permission notice shall be included in all
62copies or substantial portions of the Software.
63
64THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
65IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
66FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
67AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
68LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
69OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
70SOFTWARE.
71
72
73Copyright (C) 2016 The Qt Company Ltd.
74Contact: https://www.qt.io/licensing/
75
76This file is part of the Qt Charts module of the Qt Toolkit.
77
78$QT_BEGIN_LICENSE:GPL$
79Commercial License Usage
80Licensees holding valid commercial Qt licenses may use this file in
81accordance with the commercial license agreement provided with the
82Software or, alternatively, in accordance with the terms contained in
83a written agreement between you and The Qt Company. For licensing terms
84and conditions see https://www.qt.io/terms-conditions. For further
85information use the contact form at https://www.qt.io/contact-us.
86
87GNU General Public License Usage
88Alternatively, this file may be used under the terms of the GNU
89General Public License version 3 or (at your option) any later version
90approved by the KDE Free Qt Foundation. The licenses are as published by
91the Free Software Foundation and appearing in the file LICENSE.GPL3
92included in the packaging of this file. Please review the following
93information to ensure the GNU General Public License requirements will
94be met: https://www.gnu.org/licenses/gpl-3.0.html.
95
96$QT_END_LICENSE$
diff --git a/Makefile.build b/Makefile.build
new file mode 100644
index 0000000..fad016d
--- /dev/null
+++ b/Makefile.build
@@ -0,0 +1,41 @@
1-include ../../Rules.make
2
3ENV_SETUP ?= ../../linux-devkit/environment-setup
4DESTDIR ?=
5all: release
6
7.PHONY: qmake
8qmake : pdm-anomaly-detection.pro
9 @. ${ENV_SETUP}; \
10 qmake CONFIG+=release pdm-anomaly-detection.pro
11
12qmake_debug : pdm-anomaly-detection.pro
13 @. ${ENV_SETUP}; \
14 qmake CONFIG+=debug pdm-anomaly-detection.pro
15
16debug : qmake_debug
17 @. ${ENV_SETUP}; \
18 make
19
20release : qmake
21 @. ${ENV_SETUP}; \
22 make
23
24clean : qmake
25 @. ${ENV_SETUP}; \
26 make distclean
27
28install_common:
29 @if [ ! -d $(DESTDIR) ] ; then \
30 echo "The extracted target filesystem directory doesn't exist."; \
31 echo "Please run setup.sh in the SDK's root directory and then try again."; \
32 exit 1; \
33 fi
34 @install -d ${DESTDIR}/usr/bin
35 @install RnnPdmAnomalyDetection ${DESTDIR}/usr/bin
36
37install: release install_common
38 @echo "pdm-anomaly-detection release version installed."
39
40install_debug: debug install_common
41 @echo "pdm-anomaly-detection debug version installed."
diff --git a/datasource.cpp b/datasource.cpp
index 8376f05..6d83302 100644
--- a/datasource.cpp
+++ b/datasource.cpp
@@ -1,3 +1,64 @@
1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Charts module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 or (at your option) any later version
20** approved by the KDE Free Qt Foundation. The licenses are as published by
21** the Free Software Foundation and appearing in the file LICENSE.GPL3
22** included in the packaging of this file. Please review the following
23** information to ensure the GNU General Public License requirements will
24** be met: https://www.gnu.org/licenses/gpl-3.0.html.
25**
26** $QT_END_LICENSE$
27**
28****************************************************************************/
29/*
30 * Copyright (c) 2019, Texas Instruments Incorporated
31 * All rights reserved.
32 *
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
35 * are met:
36 *
37 * * Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39 *
40 * * Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in the
42 * documentation and/or other materials provided with the distribution.
43 *
44 * * Neither the name of Texas Instruments Incorporated nor the names of
45 * its contributors may be used to endorse or promote products derived
46 * from this software without specific prior written permission.
47 *
48 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
49 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
50 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
51 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
52 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
53 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
54 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
55 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
56 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
57 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
58 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59 *
60*/
61
1#include <iostream> 62#include <iostream>
2#include "datasource.h" 63#include "datasource.h"
3#include <QtCharts/QXYSeries> 64#include <QtCharts/QXYSeries>
diff --git a/datasource.h b/datasource.h
index ae88321..9adb5eb 100644
--- a/datasource.h
+++ b/datasource.h
@@ -1,3 +1,64 @@
1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Charts module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 or (at your option) any later version
20** approved by the KDE Free Qt Foundation. The licenses are as published by
21** the Free Software Foundation and appearing in the file LICENSE.GPL3
22** included in the packaging of this file. Please review the following
23** information to ensure the GNU General Public License requirements will
24** be met: https://www.gnu.org/licenses/gpl-3.0.html.
25**
26** $QT_END_LICENSE$
27**
28****************************************************************************/
29/*
30 * Copyright (c) 2019, Texas Instruments Incorporated
31 * All rights reserved.
32 *
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
35 * are met:
36 *
37 * * Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39 *
40 * * Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in the
42 * documentation and/or other materials provided with the distribution.
43 *
44 * * Neither the name of Texas Instruments Incorporated nor the names of
45 * its contributors may be used to endorse or promote products derived
46 * from this software without specific prior written permission.
47 *
48 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
49 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
50 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
51 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
52 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
53 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
54 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
55 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
56 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
57 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
58 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59 *
60*/
61
1#ifndef DATASOURCE_H 62#ifndef DATASOURCE_H
2#define DATASOURCE_H 63#define DATASOURCE_H
3 64
diff --git a/lstm_infer.cpp b/lstm_infer.cpp
index 2ad5d60..3ec8403 100644
--- a/lstm_infer.cpp
+++ b/lstm_infer.cpp
@@ -1,7 +1,36 @@
1/* 1/*
2Compile with: 2 * Copyright (c) 2019, Texas Instruments Incorporated
3g++ --std=c++11 -Wall -O3 test_cpp_model.cpp onnx_model.cpp utils.cpp config.cpp -o output 3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
4*/ 32*/
33
5#include <stdio.h> 34#include <stdio.h>
6#include <stdlib.h> 35#include <stdlib.h>
7#include <string.h> 36#include <string.h>
diff --git a/lstm_infer.h b/lstm_infer.h
new file mode 100644
index 0000000..4c6747a
--- /dev/null
+++ b/lstm_infer.h
@@ -0,0 +1,40 @@
1/*
2 * Copyright (c) 2019, Texas Instruments Incorporated
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32*/
33
34#ifndef LSTM_INFER_H
35#define LSTM_INFER_H
36
37void lstmSetup(void);
38void runLstm(double lstm_in1, double lstm_in2, double *lstm_out1, double *lstm_out2);
39
40#endif //LSTM_INFER_H
diff --git a/main.cpp b/main.cpp
index 2988119..b35598e 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,40 +1,110 @@
1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Charts module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 or (at your option) any later version
20** approved by the KDE Free Qt Foundation. The licenses are as published by
21** the Free Software Foundation and appearing in the file LICENSE.GPL3
22** included in the packaging of this file. Please review the following
23** information to ensure the GNU General Public License requirements will
24** be met: https://www.gnu.org/licenses/gpl-3.0.html.
25**
26** $QT_END_LICENSE$
27**
28****************************************************************************/
29/*
30 * Copyright (c) 2019, Texas Instruments Incorporated
31 * All rights reserved.
32 *
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
35 * are met:
36 *
37 * * Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39 *
40 * * Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in the
42 * documentation and/or other materials provided with the distribution.
43 *
44 * * Neither the name of Texas Instruments Incorporated nor the names of
45 * its contributors may be used to endorse or promote products derived
46 * from this software without specific prior written permission.
47 *
48 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
49 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
50 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
51 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
52 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
53 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
54 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
55 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
56 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
57 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
58 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59 *
60*/
61
1#include <QtWidgets/QApplication> 62#include <QtWidgets/QApplication>
2#include <QtQml/QQmlContext> 63#include <QtQml/QQmlContext>
3#include <QtQuick/QQuickView> 64#include <QtQuick/QQuickView>
4#include <QtQml/QQmlEngine> 65#include <QtQml/QQmlEngine>
5#include <QtCore/QDir> 66#include <QtCore/QDir>
67
6#include "datasource.h" 68#include "datasource.h"
7#include <iostream> // std::cout 69#include "motor_pdm.h"
8#include <thread> // std::thread
9 70
10int motor_pdm_process(void); 71#include <iostream>
72#include <thread>
11 73
12double mu1, mu2, sig1, sig2; 74/*********************************************************************************
13double relative_threshold = 1.5; 75 * This is the main function for PdM (predictive maintenance) - anomaly detection
76 * It uses Qt/QML for real-time display of the sensor data and detection results.
77 * motor_pdm_process is the main thread for anomaly detection, using RNN;
78 * It also starts another thread of uart_stream_parser to get the sensor input.
79 *********************************************************************************/
80pdmContext_t pdmContext;
14int main(int argc, char *argv[]) 81int main(int argc, char *argv[])
15{ 82{
16 83 int ret;
17 //Get normalization parameters and relative threshold 84 /* Get normalization parameters and relative threshold */
18 if(argc < 5) { 85 if(argc < 5) {
19 printf("\nUsage:%s mu1 mu2 sig1 sig2 elative-threshold\n", argv[0]); 86 printf("\nUsage:%s mu1 mu2 sig1 sig2 relative-threshold\n", argv[0]);
20 printf("\nTo set the relative threshold value, use an addtional positive value >= 1\n"); 87 printf("\nTo set the relative threshold value, use an additional positive value >= 1\n");
21 return -1; 88 return -1;
22 } 89 }
23 mu1 = atof(argv[1]); 90 pdmContext.mu1 = atof(argv[1]);
24 mu2 = atof(argv[2]); 91 pdmContext.mu2 = atof(argv[2]);
25 sig1 = atof(argv[3]); 92 pdmContext.sig1 = atof(argv[3]);
26 sig2 = atof(argv[4]); 93 pdmContext.sig2 = atof(argv[4]);
27 94
28 if(argc > 5) 95 if(argc > 5) {
29 relative_threshold = atof(argv[5]); 96 pdmContext.relative_threshold = atof(argv[5]);
97 } else {
98 pdmContext.relative_threshold = 1.5;
99 }
30 100
31 // Qt Charts uses Qt Graphics View Framework for drawing, therefore QApplication must be used. 101 /* Qt Charts uses Qt Graphics View Framework for drawing, therefore QApplication must be used. */
32 QApplication app(argc, argv); 102 QApplication app(argc, argv);
33 103
34 QQuickView viewer; 104 QQuickView viewer;
35 105
36 // The following are needed to make examples run without having to install the module 106 /* The following are needed to make examples run without having to install the module */
37 // in desktop environments. 107 /* in desktop environments. */
38#ifdef Q_OS_WIN 108#ifdef Q_OS_WIN
39 QString extraImportPath(QStringLiteral("%1/../../../../%2")); 109 QString extraImportPath(QStringLiteral("%1/../../../../%2"));
40#else 110#else
@@ -44,17 +114,27 @@ int main(int argc, char *argv[])
44 QString::fromLatin1("qml"))); 114 QString::fromLatin1("qml")));
45 QObject::connect(viewer.engine(), &QQmlEngine::quit, &viewer, &QWindow::close); 115 QObject::connect(viewer.engine(), &QQmlEngine::quit, &viewer, &QWindow::close);
46 116
117 /* Set the title of the Qt window */
47 viewer.setTitle(QStringLiteral("Deep Learning based Predictive Maintenance Demo on Sitara Edge Devices")); 118 viewer.setTitle(QStringLiteral("Deep Learning based Predictive Maintenance Demo on Sitara Edge Devices"));
48 119
120 /* Start the thread for conducting anomaly detection on motor sensor data */
49 std::thread motor_pdm_process_thread (motor_pdm_process); 121 std::thread motor_pdm_process_thread (motor_pdm_process);
50 122
123 /* Set up the data source object for displaying sensor data and detection results */
51 DataSource dataSource(&viewer); 124 DataSource dataSource(&viewer);
52 viewer.rootContext()->setContextProperty("dataSource", &dataSource); 125 viewer.rootContext()->setContextProperty("dataSource", &dataSource);
53 126
54 viewer.setSource(QUrl("qrc:/qml/oscilloscope/main.qml")); 127 /* Start the Qt display */
128 viewer.setSource(QUrl("qrc:/qml/pdm-anomaly-detection/main.qml"));
55 viewer.setResizeMode(QQuickView::SizeRootObjectToView); 129 viewer.setResizeMode(QQuickView::SizeRootObjectToView);
56 viewer.setColor(QColor("#f5f5dc")); 130 viewer.setColor(QColor("#f5f5dc"));
57 viewer.show(); 131 viewer.show();
58 132
59 return app.exec(); 133 ret = app.exec();
134
135 /* Detach the thread: avoid the message of "terminate called without an active exception"
136 * when closing the Qt window */
137 motor_pdm_process_thread.detach();
138
139 return ret;
60} 140}
diff --git a/motor-pdm.cpp b/motor-pdm.cpp
deleted file mode 100644
index 9e60df5..0000000
--- a/motor-pdm.cpp
+++ /dev/null
@@ -1,228 +0,0 @@
1#include <stdio.h>
2#include <stdint.h>
3#include <stdlib.h>
4#include <string.h>
5#include <memory.h>
6#include <fcntl.h>
7#include <sys/stat.h>
8#include <sys/types.h>
9#include <unistd.h>
10
11#include <iostream>
12#include <thread>
13#include <chrono>
14
15//////////////////////////////////////////////////////////////
16// Filter Code Definitions
17//////////////////////////////////////////////////////////////
18// maximum number of inputs that can be handled
19// in one function call
20#define SAMPLES 200
21// maximum length of filter than can be handled
22#define FIRFLT_LEN 1001
23// buffer to hold all of the input samples
24#define BUFFER_LEN (FIRFLT_LEN - 1 + SAMPLES)
25
26// delay line to hold input samples
27double insampPH1[ BUFFER_LEN ];
28double insampPH2[ BUFFER_LEN ];
29double insampPH3[ BUFFER_LEN ];
30// LP filter coefficients
31#define DRATIO 200
32double coeffs[ FIRFLT_LEN ];
33
34// Each sample tick is 20ms long
35#define START_FIND_THRESHOLD 150
36#define STOP_FIND_THRESHOLD 1500
37#define HANGOVER_TIME 20
38
39#define max(a,b) (a > b ? a : b)
40
41int uart_get_data(int sample_count, float *samples_array);
42void uart_stream_parser(int mode_op);
43void lstmSetup(void);
44void runLstm(double lstm_in1, double lstm_in2, double *lstm_out1, double *lstm_out2);
45
46// FIR init
47void firFloatInit( double *insamp, int len_delay_line)
48{
49 int i;
50 for (i = 0; i < len_delay_line; i ++) insamp[i] = 0.0;
51}
52
53// the FIR filter function
54void firFloat( double *coeffs, double *insamp, int filterLength,
55 double *input, int length,
56 double *output)
57{
58 double acc; // accumulator for MACs
59 double *coeffp; // pointer to coefficients
60 double *inputp; // pointer to input samples
61 int n,j=0;
62 int k;
63 // put the new samples at the high end of the buffer
64 memcpy( &insamp[filterLength - 1], input,
65 length * sizeof(double) );
66 // apply the filter to each input sample
67 for ( n = 0; n < length; n=n+DRATIO ) {
68 // calculate output n
69 coeffp = coeffs;
70 inputp = &insamp[filterLength - 1 + n];
71 acc = 0;
72 for ( k = 0; k < filterLength; k++ )
73 {
74 acc += (*coeffp++) * (*inputp--);
75 }
76 output[j++] = acc;
77 }
78 // shift input samples back in time for next time
79 memmove( &insamp[0], &insamp[length], (filterLength - 1) * sizeof(double) );
80}
81
82#define DISPLAY_VECTOR 6
83#define DISPLAY_MAX_BUFFER (DISPLAY_VECTOR*64*4096)
84static int display_rd_data_cnt = 0;
85static int display_wr_data_cnt = 0;
86static double data_ready_to_display[DISPLAY_MAX_BUFFER];
87
88int display_wr_idx = 0;
89
90int motor_pdm_get_data(int samples_count, double *samples_array)
91{
92 int rd_idx;
93 if(display_wr_data_cnt >= (display_rd_data_cnt + samples_count*DISPLAY_VECTOR))
94 {
95 for (int i = 0; i < samples_count; i ++)
96 {
97 rd_idx = display_rd_data_cnt % DISPLAY_MAX_BUFFER;
98 for (int j=0; j<DISPLAY_VECTOR; j++)
99 {
100 samples_array[DISPLAY_VECTOR*i + j] = data_ready_to_display[rd_idx + j];
101 }
102 display_rd_data_cnt += DISPLAY_VECTOR;
103 }
104
105 display_rd_data_cnt -= (127 * samples_count*DISPLAY_VECTOR) / 128;
106 return samples_count;
107 } else return 0;
108}
109
110extern double mu1, mu2, sig1, sig2;
111extern double relative_threshold;
112int motor_pdm_process(void)
113{
114 int size;
115 double floatInput1[SAMPLES];
116 double floatInput2[SAMPLES];
117 double floatInput3[SAMPLES];
118 double floatOutput1[SAMPLES/DRATIO];
119 double floatOutput2[SAMPLES/DRATIO];
120 double floatOutput3[SAMPLES/DRATIO];
121 double predict_threshold_err = 0.0;
122 double predict1 = 0.0;
123 double predict2 = 0.0;
124 FILE *coeff_fid;
125 int samples_counter = 0;
126 int restart_hangover_timer = 0;
127 int ad_detected = 0;
128 int pdmState = 0;
129 float samples_array[3*SAMPLES];
130
131 //Pick up decimating FIR filter coefficients
132 coeff_fid = fopen( "coeff.bin", "rb" );
133 if ( coeff_fid == 0 ) {
134 printf("\n...couldn't open coeff.bin file (Decimating FIR filter coefficients)\n");
135 return -1;
136 }
137 fread(coeffs, sizeof(double), FIRFLT_LEN, coeff_fid );
138 fclose( coeff_fid );
139
140 lstmSetup();
141 // initialize the filter delay lines
142 firFloatInit(insampPH1, BUFFER_LEN);
143 firFloatInit(insampPH2, BUFFER_LEN);
144
145 //Start UART reading, and parsing thread. Parsed data are logged into a buffer
146 std::thread sensorStream (uart_stream_parser, 0);
147 // Processs loop
148 while(1)
149 {
150 // read samples from UART pipe
151 size = uart_get_data(SAMPLES, samples_array);
152 if(size == SAMPLES)
153 { // It means, at least this many SAMPLES are available
154 for(int i = 0; i < SAMPLES; i ++) {
155 floatInput1[i] = (double)samples_array[3*i + 0];
156 floatInput2[i] = (double)samples_array[3*i + 1];
157 floatInput3[i] = (double)samples_array[3*i + 2];
158 }
159 // perform the filtering
160 // One decimated sample generated
161 firFloat( coeffs, insampPH1, FIRFLT_LEN, floatInput1, SAMPLES, floatOutput1 );
162 firFloat( coeffs, insampPH2, FIRFLT_LEN, floatInput2, SAMPLES, floatOutput2 );
163 firFloat( coeffs, insampPH3, FIRFLT_LEN, floatInput3, SAMPLES, floatOutput3 );
164
165 // Writting too fast, do write side throttling
166 if(display_wr_data_cnt > (display_rd_data_cnt + DISPLAY_MAX_BUFFER - 16))
167 std::this_thread::sleep_for(std::chrono::milliseconds(100));
168
169 for (int i = 0; i < SAMPLES/DRATIO; i ++)
170 {
171 display_wr_idx = display_wr_data_cnt % DISPLAY_MAX_BUFFER;
172 data_ready_to_display[display_wr_idx+0] = floatOutput1[i];
173 data_ready_to_display[display_wr_idx+1] = floatOutput2[i];
174 data_ready_to_display[display_wr_idx+2] = floatOutput3[i];
175 display_wr_data_cnt += 3;
176 }
177
178 //Calculate prediction error (using previously predicted samples)
179 double predict_error = (floatOutput1[0] - predict1) * (floatOutput1[0] - predict1);
180 predict_error += (floatOutput2[0] - predict2) * (floatOutput2[0] - predict2);
181
182 ad_detected = 0;
183
184 if(samples_counter > START_FIND_THRESHOLD)
185 {
186 if(samples_counter < STOP_FIND_THRESHOLD)
187 { // Find error threshold
188 pdmState = 100;
189 predict_threshold_err = max(predict_error, predict_threshold_err);
190 restart_hangover_timer = 0;
191 } else {
192 pdmState = -100;
193 // Anomaly detection mode!
194 // ...implemented hangover
195 if(predict_error > relative_threshold * predict_threshold_err)
196 {
197 restart_hangover_timer = samples_counter;
198 }
199 if((samples_counter - restart_hangover_timer) < HANGOVER_TIME)
200 {
201 ad_detected = 1;
202 }
203 }
204 }
205
206 display_wr_idx = display_wr_data_cnt % DISPLAY_MAX_BUFFER;
207 data_ready_to_display[display_wr_idx+0] = predict_error;
208 data_ready_to_display[display_wr_idx+1] = predict_threshold_err*relative_threshold + pdmState;
209 data_ready_to_display[display_wr_idx+2] = ad_detected * predict_threshold_err *relative_threshold * 1.25;
210 display_wr_data_cnt += 3;
211
212 //Normalize
213 double lstm_out1, lstm_in1 = (floatOutput1[0] - mu1) / sig1;
214 double lstm_out2, lstm_in2 = (floatOutput2[0] - mu2) / sig2;
215 //Run LSTM network
216 runLstm(lstm_in1, lstm_in2, &lstm_out1, &lstm_out2);
217 //Denormalize
218 predict1 = lstm_out1 * sig1 + mu1;
219 predict2 = lstm_out2 * sig2 + mu2;
220
221 samples_counter ++; // Increamented at decimated rate!!!
222 } else {
223 std::this_thread::sleep_for(std::chrono::milliseconds(100));
224 }
225 }
226
227 return 0;
228}
diff --git a/motor_pdm.cpp b/motor_pdm.cpp
new file mode 100644
index 0000000..62cb377
--- /dev/null
+++ b/motor_pdm.cpp
@@ -0,0 +1,285 @@
1/*
2 * Copyright (c) 2019, Texas Instruments Incorporated
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32*/
33
34/*
35 * Copyright 2009 Shawn Stevenson
36 *
37 * Permission is hereby granted, free of charge, to any person obtaining a copy
38 * of this software and associated documentation files (the "Software"), to deal
39 * in the Software without restriction, including without limitation the rights
40 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
41 * copies of the Software, and to permit persons to whom the Software is
42 * furnished to do so, subject to the following conditions:
43
44 * The above copyright notice and this permission notice shall be included in all
45 * copies or substantial portions of the Software.
46
47 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
48 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
49 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
50 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
51 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
52 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
53 * SOFTWARE.
54 *
55*/
56
57#include <stdio.h>
58#include <stdint.h>
59#include <stdlib.h>
60#include <string.h>
61#include <memory.h>
62#include <fcntl.h>
63#include <sys/stat.h>
64#include <sys/types.h>
65#include <unistd.h>
66
67#include "lstm_infer.h"
68#include "psensors.h"
69#include "motor_pdm_loc.h"
70#include "motor_pdm.h"
71
72#include <iostream>
73#include <thread>
74#include <chrono>
75
76/* FIR initialization */
77void firFloatInit( double *insamp, int len_delay_line)
78{
79 int i;
80 for (i = 0; i < len_delay_line; i ++) {
81 insamp[i] = 0.0;
82 }
83}
84
85/* The FIR filter with downsampling by DRATION*/
86void firFloat( double *coeffs, double *insamp, int filterLength,
87 double *input, int length,
88 double *output)
89{
90 double acc; /* accumulator for MACs */
91 double *coeffp; /* pointer to coefficients */
92 double *inputp; /* pointer to input samples */
93 int n,j=0;
94 int k;
95
96 /* put the new samples at the high end of the buffer */
97 memcpy( &insamp[filterLength - 1], input,
98 length * sizeof(double) );
99 /* apply the filter to each input sample */
100 for ( n = 0; n < length; n=n+DRATIO ) {
101 /* calculate output n */
102 coeffp = coeffs;
103 inputp = &insamp[filterLength - 1 + n];
104 acc = 0;
105 for ( k = 0; k < filterLength; k++ ) {
106 acc += (*coeffp++) * (*inputp--);
107 }
108 output[j++] = acc;
109 }
110 /* shift input samples back in time for next time */
111 memmove( &insamp[0], &insamp[length], (filterLength - 1) * sizeof(double) );
112}
113
114/* Send the buffered sensor data and PdM detection results downstream for Qt display */
115int motor_pdm_get_data(int samples_count, double *samples_array)
116{
117 int rd_idx;
118 /* When the number of sensor data points reach samples_count, send them for Qt display*/
119 if(display_wr_data_cnt >= (display_rd_data_cnt + samples_count*DISPLAY_VECTOR)) {
120 for (int i = 0; i < samples_count; i ++) {
121 rd_idx = display_rd_data_cnt % DISPLAY_MAX_BUFFER;
122 for (int j=0; j<DISPLAY_VECTOR; j++) {
123 samples_array[DISPLAY_VECTOR*i + j] = display_data_ready_to_use[rd_idx + j];
124 }
125 display_rd_data_cnt += DISPLAY_VECTOR;
126 }
127 /* Do data overlapping to make the time serires move slowly */
128 display_rd_data_cnt -= (127 * samples_count*DISPLAY_VECTOR) / 128;
129 return samples_count;
130 } else {
131 return 0;
132 }
133}
134
135/*****************************************************************************************
136 * Main call flow for anomaly detection using RNN (LSTM)
137 *
138 * Step 1: read sensor data, including motor position and the two phase currents
139 * Step 2: pre-process the sensor data: downsampling by 200 and lowpass filtering
140 * Step 3: normalization for the input: phase currents at t[n]
141 * Step 4: RNN prediction: predict the future output from the current input with LSTM
142 * Step 5: de-normalization for the predicted output: predicted phase currents at t[n+1]
143 * Step 6: calculate the predicator error by comparing the predicted phase current at
144 * t[n+1] with the actual phase currents at t[n+1].
145 * The beginning predication errors are for the normal scenario, and used for
146 * calibration to find the error threshold for future anomaly detection.
147 * After the calibration, it enters the anomaly detection mode:
148 * predication errors larger than the threahold (with hangover) are declared
149 * as anomalies
150 *
151 * Decimated sensor data and detection results are also recoreded for Qt display
152 *****************************************************************************************/
153extern pdmContext_t pdmContext;
154#define max(a,b) (a > b ? a : b)
155
156int motor_pdm_process(void)
157{
158 int size;
159 /* Input sample array */
160 double floatInput1[SAMPLES];
161 double floatInput2[SAMPLES];
162 double floatInput3[SAMPLES];
163 /* Onput sample array after lowpass filtering and downsampling */
164 double floatOutput1[SAMPLES/DRATIO];
165 double floatOutput2[SAMPLES/DRATIO];
166 double floatOutput3[SAMPLES/DRATIO];
167 /* Delay line to hold input samples */
168 double insampPH1[ BUFFER_LEN ];
169 double insampPH2[ BUFFER_LEN ];
170 double insampPH3[ BUFFER_LEN ];
171 /* File storing the coefficients of the FIR filter */
172 FILE *coeff_fid;
173
174 double predict_threshold_err = 0.0;
175 double predict1 = 0.0;
176 double predict2 = 0.0;
177
178 int samples_counter = 0;
179 int restart_hangover_timer = 0;
180 int ad_detected = 0;
181 int pdmState = 0;
182
183 int display_wr_idx = 0;
184
185 /* For storing the incoming sensor data */
186 float samples_array[3*SAMPLES];
187
188 /* Read decimating FIR filter coefficients from file */
189 coeff_fid = fopen( "coeff.bin", "rb" );
190 if ( coeff_fid == 0 ) {
191 printf("\n...couldn't open coeff.bin file (Decimating FIR filter coefficients)\n");
192 return -1;
193 }
194 fread(coeffs, sizeof(double), FIRFLT_LEN, coeff_fid );
195 fclose( coeff_fid );
196
197 /* Initialize LSTM layers */
198 lstmSetup();
199
200 /* Initialize the filter delay lines */
201 firFloatInit(insampPH1, BUFFER_LEN);
202 firFloatInit(insampPH2, BUFFER_LEN);
203 firFloatInit(insampPH3, BUFFER_LEN);
204
205 /* Start the UART reading and parsing thread. Parsed data are logged into a buffer */
206 std::thread sensorStream (uart_stream_parser, 0);
207
208 /* Processs loop */
209 while(1) {
210 /* Read samples from UART pipe */
211 size = uart_get_data(SAMPLES, samples_array);
212
213 if(size == SAMPLES) { /* It means, at least this many SAMPLES are available */
214 for(int i = 0; i < SAMPLES; i ++) {
215 floatInput1[i] = (double)samples_array[3*i + 0];
216 floatInput2[i] = (double)samples_array[3*i + 1];
217 floatInput3[i] = (double)samples_array[3*i + 2];
218 }
219 /* Perform the filtering: one decimated sample generated */
220 firFloat( coeffs, insampPH1, FIRFLT_LEN, floatInput1, SAMPLES, floatOutput1 );
221 firFloat( coeffs, insampPH2, FIRFLT_LEN, floatInput2, SAMPLES, floatOutput2 );
222 firFloat( coeffs, insampPH3, FIRFLT_LEN, floatInput3, SAMPLES, floatOutput3 );
223
224 /* Writting too fast, do write side throttling */
225 if(display_wr_data_cnt > (display_rd_data_cnt + DISPLAY_MAX_BUFFER - 16)) {
226 std::this_thread::sleep_for(std::chrono::milliseconds(100));
227 }
228
229 /* Write the decimated sensor data to the buffer array to prepare for the Qt display*/
230 for (int i = 0; i < SAMPLES/DRATIO; i ++) {
231 display_wr_idx = display_wr_data_cnt % DISPLAY_MAX_BUFFER;
232 display_data_ready_to_use[display_wr_idx+0] = floatOutput1[i];
233 display_data_ready_to_use[display_wr_idx+1] = floatOutput2[i];
234 display_data_ready_to_use[display_wr_idx+2] = floatOutput3[i];
235 display_wr_data_cnt += 3;
236 }
237
238 /* Calculate prediction error (using previously predicted samples) */
239 double predict_error = (floatOutput1[0] - predict1) * (floatOutput1[0] - predict1);
240 predict_error += (floatOutput2[0] - predict2) * (floatOutput2[0] - predict2);
241
242 ad_detected = 0;
243
244 if(samples_counter > START_FIND_THRESHOLD) {
245 if(samples_counter < STOP_FIND_THRESHOLD) {
246 /* Calibration at the beginning to find the error threshold */
247 pdmState = 100;
248 predict_threshold_err = max(predict_error, predict_threshold_err);
249 restart_hangover_timer = 0;
250 } else {
251 pdmState = -100;
252 /* Anomaly detection mode with hangover to increase robustness */
253 if(predict_error > pdmContext.relative_threshold * predict_threshold_err) {
254 restart_hangover_timer = samples_counter;
255 }
256 if((samples_counter - restart_hangover_timer) < HANGOVER_TIME) {
257 ad_detected = 1;
258 }
259 }
260 }
261
262 /* Write the detection results to the buffer array to prepare for the Qt display*/
263 display_wr_idx = display_wr_data_cnt % DISPLAY_MAX_BUFFER;
264 display_data_ready_to_use[display_wr_idx+0] = predict_error;
265 display_data_ready_to_use[display_wr_idx+1] = predict_threshold_err*pdmContext.relative_threshold + pdmState;
266 display_data_ready_to_use[display_wr_idx+2] = ad_detected * predict_threshold_err *pdmContext.relative_threshold * 1.25;
267 display_wr_data_cnt += 3;
268
269 /* Normalize */
270 double lstm_out1, lstm_in1 = (floatOutput1[0] - pdmContext.mu1) / pdmContext.sig1;
271 double lstm_out2, lstm_in2 = (floatOutput2[0] - pdmContext.mu2) / pdmContext.sig2;
272 /* Run LSTM network for prediction */
273 runLstm(lstm_in1, lstm_in2, &lstm_out1, &lstm_out2);
274 /* Denormalize */
275 predict1 = lstm_out1 * pdmContext.sig1 + pdmContext.mu1;
276 predict2 = lstm_out2 * pdmContext.sig2 + pdmContext.mu2;
277
278 /* Increment the sample counter at the decimated rate */
279 samples_counter ++;
280 } else {
281 std::this_thread::sleep_for(std::chrono::milliseconds(100));
282 }
283 }
284 return 0;
285}
diff --git a/motor_pdm.h b/motor_pdm.h
new file mode 100644
index 0000000..2d50a59
--- /dev/null
+++ b/motor_pdm.h
@@ -0,0 +1,45 @@
1/*
2 * Copyright (c) 2019, Texas Instruments Incorporated
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32*/
33
34#ifndef MOTOR_PDM_H
35#define MOTOR_PDM_H
36
37struct pdmContext_t {
38 double mu1, mu2, sig1, sig2; /* mean and std for normalizing/denormalizing the two phase currents*/
39 double relative_threshold; /* relative ratio (>1) on the maximal prediction error from the calibration stage
40 to set the error threshold for anomaly detection */
41};
42
43int motor_pdm_process(void);
44
45#endif //MOTOR_PDM_H
diff --git a/motor_pdm_loc.h b/motor_pdm_loc.h
new file mode 100644
index 0000000..3aa577c
--- /dev/null
+++ b/motor_pdm_loc.h
@@ -0,0 +1,66 @@
1/*
2 * Copyright (c) 2019, Texas Instruments Incorporated
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32*/
33
34#ifndef MOTOR_PDM_LOC_H
35#define MOTOR_PDM_LOC_H
36
37/* Filter definitions */
38/* Maximum number of inputs that can be handled in one function call */
39#define SAMPLES 200
40/* Maximum length of filter than can be handled */
41#define FIRFLT_LEN 1001
42/* Buffer to hold all of the input samples */
43#define BUFFER_LEN (FIRFLT_LEN - 1 + SAMPLES)
44/* FIR filter coefficients */
45double coeffs[ FIRFLT_LEN ];
46/* Down-sampling ratio*/
47#define DRATIO 200
48
49/* Anomaly detection parameters*/
50#define START_FIND_THRESHOLD 150
51#define STOP_FIND_THRESHOLD 1500
52#define HANGOVER_TIME 20
53
54/* Buffering for Qt display definitions */
55#define DISPLAY_VECTOR 6
56#define DISPLAY_MAX_BUFFER (DISPLAY_VECTOR*64*4096)
57static int display_rd_data_cnt = 0;
58static int display_wr_data_cnt = 0;
59static double display_data_ready_to_use[DISPLAY_MAX_BUFFER];
60
61void firFloatInit( double *insamp, int len_delay_line);
62void firFloat( double *coeffs, double *insamp, int filterLength,
63 double *input, int length,
64 double *output);
65
66#endif //MOTOR_PDM_LOC_H
diff --git a/oscilloscope.pro b/oscilloscope.pro
deleted file mode 100644
index effdd51..0000000
--- a/oscilloscope.pro
+++ /dev/null
@@ -1,28 +0,0 @@
1QT += charts qml quick
2
3DEFINES += QRANDOMGENERATOR_MISSING
4
5HEADERS += \
6 datasource.h\
7 config.h \
8 LSTM_model.h \
9 onnx_model.h
10
11SOURCES += \
12 main.cpp \
13 datasource.cpp \
14 psensors.cpp \
15 motor-pdm.cpp \
16 lstm_infer.cpp \
17 onnx_model.cpp \
18 config.cpp \
19
20RESOURCES += \
21 resources.qrc
22
23DISTFILES += \
24 qml/oscilloscope/*
25
26target.path = $$[QT_INSTALL_EXAMPLES]/charts/oscilloscope
27INSTALLS += target
28TARGET = RnnPdmAnomalyDetection
diff --git a/pdm-anomaly-detection.pro b/pdm-anomaly-detection.pro
new file mode 100644
index 0000000..a3bd704
--- /dev/null
+++ b/pdm-anomaly-detection.pro
@@ -0,0 +1,42 @@
1QT += charts qml quick
2
3DEFINES += QRANDOMGENERATOR_MISSING
4
5HEADERS += \
6 datasource.h\
7 config.h \
8 LSTM_model.h \
9 onnx_model.h \
10 lstm_infer.h \
11 motor_pdm.h \
12 psensors.h \
13 motor_pdm_loc.h
14
15SOURCES += \
16 main.cpp \
17 datasource.cpp \
18 psensors.cpp \
19 motor_pdm.cpp \
20 lstm_infer.cpp \
21 onnx_model.cpp \
22 config.cpp \
23
24RESOURCES += \
25 resources.qrc
26
27DISTFILES += \
28 qml/pdm-anomaly-detection/*
29
30
31# Additional import path used to resolve QML modules in Qt Creator's code model
32QML_IMPORT_PATH =
33
34# Additional import path used to resolve QML modules just for Qt Quick Designer
35QML_DESIGNER_IMPORT_PATH =
36
37# Default rules for deployment.
38qnx: target.path = /tmp/$${TARGET}/bin
39else: unix:!android: target.path = /opt/$${TARGET}/bin
40!isEmpty(target.path): INSTALLS += target
41
42TARGET = RnnPdmAnomalyDetection
diff --git a/psensors.cpp b/psensors.cpp
index 004dfdb..cfe3752 100644
--- a/psensors.cpp
+++ b/psensors.cpp
@@ -1,3 +1,36 @@
1/*
2 * Copyright (c) 2019, Texas Instruments Incorporated
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32*/
33
1#include <stdio.h> 34#include <stdio.h>
2#include <stdlib.h> 35#include <stdlib.h>
3#include <string.h> 36#include <string.h>
@@ -7,144 +40,160 @@
7#include <sys/types.h> 40#include <sys/types.h>
8#include <unistd.h> 41#include <unistd.h>
9 42
43#include "psensors.h"
44
10#include <iostream> 45#include <iostream>
11#include <thread> 46#include <thread>
12#include <chrono> 47#include <chrono>
13 48
14//#define VERBOSE 49//#define VERBOSE
15 50
16#define MAX_BUFFER (3*64*16384) 51/* Define the buffer to store the incoming sensor data and the read/write counter*/
17static int rd_data_cnt = 0; 52static int psensors_rd_data_cnt = 0;
18static int wr_data_cnt = 0; 53static int psensors_wr_data_cnt = 0;
19static float data_ready_to_use[MAX_BUFFER]; 54static float psensors_data_ready_to_use[MAX_BUFFER];
20 55
56/* Send the buffered sensor data to downstream for further processing */
21int uart_get_data(int samples_count, float *samples_array) 57int uart_get_data(int samples_count, float *samples_array)
22{ 58{
23 int rd_idx; 59 int rd_idx;
24#ifdef VERBOSE 60#ifdef VERBOSE
25 printf ("\nwr=%d rd=%d cnt=%d ", wr_data_cnt, rd_data_cnt, samples_count); 61 printf ("\nwr=%d rd=%d cnt=%d ", psensors_wr_data_cnt, psensors_rd_data_cnt, samples_count);
26#endif 62#endif
27 if(wr_data_cnt >= (rd_data_cnt + samples_count*3)) 63 /* When the number of sensor data points reach samples_count, send them to downstream */
28 { 64 if(psensors_wr_data_cnt >= (psensors_rd_data_cnt + samples_count*3)) {
29 for (int i = 0; i < samples_count; i ++) 65 for (int i = 0; i < samples_count; i ++) {
30 { 66 rd_idx = psensors_rd_data_cnt % MAX_BUFFER;
31 rd_idx = rd_data_cnt % MAX_BUFFER; 67 samples_array[3*i + 0] = psensors_data_ready_to_use[rd_idx + 0];
32 samples_array[3*i + 0] = data_ready_to_use[rd_idx + 0]; 68 samples_array[3*i + 1] = psensors_data_ready_to_use[rd_idx + 1];
33 samples_array[3*i + 1] = data_ready_to_use[rd_idx + 1]; 69 samples_array[3*i + 2] = psensors_data_ready_to_use[rd_idx + 2];
34 samples_array[3*i + 2] = data_ready_to_use[rd_idx + 2]; 70 psensors_rd_data_cnt += 3;
35 rd_data_cnt += 3; 71 }
36 } 72 return samples_count;
37 return samples_count; 73 } else return 0;
38 } else return 0;
39} 74}
40 75
41void uart_stream_parser(int mode_op) { 76/* Parse the incoming sensor data and write the parsed sensor data into the buffer */
42const char *log_filename = mode_op & 0x01 ? "parser.txt" : NULL; 77void uart_stream_parser(int mode_op)
43FILE *fout; 78{
44int wr_idx = 0; 79 const char *log_filename = mode_op & 0x01 ? "parser.txt" : NULL;
80 FILE *fout;
81 int wr_idx = 0;
45#ifdef VERBOSE 82#ifdef VERBOSE
46int prev_sync = 0; 83 int prev_sync = 0;
47#endif 84#endif
48int prev_cnt = 0; 85 int prev_cnt = 0;
49unsigned int val1, val_phases, val_position; 86 unsigned int val1, val_phases, val_position;
50short int_phase1, int_phase2; 87 short int_phase1, int_phase2;
51float phase1, phase2, position; 88 float phase1, phase2, position;
52unsigned char all_zeros[256]; 89 unsigned char all_zeros[256];
53unsigned char line_in[256]; 90 unsigned char line_in[256];
54int sync_i = (1 << 31); 91 int sync_i = (1 << 31);
55int cnt, err_flag = 0; 92 int cnt, err_flag = 0;
56int fd; 93 int fd;
57// FIFO file path 94 /* FIFO file path */
58const char * myfifo = "/tmp/myfifo"; 95 const char * pdmfifo = "/tmp/pdmfifo";
59 96
60 memset(all_zeros, 0, 256); 97 memset(all_zeros, 0, 256);
61 memset(line_in, 0, 256); 98 memset(line_in, 0, 256);
62 99
63 // Creating the named file(FIFO) 100 /* Creating the named file(FIFO) */
64 mkfifo(myfifo, 0666); 101 mkfifo(pdmfifo, 0666);
65 102
66 // Open FIFO for Read only 103 /* Open FIFO for Read only */
67 fd = open(myfifo, O_RDONLY); 104 fd = open(pdmfifo, O_RDONLY);
68 105
69 if(log_filename) 106 if(log_filename) {
70 { 107 fout = fopen(log_filename, "wt");
71 fout = fopen(log_filename, "wt");
72 }
73
74 for (int i = 0; ; i ++)
75 { // Shift delay line left for one byte
76 for(int j = 1; j < 256; j ++) line_in[j - 1] = line_in[j];
77 if(read(fd, &line_in[255], 1) != 1) {
78 line_in[255] = 0;
79 if(wr_data_cnt <= rd_data_cnt) { // Continue processing until all buffered samples are processed
80 // No unprocessed bytes left, sleep for some time as there is nothing on input
81 std::this_thread::sleep_for(std::chrono::milliseconds(20));
82 continue;
83 }
84 } 108 }
85 109
86 // Writting too fast, do write side throttling 110 for (int i = 0; ; i ++) {
87 if((mode_op & 0x02) && (wr_data_cnt > (rd_data_cnt + MAX_BUFFER - 16))) 111 /* Shift delay line left for one byte */
88 std::this_thread::sleep_for(std::chrono::milliseconds(100)); 112 for(int j = 1; j < 256; j ++) {
89 113 line_in[j - 1] = line_in[j];
90 if(line_in[0] == 0xce && 114 }
91 line_in[1] == 0xfa && 115 if(read(fd, &line_in[255], 1) != 1) {
92 line_in[2] == 0xbe && 116 line_in[255] = 0;
93 line_in[3] == 0xba 117 /* Continue processing until all buffered samples are processed */
94 ) 118 if(psensors_wr_data_cnt <= psensors_rd_data_cnt) {
95 { 119 /* No unprocessed bytes left, sleep for some time as there is nothing on input */
96 cnt = *(unsigned int *)&line_in[1*4]; 120 std::this_thread::sleep_for(std::chrono::milliseconds(20));
97 sync_i = i + 2*4; 121 continue;
122 }
123 }
124
125 /* Writting too fast, do write side throttling */
126 if((mode_op & 0x02) && (psensors_wr_data_cnt > (psensors_rd_data_cnt + MAX_BUFFER - 16))) {
127 std::this_thread::sleep_for(std::chrono::milliseconds(100));
128 }
129
130 /* Parsing the magic word and counter at the beginning */
131 if(line_in[0] == 0xce &&
132 line_in[1] == 0xfa &&
133 line_in[2] == 0xbe &&
134 line_in[3] == 0xba) {
135 cnt = *(unsigned int *)&line_in[1*4];
136 sync_i = i + 2*4;
98#ifdef VERBOSE 137#ifdef VERBOSE
99 printf ("\n%08x, %8d:%8d ... %8d[%8d]\n", *(unsigned int *)&line_in[0], i, cnt, 138 printf ("\n%08x, %8d:%8d ... %8d[%8d]\n", *(unsigned int *)&line_in[0], i, cnt,
100 sync_i - prev_sync, cnt - prev_cnt); 139 sync_i - prev_sync, cnt - prev_cnt);
101 prev_sync = sync_i; 140 prev_sync = sync_i;
102#endif 141#endif
103 if((i >= 4*1024) && (cnt - prev_cnt) != 1023) err_flag |= 1; 142 if((i >= 4*1024) && (cnt - prev_cnt) != 1023) {
104 prev_cnt = cnt; 143 err_flag |= 1;
105 } 144 }
106 if((i - sync_i) >= 0) 145 prev_cnt = cnt;
107 { 146 }
147 if((i - sync_i) >= 0) {
108#ifdef VERBOSE 148#ifdef VERBOSE
109 if(((i - sync_i) % (2*4)) == 0) printf ("\n[%8d, %8d] ... ", i, sync_i); 149 if(((i - sync_i) % (2*4)) == 0) {
150 printf ("\n[%8d, %8d] ... ", i, sync_i);
151 }
110#endif 152#endif
111 if(((i - sync_i) % 4) == 0) 153 if(((i - sync_i) % 4) == 0) {
112 { 154 /* Get position data */
113 val1 = *(unsigned int *)&line_in[0]; 155 val1 = *(unsigned int *)&line_in[0];
114#ifdef VERBOSE 156#ifdef VERBOSE
115 printf ("%08x ", val1); 157 printf ("%08x ", val1);
116#endif 158#endif
117 if(((i - sync_i) % 8) == 0) { 159 /* Get phase current data */
118 val_phases = val1; 160 if(((i - sync_i) % 8) == 0) {
119 } else { 161 val_phases = val1;
120 val_position = (int)val1; 162 } else {
121 int_phase1 = (short)(val_phases >> 16); 163 /* Calculate the position and the two phase currents */
122 int_phase2 = (short)((val_phases << 16) >> 16); 164 val_position = (int)val1;
123 phase1 = (float)int_phase1 / 32767.0; 165 int_phase1 = (short)(val_phases >> 16);
124 phase2 = (float)int_phase2 / 32767.0; 166 int_phase2 = (short)((val_phases << 16) >> 16);
125 position = (float)val_position / 33554432.0f; 167 phase1 = (float)int_phase1 / 32767.0;
126 168 phase2 = (float)int_phase2 / 32767.0;
127 /* throttling when there is no incoming sensor data */ 169 position = (float)val_position / 33554432.0f;
128 if(phase1 == 0) { 170
129 std::this_thread::sleep_for(std::chrono::milliseconds(20)); 171 /* Throttling when there is no incoming sensor data */
130 continue; 172 if(phase1 == 0) {
131 } 173 std::this_thread::sleep_for(std::chrono::milliseconds(20));
132 174 continue;
133 if(log_filename) fprintf(fout, "%8.5f %8.5f %8.5f\n", phase1, phase2, position); 175 }
176
177 if(log_filename) {
178 fprintf(fout, "%8.5f %8.5f %8.5f\n", phase1, phase2, position);
179 }
134#ifdef VERBOSE 180#ifdef VERBOSE
135 printf("... %8.5f %8.5f %8.5f", phase1, phase2, position); 181 printf("... %8.5f %8.5f %8.5f", phase1, phase2, position);
136#endif 182#endif
137 wr_idx = wr_data_cnt % MAX_BUFFER; 183 /* Write the sensor data to the buffer array */
138 data_ready_to_use[wr_idx + 0] = phase1; 184 wr_idx = psensors_wr_data_cnt % MAX_BUFFER;
139 data_ready_to_use[wr_idx + 1] = phase2; 185 psensors_data_ready_to_use[wr_idx + 0] = phase1;
140 data_ready_to_use[wr_idx + 2] = position; 186 psensors_data_ready_to_use[wr_idx + 1] = phase2;
141 wr_data_cnt += 3; 187 psensors_data_ready_to_use[wr_idx + 2] = position;
142 } 188 psensors_wr_data_cnt += 3;
143 } 189 }
190 }
191 }
192 }
193 printf("\nEnd of stream!!!\n"); fflush(stdout);
194 if(log_filename) {
195 fclose(fout);
144 } 196 }
145 } 197 close(fd);
146 printf("\nEnd of stream!!!\n"); fflush(stdout);
147 if(log_filename) fclose(fout);
148 close(fd);
149} 198}
150/** nothing past this point **/ 199/** nothing past this point **/
diff --git a/psensors.h b/psensors.h
new file mode 100644
index 0000000..eb46a73
--- /dev/null
+++ b/psensors.h
@@ -0,0 +1,42 @@
1/*
2 * Copyright (c) 2019, Texas Instruments Incorporated
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32*/
33
34#ifndef PSENSOR_H
35#define PSENSOR_H
36
37#define MAX_BUFFER (3*64*16384)
38
39int uart_get_data(int sample_count, float *samples_array);
40void uart_stream_parser(int mode_op);
41
42#endif //PSENSOR_H
diff --git a/qml/oscilloscope/ControlPanel.qml b/qml/oscilloscope/ControlPanel.qml
deleted file mode 100644
index c9554de..0000000
--- a/qml/oscilloscope/ControlPanel.qml
+++ /dev/null
@@ -1,17 +0,0 @@
1import QtQuick 2.1
2import QtQuick.Layouts 1.0
3
4ColumnLayout {
5 property alias imageDisplayButton: imageDisplayButton
6 spacing: 8
7 Layout.fillHeight: true
8 signal imageDisplayChanged(bool enabled)
9
10 MultiButton {
11 id: imageDisplayButton
12 text: " Setup Image and Diagram"
13 items: ["Show", "Hide"]
14 currentSelection: 0
15 onSelectionChanged: imageDisplayChanged(currentSelection == 1);
16 }
17}
diff --git a/qml/oscilloscope/MultiButton.qml b/qml/oscilloscope/MultiButton.qml
deleted file mode 100644
index b06f319..0000000
--- a/qml/oscilloscope/MultiButton.qml
+++ /dev/null
@@ -1,40 +0,0 @@
1import QtQuick 2.0
2import QtQuick.Controls 1.0
3import QtQuick.Controls.Styles 1.0
4
5Item {
6 id: button
7
8 property string text: "Option: "
9 property variant items: ["first"]
10 property int currentSelection: 0
11 signal selectionChanged(variant selection)
12
13 signal clicked
14
15 implicitWidth: buttonText.implicitWidth + 5
16 implicitHeight: buttonText.implicitHeight + 10
17
18 Button {
19 id: buttonText
20 width: parent.width
21 height: parent.height
22
23 style: ButtonStyle {
24 label: Component {
25 Text {
26 text: button.items[currentSelection] + button.text
27 clip: true
28 wrapMode: Text.WordWrap
29 verticalAlignment: Text.AlignVCenter
30 horizontalAlignment: Text.AlignHCenter
31 anchors.fill: parent
32 }
33 }
34 }
35 onClicked: {
36 currentSelection = (currentSelection + 1) % items.length;
37 selectionChanged(button.items[currentSelection]);
38 }
39 }
40}
diff --git a/qml/oscilloscope/PdmView.qml b/qml/oscilloscope/PdmView.qml
deleted file mode 100644
index dfbe9ec..0000000
--- a/qml/oscilloscope/PdmView.qml
+++ /dev/null
@@ -1,74 +0,0 @@
1import QtQuick 2.0
2import QtCharts 2.1
3
4ChartView {
5 id: chartViewPdm
6 animationOptions: ChartView.NoAnimation
7 theme: ChartView.ChartThemeBlueCerulean
8 property bool openGL: true
9 property bool openGLSupported: true
10
11 legend.font.pointSize: 16
12
13 ValueAxis {
14 id: axisY1
15 min: 0
16 max: 0.003
17 }
18
19 ValueAxis {
20 id: axisX
21 min: 0
22 max: 256
23 }
24
25 LineSeries {
26 id: lineSeries1Pdm
27 name: "Prediction Error"
28 width: 3
29 color: "sandybrown"
30 axisX: axisX
31 axisY: axisY1
32 useOpenGL: chartViewPdm.openGL
33 }
34 LineSeries {
35 id: lineSeries2Pdm
36 name: "Threshold"
37 width: 3
38 color: "#1e90ff"
39 axisX: axisX
40 axisY: axisY1
41 useOpenGL: chartViewPdm.openGL
42 }
43 LineSeries {
44 id: lineSeries3Pdm
45 name: "Anomaly"
46 width: 3
47 color: "#ff0000"
48 axisX: axisX
49 axisY: axisY1
50 useOpenGL: chartViewPdm.openGL
51 }
52
53 Timer {
54 id: refreshTimer
55 interval: 1 / 30 * 1000 // 30 Hz
56 running: true
57 repeat: true
58 onTriggered: {
59 dataSource.update(3, chartViewPdm.series(0));
60 dataSource.update(4, chartViewPdm.series(1));
61 dataSource.update(5, chartViewPdm.series(2));
62 }
63 }
64
65 function createAxis(min, max) {
66 // The following creates a ValueAxis object that can be then set as a x or y axis for a series
67 return Qt.createQmlObject("import QtQuick 2.0; import QtCharts 2.0; ValueAxis { min: "
68 + min + "; max: " + max + " }", chartViewPdm);
69 }
70
71 function changeRefreshRate(rate) {
72 refreshTimer.interval = 1 / Number(rate) * 1000;
73 }
74}
diff --git a/qml/oscilloscope/ScopeView.qml b/qml/oscilloscope/ScopeView.qml
deleted file mode 100644
index 72191d0..0000000
--- a/qml/oscilloscope/ScopeView.qml
+++ /dev/null
@@ -1,81 +0,0 @@
1import QtQuick 2.0
2import QtCharts 2.1
3
4ChartView {
5 id: chartView
6 animationOptions: ChartView.NoAnimation
7 theme: ChartView.ChartThemeBlueCerulean
8 property bool openGL: true
9 property bool openGLSupported: true
10
11 legend.font.pointSize: 16
12
13 ValueAxis {
14 id: axisY1
15 min: -0.12
16 max: 0.12
17 }
18
19 ValueAxis {
20 id: axisY3
21 min: 0
22 max: 1.1
23 }
24
25 ValueAxis {
26 id: axisX
27 min: 0
28 max: 256
29 }
30
31 LineSeries {
32 id: lineSeries1
33 name: "Phase Current 1"
34 color: "darkturquoise"
35 width: 3
36 axisX: axisX
37 axisY: axisY1
38 useOpenGL: chartView.openGL
39 }
40 LineSeries {
41 id: lineSeries2
42 name: "Phase Current 2"
43 color: "forestgreen"
44 width: 3
45 axisX: axisX
46 axisYRight: axisY1
47 useOpenGL: chartView.openGL
48 }
49 LineSeries {
50 id: lineSeries3
51 name: "Position"
52 width: 3
53 color: "orange"
54 axisX: axisX
55 axisYRight: axisY3
56 useOpenGL: chartView.openGL
57 }
58
59 Timer {
60 id: refreshTimer
61 interval: 1 / 30 * 1000 // 30 Hz
62 running: true
63 repeat: true
64 onTriggered: {
65 dataSource.getdata();
66 dataSource.update(0, chartView.series(0));
67 dataSource.update(1, chartView.series(1));
68 dataSource.update(2, chartView.series(2));
69 }
70 }
71
72 function createAxis(min, max) {
73 // The following creates a ValueAxis object that can be then set as a x or y axis for a series
74 return Qt.createQmlObject("import QtQuick 2.0; import QtCharts 2.0; ValueAxis { min: "
75 + min + "; max: " + max + " }", chartView);
76 }
77
78 function changeRefreshRate(rate) {
79 refreshTimer.interval = 1 / Number(rate) * 1000;
80 }
81}
diff --git a/qml/oscilloscope/main.qml b/qml/oscilloscope/main.qml
deleted file mode 100644
index d5972c7..0000000
--- a/qml/oscilloscope/main.qml
+++ /dev/null
@@ -1,142 +0,0 @@
1import QtQuick 2.0
2
3Item {
4 id: main
5 width: 1920
6 height: 1080
7
8 Text {
9 anchors.top: parent.top
10 anchors.topMargin: 50
11 anchors.left: parent.left
12 anchors.leftMargin: 50
13 text: "Deep Learning based Predictive Maintenance (PdM) on Sitara Edge Devices"
14 font.family: "Helvetica"
15 font.pointSize: 36
16 font.bold: true
17 color: "red"
18 }
19
20 Image {
21 source: "./ti-logo.png"
22 scale: 0.35
23 anchors.bottom: parent.bottom
24 anchors.bottomMargin: 35
25 anchors.right: parent.right
26 anchors.rightMargin: -80
27 }
28
29 ControlPanel {
30 id: controlPanel
31 anchors.bottom: parent.bottom
32 anchors.bottomMargin: 75
33 anchors.left: parent.left
34 anchors.leftMargin: 60
35 onImageDisplayChanged: {
36 picmotordrive.visible = (!picmotordrive.visible);
37 picanomalydetection.visible = (!picanomalydetection.visible);
38 picsystemmodel.visible = (!picsystemmodel.visible);
39 }
40 }
41
42 ScopeView {
43 id: scopeView
44 anchors.top: parent.top
45 anchors.topMargin: 200
46 anchors.bottom: parent.bottom
47 anchors.bottomMargin: 100
48 anchors.left: parent.left
49 anchors.leftMargin: 50
50 anchors.right: parent.right
51 anchors.rightMargin: 950
52 }
53
54 Image {
55 id: picmotordrive
56 source: "./motor-drive.png"
57 scale: 0.83
58 visible: false
59 anchors.top: scopeView.top
60 anchors.topMargin: 80
61 anchors.right: scopeView.right
62 anchors.rightMargin: 200
63 }
64
65
66 PdmView {
67 id: pdmView
68 anchors.top: parent.top
69 anchors.topMargin: 200
70 anchors.bottom: parent.bottom
71 anchors.bottomMargin: 100
72 anchors.left: scopeView.right
73 anchors.right: parent.right
74 anchors.rightMargin: 50
75 }
76
77 Image {
78 id: picanomalydetection
79 source: "./anomaly-detection.png"
80 scale: 0.85
81 visible: false
82 anchors.top: pdmView.top
83 anchors.topMargin: 70
84 anchors.right: pdmView.right
85 anchors.rightMargin: 370
86 }
87
88 Image {
89 id: picsystemmodel
90 source: "./system-model.png"
91 scale: 0.8
92 visible: false
93 anchors.top: pdmView.top
94 anchors.topMargin:160
95 anchors.right: pdmView.right
96 anchors.rightMargin: 15
97 }
98
99 Text {
100 text: "Real-time Sensor Input"
101 font.family: "Helvetica"
102 font.pointSize: 22
103 color: "red"
104 anchors.top: parent.top
105 anchors.topMargin: 150
106 anchors.left: parent.left
107 anchors.leftMargin: 280
108 }
109
110 Text {
111 text: "Real-time Anomaly Detection"
112 font.family: "Helvetica"
113 font.pointSize: 22
114 color: "red"
115 anchors.top: parent.top
116 anchors.topMargin: 150
117 anchors.right: parent.right
118 anchors.rightMargin: 280
119 }
120
121 Text {
122 text: dataSource.pdmStage
123 font.family: "Helvetica"
124 font.pointSize: 22
125 color: "green"
126 anchors.top: parent.top
127 anchors.topMargin: 650
128 anchors.right: parent.right
129 anchors.rightMargin: 460
130 }
131
132 Text {
133 text: dataSource.anomalyDetection
134 font.family: "Helvetica"
135 font.pointSize: 24
136 color: "red"
137 anchors.top: parent.top
138 anchors.topMargin: 650
139 anchors.right: parent.right
140 anchors.rightMargin: 125
141 }
142}
diff --git a/qml/pdm-anomaly-detection/ControlPanel.qml b/qml/pdm-anomaly-detection/ControlPanel.qml
new file mode 100644
index 0000000..a450712
--- /dev/null
+++ b/qml/pdm-anomaly-detection/ControlPanel.qml
@@ -0,0 +1,80 @@
1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Charts module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 or (at your option) any later version
20** approved by the KDE Free Qt Foundation. The licenses are as published by
21** the Free Software Foundation and appearing in the file LICENSE.GPL3
22** included in the packaging of this file. Please review the following
23** information to ensure the GNU General Public License requirements will
24** be met: https://www.gnu.org/licenses/gpl-3.0.html.
25**
26** $QT_END_LICENSE$
27**
28****************************************************************************/
29/*
30 * Copyright (c) 2019, Texas Instruments Incorporated
31 * All rights reserved.
32 *
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
35 * are met:
36 *
37 * * Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39 *
40 * * Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in the
42 * documentation and/or other materials provided with the distribution.
43 *
44 * * Neither the name of Texas Instruments Incorporated nor the names of
45 * its contributors may be used to endorse or promote products derived
46 * from this software without specific prior written permission.
47 *
48 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
49 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
50 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
51 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
52 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
53 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
54 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
55 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
56 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
57 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
58 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59 *
60*/
61
62import QtQuick 2.1
63import QtQuick.Layouts 1.0
64
65ColumnLayout {
66 property alias imageDisplayButton: imageDisplayButton
67 spacing: 8
68 Layout.fillHeight: true
69 signal imageDisplayChanged(bool enabled)
70
71 /* Button to show/hide images for the motor setup, call flow, and system model */
72 /* By default, the images are shown with the button prompting to hide them */
73 MultiButton {
74 id: imageDisplayButton
75 text: " Setup Image and Diagram"
76 items: ["Hide", "Show"]
77 currentSelection: 0
78 onSelectionChanged: imageDisplayChanged(currentSelection == 1);
79 }
80}
diff --git a/qml/pdm-anomaly-detection/MultiButton.qml b/qml/pdm-anomaly-detection/MultiButton.qml
new file mode 100644
index 0000000..e3efa06
--- /dev/null
+++ b/qml/pdm-anomaly-detection/MultiButton.qml
@@ -0,0 +1,101 @@
1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Charts module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 or (at your option) any later version
20** approved by the KDE Free Qt Foundation. The licenses are as published by
21** the Free Software Foundation and appearing in the file LICENSE.GPL3
22** included in the packaging of this file. Please review the following
23** information to ensure the GNU General Public License requirements will
24** be met: https://www.gnu.org/licenses/gpl-3.0.html.
25**
26** $QT_END_LICENSE$
27**
28****************************************************************************/
29/*
30 * Copyright (c) 2019, Texas Instruments Incorporated
31 * All rights reserved.
32 *
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
35 * are met:
36 *
37 * * Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39 *
40 * * Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in the
42 * documentation and/or other materials provided with the distribution.
43 *
44 * * Neither the name of Texas Instruments Incorporated nor the names of
45 * its contributors may be used to endorse or promote products derived
46 * from this software without specific prior written permission.
47 *
48 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
49 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
50 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
51 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
52 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
53 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
54 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
55 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
56 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
57 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
58 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59 *
60*/
61
62import QtQuick 2.0
63import QtQuick.Controls 1.0
64import QtQuick.Controls.Styles 1.0
65
66Item {
67 id: button
68
69 property string text: "Option: "
70 property variant items: ["first"]
71 property int currentSelection: 0
72 signal selectionChanged(variant selection)
73
74 signal clicked
75
76 implicitWidth: buttonText.implicitWidth + 5
77 implicitHeight: buttonText.implicitHeight + 10
78
79 Button {
80 id: buttonText
81 width: parent.width
82 height: parent.height
83
84 style: ButtonStyle {
85 label: Component {
86 Text {
87 text: button.items[currentSelection] + button.text
88 clip: true
89 wrapMode: Text.WordWrap
90 verticalAlignment: Text.AlignVCenter
91 horizontalAlignment: Text.AlignHCenter
92 anchors.fill: parent
93 }
94 }
95 }
96 onClicked: {
97 currentSelection = (currentSelection + 1) % items.length;
98 selectionChanged(button.items[currentSelection]);
99 }
100 }
101}
diff --git a/qml/pdm-anomaly-detection/PdmView.qml b/qml/pdm-anomaly-detection/PdmView.qml
new file mode 100644
index 0000000..381950d
--- /dev/null
+++ b/qml/pdm-anomaly-detection/PdmView.qml
@@ -0,0 +1,141 @@
1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Charts module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 or (at your option) any later version
20** approved by the KDE Free Qt Foundation. The licenses are as published by
21** the Free Software Foundation and appearing in the file LICENSE.GPL3
22** included in the packaging of this file. Please review the following
23** information to ensure the GNU General Public License requirements will
24** be met: https://www.gnu.org/licenses/gpl-3.0.html.
25**
26** $QT_END_LICENSE$
27**
28****************************************************************************/
29/*
30 * Copyright (c) 2019, Texas Instruments Incorporated
31 * All rights reserved.
32 *
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
35 * are met:
36 *
37 * * Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39 *
40 * * Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in the
42 * documentation and/or other materials provided with the distribution.
43 *
44 * * Neither the name of Texas Instruments Incorporated nor the names of
45 * its contributors may be used to endorse or promote products derived
46 * from this software without specific prior written permission.
47 *
48 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
49 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
50 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
51 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
52 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
53 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
54 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
55 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
56 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
57 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
58 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59 *
60*/
61
62import QtQuick 2.0
63import QtCharts 2.1
64
65ChartView {
66 id: chartViewPdm
67 animationOptions: ChartView.NoAnimation
68 theme: ChartView.ChartThemeBlueCerulean
69 property bool openGL: true
70 property bool openGLSupported: true
71
72 legend.font.pointSize: 16
73
74 ValueAxis {
75 id: axisY1
76 min: 0
77 max: 0.003
78 }
79
80 ValueAxis {
81 id: axisX
82 min: 0
83 max: 256
84 }
85
86 /* Line series for prediction error */
87 LineSeries {
88 id: lineSeries1Pdm
89 name: "Prediction Error"
90 width: 3
91 color: "sandybrown"
92 axisX: axisX
93 axisY: axisY1
94 useOpenGL: chartViewPdm.openGL
95 }
96
97 /* Line series to draw the threshold line */
98 LineSeries {
99 id: lineSeries2Pdm
100 name: "Threshold"
101 width: 3
102 color: "#1e90ff"
103 axisX: axisX
104 axisY: axisY1
105 useOpenGL: chartViewPdm.openGL
106 }
107
108 /* Line series to draw the anomaly line */
109 LineSeries {
110 id: lineSeries3Pdm
111 name: "Anomaly"
112 width: 3
113 color: "#ff0000"
114 axisX: axisX
115 axisY: axisY1
116 useOpenGL: chartViewPdm.openGL
117 }
118
119 /* Timer to update the detection result display */
120 Timer {
121 id: refreshTimer
122 interval: 1 / 30 * 1000 // 30 Hz
123 running: true
124 repeat: true
125 onTriggered: {
126 dataSource.update(3, chartViewPdm.series(0));
127 dataSource.update(4, chartViewPdm.series(1));
128 dataSource.update(5, chartViewPdm.series(2));
129 }
130 }
131
132 function createAxis(min, max) {
133 // The following creates a ValueAxis object that can be then set as a x or y axis for a series
134 return Qt.createQmlObject("import QtQuick 2.0; import QtCharts 2.0; ValueAxis { min: "
135 + min + "; max: " + max + " }", chartViewPdm);
136 }
137
138 function changeRefreshRate(rate) {
139 refreshTimer.interval = 1 / Number(rate) * 1000;
140 }
141}
diff --git a/qml/pdm-anomaly-detection/ScopeView.qml b/qml/pdm-anomaly-detection/ScopeView.qml
new file mode 100644
index 0000000..4b8cccb
--- /dev/null
+++ b/qml/pdm-anomaly-detection/ScopeView.qml
@@ -0,0 +1,148 @@
1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Charts module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 or (at your option) any later version
20** approved by the KDE Free Qt Foundation. The licenses are as published by
21** the Free Software Foundation and appearing in the file LICENSE.GPL3
22** included in the packaging of this file. Please review the following
23** information to ensure the GNU General Public License requirements will
24** be met: https://www.gnu.org/licenses/gpl-3.0.html.
25**
26** $QT_END_LICENSE$
27**
28****************************************************************************/
29/*
30 * Copyright (c) 2019, Texas Instruments Incorporated
31 * All rights reserved.
32 *
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
35 * are met:
36 *
37 * * Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39 *
40 * * Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in the
42 * documentation and/or other materials provided with the distribution.
43 *
44 * * Neither the name of Texas Instruments Incorporated nor the names of
45 * its contributors may be used to endorse or promote products derived
46 * from this software without specific prior written permission.
47 *
48 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
49 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
50 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
51 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
52 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
53 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
54 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
55 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
56 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
57 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
58 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59 *
60*/
61
62import QtQuick 2.0
63import QtCharts 2.1
64
65ChartView {
66 id: chartView
67 animationOptions: ChartView.NoAnimation
68 theme: ChartView.ChartThemeBlueCerulean
69 property bool openGL: true
70 property bool openGLSupported: true
71
72 legend.font.pointSize: 16
73
74 ValueAxis {
75 id: axisY1
76 min: -0.12
77 max: 0.12
78 }
79
80 ValueAxis {
81 id: axisY3
82 min: 0
83 max: 1.1
84 }
85
86 ValueAxis {
87 id: axisX
88 min: 0
89 max: 256
90 }
91
92 /* Line series for phase current 1 */
93 LineSeries {
94 id: lineSeries1
95 name: "Phase Current 1"
96 color: "darkturquoise"
97 width: 3
98 axisX: axisX
99 axisY: axisY1
100 useOpenGL: chartView.openGL
101 }
102
103 /* Line series for phase current 2 */
104 LineSeries {
105 id: lineSeries2
106 name: "Phase Current 2"
107 color: "forestgreen"
108 width: 3
109 axisX: axisX
110 axisYRight: axisY1
111 useOpenGL: chartView.openGL
112 }
113
114 /* Line series for angular position */
115 LineSeries {
116 id: lineSeries3
117 name: "Position"
118 width: 3
119 color: "orange"
120 axisX: axisX
121 axisYRight: axisY3
122 useOpenGL: chartView.openGL
123 }
124
125 /* Timer to retrieve data and update the sensor reading display */
126 Timer {
127 id: refreshTimer
128 interval: 1 / 30 * 1000 // 30 Hz
129 running: true
130 repeat: true
131 onTriggered: {
132 dataSource.getdata();
133 dataSource.update(0, chartView.series(0));
134 dataSource.update(1, chartView.series(1));
135 dataSource.update(2, chartView.series(2));
136 }
137 }
138
139 function createAxis(min, max) {
140 // The following creates a ValueAxis object that can be then set as a x or y axis for a series
141 return Qt.createQmlObject("import QtQuick 2.0; import QtCharts 2.0; ValueAxis { min: "
142 + min + "; max: " + max + " }", chartView);
143 }
144
145 function changeRefreshRate(rate) {
146 refreshTimer.interval = 1 / Number(rate) * 1000;
147 }
148}
diff --git a/qml/oscilloscope/anomaly-detection.png b/qml/pdm-anomaly-detection/anomaly-detection.png
index 9428300..9428300 100644
--- a/qml/oscilloscope/anomaly-detection.png
+++ b/qml/pdm-anomaly-detection/anomaly-detection.png
Binary files differ
diff --git a/qml/pdm-anomaly-detection/main.qml b/qml/pdm-anomaly-detection/main.qml
new file mode 100644
index 0000000..e704c12
--- /dev/null
+++ b/qml/pdm-anomaly-detection/main.qml
@@ -0,0 +1,214 @@
1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Charts module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 or (at your option) any later version
20** approved by the KDE Free Qt Foundation. The licenses are as published by
21** the Free Software Foundation and appearing in the file LICENSE.GPL3
22** included in the packaging of this file. Please review the following
23** information to ensure the GNU General Public License requirements will
24** be met: https://www.gnu.org/licenses/gpl-3.0.html.
25**
26** $QT_END_LICENSE$
27**
28****************************************************************************/
29/*
30 * Copyright (c) 2019, Texas Instruments Incorporated
31 * All rights reserved.
32 *
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
35 * are met:
36 *
37 * * Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39 *
40 * * Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in the
42 * documentation and/or other materials provided with the distribution.
43 *
44 * * Neither the name of Texas Instruments Incorporated nor the names of
45 * its contributors may be used to endorse or promote products derived
46 * from this software without specific prior written permission.
47 *
48 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
49 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
50 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
51 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
52 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
53 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
54 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
55 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
56 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
57 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
58 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59 *
60*/
61
62import QtQuick 2.0
63
64Item {
65 id: main
66 width: 1920
67 height: 1080
68
69 /* Demo title at the top */
70 Text {
71 anchors.top: parent.top
72 anchors.topMargin: 50
73 anchors.left: parent.left
74 anchors.leftMargin: 50
75 text: "Deep Learning based Predictive Maintenance (PdM) on Sitara Edge Devices"
76 font.family: "Helvetica"
77 font.pointSize: 36
78 font.bold: true
79 color: "red"
80 }
81
82 /* TI logo image at the bottom right */
83 Image {
84 source: "./ti-logo.png"
85 scale: 0.35
86 anchors.bottom: parent.bottom
87 anchors.bottomMargin: 35
88 anchors.right: parent.right
89 anchors.rightMargin: -80
90 }
91
92 /* Control button at bottom left to hide/show the images for setup, call flow, and system model */
93 ControlPanel {
94 id: controlPanel
95 anchors.bottom: parent.bottom
96 anchors.bottomMargin: 75
97 anchors.left: parent.left
98 anchors.leftMargin: 60
99 onImageDisplayChanged: {
100 picmotordrive.visible = (!picmotordrive.visible);
101 picanomalydetection.visible = (!picanomalydetection.visible);
102 picsystemmodel.visible = (!picsystemmodel.visible);
103 }
104 }
105
106 /* Display sensor readings at the left panel */
107 ScopeView {
108 id: scopeView
109 anchors.top: parent.top
110 anchors.topMargin: 200
111 anchors.bottom: parent.bottom
112 anchors.bottomMargin: 100
113 anchors.left: parent.left
114 anchors.leftMargin: 50
115 anchors.right: parent.right
116 anchors.rightMargin: 950
117 }
118
119 /* Image for motor drive setup */
120 Image {
121 id: picmotordrive
122 source: "./motor-drive.png"
123 scale: 0.83
124 visible: true
125 anchors.top: scopeView.top
126 anchors.topMargin: 80
127 anchors.right: scopeView.right
128 anchors.rightMargin: 200
129 }
130
131 /* Display prediction error and anomaly from RNN prediction */
132 PdmView {
133 id: pdmView
134 anchors.top: parent.top
135 anchors.topMargin: 200
136 anchors.bottom: parent.bottom
137 anchors.bottomMargin: 100
138 anchors.left: scopeView.right
139 anchors.right: parent.right
140 anchors.rightMargin: 50
141 }
142
143 /* Image for call flow of anomaly detection */
144 Image {
145 id: picanomalydetection
146 source: "./anomaly-detection.png"
147 scale: 0.85
148 visible: true
149 anchors.top: pdmView.top
150 anchors.topMargin: 70
151 anchors.right: pdmView.right
152 anchors.rightMargin: 370
153 }
154
155 /* Image for system model of anomaly detection */
156 Image {
157 id: picsystemmodel
158 source: "./system-model.png"
159 scale: 0.8
160 visible: true
161 anchors.top: pdmView.top
162 anchors.topMargin:160
163 anchors.right: pdmView.right
164 anchors.rightMargin: 15
165 }
166
167 /* Caption for sensor reading panel */
168 Text {
169 text: "Real-time Sensor Input"
170 font.family: "Helvetica"
171 font.pointSize: 22
172 color: "red"
173 anchors.top: parent.top
174 anchors.topMargin: 150
175 anchors.left: parent.left
176 anchors.leftMargin: 280
177 }
178
179 /* Caption for anomaly detection panel */
180 Text {
181 text: "Real-time Anomaly Detection"
182 font.family: "Helvetica"
183 font.pointSize: 22
184 color: "red"
185 anchors.top: parent.top
186 anchors.topMargin: 150
187 anchors.right: parent.right
188 anchors.rightMargin: 280
189 }
190
191 /* Status string: calibration or looking for anomaly */
192 Text {
193 text: dataSource.pdmStage
194 font.family: "Helvetica"
195 font.pointSize: 22
196 color: "green"
197 anchors.top: parent.top
198 anchors.topMargin: 650
199 anchors.right: parent.right
200 anchors.rightMargin: 460
201 }
202
203 /* Detection result string: empty for anomaly detected */
204 Text {
205 text: dataSource.anomalyDetection
206 font.family: "Helvetica"
207 font.pointSize: 24
208 color: "red"
209 anchors.top: parent.top
210 anchors.topMargin: 650
211 anchors.right: parent.right
212 anchors.rightMargin: 125
213 }
214}
diff --git a/qml/oscilloscope/motor-drive.png b/qml/pdm-anomaly-detection/motor-drive.png
index 13f6393..13f6393 100644
--- a/qml/oscilloscope/motor-drive.png
+++ b/qml/pdm-anomaly-detection/motor-drive.png
Binary files differ
diff --git a/qml/oscilloscope/system-model.png b/qml/pdm-anomaly-detection/system-model.png
index 983827f..983827f 100644
--- a/qml/oscilloscope/system-model.png
+++ b/qml/pdm-anomaly-detection/system-model.png
Binary files differ
diff --git a/qml/oscilloscope/ti-logo.png b/qml/pdm-anomaly-detection/ti-logo.png
index 9763773..9763773 100644
--- a/qml/oscilloscope/ti-logo.png
+++ b/qml/pdm-anomaly-detection/ti-logo.png
Binary files differ
diff --git a/resources.qrc b/resources.qrc
index 4a7ebaf..fff127a 100644
--- a/resources.qrc
+++ b/resources.qrc
@@ -1,13 +1,13 @@
1<RCC> 1<RCC>
2 <qresource prefix="/"> 2 <qresource prefix="/">
3 <file>qml/oscilloscope/main.qml</file> 3 <file>qml/pdm-anomaly-detection/main.qml</file>
4 <file>qml/oscilloscope/ControlPanel.qml</file> 4 <file>qml/pdm-anomaly-detection/ControlPanel.qml</file>
5 <file>qml/oscilloscope/ScopeView.qml</file> 5 <file>qml/pdm-anomaly-detection/ScopeView.qml</file>
6 <file>qml/oscilloscope/PdmView.qml</file> 6 <file>qml/pdm-anomaly-detection/PdmView.qml</file>
7 <file>qml/oscilloscope/MultiButton.qml</file> 7 <file>qml/pdm-anomaly-detection/MultiButton.qml</file>
8 <file>qml/oscilloscope/ti-logo.png</file> 8 <file>qml/pdm-anomaly-detection/ti-logo.png</file>
9 <file>qml/oscilloscope/motor-drive.png</file> 9 <file>qml/pdm-anomaly-detection/motor-drive.png</file>
10 <file>qml/oscilloscope/anomaly-detection.png</file> 10 <file>qml/pdm-anomaly-detection/anomaly-detection.png</file>
11 <file>qml/oscilloscope/system-model.png</file> 11 <file>qml/pdm-anomaly-detection/system-model.png</file>
12 </qresource> 12 </qresource>
13</RCC> 13</RCC>