Bugfix : génération des plot bugée, simplification de la gestion des threads

This commit is contained in:
Philippe Roy 2023-01-28 17:39:15 +01:00
parent 95fbbfa09c
commit 370179d501
7 changed files with 53 additions and 71 deletions

View File

@ -87,6 +87,7 @@ def commandes():
" rad - cabine_vitesse : " +str(round(cabine_vitesse, 3))+" mm/s - moteur_vitesse : " +str(round(mot_vitesse, 3))+
" rad/s - cabine_pas : " +str(round(cabine_pas, 3))+" mm/impulsion - moteur_pas : " +str(round(mot_pas, 3))+" rad/impulsion")
plot(['mot_angle', 'mot_vitesse', 'cabine_z', 'cabine_vitesse'])
fin() # A garder
@ -96,6 +97,6 @@ def commandes():
###############################################################################
if __name__=='start':
thread_cmd_start(commandes)
start(commandes)
if __name__=='stop':
stop()

View File

@ -1,5 +1,5 @@
import bge # Bibliothèque Blender Game Engine (UPBGE)
from twin_threading import thread_cmd_start, thread_cmd_stop, thread_cmd_end # Multithreading
import twin_threading # Multithreading (multitâches)
from twin_serial import jumeau, jumeau_stop, serial_close # Liaison série
from twin_daq import get, daq, csv_generate, plot, plot_generate # Acquisition des données
import time
@ -23,6 +23,12 @@ JUST_RELEASED = bge.logic.KX_INPUT_JUST_RELEASED
ACTIVATE = bge.logic.KX_INPUT_ACTIVE
# JUST_DEACTIVATED = bge.logic.KX_SENSOR_JUST_DEACTIVATED
# Threads de commandes
threads_cmd=[]
# Threads de visualisation de données
threads_plot=[]
###############################################################################
# Voyants
###############################################################################
@ -115,12 +121,19 @@ def set_t (date):
def reset_t ():
scene.objects['System']['time']=0
##
# Départ
##
def start(fct):
twin_threading.start(threads_cmd, "commands", fct)
##
# Arrêt
##
def stop():
# Jumeau
if scene.objects['System']['twins']:
serial_close(scene.objects['System']['board'])
@ -130,35 +143,21 @@ def stop():
if scene.objects['System']['daq']:
csv_generate()
if scene.objects['System']['plot']:
plot_generate()
scene.objects['System']['plot_draw']=False # Plot
plot_generate(threads_plot)
# Thread
thread_cmd_stop()
twin_threading.stop(threads_cmd, "commands")
##
# Fin naturelle
##
def end():
# Jumeau
if scene.objects['System']['twins']:
serial_close(scene.objects['System']['board'])
time.sleep(1)
# Suivi de données
if scene.objects['System']['daq']:
csv_generate()
if scene.objects['System']['plot']:
plot_generate()
scene.objects['System']['plot_draw']=False # Plot
# Thread
thread_cmd_end()
fin()
def fin():
end()
def quit():
end()
if scene.objects['System']['debug_thread']:
print ("Thread commands is arrived.")
time.sleep(0.125)
scene.objects['System']['thread_cmd']=False
time.sleep(0.125)

Binary file not shown.

View File

