Commit 0ae8b3de authored by Yassine's avatar Yassine
Browse files

fichiers info

parent 55708b68
This diff is collapsed.
import os
os.system("echo "" > motor.csv")
\ No newline at end of file
import tkinter as tk
r = tk.Tk()
r.title('Générateur équations différentielles')
e1 = tk.Entry(r)
e1.pack()
button = tk.Button(r, text='Stop', width=25, command=r.destroy)
button.pack()
r.mainloop()
\ No newline at end of file
#motor.py
import timeseries
valeurs = (0.5,0.0044,0.300,0.1,10)
def create(valeurs):
R,J,L,K,U = valeurs[0],valeurs[1],valeurs[2],valeurs[3],valeurs[4]
m = {'R' : R, 'J': J, 'L':L, 'K':K, 'U':U}
m["omega0"]=0.0
m["omega1"]=0.0
m["omega2"]=0.0
return m
def get_r(m): return m['R']
def get_j(m): return m['J']
def get_l(m): return m['L']
def get_k(m): return m['K']
def get_u(m): return m['U']
def get_omega0(m): return m['omega0']
def get_omega1(m): return m['omega1']
def get_omega2(m): return m['omega2']
def set_r(m,value): m['R'] = value
def set_j(m,value): m['J'] = value
def set_l(m,value): m['L'] = value
def set_k(m,value): m['K'] = value
def set_u(m,value): m['U'] = value
def set_omega0(m,value): m['omega0'] = value
def set_omega1(m,value): m['omega1'] = value
def set_omega2(m,value): m['omega2'] = value
def simulate(m,sim_dt, log_dt, duration):
ts = timeseries.create()
t = 0
data = []
log_timer = 0
c0 = m['K']*m['U']/(m['L']*m['J'])
c1 = (m['K']**2)/(m['J']*m['L'])
c2 = m['R']/m['L']
o0 = m['omega0']
o1 = m['omega1']
o2 = m['omega2']
while t < duration :
m['omega2']=m['K']*m['U']/(m['L']*m['J'])-m['R']/m['L']*m['omega1']-(m['K']*m['K']/(m["L"]*m['J']))*m['omega0']
m['omega1']+=sim_dt*m['omega2']
m['omega0']+=sim_dt*m['omega1']
t += sim_dt
log_timer += sim_dt
if log_timer > log_dt :
log_timer = 0
data.append([t,m['omega0'],m['omega1'],m['omega2']])
timeseries.set_data(ts,data)
timeseries.set_labels(ts,['Time(s)','Omega0','Omega1','Omega2'])
return ts
if __name__ == '__main__':
motor = create(valeurs)
ts = simulate(motor,0.001,0.01,7.0)
timeseries.plot(ts)
timeseries.dump(ts,'motor.csv')
This diff is collapsed.
#motor.py
import timeseries
import tkinter as tk
#Constructeurs
def create(a,b,c,f):
m = {
#On a ay" + by' + cy = f
"a" : a,
"b" : b,
"c" : c,
"f" : f
}
m["y0"]=0.0
m["y1"]=0.0
m["y2"]=0.0
return m
#Accesseurs
def get_a(m): return m['a']
def get_b(m): return m['b']
def get_c(m): return m['c']
def get_f(m): return m['f']
def get_y0(m): return m['y0']
def get_y1(m): return m['y1']
def get_y2(m): return m['y2']
#Modificateurs
def set_a(m,value): m['a'] = value
def set_b(m,value): m['b'] = value
def set_c(m,value): m['c'] = value
def set_f(m,value): m['f'] = value
def set_y0(m,value): m['y0'] = value
def set_y1(m,value): m['y1'] = value
def set_y2(m,value): m['y2'] = value
def simulate(m,sim_dt, log_dt, duration):
ts = timeseries.create()
t = 0
data = []
log_timer = 0
#définition des constantes
y0 = m['y0']
y1 = m['y1']
y2 = m['y2']
a = m["a"]
b = m["b"]
c = m["c"]
f = m["f"]
while t < duration :
#Méthode d'Euler implicite
y2 = (f/a) - (b/a)*y1 -(c/a)*y0
y1 += y2 * sim_dt
y0 += y1 * sim_dt
t += sim_dt
log_timer += sim_dt
if log_timer > log_dt :
log_timer = 0
data.append([t,y0,y1,y2])
timeseries.set_data(ts,data)
timeseries.set_labels(ts,['Time(s)','y','y\'','y"'])
return ts
def main(a,b,c,f,sim_dt,log_dt,duration):
motor = create(a,b,c,f)
ts = simulate(motor,sim_dt,log_dt,duration)
timeseries.plot(ts)
timeseries.dump(ts,'motor.csv')
if __name__ == '__main__':
#Paramètres initiales pour l'interface
r = tk.Tk()
r.title("Simulateur d'équations différentielles")
#Corps de l'interface
model = tk.Label(r, text="l'équa diff est de type: ay\" + by' + cy = f")
model.grid(row=0, column=0)
a_label = tk.Label(r,text="a: ")
a_label.grid(row=2,column=0)
a_entry = tk.Entry(r)
a_entry.grid(row=2,column=1)
b_label = tk.Label(r,text="b: ")
b_label.grid(row=3,column=0)
b_entry = tk.Entry(r)
b_entry.grid(row=3,column=1)
c_label = tk.Label(r,text="c: ")
c_label.grid(row=4,column=0)
c_entry = tk.Entry(r)
c_entry.grid(row=4,column=1)
f_label = tk.Label(r,text="f: ")
f_label.grid(row=5,column=0)
f_entry = tk.Entry(r)
f_entry.grid(row=5,column=1)
sim_dt_label = tk.Label(r,text="sim_dt: ")
sim_dt_label.grid(row=6,column=0)
sim_dt_entry = tk.Entry(r)
sim_dt_entry.grid(row=6,column=1)
log_dt_label = tk.Label(r,text="log_dt: ")
log_dt_label.grid(row=7,column=0)
log_dt_entry = tk.Entry(r)
log_dt_entry.grid(row=7,column=1)
duration_label = tk.Label(r,text="Durée: ")
duration_label.grid(row=8,column=0)
duration_entry = tk.Entry(r)
duration_entry.grid(row=8,column=1)
def all():
a = float(a_entry.get())
b = float(b_entry.get())
c = float(c_entry.get())
f = float(f_entry.get())
sim_dt = float(sim_dt_entry.get())
log_dt = float(log_dt_entry.get())
duration = float(duration_entry.get())
main(a,b,c,f,sim_dt,log_dt,duration)
Generate_button = tk.Button(r,text="Simuler", command=all)
Generate_button.grid(row=9,column=1)
r.mainloop()
#####################
# #
# TimeSeries.py #
# 05/2022 #
# ENIB/ZG2 #
# G. desmeulles #
# #
#####################
import csv
import matplotlib.pyplot as plt
#constructor
def create(filename=None,time_stamp_column_number=0):
ts={'data':[],'labels':[]}
if filename!=None:
with open(filename, newline='') as csvfile:
spamreader = csv.reader(csvfile, delimiter=',', quotechar='"')
for row in spamreader:
ts['data'].append(row)
ts['labels']=ts['data'].pop(0)
if time_stamp_column_number:
swap_column(ts,0,time_stamp_column_number)
ts['xlabel']=ts['labels'][0]
return ts
#accessor/mutators
def get_data(ts): return ts['data'][:]
def get_labels(ts): return ts['labels'][:]
def set_data(ts,data): ts['data']=data
def set_labels(ts,labels): ts['labels']=labels
#operations
def swap_column(ts,n1,n2):
for row in ts['data']:
row.insert(n1,row.pop(n2))
ts['labels'].insert(n1,ts['labels'].pop(n2))
def plot(ts,x_label=None,y_label="",title="",filename=None):
if x_label==None:
x_label=ts['labels'][0]
nb_columns=len(ts['data'][0])
columns=[[] for x in range(nb_columns)]
for i in range(0,len(ts['data'])):
for j in range(nb_columns) :
columns[j].append(float(ts['data'][i][j]))
fig, ax = plt.subplots()
for i in range(nb_columns-1):
ax.plot(columns[0], columns[i+1], label=ts['labels'][i+1])
ax.set(xlabel=x_label, ylabel=y_label, title=title)
ax.legend()
plt.show()
if filename:
fig.savefig(filename)
#Nouvelle fonction
def dump(ts,filename):
with open(filename, 'w', newline='') as csvfile:
spamwriter = csv.writer(csvfile, delimiter=',',)
spamwriter.writerow(ts['labels'])
for line in ts['data']:
output = []
for val in line:
output.append(str(val))
spamwriter.writerow(output)
if __name__=='__main__':
print('test TimeSeries.py')
ts = create('HCSR04_data4_ressort_2022_03_10.csv',3)
print(ts)
plot(ts,y_label='distance(mm)',title='Courbe ZG2!!',filename='test.png')
dump(ts,'test.csv')
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment