mirror of
https://forge.apps.education.fr/blender-edutech/jumeaux-numeriques.git
synced 2024-01-27 06:56:18 +01:00
Configuration du plot statique
This commit is contained in:
parent
72dbc3f914
commit
5243d26bd4
@ -28,26 +28,26 @@ scene = bge.logic.getCurrentScene()
|
|||||||
|
|
||||||
public_vars = {
|
public_vars = {
|
||||||
't' : [['System','time'], [], []],
|
't' : [['System','time'], [], []],
|
||||||
'bp_ext' : [['Bp cote rue','activated'], ['pin', 'd','i'], ['o','-', 'green', 1]],
|
'bp_ext' : [['Bp cote rue','activated'], ['pin', 'd','i'], ['.','-', 'green', 1]],
|
||||||
'bp_ext_r' : [['Bp cote rue','activated_real'], [], ['o','--', 'green', 1]],
|
'bp_ext_r' : [['Bp cote rue','activated_real'], [], ['.','--', 'green', 1]],
|
||||||
'bp_int' : [['Bp cote cour','activated'], ['pin', 'd','i'], ['o','-', 'darkgreen', 1]],
|
'bp_int' : [['Bp cote cour','activated'], ['pin', 'd','i'], ['.','-', 'darkgreen', 1]],
|
||||||
'bp_int_r' : [['Bp cote cour','activated_real'], [], ['o','--', 'darkgreen', 1]],
|
'bp_int_r' : [['Bp cote cour','activated_real'], [], ['.','--', 'darkgreen', 1]],
|
||||||
'fdc_o' : [['Microrupteur fdc ouvert','activated'], ['pin', 'd','i'], ['o','-', 'orange', 1]],
|
'fdc_o' : [['Microrupteur fdc ouvert','activated'], ['pin', 'd','i'], ['.','-', 'orange', 1]],
|
||||||
'fdc_o_r' : [['Microrupteur fdc ouvert','activated_real'], [], ['o','--', 'orange', 1]],
|
'fdc_o_r' : [['Microrupteur fdc ouvert','activated_real'], [], ['.','--', 'orange', 1]],
|
||||||
'fdc_f' : [['Microrupteur fdc ferme','activated'], ['pin', 'd','i'], ['o','-', 'darkorange', 1]],
|
'fdc_f' : [['Microrupteur fdc ferme','activated'], ['pin', 'd','i'], ['.','-', 'darkorange', 1]],
|
||||||
'fdc_f_r' : [['Microrupteur fdc ferme','activated_real'], [], ['o','--', 'darkorange', 1]],
|
'fdc_f_r' : [['Microrupteur fdc ferme','activated_real'], [], ['.','--', 'darkorange', 1]],
|
||||||
'mot_o' : [['Moteur','open'], ['pin_open', 'd','o'], ['o','-', 'violet', 1]],
|
'mot_o' : [['Moteur','open'], ['pin_open', 'd','o'], ['.','-', 'violet', 1]],
|
||||||
'mot_f' : [['Moteur','close'], ['pin_close', 'd','o'], ['o','-', 'darkviolet', 1]],
|
'mot_f' : [['Moteur','close'], ['pin_close', 'd','o'], ['.','-', 'darkviolet', 1]],
|
||||||
'mot_angle' : [['Moteur','alpha'], [], ['o','-', 'blue', 1]],
|
'mot_angle' : [['Moteur','alpha'], [], ['.','-', 'blue', 1]],
|
||||||
'mot_vitesse' : [['Moteur','speed'], [], ['o','-', 'darkblue', 1]],
|
'mot_vitesse' : [['Moteur','speed'], [], ['.','-', 'darkblue', 1]],
|
||||||
'mot_pas' : [['Moteur','step'], [], []],
|
'mot_pas' : [['Moteur','step'], [], []],
|
||||||
'portail_x' : [['Portail','x'], [], ['o','-', 'turquoise', 1]],
|
'portail_x' : [['Portail','x'], [], ['.','-', 'turquoise', 1]],
|
||||||
'portail_vitesse' : [['Portail','speed'], [], ['o','-', 'darkturquoise', 1]],
|
'portail_vitesse' : [['Portail','speed'], [], ['.','-', 'darkturquoise', 1]],
|
||||||
'portail_pas' : [['Portail','step'], [], []],
|
'portail_pas' : [['Portail','step'], [], []],
|
||||||
'gyr' : [['Led','activated'], ['pin', 'd','o'], ['o','-', 'gold', 1]],
|
'gyr' : [['Led','activated'], ['pin', 'd','.'], ['.','-', 'gold', 1]],
|
||||||
'ir_emet' : [['Emetteur IR', 'activated'], ['pin', 'd','o'],['o','-', 'red', 1]],
|
'ir_emet' : [['Emetteur IR', 'activated'], ['pin', 'd','o'],['.','-', 'red', 1]],
|
||||||
'ir_recep' : [['Recepteur IR','activated'], ['pin', 'd','i'],['o','-', 'darkred', 1]],
|
'ir_recep' : [['Recepteur IR','activated'], ['pin', 'd','i'],['.','-', 'darkred', 1]],
|
||||||
'ir_recep_r' : [['Recepteur IR','activated_real'], [],['o','--', 'darkred', 1]]}
|
'ir_recep_r' : [['Recepteur IR','activated_real'], [],['.','--', 'darkred', 1]]}
|
||||||
|
|
||||||
# Couleurs
|
# Couleurs
|
||||||
color_passive = (0.800, 0.005, 0.315,1) # bouton non activable : magenta
|
color_passive = (0.800, 0.005, 0.315,1) # bouton non activable : magenta
|
||||||
|
@ -47,9 +47,11 @@ def commandes():
|
|||||||
gyr(False)
|
gyr(False)
|
||||||
print ("")
|
print ("")
|
||||||
|
|
||||||
daq(['mot_angle', 'mot_vitesse', 'portail_x', 'portail_vitesse'])
|
# daq(['mot_angle', 'mot_vitesse', 'portail_x', 'portail_vitesse'])
|
||||||
|
daq(['bp_ext', 'bp_ext_r', 'bp_int', 'bp_int_r', 'fdc_o', 'fdc_o_r', 'fdc_f', 'fdc_f_r', 'mot_o', 'mot_f', 'mot_angle', 'mot_vitesse', 'portail_x', 'portail_vitesse', 'gyr', 'ir_emet', 'ir_recep', 'ir_recep_r'])
|
||||||
|
# daq(['bp_ext', 'bp_ext_r', 'bp_int', 'bp_int_r', 'fdc_o', 'fdc_o_r', 'fdc_f', 'fdc_f_r', 'mot_o', 'mot_f', 'gyr'])
|
||||||
reset_t()
|
reset_t()
|
||||||
|
|
||||||
# Fermeture
|
# Fermeture
|
||||||
mot_digitset (1256) # Vitesse par défaut 125,6 rad /s ( 20 tr / s )
|
mot_digitset (1256) # Vitesse par défaut 125,6 rad /s ( 20 tr / s )
|
||||||
t0,x0, a0= get('t'), get('portail_x'), get('mot_angle')
|
t0,x0, a0= get('t'), get('portail_x'), get('mot_angle')
|
||||||
@ -68,7 +70,7 @@ def commandes():
|
|||||||
# " rad - portail_vitesse : " +str(round(portail_vitesse, 3))+" mm/s - moteur_vitesse : " +str(round(mot_vitesse, 3))+
|
# " rad - portail_vitesse : " +str(round(portail_vitesse, 3))+" mm/s - moteur_vitesse : " +str(round(mot_vitesse, 3))+
|
||||||
# " rad/s - portail_pas : " +str(round(portail_pas, 3))+" mm/impulsion - moteur_pas : " +str(round(mot_pas, 3))+" rad/impulsion")
|
# " rad/s - portail_pas : " +str(round(portail_pas, 3))+" mm/impulsion - moteur_pas : " +str(round(mot_pas, 3))+" rad/impulsion")
|
||||||
# print ("")
|
# print ("")
|
||||||
|
|
||||||
# Ouverture
|
# Ouverture
|
||||||
mot_digitset () # Vitesse par défaut 125,6 rad /s ( 20 tr / s )
|
mot_digitset () # Vitesse par défaut 125,6 rad /s ( 20 tr / s )
|
||||||
mot_digitset (2000) # Vitesse par défaut 125,6 rad /s ( 20 tr / s )
|
mot_digitset (2000) # Vitesse par défaut 125,6 rad /s ( 20 tr / s )
|
||||||
@ -88,15 +90,16 @@ def commandes():
|
|||||||
# " rad - portail_vitesse : " +str(round(portail_vitesse, 3))+" mm/s - moteur_vitesse : " +str(round(mot_vitesse, 3))+
|
# " rad - portail_vitesse : " +str(round(portail_vitesse, 3))+" mm/s - moteur_vitesse : " +str(round(mot_vitesse, 3))+
|
||||||
# " rad/s - portail_pas : " +str(round(portail_pas, 3))+" mm/impulsion - moteur_pas : " +str(round(mot_pas, 3))+" rad/impulsion")
|
# " rad/s - portail_pas : " +str(round(portail_pas, 3))+" mm/impulsion - moteur_pas : " +str(round(mot_pas, 3))+" rad/impulsion")
|
||||||
|
|
||||||
plot()
|
plot(['bp_ext', 'bp_ext_r', 'bp_int', 'bp_int_r', 'fdc_o', 'fdc_o_r', 'fdc_f', 'fdc_f_r', 'mot_o', 'mot_f', 'gyr', ['mot_angle', 'mot_vitesse', 'portail_x', 'portail_vitesse']])
|
||||||
fin() # A garder
|
fin() # A garder
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# En: External call << DONT CHANGE THIS SECTION >>
|
# En: External call << DONT CHANGE THIS SECTION >>
|
||||||
# Fr: Appel externe << NE PAS MODIFIER CETTE SECTION >>
|
# Fr: Appel externe << NE PAS MODIFIER CETTE SECTION >>
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
if __name__=='start':
|
if __name__=='start':
|
||||||
thread_cmd_start(commandes)
|
thread_cmd_start(commandes)
|
||||||
if __name__=='stop':
|
if __name__=='stop':
|
||||||
stop()
|
stop()
|
||||||
|
|
||||||
|
Binary file not shown.
15
twin.py
15
twin.py
@ -33,8 +33,7 @@ system=importlib.import_module(scene.objects['System']['script'][:-4]) # Systèm
|
|||||||
sys.setrecursionlimit(10**5) # Limite sur la récursivité (valeur par défaut : 1000) -> segfault de Blender
|
sys.setrecursionlimit(10**5) # Limite sur la récursivité (valeur par défaut : 1000) -> segfault de Blender
|
||||||
|
|
||||||
# Config file
|
# Config file
|
||||||
twin_config = ET.parse('twin_config.xml')
|
twin_config = ET.parse('twin_config.xml').getroot()
|
||||||
twin_config_tree = twin_config.getroot()
|
|
||||||
|
|
||||||
# Couleurs
|
# Couleurs
|
||||||
color_cmd = (0.8, 0.8, 0.8, 1) # Blanc
|
color_cmd = (0.8, 0.8, 0.8, 1) # Blanc
|
||||||
@ -73,10 +72,10 @@ def keyboard(cont):
|
|||||||
# Maj du fichier de config (screen size : data/config/screen/width-> [0][0].text)
|
# Maj du fichier de config (screen size : data/config/screen/width-> [0][0].text)
|
||||||
screen_width = bge.render.getWindowWidth()
|
screen_width = bge.render.getWindowWidth()
|
||||||
screen_height = bge.render.getWindowHeight()
|
screen_height = bge.render.getWindowHeight()
|
||||||
twin_config_tree[0][0].text=str(screen_width)
|
twin_config[0][0].text=str(screen_width)
|
||||||
twin_config_tree[0][1].text=str(screen_height)
|
twin_config[0][1].text=str(screen_height)
|
||||||
twin_config_tree[0][2].text=str(scene.objects['About']['quality'])
|
twin_config[0][2].text=str(scene.objects['About']['quality'])
|
||||||
buffer_xml = ET.tostring(twin_config_tree)
|
buffer_xml = ET.tostring(twin_config)
|
||||||
with open("twin_config.xml", "wb") as f:
|
with open("twin_config.xml", "wb") as f:
|
||||||
f.write(buffer_xml)
|
f.write(buffer_xml)
|
||||||
|
|
||||||
@ -128,9 +127,9 @@ def keyboard(cont):
|
|||||||
def cmd_init():
|
def cmd_init():
|
||||||
|
|
||||||
# Fichier de config (screen size : data/config/screen/width-> [0][0].text, height-> [0][1].text)
|
# Fichier de config (screen size : data/config/screen/width-> [0][0].text, height-> [0][1].text)
|
||||||
bge.render.setWindowSize(int(twin_config_tree[0][0].text),int(twin_config_tree[0][1].text))
|
bge.render.setWindowSize(int(twin_config[0][0].text),int(twin_config[0][1].text))
|
||||||
quality_eevee=('NOSMAA', 'LOW', 'MEDIUM','HIGH','ULTRA')
|
quality_eevee=('NOSMAA', 'LOW', 'MEDIUM','HIGH','ULTRA')
|
||||||
scene.objects['About']['quality'] = int(twin_config_tree[0][2].text)
|
scene.objects['About']['quality'] = int(twin_config[0][2].text)
|
||||||
if quality_eevee[scene.objects['About']['quality']] == 'NOSMAA':
|
if quality_eevee[scene.objects['About']['quality']] == 'NOSMAA':
|
||||||
eevee.smaa_quality= 'LOW'
|
eevee.smaa_quality= 'LOW'
|
||||||
eevee.use_eevee_smaa = False
|
eevee.use_eevee_smaa = False
|
||||||
|
@ -217,7 +217,7 @@ def quality_up(cont):
|
|||||||
eevee.use_eevee_smaa = False
|
eevee.use_eevee_smaa = False
|
||||||
else:
|
else:
|
||||||
eevee.use_eevee_smaa = True
|
eevee.use_eevee_smaa = True
|
||||||
print (sys.platform)
|
# print (sys.platform)
|
||||||
if sys.platform=="linux": # Plantage sur Windows
|
if sys.platform=="linux": # Plantage sur Windows
|
||||||
eevee.smaa_quality= quality_eevee[scene.objects['About']['quality']]
|
eevee.smaa_quality= quality_eevee[scene.objects['About']['quality']]
|
||||||
|
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
<data>
|
<data>
|
||||||
<screen>
|
<screen>
|
||||||
<width>1609</width>
|
<width>792</width>
|
||||||
<height>905</height>
|
<height>445</height>
|
||||||
<quality>1</quality>
|
<quality>4</quality>
|
||||||
</screen>
|
</screen>
|
||||||
|
<plot>
|
||||||
|
<config>True</config>
|
||||||
|
</plot>
|
||||||
</data>
|
</data>
|
89
twin_daq.py
89
twin_daq.py
@ -5,6 +5,7 @@ import importlib
|
|||||||
import subprocess # Multiprocessus
|
import subprocess # Multiprocessus
|
||||||
import time
|
import time
|
||||||
import csv
|
import csv
|
||||||
|
import xml.etree.ElementTree as ET # Creating/parsing XML file
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# twin_daq.py
|
# twin_daq.py
|
||||||
@ -44,24 +45,30 @@ def get(data):
|
|||||||
# Enregistrement des données
|
# Enregistrement des données
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
##
|
||||||
# Activation du mode DAQ
|
# Activation du mode DAQ
|
||||||
|
##
|
||||||
|
|
||||||
def daq(data):
|
def daq(data):
|
||||||
daq_data.clear()
|
daq_data.clear()
|
||||||
scene.objects['System']['daq_var'] =[]
|
scene.objects['System']['daq_var'] =[]
|
||||||
data_line = ['t']
|
row = ['t']
|
||||||
for var in data:
|
for var in data:
|
||||||
scene.objects['System']['daq_var'].append([daq_config[var][0][0], daq_config[var][0][1]])
|
scene.objects['System']['daq_var'].append([daq_config[var][0][0], daq_config[var][0][1]])
|
||||||
data_line.append(var)
|
row.append(var)
|
||||||
print ("Acquisition des données :", scene.objects['System']['daq_var'])
|
# print ("Acquisition des données :", scene.objects['System']['daq_var'])
|
||||||
daq_data.append(data_line)
|
daq_data.append(row)
|
||||||
scene.objects['System']['daq']=True
|
scene.objects['System']['daq']=True
|
||||||
|
|
||||||
|
##
|
||||||
# Ajout des données (fps = 60)
|
# Ajout des données (fps = 60)
|
||||||
|
##
|
||||||
|
|
||||||
def daq_add(cont):
|
def daq_add(cont):
|
||||||
data_line = [round(scene.objects['System']['time'], 3)]
|
row = [round(scene.objects['System']['time'], 3)]
|
||||||
for var in scene.objects['System']['daq_var']:
|
for var in scene.objects['System']['daq_var']:
|
||||||
data_line.append(round(scene.objects[var[0]][var[1]], 3))
|
row.append(round(scene.objects[var[0]][var[1]], 3))
|
||||||
daq_data.append(data_line)
|
daq_data.append(row)
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Tableau CSV
|
# Tableau CSV
|
||||||
@ -74,11 +81,13 @@ def localize_floats(row):
|
|||||||
for el in row
|
for el in row
|
||||||
]
|
]
|
||||||
|
|
||||||
|
##
|
||||||
# Génération du fichier
|
# Génération du fichier
|
||||||
|
##
|
||||||
|
|
||||||
def csv_generate():
|
def csv_generate():
|
||||||
scene.objects['System']['daq']=False
|
scene.objects['System']['daq']=False
|
||||||
fichier_csv=scene.objects['System']['system']+'.csv'
|
fichier_csv=scene.objects['System']['system']+'.csv'
|
||||||
print ("Génération du fichier :", fichier_csv)
|
|
||||||
scene.objects['Cmd-text']['modal']= True
|
scene.objects['Cmd-text']['modal']= True
|
||||||
scene.objects['Cmd-text']['Text']= "Génération du fichier : "+fichier_csv
|
scene.objects['Cmd-text']['Text']= "Génération du fichier : "+fichier_csv
|
||||||
scene.objects['Cmd-text'].setVisible(True,False)
|
scene.objects['Cmd-text'].setVisible(True,False)
|
||||||
@ -91,17 +100,70 @@ def csv_generate():
|
|||||||
# Graphique statique
|
# Graphique statique
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
##
|
||||||
|
# Création du fichier twin_plot.xml (configuration du graphique)
|
||||||
|
##
|
||||||
|
|
||||||
|
def plot_config_generate(data_groups):
|
||||||
|
|
||||||
|
# Création du XML
|
||||||
|
daq_config_list=list(daq_config)
|
||||||
|
xml_data = ET.Element('data')
|
||||||
|
xml_figure = ET.SubElement(xml_data, 'figure')
|
||||||
|
xml_plot = ET.SubElement(xml_figure, 'plot')
|
||||||
|
for var in daq_config_list:
|
||||||
|
xml_var = ET.SubElement(xml_plot, 'var')
|
||||||
|
xml_var.text=var
|
||||||
|
if len(daq_config[var][2]) >=4:
|
||||||
|
xml_mark = ET.SubElement(xml_var, 'marker')
|
||||||
|
xml_mark.text=daq_config[var][2][0]
|
||||||
|
xml_line = ET.SubElement(xml_var, 'linestyle')
|
||||||
|
xml_line.text=daq_config[var][2][1]
|
||||||
|
xml_color = ET.SubElement(xml_var, 'color')
|
||||||
|
xml_color.text=daq_config[var][2][2]
|
||||||
|
xml_size = ET.SubElement(xml_var, 'linewidth')
|
||||||
|
xml_size.text=str(daq_config[var][2][3])
|
||||||
|
|
||||||
|
# Détection de groupe de graphique
|
||||||
|
data_group_i=0
|
||||||
|
xml_group = ET.SubElement(xml_var, 'group')
|
||||||
|
xml_group.text="-1" # Pas de groupe par défaut
|
||||||
|
for data_group in data_groups:
|
||||||
|
if isinstance(data_group, list):
|
||||||
|
data_group_i+=1
|
||||||
|
for data_subgroup in data_group: # Scan du sous-groupe
|
||||||
|
if data_subgroup == var:
|
||||||
|
xml_group.text=str(data_group_i)
|
||||||
|
else:
|
||||||
|
if data_group == var: # Pas de groupe
|
||||||
|
xml_group.text="0"
|
||||||
|
|
||||||
|
# Ecriture fichier
|
||||||
|
plot_config = ET.ElementTree(xml_data)
|
||||||
|
with open("plot_config.xml", "wb") as f: # XML généré plat (not pretty print)
|
||||||
|
plot_config.write(f)
|
||||||
|
|
||||||
|
##
|
||||||
# Activation du mode Plot
|
# Activation du mode Plot
|
||||||
def plot():
|
##
|
||||||
|
|
||||||
|
def plot(data_groups):
|
||||||
|
plot_config_generate(data_groups)
|
||||||
scene.objects['System']['plot']=True
|
scene.objects['System']['plot']=True
|
||||||
|
|
||||||
|
##
|
||||||
# Fermer le processus du graphique
|
# Fermer le processus du graphique
|
||||||
|
##
|
||||||
|
|
||||||
def plot_close():
|
def plot_close():
|
||||||
if scene.objects['System']['plot_proc'] is not None:
|
if scene.objects['System']['plot_proc'] is not None:
|
||||||
if scene.objects['System']['plot_proc'].poll()==None:
|
if scene.objects['System']['plot_proc'].poll()==None:
|
||||||
scene.objects['System']['plot_proc'].terminate()
|
scene.objects['System']['plot_proc'].terminate()
|
||||||
|
|
||||||
|
##
|
||||||
# Génération du graphique
|
# Génération du graphique
|
||||||
|
##
|
||||||
|
|
||||||
def plot_generate():
|
def plot_generate():
|
||||||
plot_close()
|
plot_close()
|
||||||
fichier_csv=scene.objects['System']['system']+'.csv'
|
fichier_csv=scene.objects['System']['system']+'.csv'
|
||||||
@ -113,12 +175,18 @@ def plot_generate():
|
|||||||
# FIXME : ne marche pas
|
# FIXME : ne marche pas
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
##
|
||||||
# Mise en forme de décimaux
|
# Mise en forme de décimaux
|
||||||
|
##
|
||||||
|
|
||||||
def truncate(n, decimals=0):
|
def truncate(n, decimals=0):
|
||||||
multiplier = 10**decimals
|
multiplier = 10**decimals
|
||||||
return int(n* multiplier)/multiplier
|
return int(n* multiplier)/multiplier
|
||||||
|
|
||||||
|
##
|
||||||
# Création du graphique interactif
|
# Création du graphique interactif
|
||||||
|
##
|
||||||
|
|
||||||
def plot_start(data):
|
def plot_start(data):
|
||||||
# subprocess.run([sys.executable, os.path.join(os.getcwd(), "twin_plot.py")], , stdin=subprocess.PIPE) # Process bloquant
|
# subprocess.run([sys.executable, os.path.join(os.getcwd(), "twin_plot.py")], , stdin=subprocess.PIPE) # Process bloquant
|
||||||
|
|
||||||
@ -141,7 +209,10 @@ def plot_start(data):
|
|||||||
# # print("Blender stout : ", stout)
|
# # print("Blender stout : ", stout)
|
||||||
scene.objects['System']['plot']=True
|
scene.objects['System']['plot']=True
|
||||||
|
|
||||||
|
##
|
||||||
# Ajout des données (fps = 60)
|
# Ajout des données (fps = 60)
|
||||||
|
##
|
||||||
|
|
||||||
def plot_add(cont):
|
def plot_add(cont):
|
||||||
if cont.sensors['Plot'].positive :
|
if cont.sensors['Plot'].positive :
|
||||||
|
|
||||||
|
100
twin_plot_qt.py
100
twin_plot_qt.py
@ -1,6 +1,10 @@
|
|||||||
import sys
|
import sys
|
||||||
import random
|
import random
|
||||||
|
import importlib
|
||||||
import matplotlib
|
import matplotlib
|
||||||
|
import csv
|
||||||
|
import xml.etree.ElementTree as ET # Creating/parsing XML file
|
||||||
|
|
||||||
matplotlib.use('Qt5Agg')
|
matplotlib.use('Qt5Agg')
|
||||||
from PyQt5 import QtCore, QtGui, QtWidgets
|
from PyQt5 import QtCore, QtGui, QtWidgets
|
||||||
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg, NavigationToolbar2QT as NavigationToolbar
|
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg, NavigationToolbar2QT as NavigationToolbar
|
||||||
@ -16,12 +20,22 @@ from matplotlib.figure import Figure
|
|||||||
# @license: GNU GPL
|
# @license: GNU GPL
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
# UPBGE scene
|
# Lecture des configurations
|
||||||
# scene = bge.logic.getCurrentScene()
|
twin_config = ET.parse('twin_config.xml').getroot()
|
||||||
|
plot_config_tree = ET.parse('plot_config.xml').getroot()
|
||||||
|
plot_config={}
|
||||||
|
|
||||||
# Récupérer le brochage du jumeau réel
|
###############################################################################
|
||||||
# system=importlib.import_module(scene.objects['Doc']['system']) # Système
|
# Configuration des plots
|
||||||
# pin_config = system.get_pin_config()
|
###############################################################################
|
||||||
|
|
||||||
|
def plot_config_dict():
|
||||||
|
for var in plot_config_tree[0][0]:
|
||||||
|
var_dict={}
|
||||||
|
for i in range (len(var)):
|
||||||
|
if var[i] is not None:
|
||||||
|
var_dict.update({var[i].tag : var[i].text})
|
||||||
|
plot_config.update({var.text: var_dict})
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Zone de dessin
|
# Zone de dessin
|
||||||
@ -98,11 +112,6 @@ class DynamicPlot(QtWidgets.QMainWindow):
|
|||||||
# self.xdata = self.xdata + [float(msg_list[0])]
|
# self.xdata = self.xdata + [float(msg_list[0])]
|
||||||
# self.ydata = self.ydata + [float(msg_list[1])]
|
# self.ydata = self.ydata + [float(msg_list[1])]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# # Lecture du Pipe
|
# # Lecture du Pipe
|
||||||
# # i=0
|
# # i=0
|
||||||
# # lines = sys.stdin.readlines()
|
# # lines = sys.stdin.readlines()
|
||||||
@ -130,12 +139,7 @@ class DynamicPlot(QtWidgets.QMainWindow):
|
|||||||
# if msg_list[0] != "":
|
# if msg_list[0] != "":
|
||||||
# self.xdata = self.xdata + [float(msg_list[0])]
|
# self.xdata = self.xdata + [float(msg_list[0])]
|
||||||
# self.ydata = self.ydata + [float(msg_list[1])]
|
# self.ydata = self.ydata + [float(msg_list[1])]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# for line in msg_lines:
|
# for line in msg_lines:
|
||||||
# msg_list=line.split(',')
|
# msg_list=line.split(',')
|
||||||
@ -144,7 +148,6 @@ class DynamicPlot(QtWidgets.QMainWindow):
|
|||||||
# self.xdata = self.xdata + [float(msg_list[0])]
|
# self.xdata = self.xdata + [float(msg_list[0])]
|
||||||
# self.ydata = self.ydata + [float(msg_list[1])]
|
# self.ydata = self.ydata + [float(msg_list[1])]
|
||||||
|
|
||||||
|
|
||||||
# for line in sys.stdin:
|
# for line in sys.stdin:
|
||||||
# msg_list=msg.split(',')
|
# msg_list=msg.split(',')
|
||||||
# print(msg_list)
|
# print(msg_list)
|
||||||
@ -152,7 +155,6 @@ class DynamicPlot(QtWidgets.QMainWindow):
|
|||||||
# self.xdata = self.xdata + [float(msg_list[0])]
|
# self.xdata = self.xdata + [float(msg_list[0])]
|
||||||
# self.ydata = self.ydata + [float(msg_list[1])]
|
# self.ydata = self.ydata + [float(msg_list[1])]
|
||||||
|
|
||||||
|
|
||||||
# self.ydata = self.ydata + [random.randint(0, 10)]
|
# self.ydata = self.ydata + [random.randint(0, 10)]
|
||||||
# Drop off the first y element, append a new one.
|
# Drop off the first y element, append a new one.
|
||||||
# self.ydata = self.ydata[1:] + [random.randint(0, 10)]
|
# self.ydata = self.ydata[1:] + [random.randint(0, 10)]
|
||||||
@ -176,9 +178,10 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
super(MainWindow, self).__init__(*args, **kwargs)
|
super(MainWindow, self).__init__(*args, **kwargs)
|
||||||
self.canvas = MplCanvas(self, width=5, height=4, dpi=100)
|
self.canvas = MplCanvas(self, width=5, height=4, dpi=100)
|
||||||
toolbar = NavigationToolbar(self.canvas, self)
|
toolbar = NavigationToolbar(self.canvas, self)
|
||||||
plt = self.canvas.subplot
|
# plt = self.canvas.subplot
|
||||||
|
# plt.cla()
|
||||||
|
|
||||||
# Implantation
|
# Implantation de la fenêtre
|
||||||
layout = QtWidgets.QVBoxLayout()
|
layout = QtWidgets.QVBoxLayout()
|
||||||
layout.addWidget(toolbar)
|
layout.addWidget(toolbar)
|
||||||
layout.addWidget(self.canvas)
|
layout.addWidget(self.canvas)
|
||||||
@ -186,15 +189,56 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
widget.setLayout(layout)
|
widget.setLayout(layout)
|
||||||
self.setCentralWidget(widget)
|
self.setCentralWidget(widget)
|
||||||
|
|
||||||
# Lecture des données
|
# Lecture fichier CSV
|
||||||
print ("Qt : fichier de données :", sys.argv[1])
|
fields = []
|
||||||
n_data = 50
|
rows = []
|
||||||
self.xdata = list(range(n_data))
|
with open(sys.argv[1], newline='') as csvfile:
|
||||||
self.ydata = [random.randint(0, 10) for i in range(n_data)]
|
csvreader = csv.reader(csvfile, delimiter=';')
|
||||||
|
fields = next(csvreader)
|
||||||
|
for row in csvreader:
|
||||||
|
rows.append(row)
|
||||||
|
|
||||||
# Plot
|
# Mise en tableau à deux colonnes (xdata,ydata)
|
||||||
plt.cla()
|
xdata=[]
|
||||||
plt.plot(self.xdata, self.ydata, 'b')
|
ydata=[]
|
||||||
|
i=0
|
||||||
|
for field in fields:
|
||||||
|
xdata_row=[]
|
||||||
|
ydata_row=[]
|
||||||
|
for row in rows:
|
||||||
|
xdata_row.append(float(row[0].replace(',', '.'))) # Revenir au format US des décimaux
|
||||||
|
ydata_row.append(float(row[i].replace(',', '.'))) # Revenir au format US des décimaux
|
||||||
|
xdata.append(xdata_row)
|
||||||
|
ydata.append(ydata_row)
|
||||||
|
i+=1
|
||||||
|
|
||||||
|
# Plots
|
||||||
|
plot_config_dict() # Configuration des plots
|
||||||
|
# FIXME : multiplot à faire
|
||||||
|
# plts = []
|
||||||
|
# plt_i=0
|
||||||
|
# for i in range(len(fields)):
|
||||||
|
# if i != 0 or plot_config[fields[i]]['group']=="-1" : # i=0 -> Ne pas afficher car c'est temps (variable t)
|
||||||
|
# if plot_config[fields[i]]['group']=="0" : # Pas de groupe : nouveau plot
|
||||||
|
# plts.append(self.canvas.subplot)
|
||||||
|
|
||||||
|
plt = self.canvas.subplot
|
||||||
|
plt.cla()
|
||||||
|
for i in range(len(fields)):
|
||||||
|
if i != 0 : # i=0 -> Ne pas afficher car c'est temps (variable t)
|
||||||
|
if twin_config[1][0].text == "True": # Configuration des plots activée
|
||||||
|
plt.plot(xdata[i], ydata[i], label=fields[i], color=plot_config[fields[i]]['color'],
|
||||||
|
linewidth=plot_config[fields[i]]['linewidth'], linestyle=plot_config[fields[i]]['linestyle'], marker=plot_config[fields[i]]['marker'])
|
||||||
|
else:
|
||||||
|
plt.plot(xdata[i], ydata[i], '.-', label=fields[i])
|
||||||
|
|
||||||
|
# Décoration
|
||||||
|
plt.set_xlabel("Temps (s)")
|
||||||
|
plt.set_ylabel("Valeurs")
|
||||||
|
plt.set_title(sys.argv[1])
|
||||||
|
plt.axhline(linewidth=1, color='k')
|
||||||
|
plt.grid(True, linestyle='--')
|
||||||
|
plt.legend()
|
||||||
|
|
||||||
# Redraw
|
# Redraw
|
||||||
self.canvas.draw()
|
self.canvas.draw()
|
||||||
|
Loading…
Reference in New Issue
Block a user