Commit 8a500a83 authored by Yassine's avatar Yassine
Browse files

app info

parent 3698d95e
......@@ -341,6 +341,12 @@ $$Tension = 5V$$
L'intervalle de temps entre 2 mesures n’est pas toujours la même. En effet, le "void loop()" ne s’exécute pas à la même vitesse suivant l’action à effectuer ( en fonction de la position du mobile.) La ligne //delay(10); fait attendre que l’action a effectuer soit terminée avant de recommencer. \\
Il est nécessaire ainsi de réaliser une une interruption afin d’uniformiser les temps.
\paragraph{Activité 5}\mbox{}\\
ISR = action à réaliser durant laquelle le programme de l’Arduino est interrompu.\\
Dans notre cas, on utilisera la fonction attachInterrupt() qui prend en arguments le numéro de broche, les instructions à effectuer durant l’interactiin (ISR), et l’état des broches pour lequel les interruptions doivent se déclencher. Ici le pin 5 numérique de la diode rouge est appelé PCINT3 et la broche analogique 9 de la diode verte est appelée PCINT0.\\
\section{Partie Mathématiques}
\subsection{Semaine 1}
......
import tkinter as tk
from tkinter import ttk
from tkinter import filedialog as fd
from tkinter.messagebox import showinfo
import new_plot
import webbrowser
import os
def github():
webbrowser.open("https://www.youtube.com/watch?v=dQw4w9WgXcQ&ab_channel=RickAstley")
def plus_info():
info_window = tk.Toplevel(app)
yassine = tk.Label(info_window, text="Made by Yassine SAHEB ETTABAA")
yassine.pack()
date = tk.Label(info_window, text="Juin 2022")
date.pack()
def generateur_courbes():
newWindow = tk.Toplevel(app)
label = tk.Label(
newWindow, text="Choisir le ou les fichiers csv à simuler")
label.pack()
files = []
def select_files():
filetypes = (
('text files', '*.csv'),
('All files', '*.*')
)
filenames = fd.askopenfilenames(
title='Selectionner les fichiers',
initialdir='./',
filetypes=filetypes)
for i in filenames:
i = os.path.basename(i)
showinfo(
title='Fichiers sélectionnés',
message=filenames
)
simul_window = tk.Toplevel(newWindow)
newWindow.destroy()
newWindow.update()
new = tk.Toplevel(app)
new.title("Simulateur de Courbes")
new.geometry("700x300")
new.resizable(False, False)
label = tk.Label(
new, text="Choisir les paramètres pour simuler les courbes")
label.place(relx=0.5, rely=0.1, anchor=tk.CENTER)
x_label = tk.Label(
new, text="Choisir l'axe des abscisses et l'unité")
x_label.place(relx=0.5, rely=0.2, anchor=tk.CENTER)
x_entry = tk.Entry(new)
x_entry.place(relx=0.5, rely=0.3, anchor=tk.CENTER)
y_label = tk.Label(
new, text="Choisir l'axe des ordonnées et l'unité")
y_label.place(relx=0.5, rely=0.4, anchor=tk.CENTER)
y_entry = tk.Entry(new)
y_entry.place(relx=0.5, rely=0.5, anchor=tk.CENTER)
time_label = tk.Label(
new, text="Position de colonne temps: Mettre -1 si c'est à la fin")
time_label.place(relx=0.5, rely=0.6, anchor=tk.CENTER)
time_entry = tk.Entry(new)
time_entry.place(relx=0.5, rely=0.7, anchor=tk.CENTER)
save = tk.StringVar()
save_button = tk.Radiobutton(new,
text="Enregistrer les courbes",
value="save",
variable=save)
save_button.place(relx=0.5, rely=0.8, anchor=tk.CENTER)
final_label = tk.Label(
new, text="Les courbes vont être enregistrées dans le répertoire appelé results")
final_label.place(relx=0.5, rely=0.87, anchor=tk.CENTER)
def sim():
saving = save.get()
if saving == "save":
saving = True
else:
saving = False
x_label = x_entry.get()
y_label = y_entry.get()
time_column = int(time_entry.get())
for i in filenames:
new_plot.create_time_series(os.path.basename(i), time_column, x_label, y_label, saving)
sim_Button = tk.Button(new, text="Simuler", command=sim)
sim_Button.place(relx=0.5, rely=0.95, anchor=tk.CENTER)
print(filenames)
# open button
open_button = ttk.Button(
newWindow,
text='Selectionner les fichiers',
command=select_files
)
open_button.pack(expand=True)
#############Equa diffs#######
#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,x_label,y_label,filename):
ts = new_plot.create_time_series(None,0,x_label,y_label,False)
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])
new_plot.set_data(ts,data)
new_plot.set_labels(ts,['Time(s)','y','y\'','y"'])
return ts
def main(a,b,c,f,sim_dt,log_dt,duration,x_label,y_label,filename):
filename += ".csv"
motor = create(a,b,c,f)
ts = simulate(motor,sim_dt,log_dt,duration,x_label,y_label,filename)
new_plot.plot(ts,filename,x_label,y_label,None)
new_plot.dump(ts,filename)
def equa_diff():
equa_window = tk.Toplevel(app)
equa_window.title("Simulateur d'équations différentielles")
equa_window.geometry("700x300")
equa_window.resizable(False,False)
#Corps de l'interface
model = tk.Label(equa_window, text="l'équa diff est de type: ay\" + by' + cy = f")
model.grid(row=0, column=0)
a_label = tk.Label(equa_window,text="a: ")
a_label.grid(row=2,column=0)
a_entry = tk.Entry(equa_window)
a_entry.grid(row=2,column=1)
b_label = tk.Label(equa_window,text="b: ")
b_label.grid(row=3,column=0)
b_entry = tk.Entry(equa_window)
b_entry.grid(row=3,column=1)
c_label = tk.Label(equa_window,text="c: ")
c_label.grid(row=4,column=0)
c_entry = tk.Entry(equa_window)
c_entry.grid(row=4,column=1)
f_label = tk.Label(equa_window,text="f: ")
f_label.grid(row=5,column=0)
f_entry = tk.Entry(equa_window)
f_entry.grid(row=5,column=1)
sim_dt_label = tk.Label(equa_window,text="sim_dt (intervalle (en s) entre chaque point, exemple:0.01): ")
sim_dt_label.grid(row=6,column=0)
sim_dt_entry = tk.Entry(equa_window)
sim_dt_entry.grid(row=6,column=1)
log_dt_label = tk.Label(equa_window,text="log_dt (intervalle de l'output (en s) exemple: 0.1): ")
log_dt_label.grid(row=7,column=0)
log_dt_entry = tk.Entry(equa_window)
log_dt_entry.grid(row=7,column=1)
duration_label = tk.Label(equa_window,text="Durée (ou limite de l'axe x) de la simulation : ")
duration_label.grid(row=8,column=0)
duration_entry = tk.Entry(equa_window)
duration_entry.grid(row=8,column=1)
name_label = tk.Label(equa_window,text="Nom du fichier csv à créer")
name_label.grid(row=9,column=0)
name_entry = tk.Entry(equa_window)
name_entry.grid(row=9,column=1)
x_label = tk.Label(equa_window,text="Nom de l'axe des abscisses: ")
x_label.grid(row=10,column=0)
x_entry = tk.Entry(equa_window)
x_entry.grid(row=10,column=1)
y_label = tk.Label(equa_window,text="Nom de l'axe des ordonnées: ")
y_label.grid(row=11,column=0)
y_entry = tk.Entry(equa_window)
y_entry.grid(row=11,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())
name = name_entry.get()
x = x_entry.get()
y = y_entry.get()
main(a,b,c,f,sim_dt,log_dt,duration,x,y,name)
Generate_button = tk.Button(equa_window,text="Simuler", command=all)
Generate_button.grid(row=12,column=1)
######Appli Main######
app = tk.Tk()
app.geometry("550x200")
app.title("Equations différentielles")
app.resizable(False, False)
sim_courbe_button = tk.Button(app,
text="Simulateur de Courbes",
command=generateur_courbes,
height=2,
width=30)
sim_courbe_button.place(relx=0.5, rely=0.2, anchor=tk.CENTER)
gen_equa_button = tk.Button(app,
text="Simulateur d\'équations différentielles",
command=equa_diff,
height=2,
width=30)
gen_equa_button.place(relx=0.5, rely=0.4, anchor=tk.CENTER)
git_button = tk.Button(app,
text="Accéder au Github",
command=github,
height=2,
width=30)
git_button.place(relx=0.5, rely=0.6, anchor=tk.CENTER)
info_button = tk.Button(app,
text="Plus d'informations",
command=plus_info,
height=2,
width=30)
info_button.place(relx=0.5, rely=0.8, anchor=tk.CENTER)
app.mainloop()
import csv
import matplotlib.pyplot as plt
import os
#Constructeur
def create_time_series(filename=None,time_column=None,x_label=None,y_label=None,save=None):
time_series = { #creates a new dictionnary
"data" : [],
"labels" : None
}
if filename!=None and time_column!= None and x_label!=None and y_label!=None and save!=None:
with open(filename, newline='',encoding='utf8') as csvfile: #opens csv file
spamreader = csv.reader(csvfile)
for row in spamreader: #adds rows to data
time_series["data"].append(row)
time_series["labels"] = time_series["data"].pop(0)
if time_column != 0: #If the first column of the file isn't the time column
swap_column(time_series,time_column)
plot(time_series,filename,x_label,y_label,save)
return time_series
#Accesseurs
def get_data(t_s):
return t_s["data"]
def get_labels(t_s):
return t_s["labels"]
#Mutateurs
def set_data(t_s,data):
t_s["data"] = data
return
def set_labels(t_s,labels):
t_s["labels"] = labels
return
def swap_column(ts,time_column):
if time_column == -1:
time_column = len(ts["data"][0])-1
#print(time_column)
for i in ts["data"]:
i.insert(0,i.pop(time_column))
ts["labels"].insert(0,ts["labels"].pop(time_column))
def plot(ts,filename,x_label,y_label,save):
nb_curves=len(ts['data'][0])-1
#initiation columns list
columns=[[] for x in range(nb_curves+1)]
#fill columns
for i in range(0,len(ts['data'])):
columns[0].append(float(ts['data'][i][0])) #timestamp
for j in range(nb_curves) :
columns[j+1].append(float(ts['data'][i][j+1])) #y values
fig, ax = plt.subplots()
for i in range(nb_curves):
ax.plot(columns[0], columns[1+i], label=ts['labels'][i+1])
plt.xlabel(x_label)
plt.ylabel(y_label)
plt.title(remove_file_extension(filename))
ax.legend()
plt.show()
if save == True:
new_filename = remove_file_extension(filename)
r = os.path.isdir('results')
if r == True:
fig.savefig("./results/"+new_filename+".png")
else:
os.system("mkdir results")
fig.savefig("./results/"+new_filename+".png")
def remove_file_extension(filename):
l = list(filename)
index_point = 0
for i in range(len(l)):
if l[i] == ".":
index_point = i
del l[index_point:]
return ''.join(l)
def dump(ts,filename):
'''save ts in a file'''
print(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__':
#create_time_series("test.csv",-1,"temps","position",True)
\ No newline at end of file
#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 #
# #
#####################