Showing
18 changed files
with
479 additions
and
0 deletions
code/acc_test_2.py
0 → 100644
1 | +import smbus #import SMBus module of I2C | ||
2 | +from time import sleep #import | ||
3 | +import time | ||
4 | +import threading | ||
5 | + | ||
6 | +#some MPU6050 Registers and their Address | ||
7 | +PWR_MGMT_1 = 0x6B | ||
8 | +SMPLRT_DIV = 0x19 | ||
9 | +CONFIG = 0x1A | ||
10 | +GYRO_CONFIG = 0x1B | ||
11 | +INT_ENABLE = 0x38 | ||
12 | +ACCEL_XOUT_H = 0x3B | ||
13 | +ACCEL_YOUT_H = 0x3D | ||
14 | +ACCEL_ZOUT_H = 0x3F | ||
15 | +GYRO_XOUT_H = 0x43 | ||
16 | +GYRO_YOUT_H = 0x45 | ||
17 | +GYRO_ZOUT_H = 0x47 | ||
18 | + | ||
19 | +bus = smbus.SMBus(1) # or bus = smbus.SMBus(0) for older version boards | ||
20 | +Device_Address = 0x68 # MPU6050 device address | ||
21 | + | ||
22 | +def MPU_Init(): | ||
23 | + #write to sample rate register | ||
24 | + bus.write_byte_data(Device_Address, SMPLRT_DIV, 7) | ||
25 | + | ||
26 | + #Write to power management register | ||
27 | + bus.write_byte_data(Device_Address, PWR_MGMT_1, 1) | ||
28 | + | ||
29 | + #Write to Configuration register | ||
30 | + bus.write_byte_data(Device_Address, CONFIG, 0) | ||
31 | + | ||
32 | + #Write to Gyro configuration register | ||
33 | + bus.write_byte_data(Device_Address, GYRO_CONFIG, 24) | ||
34 | + | ||
35 | + #Write to interrupt enable register | ||
36 | + bus.write_byte_data(Device_Address, INT_ENABLE, 1) | ||
37 | + | ||
38 | +def read_raw_data(addr): | ||
39 | + #Accelero and Gyro value are 16-bit | ||
40 | + high = bus.read_byte_data(Device_Address, addr) | ||
41 | + low = bus.read_byte_data(Device_Address, addr+1) | ||
42 | + | ||
43 | + #concatenate higher and lower value | ||
44 | + value = ((high << 8) | low) | ||
45 | + | ||
46 | + #to get signed value from mpu6050 | ||
47 | + if(value > 32768): | ||
48 | + value = value - 65536 | ||
49 | + return value | ||
50 | + | ||
51 | +def start_record(data): | ||
52 | + MPU_Init() | ||
53 | + t = threading.currentThread() | ||
54 | + print (" Reading Data of Gyroscope and Accelerometer") | ||
55 | + | ||
56 | + start_time=time.time() | ||
57 | + | ||
58 | + while getattr(t, "do_run", True): | ||
59 | + acc_x = read_raw_data(ACCEL_XOUT_H) | ||
60 | + acc_y = read_raw_data(ACCEL_YOUT_H) | ||
61 | + acc_z = read_raw_data(ACCEL_ZOUT_H) | ||
62 | + | ||
63 | + value=abs(acc_x+acc_y+acc_z)/10 | ||
64 | + data.append(value) | ||
65 | + print(value) | ||
66 | + | ||
67 | + if(time.time()>start_time+10): | ||
68 | + break |
code/note.py
0 → 100644
1 | +from flask import Flask, send_file,request,send_from_directory, render_template | ||
2 | +import matlab.engine | ||
3 | +from werkzeug.utils import secure_filename | ||
4 | +import os | ||
5 | +import json | ||
6 | +app = Flask(__name__) | ||
7 | + | ||
8 | +@app.route('/', methods=['GET']) | ||
9 | +def maiddn(): | ||
10 | + return render_template('view.html') | ||
11 | + | ||
12 | +@app.route('/upload', methods=['POST']) | ||
13 | +def upload_file(): | ||
14 | + params = json.loads(request.get_data(), encoding='utf-8') | ||
15 | + data=params['datas'] | ||
16 | + print(len(data)) | ||
17 | + make_wav_file(data) | ||
18 | + return send_file("test.wav", attachment_filename='test.wav', as_attachment=True) | ||
19 | + | ||
20 | + | ||
21 | +def make_wav_file(data): | ||
22 | + print('convert is loading') | ||
23 | + eng = matlab.engine.start_matlab() | ||
24 | + l1=[] | ||
25 | + for t in data: | ||
26 | + try: | ||
27 | + l1.append(int(t)) | ||
28 | + except: | ||
29 | + print(t) | ||
30 | + l2 = [n/10000 for n in l1] | ||
31 | + data = matlab.double(l2) | ||
32 | + filename = 'test.wav' | ||
33 | + eng.audiowrite(filename, data, 1000, nargout=0) | ||
34 | + eng.quit() | ||
35 | + | ||
36 | +@app.route('/combine', methods=['POST']) | ||
37 | +def combineMp4Wav(): | ||
38 | + print(request.files) | ||
39 | + if 'Video' not in request.files: | ||
40 | + print("error") | ||
41 | + return "error" | ||
42 | + file = request.files['Video'] | ||
43 | + print(file) | ||
44 | + file.save("video.mp4") | ||
45 | + os.system("ffmpeg -i video.mp4 -i test.wav -c:v copy -c:a aac -strict experimental -vcodec libx264 -map 0:v:0 -map 1:a:0 -y output.mp4") | ||
46 | + return "Success" | ||
47 | + | ||
48 | + | ||
49 | +if __name__ == '__main__': | ||
50 | + app.run(host='0.0.0.0', port=80) |
File moved
File moved
code/static/app.js
0 → 100644
1 | +import { WaveGroup } from "./wavegroup.js"; | ||
2 | + | ||
3 | +class App{ | ||
4 | + constructor(){ | ||
5 | + this.canvas = document.createElement('canvas'); | ||
6 | + this.ctx = this.canvas.getContext('2d'); | ||
7 | + document.body.appendChild(this.canvas); | ||
8 | + | ||
9 | + this.waveGroup = new WaveGroup(); | ||
10 | + | ||
11 | + window.addEventListener('resize', this.resize.bind(this), false); | ||
12 | + this.resize(); | ||
13 | + | ||
14 | + requestAnimationFrame(this.animate.bind(this)); | ||
15 | + } | ||
16 | + | ||
17 | + resize() { | ||
18 | + this.stageWidth = document.body.clientWidth; | ||
19 | + this.stageHeight = document.body.clientHeight; | ||
20 | + | ||
21 | + this.canvas.width = this.stageWidth * 2; | ||
22 | + this.canvas.height = this.stageHeight * 2; | ||
23 | + this.ctx.scale(2,2); | ||
24 | + | ||
25 | + this.waveGroup.resize(this.stageWidth,this.stageHeight); | ||
26 | + } | ||
27 | + | ||
28 | + animate(t){ | ||
29 | + this.ctx.clearRect(0,0,this.stageWidth,this.stageHeight); | ||
30 | + this.waveGroup.draw(this.ctx); | ||
31 | + requestAnimationFrame(this.animate.bind(this)); | ||
32 | + } | ||
33 | +} | ||
34 | + | ||
35 | +window.onload = () =>{ | ||
36 | + new App(); | ||
37 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
code/static/output.mp4
0 → 100644
No preview for this file type
code/static/point.js
0 → 100644
1 | +export class Point { | ||
2 | + constructor(index, x, y){ | ||
3 | + this.x = x; | ||
4 | + this.y = y; | ||
5 | + this.fixedY = y; | ||
6 | + this.speed = 0.03; | ||
7 | + this.cur = index; | ||
8 | + this.max = Math.random() * 100 +200; | ||
9 | + } | ||
10 | + | ||
11 | + update() { | ||
12 | + this.cur += this.speed; | ||
13 | + this.y = this.fixedY + (Math.sin(this.cur) * this.max); | ||
14 | + } | ||
15 | + | ||
16 | + | ||
17 | + | ||
18 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
code/static/style.css
0 → 100644
1 | +*{ | ||
2 | + user-select: none; | ||
3 | + -ms-user-select: none; | ||
4 | + outline: 0; | ||
5 | + margin: 0; | ||
6 | + padding: 0; | ||
7 | + -webkit-tap-highlight-color: rgba(0, 0, 0, 0); | ||
8 | +} | ||
9 | + | ||
10 | +html { | ||
11 | + width: 100%; | ||
12 | + height: 100%; | ||
13 | +} | ||
14 | + | ||
15 | +body { | ||
16 | + width: 100%; | ||
17 | + height: 100%; | ||
18 | + overflow: hidden; | ||
19 | + background-color: #ffffff; | ||
20 | +} | ||
21 | + | ||
22 | +canvas { | ||
23 | + width: 100%; | ||
24 | + height: 100%; | ||
25 | +} | ||
26 | + | ||
27 | +button { | ||
28 | + width:100px; | ||
29 | + background-color: #f8585b; | ||
30 | + border: none; | ||
31 | + color:#fff; | ||
32 | + padding: 15px 0; | ||
33 | + border-radius:10px; | ||
34 | + text-align: center; | ||
35 | + text-decoration: none; | ||
36 | + display: inline-block; | ||
37 | + font-size: 20px; | ||
38 | + margin: 4px; | ||
39 | + cursor: pointer; | ||
40 | +} |
code/static/wave.js
0 → 100644
1 | +import { | ||
2 | + Point | ||
3 | +} from './point.js' | ||
4 | +export class Wave { | ||
5 | + constructor(index, totalPoints, color) { | ||
6 | + this.index = index; | ||
7 | + this.totalPoints = totalPoints; | ||
8 | + this.color = color; | ||
9 | + this.points = []; | ||
10 | + } | ||
11 | + | ||
12 | + resize(stageWidth, stageHeight){ | ||
13 | + this.stageWidth = stageWidth; | ||
14 | + this.stageHeight = stageHeight; | ||
15 | + | ||
16 | + this.centerX = stageWidth /2; | ||
17 | + this.centerY = stageHeight /2; | ||
18 | + | ||
19 | + this.pointGap = this.stageWidth/ (this.totalPoints - 1); | ||
20 | + | ||
21 | + | ||
22 | + this.init(); | ||
23 | + | ||
24 | + } | ||
25 | + init(){ | ||
26 | + this.points = []; | ||
27 | + for (let i = 0; i < this.totalPoints; i++){ | ||
28 | + const point = new Point( | ||
29 | + this.index +i, | ||
30 | + this.pointGap * i, | ||
31 | + this.centerY, | ||
32 | + ); | ||
33 | + this.points[i] = point; | ||
34 | + } | ||
35 | + } | ||
36 | + draw(ctx) { | ||
37 | + ctx.beginPath(); | ||
38 | + ctx.fillStyle = this.color; | ||
39 | + let prevX = this.points[0].x; | ||
40 | + let prevY = this.points[0].y; | ||
41 | + | ||
42 | + ctx.moveTo(prevX,prevY); | ||
43 | + for(let i = 1; i < this.totalPoints; i++){ | ||
44 | + if (i < this.totalPoints - 1){ | ||
45 | + this.points[i].update(); | ||
46 | + | ||
47 | + } | ||
48 | + const cx = (prevX + this.points[i].x) / 2; | ||
49 | + const cy = (prevY + this.points[i].y) / 2; | ||
50 | + | ||
51 | + ctx.quadraticCurveTo(prevX, prevY, cx,cy); | ||
52 | + | ||
53 | + prevX = this.points[i].x; | ||
54 | + prevY = this.points[i].y; | ||
55 | + } | ||
56 | + | ||
57 | + ctx.lineTo(prevX,prevY); | ||
58 | + ctx.lineTo(this.stageWidth,this.stageHeight); | ||
59 | + ctx.lineTo(this.points[0].x,this.stageHeight); | ||
60 | + ctx.fill(); | ||
61 | + ctx.closePath(); | ||
62 | + } | ||
63 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
code/static/wavegroup.js
0 → 100644
1 | +import{ | ||
2 | + Wave | ||
3 | +} from './wave.js' | ||
4 | + | ||
5 | +export class WaveGroup { | ||
6 | + constructor(){ | ||
7 | + this.totalWaves = 3; | ||
8 | + this.totalPoints = 6; | ||
9 | + | ||
10 | + this.color = ['rgba(255,199,235,0.4)','rgba(255,146,199,0.4)','rgba(0,87,158,0.4)']; | ||
11 | + | ||
12 | + this.waves = []; | ||
13 | + | ||
14 | + for (let i = 0; i < this.totalWaves; i++){ | ||
15 | + const wave = new Wave( | ||
16 | + i, | ||
17 | + this.totalPoints, | ||
18 | + this.color[i] | ||
19 | + ); | ||
20 | + this.waves[i] = wave; | ||
21 | + } | ||
22 | + } | ||
23 | + resize(stageWidth, stageHeight){ | ||
24 | + for (let i =0; i < this.totalWaves; i++){ | ||
25 | + const wave = this.waves[i]; | ||
26 | + wave.resize(stageWidth,stageHeight); | ||
27 | + | ||
28 | + } | ||
29 | + } | ||
30 | + draw(ctx){ | ||
31 | + for (let i =0; i < this.totalWaves; i++){ | ||
32 | + const wave = this.waves[i]; | ||
33 | + wave.draw(ctx); | ||
34 | + } | ||
35 | + | ||
36 | + } | ||
37 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
code/templates/index.html
0 → 100644
1 | +<!DOCTYPE html> | ||
2 | +<html lang="en"> | ||
3 | + <head> | ||
4 | + <meta charset="UTF-8"> | ||
5 | + <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> | ||
6 | + <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0"> | ||
7 | + <title>Haptic Recording</title> | ||
8 | + <link rel="stylesheet" href="{{url_for('static', filename = 'style.css')}}"> | ||
9 | + <style> | ||
10 | + #start { | ||
11 | + width:100px; | ||
12 | + background-color: #f8585b; | ||
13 | + border: none; | ||
14 | + color:#fff; | ||
15 | + padding: 15px 0; | ||
16 | + border-radius:10px; | ||
17 | + text-align: center; | ||
18 | + text-decoration: none; | ||
19 | + display: inline-block; | ||
20 | + font-size: 20px; | ||
21 | + margin: 4px; | ||
22 | + cursor: pointer; | ||
23 | + } | ||
24 | + </style> | ||
25 | + </head> | ||
26 | + <body> | ||
27 | + <div style="text-align: center; padding-top: 10%;"> | ||
28 | + <h1>Haptic Data Recording</h1> | ||
29 | + <p style="margin-top: 2%;">Subeen Kang & Jinhyeong Park</p> | ||
30 | + <form method ="post" action="/record"> | ||
31 | + <button style="margin-top: 10%;" type="button" id="start" > START </button> | ||
32 | + </form> | ||
33 | + </div> | ||
34 | + <script type="module" src="{{url_for('static', filename = 'app.js')}}"></script> | ||
35 | + </body> | ||
36 | +</html> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
code/templates/record.html
0 → 100644
1 | +<!DOCTYPE html> | ||
2 | +<html> | ||
3 | + <head> | ||
4 | + <meta charset="UTF-8"> | ||
5 | + <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> | ||
6 | + <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0"> | ||
7 | + <title>Haptic Recording</title> | ||
8 | + <link rel="stylesheet" href="{{url_for('static', filename = 'style.css')}}"> | ||
9 | + <style> | ||
10 | + #stop { | ||
11 | + width:100px; | ||
12 | + background-color: #f8585b; | ||
13 | + border: none; | ||
14 | + color:#fff; | ||
15 | + padding: 15px 0; | ||
16 | + border-radius:10px; | ||
17 | + text-align: center; | ||
18 | + text-decoration: none; | ||
19 | + display: inline-block; | ||
20 | + font-size: 20px; | ||
21 | + margin: 4px; | ||
22 | + cursor: pointer; | ||
23 | + } | ||
24 | + </style> | ||
25 | + </head> | ||
26 | + | ||
27 | + <body> | ||
28 | + <div style="text-align: center; padding-top: 10%;"> | ||
29 | + <h1>Converting...</h1> | ||
30 | + <h1 style="margin-top: 2%; color:#f8585b;"id="clock">00:00</h1> | ||
31 | + <form method ="post" action="/stop"> | ||
32 | + <button style="margin-top: 10%;" id="stop" type="button"> STOP </button> | ||
33 | + </form> | ||
34 | + </div> | ||
35 | + <script type="module" src="{{url_for('static', filename = 'app.js')}}"></script> | ||
36 | + </body> | ||
37 | + | ||
38 | + <script> | ||
39 | + var clockTarget = document.getElementById("clock"); | ||
40 | + var seconds = 0; | ||
41 | + var miliseconds = 0; | ||
42 | + | ||
43 | + function clock() { | ||
44 | + clockTarget .innerText = `${seconds < 10 ? `0${seconds }`: seconds }:${miliseconds < 10 ? `0${miliseconds }` :miliseconds}`; | ||
45 | + miliseconds = miliseconds +1; | ||
46 | + if(miliseconds >99){ | ||
47 | + seconds = seconds +1; | ||
48 | + miliseconds = miliseconds %100; | ||
49 | + } | ||
50 | + } | ||
51 | + | ||
52 | + var inter; | ||
53 | + function init() { | ||
54 | + clock(); | ||
55 | + inter = setInterval(clock, 10); | ||
56 | + } | ||
57 | + | ||
58 | + function stopit(){ | ||
59 | + clearInterval(inter); | ||
60 | + } | ||
61 | + | ||
62 | + document.getElementById('stop').addEventListener('click', stopit); | ||
63 | + | ||
64 | + init(); | ||
65 | + </script> | ||
66 | +</html> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
code/templates/view.html
0 → 100644
1 | +<!DOCTYPE html> | ||
2 | +<html> | ||
3 | + <body> | ||
4 | + <div style="text-align: center;"> | ||
5 | + <video controls width="900"> | ||
6 | + <source src="{{url_for('static', filename = 'output.mp4')}}" type="video/mp4"></source> | ||
7 | + 이 문장은 여러분의 브라우저가 video 태그를 지원하지 않을 때 화면에 표시됩니다! | ||
8 | + </video> | ||
9 | +</div> | ||
10 | + </body> | ||
11 | +</html> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
code/test.wav
0 → 100644
No preview for this file type
code/video.mp4
0 → 100644
No preview for this file type
code/webserver.py
0 → 100644
1 | +from flask import Flask, send_file,request,url_for,redirect, render_template | ||
2 | +import os | ||
3 | +import json | ||
4 | +import acc_test_2 | ||
5 | +import threading | ||
6 | +import multiprocessing | ||
7 | +import requests | ||
8 | +import pygame | ||
9 | +import time | ||
10 | + | ||
11 | +app = Flask(__name__) | ||
12 | +global data | ||
13 | +global th | ||
14 | +data=[] | ||
15 | +th = threading.Thread(target=acc_test_2.start_record,args=(data,)) | ||
16 | + | ||
17 | +th.setDaemon(True) | ||
18 | +@app.route('/') | ||
19 | +def upload_main(): | ||
20 | + return render_template('index.html') | ||
21 | + | ||
22 | +@app.route('/record', methods=['GET','POST']) | ||
23 | +def submit(): | ||
24 | + global th | ||
25 | + global data | ||
26 | + print(threading.enumerate()) | ||
27 | + | ||
28 | + if not th.is_alive(): | ||
29 | + print('dead') | ||
30 | + data=[] | ||
31 | + th = threading.Thread(target=acc_test_2.start_record,args=(data,)) | ||
32 | + | ||
33 | + th.start() | ||
34 | + | ||
35 | + return render_template('record.html') | ||
36 | + | ||
37 | +@app.route('/stop', methods=['GET','POST']) | ||
38 | +def stop(): | ||
39 | + th.do_run = False | ||
40 | + th.join() | ||
41 | + print("data length is " + str(len(data))) | ||
42 | + r = upload(data) | ||
43 | + return (r.content, r.status_code, r.headers.items()) | ||
44 | + | ||
45 | + | ||
46 | +def upload(datas): | ||
47 | + params={'datas':datas} | ||
48 | + url='http://192.168.0.25:80/upload' | ||
49 | + return requests.post(url,data =json.dumps(params)) | ||
50 | + | ||
51 | + | ||
52 | +if __name__ == '__main__': | ||
53 | + app.run(host='0.0.0.0', port=80) | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
No preview for this file type
면담확인서 및 주간보고서/12월 2주차 주간보고서.docx
0 → 100644
No preview for this file type
-
Please register or login to post a comment