Skip to content

Commit bdb63a2

Browse files
MileWuIRISZZW
authored andcommitted
HUST_Identification_VI_Trace_of_Appliance
1 parent 05b16eb commit bdb63a2

23 files changed

+4706
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
# Identification VI Trace of Appliance
2+
3+
This application is a prototype of **Electrical Load Identification** designed on ARC IoT DK. It can generate a VI trace chart according to the current and voltage waveforms of electrical appliances, and then identify the types of electrical appliances according to the VI trace diagram. The analog signal of **current** and Voltage is collected by **Current Transformer(CT)** and **Potential Transformer(PT)**, then converted into digital signal by **ATT7053** (*power acquisition chip*).
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+
The detailed monitoring of power user's electric load (load monitoring) is the first step to realize power demand side management (DSM). Load monitoring technology monitors the detailed operation status of each kind of electrical appliances within the user by sampling and analyzing the total load data of users, so as to obtain the data information of power consumption and electricity consumption behavior of each kind of electrical appliances of power users Power companies and other parties are of great significance. In terms of users, such as the smart socket with load identification, it can count the power consumption of household appliances and control the appliances in real time; in the aspect of power grid, such as smart meter, the accuracy of load modeling can be improved by load monitoring, such as considering the time-varying and distribution of load to achieve higher precision load modeling.
31+
32+
We used Synopsys IOT DK to design the system,which can generate VI trace map through current and voltage data measured by sensors. Each kind of electrical appliance corresponds to different VI trace diagram. Through the neural network API provided by embarc MLI library, CNN algorithm can be run on Embedded MCU to identify VI trace map, which avoids uploading data to the cloud for identification, reduces the delay of the system, and makes it better adaptive quotient Business environment requirements.
33+
34+
### Function
35+
* Identifying Electrical Appliances. *At present, it can identify five kinds of electrical appliances by their VI trace(Fan, Compact Fluorescent Lamp, Laptop charger, Hairdryer, Incandescent Light Bulb)*
36+
* Display the VI trace of the current appliance and show the appliance`s name on OLED
37+
38+
39+
### Appearance
40+
* **System View**
41+
![System Overall][1]
42+
43+
44+
### Video
45+
[ Electrical Load Identification demo video ][2]
46+
47+
## Hardware and Software Setup
48+
49+
-------------------------------
50+
### Required Hardware
51+
* Necessary Hardware:
52+
- ARC IoT Development Kit(IoT DK) *1
53+
- ATT7053 *1
54+
- ZMCT103 *1
55+
- ZMPT107 *1
56+
- OLED(12864) *1
57+
* Practicality picture
58+
59+
![](.\doc\practicality picture.JPG)
60+
61+
---------------------------------
62+
63+
### Required Software
64+
* ARC GNU Toolchain 2019.06
65+
* embarc_osp(Branch:embarc_mli): https://github.com/foss-for-synopsys-dwc-arc-processors/embarc_osp.git
66+
* Serial port terminal, such as SecureCRT or Xshell
67+
* Python3.6
68+
* Pycharm
69+
* Tensorflow 1.13.1
70+
71+
### Hardware Connection
72+
1. Connect ATT7053 module to IoT DK 2x18 Pin Extension Header(Using SPI0 interface and SPI0_CS1 Pin).
73+
3. Connect OLED module to IoT DK 2x18 Pin Extension Header(Using IIC0 interface).
74+
4. Make sure your power regulator connect is correct,including the voltage and polarity.
75+
5. After all connector has been connected correctly,connect the Li-po battery to power up the design.
76+
77+
## User Manual
78+
79+
### Before Running This Application
80+
* Download source code of Identification VI Trace of Appliance from github.
81+
* Make sure all connection is correct again.
82+
* Passing Zero or Fire Wire of Socket Wire through Current Transformer.
83+
* Connect the zero line and live line to the Potential Transformer.
84+
85+
86+
### Run This Application
87+
Here take IoT DK, CUR_CORE = arcem9d with ARC GNU Toolchain 2019.06 for example to show how to run this application.
88+
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`.
89+
2. Open your serial terminal such as Tera-Term on PC, and configure it to right COM port and 115200bps.
90+
3. Interact using IoT DK and serial port terminal.
91+
92+
#### Makefile
93+
94+
- Selected embarc_mli here, then you can use [embarc_mli API][4] in your application:
95+
96+
>> # Library
97+
>> LIB_SEL = embarc_mli
98+
99+
- Selected u8glib here, then you can use [u8glib API][5] in your application:
100+
101+
>> # Middleware
102+
>> MID_SEL = common u8glib
103+
104+
- Other Configure:
105+
106+
>> # use -Hpurge option to optimize the code size
107+
>> ifeq ($(TOOLCHAIN), gnu)
108+
>> ADT_COPT += -ffunction-sections -fdata-sections
109+
>> ADT_LOPT += -Wl,--gc-sections
110+
>> else
111+
>> ADT_COPT += -Hpurge
112+
>> ADT_LOPT += -Hpurge
113+
>> endif
114+
115+
116+
- Target options about EMSK and toolchain:
117+
118+
>> TOOLCHAIN=gnu
119+
>> BOARD=iotdk
120+
>> BD_VER=10
121+
>> CUR_CORE=arcem9d
122+
123+
- The relative series of the root directory, here the path of the Makefile is `./embarc_osp/application/electrical_load_identification/makefile`:
124+
125+
>> #
126+
>>
127+
>> # root dir of embARC
128+
>> #
129+
>> EMBARC_ROOT = ../..
130+
131+
- Directories of source files and header files, notice that it **is not recursive**:
132+
133+
>> # application source dirs
134+
>> APPL_CSRC_DIR = . model
135+
>> APPL_ASMSRC_DIR = .
136+
137+
>> # application include dirs
138+
>> APPL_INC_DIR = . model
139+
>> APPL_DEFINES = APPL_DEFINES = -DUSE_APPL_MEM_CONFIG -DV2DSP_XY -DMODEL_BIT_DEPTH=16 -g
140+
141+
142+
See [ embARC Example User Guide][6], **"Options to Hard-Code in the Application Makefile"** for more detailed information about **Makefile Options**.
143+
144+
#### Program flow chart
145+
![Program flow chart][7]
146+
147+
148+
149+
#### Model
150+
151+
Placing the model source code in `./model` folder.
152+
Placing the C source and header file.
153+
154+
| folder/file | Function |
155+
| ------------------ | ---------------------------------- |
156+
| coefficients_chw.c | Define weights and biases of LeNet |
157+
| constants.h | Define Constants of LeNet |
158+
| model_chw.c | Define the structure of LeNet |
159+
| model.h | the header of LeNet model |
160+
![Structural Chart of LeNet Model][8]
161+
162+
#### ATT7053 Driver
163+
164+
Placing the device ATT7053 Driver source code in `./` folder.
165+
Placing the C source and hearder file.
166+
167+
| folder/file | Function |
168+
| ------------- | ----------------------------------------------- |
169+
| spi_att7053.c | att7053 spi drivers,include read,write,init API |
170+
| spi_att7053.h | the header of att7053 drivers |
171+
172+
#### VI Image Generation Algorithm
173+
174+
Placing the Algorithm of VI Image Generation source code in `./` folder.
175+
Placing the C source and hearder file.
176+
177+
| folder/file | Function |
178+
| --------------------- | ---------------------------------------------- |
179+
| VI_image.c | generate VI image algorithm |
180+
| VI_image.h | the header of generate VI image algorithm |
181+
| hsv2rgb.c | convert VI image from HSV coding to RGB coding |
182+
| hsv2rgb.h | the header of hsv2rgb.c |
183+
| recognize_algorithm.c | VI image recognize algorithm |
184+
| recognize_algorithm.h | the header of VI image recognize algorithm |
185+
186+
#### OLED Display
187+
188+
Placing the INCLUDE source code in `./` folder.
189+
Placing the C source and header file.
190+
191+
| folder/file | Function |
192+
| -------------------- | ------------------------------------------------------------ |
193+
| VI_image_display.c | Display interface function and convert RGB images to Binary images for display |
194+
| VI_image_display.h | the hearder of oled_display |
195+
| ssd1306_app_config.h | Definition of OLED Interface |
196+
197+
198+
[1]: ./doc/pic/system blocks.jpg
199+
[2]: https://https://v.youku.com/v_show/id_XNDkyMDQyNzA3Ng==.html
200+
[3]: ./doc/pic/practicality picture.jpg
201+
[4]: https://embarc.org/embarc_mli/doc/build/html/index.html
202+
[5]: https://github.com/olikraus/u8glib/wiki
203+
[6]: https://embarc.org/embarc_osp/doc/build/html/index.html
204+
[7]: ./doc/pic/Program flow chart.jpg
205+
[8]: ./doc/pic/LeNet Model structure.jpg
206+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include "VI_image.h"
2+
#include "hsv2rgb.h"
3+
4+
#include <math.h>
5+
6+
7+
img_coor_t get_coordinate(float vdata,float idata,float v_max,float i_max){
8+
img_coor_t coordinate;
9+
coordinate.x_v=vdata/v_max*N+N;
10+
coordinate.y_i=idata/i_max*N+N;
11+
return coordinate;
12+
}
13+
14+
float findmax(float* data, int datasize){
15+
int num;
16+
float max=0;
17+
for(num=0;num<datasize;num++){
18+
if(fabs(data[num])>max){
19+
max=fabs(data[num]);
20+
}
21+
}
22+
return max;
23+
}
24+
25+
void generate_VI_image(vi_data_t* data,unsigned char* image){
26+
int i,j;
27+
float v_max,i_max,vrms,irms;
28+
float img[IMAGE_SIZE]={};
29+
v_max=findmax(data->v, PERIOD_SIZE);
30+
i_max=findmax(data->i, PERIOD_SIZE);
31+
vrms=v_max*sqrt(2)*0.5;
32+
int a,b;
33+
for(i=0;i<PERIOD_SIZE;i++){
34+
img_coor_t coor=get_coordinate(data->v[i],data->i[i],v_max,i_max);
35+
a=coor.x_v;
36+
b=coor.y_i;
37+
img[a*32+b]++;
38+
img[32*32+a*32+b]+=fabs(data->v[i]*data->i[i]);
39+
img[2*32*32+a*32+b]+=data->i[i]*data->i[i];
40+
}
41+
for(i=0;i<2*N;i++){
42+
for(j=0;j<2*N;j++){
43+
if(img[i*32+j]!=0){
44+
float H=(int)(fabs((j+0.5-N)/N)*i_max)%5*72;
45+
float S=img[32*32+i*32+j]/(v_max*sqrt(img[i*32+j]*img[2*32*32+i*32+j]*0.5));
46+
float V=50;
47+
RGBColor rgb = hsv2rgb(H,S,V);
48+
image[i*32+j]=rgb.b;
49+
image[32*32+i*32+j]=rgb.g;
50+
image[2*32*32+i*32+j]=rgb.r;
51+
}
52+
}
53+
}
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifndef _VI_GENERATE_H_
2+
#define _VI_GENERATE_H_
3+
4+
#include "spi_att7053.h"
5+
6+
7+
#define IMAGE_SIZE (32 * 32 * 3)
8+
#define PERIOD_SIZE 144
9+
#define N 16
10+
11+
typedef struct vi_data{
12+
float v[720];
13+
float i[720];
14+
}vi_data_t;
15+
16+
typedef struct img_coor{
17+
int x_v;
18+
int y_i;
19+
}img_coor_t;
20+
21+
void generate_VI_image(vi_data_t* data,unsigned char* image);
22+
23+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#include "VI_image_display.h"
2+
#include "board.h"
3+
/* middleware level*/
4+
#include "u8g.h"
5+
6+
u8g_t u8g;
7+
8+
9+
void u8g_prepare(void) {
10+
u8g_SetFont(&u8g, u8g_font_6x10); /* set the current font and reset the font reference position to "Baseline" */
11+
u8g_SetFontRefHeightExtendedText(&u8g); /* define the calculation method for the ascent and descent of the current font */
12+
u8g_SetDefaultForegroundColor(&u8g); /* assign one of the default colors as current color index */
13+
u8g_SetFontPosTop(&u8g); /* set the reference position for the character and string draw procedure */
14+
}
15+
16+
void draw_vi_image(u8g_uint_t x, u8g_uint_t y,void* vbimage){
17+
uint8_t* image_t = (uint8_t*)vbimage;
18+
int p_i=0,p_j=0;
19+
for(int i=0;i<64;i++){
20+
for(int j=0;j<64;j++){
21+
if(*(image_t+64*i+j)==1) {
22+
u8g_DrawLine(&u8g,p_i+x,p_j+y,i+x,j+y);
23+
p_i=i;
24+
p_j=j;
25+
}
26+
}
27+
}
28+
}
29+
30+
31+
uint8_t THRESHOLD = 230;
32+
void rgb2bitmap(uint8_t* src,uint8_t* dst){
33+
uint8_t* rgb_img = (uint8_t*)src;
34+
uint8_t* binary_img = (uint8_t*)dst;
35+
for(uint8_t i=0;i<32;i++){
36+
for(uint8_t j=0;j<32;j++){
37+
int b = rgb_img[32*i+j];
38+
int g = rgb_img[32*i+j+32*32];
39+
int r = rgb_img[32*i+j+32*32*2];
40+
int grey = (int)((r*30+g*59+b*11)/100);
41+
unsigned char bit=(32*i+j)%8;
42+
unsigned char pos=(32*i+j)/8;
43+
if(grey > THRESHOLD) {
44+
*(dst+pos)|= 1 << bit ;
45+
}
46+
}
47+
}
48+
}
49+
50+
void Draw_VI_Image(uint8_t* img){
51+
uint8_t binary_img[512]={0};
52+
rgb2bitmap(img,binary_img);
53+
u8g_DrawXBM (&u8g,0,0,64,64,binary_img);
54+
}
55+
void Display_app_name(uint8_t kind_index){
56+
u8g_prepare();
57+
switch (kind_index) {
58+
case 0:
59+
u8g_DrawStr(&u8g, 60,30, "Fan");
60+
break;
61+
case 1:
62+
u8g_DrawStr(&u8g, 60,30, "Hairdryer");
63+
break;
64+
case 2:
65+
u8g_DrawStr(&u8g, 60,30, "Fan");
66+
break;
67+
case 3:
68+
u8g_DrawStr(&u8g, 60,30, "Fan");
69+
break;
70+
case 4:
71+
u8g_DrawStr(&u8g, 60,30, "Fan");
72+
break;
73+
default:
74+
u8g_DrawStr(&u8g, 64,30, "None");
75+
break;
76+
}
77+
78+
}
79+
80+
void m_u8g_init(void){
81+
u8g_InitComFn(&u8g, &u8g_dev_ssd1306_128x64_2x_i2c, U8G_COM_SSD_I2C); /* create a new interface to a graphics display */
82+
u8g_Begin(&u8g); /* reset display and put it into default state */
83+
}
84+
85+
void display(uint8_t* rgb_image,uint8_t kind_index) {
86+
u8g_FirstPage(&u8g); /* marks the beginning of the picture loop; it cannot be used inside the picture loop */
87+
do {
88+
Draw_VI_Image(rgb_image);
89+
Display_app_name(kind_index);
90+
91+
} while (u8g_NextPage(&u8g));
92+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#ifndef _VI_IMAGE_DISPLAY_H_
2+
#define _VI_IMAGE_DISPLAY_H_
3+
4+
#include "embARC_toolchain.h"
5+
#include "embARC_error.h"
6+
#include "VI_image.h"
7+
8+
void m_u8g_init(void);
9+
void display(uint8_t* rgb_image,uint8_t kind_index);
10+
11+
#endif

0 commit comments

Comments
 (0)