Skip to content

Commit bbe85d2

Browse files
authored
Merge pull request #31 from tsinghua96/master
HUST Electrical Load Identification
2 parents 455c125 + 7f43251 commit bbe85d2

19 files changed

+1399
-0
lines changed
Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
# Electrical Load Identification
2+
3+
This application is a prototype of **Electrical Load Identification** designed on ARC Iot DK, which can identify the type of appliance according to the current waveform, and display it through OLED. The analog signal of **current** is collected by **Current Transformer(CT)**, then converted into digital signal by **A/D(AD7991)**. The data is input to **ARC IoT DK** for data preprocessing, then the processed data is input to **Convolutional Neural Network(CNN)** for classification. Finally, the current type of electrical appliances is displayed on **OLED**.
4+
5+
-----------------------------------------
6+
7+
- [Electrical Load Identification](#electrical-load-identification)
8+
- [Introduction](#introduction)
9+
- [Function](#function)
10+
- [Appearance](#appearance)
11+
- [Video](#video)
12+
- [Hardware and Software Setup](#hardware-and-software-setup)
13+
- [Required Hardware](#required-hardware)
14+
- [Necessary Hardware](#necessary-hardware3)
15+
- [Required Software](#required-software)
16+
- [Hardware Connection](#hardware-connection)
17+
- [User Manual](#user-manual)
18+
- [Before Running This Application](#before-running-this-application)
19+
- [Run This Application](#run-this-application)
20+
- [Makefile](#makefile)
21+
- [Program flow chart](#program-flow-chart)
22+
- [Model](#model)
23+
- [Data Processing](#data-processing)
24+
- [OLED Display](#oled-display)
25+
26+
27+
-------------------------------
28+
29+
## Introduction
30+
Non-intrusive load monitoring (NILM) is a conceptual framework for the development of power systems. Compared with traditional load monitoring methods, non-intrusive load monitoring is more intelligent. </br>NILM collects current and voltage signals during load operation by installing signal sensors at the entrance of sockets, then transfers the data to Iot DK development board, and carries out load identification through CNN built by ARC MLI library.</br>Users can make statistics and analysis of household energy consumption data, which can help users make rational use of electricity and reduce unnecessary losses.
31+
32+
### Function
33+
* Identifying Electrical Appliances. *At present, it can identify three kinds of electrical appliances and their two previous combinations (hot water kettle, electric fan, mobile phone charger)*
34+
* Display the current types of electrical appliances
35+
36+
37+
### Appearance
38+
* **System View**</br>
39+
![System Overall][1]
40+
41+
42+
### Video
43+
[ Electrical Load Identification demo video ][2]
44+
45+
## Hardware and Software Setup
46+
47+
-------------------------------
48+
### Required Hardware
49+
* Necessary Hardware:
50+
- ARC IoT Development Kit(IoT DK) *1
51+
- AD7991 *1
52+
- ZMCT103C *1
53+
- OLED(12864) *1
54+
55+
![Necessary Hardware][3]
56+
--------------------------------
57+
58+
---------------------------------
59+
60+
### Required Software
61+
* ARC GNU Toolchain 2019.03
62+
* embarc_osp(Branch:embarc_mli): https://github.com/foss-for-synopsys-dwc-arc-processors/embarc_osp.git
63+
* Serial port terminal, such as SecureCRT or Xshell
64+
* Python3.6
65+
* Pycharm
66+
* Tensorflow 1.13.1
67+
68+
### Hardware Connection
69+
1. Connect AD7991 module to IoT DK 2x18 Pin Extension Header(Using IIC0 interface).
70+
2. Connect analog output of current sensor to AD7991 CH1 channel.
71+
3. Connect OLED module to IoT DK 2x18 Pin Extension Header(Using IIC1 interface).
72+
4. Make sure your power regulator connect is correct,including the voltage and polarity.
73+
5. After all connector has been connected correctly,connect the Li-po battery to power up the design.
74+
75+
## User Manual
76+
77+
### Before Running This Application
78+
* Download source code of Electrical Load Identification from github.
79+
* Make sure all connection is correct again.
80+
* Passing Zero or Fire Wire of Socket Wire through Current Transformer.
81+
82+
83+
### Run This Application
84+
Here take IoT DK, CUR_CORE = arcem9d with ARC GNU Toolchain 2019.03 for example to show how to run this application.
85+
1. To build this applicaiton, select the proper board version, core configuration and build with selected toolchain using this command `make BOARD=iotdk BD_VER=10 CUR_CORE=arcem9d TOOLCHAIN=gnu run`.
86+
2. Open your serial terminal such as Tera-Term on PC, and configure it to right COM port and 115200bps.
87+
3. Interact using IoT DK and serial port terminal.
88+
89+
#### Makefile
90+
91+
- Selected embarc_mli here, then you can use [embarc_mli API][4] in your application:
92+
93+
>> # Library
94+
>> LIB_SEL = embarc_mli
95+
96+
- Selected u8glib here, then you can use [u8glib API][5] in your application:
97+
98+
>> # Middleware
99+
>> MID_SEL = common u8glib
100+
101+
- Selected AD7991 here:
102+
103+
>> # Device
104+
>> EXT_DEV_LIST += adc/ad7991
105+
106+
- Other Configure:
107+
108+
>> # use -Hpurge option to optimize the code size
109+
>> ifeq ($(TOOLCHAIN), gnu)
110+
>> ADT_COPT += -ffunction-sections -fdata-sections
111+
>> ADT_LOPT += -Wl,--gc-sections
112+
>> else
113+
>> ADT_COPT += -Hpurge
114+
>> ADT_LOPT += -Hpurge
115+
>> endif
116+
117+
118+
- Target options about EMSK and toolchain:
119+
120+
>> TOOLCHAIN=gnu
121+
>> BOARD=iotdk
122+
>> BD_VER=10
123+
>> CUR_CORE=arcem9d
124+
125+
- The relative series of the root directory, here the path of the Makefile is `./embarc_osp/application/electrical_load_identification/makefile`:
126+
127+
>> #
128+
>> # root dir of embARC
129+
>> #
130+
>> EMBARC_ROOT = ../..
131+
132+
- Directories of source files and header files, notice that it **is not recursive**:
133+
134+
>> # application source dirs
135+
>> APPL_CSRC_DIR = . model
136+
>> APPL_ASMSRC_DIR = .
137+
138+
>> # application include dirs
139+
>> APPL_INC_DIR = . model
140+
>> APPL_DEFINES = APPL_DEFINES = -DUSE_APPL_MEM_CONFIG -DV2DSP_XY -DMODEL_BIT_DEPTH=16 -g
141+
142+
143+
See [ embARC Example User Guide][6], **"Options to Hard-Code in the Application Makefile"** for more detailed information about **Makefile Options**.
144+
145+
#### Program flow chart
146+
![Program flow chart][7]
147+
148+
149+
150+
151+
#### Model
152+
153+
Placing the model source code in `./model` folder.
154+
Placing the C source and header file.
155+
156+
| folder/file | Function |
157+
| ---------------------------------- | -------------------------------- |
158+
| load_identification_coefficients.c | Define weights and biases of CNN |
159+
| load_identification_constants.h | Define Constants of CNN |
160+
| load_identification_model.c | Define the structure of CNN |
161+
| load_identification_model.h | the header of CNN model |
162+
![Structural Chart of CNN Model][8]
163+
164+
#### Data Processing
165+
166+
Placing the data processing source code in `./` folder.
167+
Placing the C source and hearder file.
168+
169+
| folder/file | Function |
170+
| -------------- | -------------------------------------------------- |
171+
| process.c | Processing the results input to CNN and CNN output |
172+
| process.h | the header of process |
173+
| input_buffer.c | Save collected current data |
174+
| input_buffer.h | the hearder of input_buffer |
175+
176+
177+
#### OLED Display
178+
179+
Placing the INCLUDE source code in `./` folder.
180+
Placing the C source and header file.
181+
182+
| folder/file | Function |
183+
| -------------------- | ------------------------------- |
184+
| oled_display.c | OLED display interface function |
185+
| oled_display.h | the hearder of oled_display |
186+
| ssd1306_app_config.h | Definition of OLED Interface |
187+
188+
189+
[1]: ./doc/pic/system.jpg
190+
[2]: https://v.youku.com/v_show/id_XNDI5MTM3MjQ4OA==.html?spm=a2h3j.8428770.3416059.1 "Electrical Load Identification"
191+
[3]: ./doc/pic/hardware.jpg
192+
[4]: https://embarc.org/embarc_mli/doc/build/html/index.html
193+
[5]: https://github.com/olikraus/u8glib/wiki
194+
[6]: https://embarc.org/embarc_osp/doc/build/html/index.html
195+
[7]: ./doc/pic/prog_chart.jpg
196+
[8]: ./doc/pic/CNN_graph.jpg
197+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#ifndef _APPL_MEM_CONFIG_H_
2+
#define _APPL_MEM_CONFIG_H_
3+
4+
5+
6+
#define REGION_MLI_ROM REGION_ROM
7+
#define REGION_MLI_DATA REGION_DCCM
8+
#define REGION_MLI_BSS REGION_DCCM
9+
#define REGION_MLI_ZDATA REGION_DCCM
10+
#define REGION_MLI_MODEL_P2 REGION_DCCM
11+
#define REGION_MLI_MODEL REGION_XCCM
12+
#define REGION_MLI_XDATA REGION_XCCM
13+
#define REGION_MLI_YDATA REGION_YCCM
14+
15+
#endif /* _APPL_MEM_CONFIG_H_ */
19.9 KB
Loading
51.5 KB
Loading
64.7 KB
Loading
54.4 KB
Loading
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/* ------------------------------------------
2+
* Copyright (c) 2019, Synopsys, Inc. All rights reserved.
3+
4+
* Redistribution and use in source and binary forms, with or without modification,
5+
* are permitted provided that the following conditions are met:
6+
7+
* 1) Redistributions of source code must retain the above copyright notice, this
8+
* list of conditions and the following disclaimer.
9+
10+
* 2) Redistributions in binary form must reproduce the above copyright notice,
11+
* this list of conditions and the following disclaimer in the documentation and/or
12+
* other materials provided with the distribution.
13+
14+
* 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may
15+
* be used to endorse or promote products derived from this software without
16+
* specific prior written permission.
17+
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
22+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
*
29+
--------------------------------------------- */
30+
31+
#include "embARC.h"
32+
#include "embARC_debug.h"
33+
#include "input_buffer.h"
34+
35+
/*
36+
* Input buffer declaration and settings
37+
*/
38+
static uint16_t my_index = 0;
39+
float input_buffer[DATA_SIZE] = {0};
40+
uint8_t one_frame_finish_flag = 0;
41+
42+
43+
44+
void input_buffer_push_data(float* data)
45+
{
46+
input_buffer[my_index++] = data[0];
47+
if(my_index == DATA_SIZE) {
48+
one_frame_finish_flag = 1;
49+
my_index = 0;
50+
}
51+
}
52+
53+
54+
55+
56+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/* ------------------------------------------
2+
* Copyright (c) 2019, Synopsys, Inc. All rights reserved.
3+
4+
* Redistribution and use in source and binary forms, with or without modification,
5+
* are permitted provided that the following conditions are met:
6+
7+
* 1) Redistributions of source code must retain the above copyright notice, this
8+
* list of conditions and the following disclaimer.
9+
10+
* 2) Redistributions in binary form must reproduce the above copyright notice,
11+
* this list of conditions and the following disclaimer in the documentation and/or
12+
* other materials provided with the distribution.
13+
14+
* 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may
15+
* be used to endorse or promote products derived from this software without
16+
* specific prior written permission.
17+
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
22+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
*
29+
--------------------------------------------- */
30+
#ifndef _INPUT_BUFFER_H_
31+
#define _INPUT_BUFFER_H_
32+
33+
#include "ad7991.h"
34+
35+
/* Values position inside the input buffer */
36+
#define DATA_SIZE 500
37+
38+
extern float input_buffer[DATA_SIZE];
39+
extern uint8_t one_frame_finish_flag;
40+
41+
extern void input_buffer_push_data(float *data);
42+
43+
#endif /* _INPUT_BUFFER_H_ */

0 commit comments

Comments
 (0)