-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2e85363
Showing
20 changed files
with
9,582 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__pycache__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import time | ||
|
||
class PerformanceCounter: | ||
def __init__(self): | ||
self.Count = 0 | ||
self.LastTick = time.perf_counter() | ||
|
||
|
||
def Frame(self): | ||
self.Count = self.Count + 1 | ||
|
||
tick = time.perf_counter() | ||
dt = tick - self.LastTick | ||
self.LastTick = tick | ||
|
||
return [self.Count, dt] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import socket | ||
import struct | ||
|
||
from OpenGL import GLUT, GLU, GL | ||
|
||
from PerformanceCounter import PerformanceCounter | ||
|
||
|
||
raw_data = [] | ||
|
||
|
||
AxisColor = [[1, 0, 0], [0, 1, 0], [0, 0, 1]] | ||
BarScale = [0.00005, 0.00005, 0.00005, 0.00005, 0.00005, 0.00005, 0.0015, 0.0015, 0.0015] | ||
|
||
class UdpServer: | ||
def __init__(self): | ||
self.Counter = PerformanceCounter() | ||
|
||
self.Server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | ||
self.Server.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) | ||
self.Server.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 65536 * 16) | ||
self.Server.bind(("192.168.10.13", 8000)) | ||
|
||
def Run(self): | ||
GLUT.glutInit() | ||
GLUT.glutInitDisplayMode(GLUT.GLUT_SINGLE | GLUT.GLUT_RGBA) | ||
GLUT.glutInitWindowSize(600, 600) | ||
GLUT.glutCreateWindow("3D") | ||
GLUT.glutDisplayFunc(self.Draw) | ||
GLUT.glutIdleFunc(self.Recv) | ||
|
||
GLUT.glutMainLoop() | ||
|
||
|
||
def Recv(self): | ||
raw_data = [0]*9 | ||
delta = 0 | ||
raw_count = 0 | ||
|
||
try: | ||
data, address = self.Server.recvfrom(44) | ||
|
||
#print(len(data), data) | ||
reader = lambda p: int.from_bytes(data[p:p + 2], byteorder="little", signed=True) | ||
|
||
|
||
|
||
for i in range(9): | ||
raw_data[i] = reader(i * 2) | ||
''' | ||
q0 = struct.unpack("f", data[20:24])[0] | ||
q1 = struct.unpack("f", data[24:28])[0] | ||
q2 = struct.unpack("f", data[28:32])[0] | ||
q3 = struct.unpack("f", data[32:36])[0] | ||
''' | ||
#delta = struct.unpack("f", data[36:40])[0] | ||
#raw_count = int.from_bytes(data[40:44], byteorder="little", signed=False) | ||
|
||
except Exception as e: | ||
raw_data = [] | ||
print("error", e.args) | ||
|
||
# t = count / (now_time - last_tick) | ||
[count, t] = self.Counter.Frame() | ||
#print(count, t, raw_data) | ||
|
||
self.Draw(raw_data) | ||
|
||
|
||
def Draw(self, data=None): | ||
glClear(GL_COLOR_BUFFER_BIT) | ||
|
||
''' | ||
glPushMatrix() | ||
glColor3f(1, 1, 1) | ||
#glRotate(180, 0, 0, 1) | ||
if q != None: | ||
v = q.getVector() | ||
angle = q.getAngle() * 180 / 3.14 * 2 # 四元数角 * 2 | ||
glRotate(angle, v[0], v[2], v[1]) | ||
glutWireTeapot(0.4) | ||
glPopMatrix() | ||
''' | ||
glBegin(GL_LINES) | ||
|
||
if data != None: | ||
for i in range(len(data)): | ||
x = i * 0.1 - 0.9 | ||
y = 0.75 + data[i] / 4 * BarScale[i] | ||
c = AxisColor[i % 3] | ||
|
||
glColor3f(c[0], c[1], c[2]) | ||
glVertex3f(x, 0.75, 0) | ||
glVertex3f(x, y, 0) | ||
|
||
glEnd() | ||
glFlush() | ||
|
||
|
||
if __name__ == '__main__': | ||
Server = UdpServer() | ||
Server.Run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
-0.49,1.55,-1.63,-216.99,367.44,-317.70 | ||
-0.90,-1.98,-1.87,-204.29,170.96,-265.88 | ||
-1.01,-1.98,-1.87,-214.42,-27.53,-171.76 | ||
-1.09,-1.98,-1.87,-206.00,-166.39,-93.57 | ||
-1.00,-1.98,-1.70,-153.81,-160.71,-39.12 | ||
-0.77,0.62,0.32,9.28,5.92,1.28 | ||
-0.84,0.62,0.31,17.33,-4.27,-3.91 | ||
-0.90,0.61,0.29,20.63,-10.25,-3.42 | ||
-0.93,0.62,0.28,17.94,-10.74,1.16 | ||
-0.91,0.63,0.29,11.47,-8.42,5.25 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
1.96,0.62,0.94,69.58,98.39,55.54 | ||
1.84,0.68,0.87,77.94,30.09,55.24 | ||
1.53,0.71,0.81,73.18,-22.10,40.71 | ||
1.21,0.71,0.72,52.25,-39.25,19.35 | ||
0.98,0.69,0.62,20.39,-35.34,-0.92 | ||
-0.31,0.96,-0.15,0.79,0.18,2.32 | ||
-0.36,0.96,-0.13,2.50,1.04,1.04 | ||
-0.36,0.95,-0.14,2.14,0.00,0.49 | ||
-0.37,0.95,-0.15,0.43,0.67,1.77 | ||
-0.37,0.95,-0.16,-1.34,-1.34,0.67 |
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#! /bin/bash | ||
|
||
jupyter notebook --ip 0.0.0.0 --allow-root |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import tensorflow as tf | ||
import tensorflow.keras as keras | ||
import tensorflow.keras.layers as layers | ||
import numpy as np | ||
import pandas as pd | ||
from tqdm import tqdm | ||
|
||
SAMPLES_PER_GESTURE = 70 | ||
|
||
punch = pd.read_csv('data/punch.csv', header=None) | ||
flex = pd.read_csv('data/flex.csv', header=None) | ||
print(punch) | ||
print(flex) | ||
|
||
|
||
def processData(d, v): | ||
dataX = np.empty([0, SAMPLES_PER_GESTURE*6]) | ||
dataY = np.empty([0]) | ||
|
||
data = d.values | ||
dataNum = data.shape[0] // SAMPLES_PER_GESTURE | ||
print(data.shape, data.shape[0]) | ||
|
||
for i in tqdm(range(data.shape[0])): | ||
tmp = [] | ||
for j in range(SAMPLES_PER_GESTURE): | ||
tmp += [(data[i * SAMPLES_PER_GESTURE + j][0] + 4.0) / 8.0] | ||
tmp += [(data[i * SAMPLES_PER_GESTURE + j][1] + 4.0) / 8.0] | ||
tmp += [(data[i * SAMPLES_PER_GESTURE + j][2] + 4.0) / 8.0] | ||
tmp += [(data[i * SAMPLES_PER_GESTURE + j][3] + 2000.0) / 4000.0] | ||
tmp += [(data[i * SAMPLES_PER_GESTURE + j][4] + 2000.0) / 4000.0] | ||
tmp += [(data[i * SAMPLES_PER_GESTURE + j][5] + 2000.0) / 4000.0] | ||
|
||
tmp = np.array(tmp) | ||
|
||
tmp = np.expand_dims(tmp, axis=0) | ||
|
||
dataX = np.concatenate((dataX, tmp), axis=0) | ||
dataY = np.append(dataY, v) | ||
|
||
return dataX, dataY | ||
|
||
|
||
punchX, punchY = processData(punch, 0) | ||
flexX, flexY = processData(flex, 1) | ||
dataX = np.concatenate((punchX, flexX), axis=0) | ||
dataY = np.concatenate((punchY, flexY), axis=0) | ||
|
||
permutationTrain = np.random.permutation(dataX.shape[0]) | ||
print(permutationTrain) | ||
|
||
dataX = dataX[permutationTrain] | ||
dataY = dataY[permutationTrain] | ||
print(dataY) | ||
|
||
|
||
vfoldSize = int(dataX.shape[0]/100*20) | ||
|
||
xTest = dataX[0:vfoldSize] | ||
yTest = dataY[0:vfoldSize] | ||
|
||
xTrain = dataX[vfoldSize:dataX.shape[0]] | ||
yTrain = dataY[vfoldSize:dataY.shape[0]] | ||
model = keras.Sequential() | ||
model.add(keras.layers.Dense(32, input_shape=(6*SAMPLES_PER_GESTURE,), activation='relu')) | ||
model.add(keras.layers.Dense(16, activation='relu')) | ||
model.add(keras.layers.Dense(2, activation='softmax')) | ||
adam = keras.optimizers.Adam() | ||
model.compile(loss='sparse_categorical_crossentropy', optimizer=adam, metrics=['sparse_categorical_accuracy']) | ||
model.summary() |
Oops, something went wrong.