@ -154,6 +154,7 @@ def plot(data_groups):
##
# Génération du graphique
# Threading -> reste actif après le Stop
##
def plot_generate_thread(csv_file):
@ -161,30 +162,10 @@ def plot_generate_thread(csv_file):
os.system(command)
def plot_generate(threads):
# Threading -> reste actif après le Stop
csv_file=os.path.join(os.path.split((scene.objects['System']['script']))[0], scene.objects['System']['system']+'.csv')
threads.append(threading.Thread(target=plot_generate_thread, args=(csv_file,)))
threads[len(threads)-1].start()
# exec : Bloquant
# csv_file=os.path.join(os.path.split((scene.objects['System']['script']))[0], scene.objects['System']['system']+'.csv')
# command = sys.executable + " " + os.path.join(sys.executable, os.getcwd(), "twin_plot_qt.py") + " "+ csv_file
# command2 = os.path.join(sys.executable, os.getcwd(), "twin_plot_qt.py") + " "+ csv_file
# command3 = os.path.join(sys.executable, os.getcwd(), "twin_plot_qt.py")
# exec(open(command3).read(), {}, {'csv_file': csv_file})
# subprocess : Bug
# Terminer le processus plot précédent
# if ('plot_proc' in scene.objects['System']):
# if scene.objects['System']['plot_proc'].poll()==None:
# scene.objects['System']['plot_proc'].terminate()
# Démarrer le processus plot
# fichier_csv=os.path.join(os.path.split((scene.objects['System']['script']))[0], scene.objects['System']['system']+'.csv')
# scene.objects['System']['plot_proc'] = subprocess.Popen([sys.executable, os.path.join(os.getcwd(), "twin_plot_qt.py"), fichier_csv])
# scene.objects['System']['plot']=False
###############################################################################
# Graphique interactif
# FIXME : ne marche pas

Binary file not shown.

View File

@ -84,7 +84,9 @@ def commandes():
print ("")
print ("Descendre : "+str(round(t1-t0, 3)) +" s - angle : " +str(round(a1-a0, 3)) + " rad - moteur_vitesse : " +str(round(mot_vitesse, 3))+
" rad/s - moteur_pas : " +str(round(mot_pas, 3))+" rad/impulsion")
plot (['mot_angle'])
fin() # A garder
@ -94,6 +96,6 @@ def commandes():
###############################################################################
if __name__=='start':
thread_cmd_start(commandes)
start(commandes)
if __name__=='stop':
stop()

View File

@ -1,5 +1,5 @@
import bge # Bibliothèque Blender Game Engine (UPBGE)
from twin_threading import thread_cmd_start, thread_cmd_stop, thread_cmd_end # Multithreading
import twin_threading # Multithreading (multitâches)
from twin_serial import jumeau, jumeau_stop, serial_close # Liaison série
from twin_daq import get, daq, csv_generate, plot, plot_generate # Acquisition des données
import time
@ -23,6 +23,12 @@ JUST_RELEASED = bge.logic.KX_INPUT_JUST_RELEASED
ACTIVATE = bge.logic.KX_INPUT_ACTIVE
# JUST_DEACTIVATED = bge.logic.KX_SENSOR_JUST_DEACTIVATED
# Threads de commandes
threads_cmd=[]
# Threads de visualisation de données
threads_plot=[]
###############################################################################
# Voyant
###############################################################################
@ -127,12 +133,19 @@ def set_t (date):
def reset_t ():
scene.objects['System']['time']=0
##
# Départ
##
def start(fct):
twin_threading.start(threads_cmd, "commands", fct)
##
# Arrêt
##
def stop():
# Jumeau
if scene.objects['System']['twins']:
serial_close(scene.objects['System']['board'])
@ -142,35 +155,21 @@ def stop():
if scene.objects['System']['daq']:
csv_generate()
if scene.objects['System']['plot']:
plot_generate()
scene.objects['System']['plot_draw']=False # Plot
plot_generate(threads_plot)
# Thread
thread_cmd_stop()
twin_threading.stop(threads_cmd, "commands")
##
# Fin naturelle
##
def end():
# Jumeau
if scene.objects['System']['twins']:
serial_close(scene.objects['System']['board'])
time.sleep(1)
# Suivi de données
if scene.objects['System']['daq']:
csv_generate()
if scene.objects['System']['plot']:
plot_generate()
scene.objects['System']['plot_draw']=False # Plot
# Thread
thread_cmd_end()
fin()
def fin():
end()
def quit():
end()
if scene.objects['System']['debug_thread']:
print ("Thread commands is arrived.")
time.sleep(0.125)
scene.objects['System']['thread_cmd']=False
time.sleep(0.125)