Grafiranje vrednosti

main
Jurij Podgoršek 2022-04-23 15:33:19 +02:00
parent b79b8f9dad
commit 6c4f3fb032
10 changed files with 7989 additions and 0 deletions

4
.gitignore vendored 100644
View File

@ -0,0 +1,4 @@
.~*~
.*~undo-tree~
.~lock*#
.*.swp

0
graf.csv 100644
View File

3847
graf_a.csv 100644

File diff suppressed because it is too large Load Diff

3847
graf_g.csv 100644

File diff suppressed because it is too large Load Diff

82
kegelj.scd 100644
View File

@ -0,0 +1,82 @@
// Zacetek / konec
s.boot;
s.stop;
// Server -> Boot /// Ctrl+B
// HELP: shift+ctrl+D
// recimo ugen
NetAddr.langPort;
(
SynthDef.new(\slOSC, {
// Najprej argumenti, potem variable
arg f=220, ampOsc=200, ch=0, off=0;
var so;
so = SinOsc.ar(f, off, SinOsc.kr(ampOsc));
Out.ar(ch, so);
}).add;
//s = Synth.new(\slOSC);
z = Synth.new(\slOSC);
//v = Synth.new(\slOSC);
u = Synth.new(\slOSC);
OSCFunc({
arg msg, time, addr, recvPort;
[msg, time, addr, recvPort].postln;
~gdX = msg[1];
~gdY = msg[2];
~gdZ = msg[3];
}, '/eulerDiff', n);
OSCFunc({
arg msg, time, addr, recvPort;
[msg, time, addr, recvPort].postln;
~gX = msg[1];
~gY = msg[2];
~gZ = msg[3];
}, '/euler', n);
OSCFunc({
arg msg, time, addr, recvPort;
[msg, time, addr, recvPort].postln;
~aX = msg[1];
~aY = msg[2];
~aZ = msg[3];
}, '/accel', n);
OSCFunc({
arg msg, time, addr, recvPort;
//msg.postln;
}, '/euler', n);
~polje = [];
OSCFunc({
arg msg, time, addr, recvPort;
//[msg, time, addr, recvPort].postln;
//s.get(\f, {arg f; s.set(\f, f + ~gX)});
//s.get(\f, {arg f; s.set(\f, f - (~aX / 100))});
z.get(\f, {arg f; s.set(\f, f + (~aY * 100))});
u.get(\f, {arg f; s.set(\f, f + (~aX / 10))});
//s.get(\f, {arg f; ~polje.add(f); s.set(\f, f + (~gdX * 100))});
//v.get(\f, {arg f; ~polje.add(f); s.set(\f, f + (~gdZ * 100))});
//z.get(\f, {arg f; s.set(\f, ~aY/ 10)});
//s.get(\ampOsc, {arg f; s.set(\ampOsc, f + (~gX))});
}, '/keys', n);
)
~polje;
[1, 5, 8, 7, 2, 19].plot;
[].add(123);

28
osc_graf.py 100755
View File

@ -0,0 +1,28 @@
#!/usr/bin/python3
# Risanje grafa
import matplotlib
matplotlib.use('GTK4Agg')
import matplotlib.pyplot as plt
import pandas as pd
import plotly_express as px
plt.style.use('ggplot')
#x, ax, ay, az = []
x = []
ax = []
ay = []
az = []
ga = pd.read_csv('graf_a.csv')
fig = px.line(ga, x="t", y=ga.columns[1:2])
fig.show()
gg = pd.read_csv('graf_g.csv')
fig = px.line(gg, x="t", y=gg.columns[1:4])
fig.show()
fig = px.line(gg, x="t", y=gg.columns[4:5])
fig.show()

148
oscplot.py 100755
View File

@ -0,0 +1,148 @@
#!/usr/bin/python3
# OSC komunikacija
from pythonosc.osc_server import BlockingOSCUDPServer
from pythonosc.dispatcher import Dispatcher
from time import time
from threading import Thread
# Risanje grafa
import matplotlib
matplotlib.use('GTK4Agg')
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
dispecer = Dispatcher()
srv = BlockingOSCUDPServer(("127.0.0.1", 57120), dispecer)
# Zacetna (casovna) tocka
zacetek = time()
# use ggplot style for more sophisticated visuals
plt.style.use('ggplot')
size = 1000
x_vec = []
gx_vec = []
gy_vec = []
gz_vec = []
ax_vec = []
ay_vec = []
az_vec = []
x = 0
gx = 0
gy = 0
gz = 0
ax = 0
ay = 0
az = 0
interval = 60 / 1000
razlika = 0
# Shranim "trenutne" vrednosti
def beriSenzor(address, *args):
global x, gx, gy, gz, ax, ay, az, razlika
if (address == '/accel'):
ax, ay, az = args
if (address == '/euler'):
gx, gy, gz = args
print("euler", args)
razlika = time() - zacetek
if (razlika > interval):
izrisi()
razlika = razlika % interval
fig = plt.gcf()
#gxs = fig.add_subplot()
#gys = fig.add_subplot()
#gxp, = gxs.plot([])
#gyp, = gys.plot([])
fajl_g = open("graf_g.csv", "w")
fajl_g.write("t,gx,gy,gz,rgx,rgy,rgz\n")
fajl_a = open("graf_a.csv", "w")
fajl_a.write("t,ax,ay,az\n")
def izrisi():
global x, gx, gy, gz, ax, ay, az, fig, plt, gxp, gyp, zacetek
# Dodamo casovno tocko
x = time() - zacetek
#x_vec.append(x)
fajl_g.write(str(x) + "," + str(gx) + "," + str(gy) + "," + str(gz) + "," + str(gx % 3.14) + "," + str(gy % 3.14) + "," + str(gz % 3.14) + "\n")
fajl_a.write(str(x) + "," + str(ax) + "," + str(ay) + "," + str(az) + "\n")
# Dodamo gyro in accel vrednosti v polja
#gx_vec.append(gx)
#gy_vec.append(gy)
#gz_vec.append(gz)
#ax_vec.append(ax)
#ay_vec.append(ay)
#az_vec.append(az)
#plt.cla()
#yplot.plot(x_vec, gx_vec)
#yplot.plot(x_vec, gy_vec)
#fig.set_xdata(x_vec)
#gxp.set_data(x_vec, gx_vec)
#gyp.set_data(x_vec, gy_vec)
#print("RISEMO", x, gx)
#plt.plot(x_vec, gx_vec, label="gyro x")
#plt.plot(x_vec, gy_vec)
#plt.plot(x_vec, gz_vec)
#plt.plot(x_vec, ax_vec)
#plt.plot(x_vec, ay_vec)
#plt.plot(x_vec, az_vec)
#plt.pause(0.0001)
#fig.canvas.draw()
#plt.show()
#plt.pause(0.0001)
#return gxp,
#plt.gcf().autofmt_xdate()
#plt.tight_layout()
#plt.pause(0.001)
#plt.gcf()
#plt.pause(1)
#return plt
#plt.show()
#return plt
# Animiraj na cca 60hz
#animacija = FuncAnimation(fig, izrisi, 500)
#animacija = FuncAnimation(plt.gcf(), izrisi, interval=0.05, repeat=True)
#print(animacija)
#animacija = FuncAnimation(fig, izrisi)
#plt.show()
dispecer.map("/*", beriSenzor)
# Zacni poslusat senzor
print("serving...")
srv.serve_forever()
#trd = Thread(target=srv.serve_forever).start()
# Kazi graf
#print("Kazi graf!")
#plt.tight_layout()
#plt.show()
#plt.plot([0, 0], [1, 5], [3, 7])
#print('kazem', plt)
# AJD!
file.close()
print("bye")

2
requirements.txt 100644
View File

@ -0,0 +1,2 @@
python-osc ~= 1.8.0
plotly-express ~= 0.4.1

8
scplot.scd 100644
View File

@ -0,0 +1,8 @@
{SinOsc.ar(1)}.plot(1);
{VarSaw.ar(20)}.plot(1);
{VarSaw.ar(1, 0.25)}.plot(1);
{VarSaw.ar(1, 0.25, 1)}.plot(1);
{VarSaw.ar(50!2, 0.9, 1) * 0.1}.play;

23
test.py 100755
View File

@ -0,0 +1,23 @@
#!/usr/bin/python3
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import patheffects
# Plot a straight diagonal line with ticked style path
fig, ax = plt.subplots(figsize=(6, 6))
ax.plot([0, 1], [0, 1], label="Line",
path_effects=[patheffects.withTickedStroke(spacing=7, angle=135)])
# Plot a curved line with ticked style path
nx = 101
x = np.linspace(0.0, 1.0, nx)
y = 0.3*np.sin(x*8) + 0.4
ax.plot(x, y, label="Curve", path_effects=[patheffects.withTickedStroke()])
ax.legend()
plt.show()
print("PLOT!")
print(plt)