mirror of
https://forge.apps.education.fr/blender-edutech/jumeaux-numeriques.git
synced 2024-01-27 06:56:18 +01:00
100 lines
4.3 KiB
Python
100 lines
4.3 KiB
Python
import bge # Bibliothèque Blender Game Engine (UPBGE)
|
|
import os
|
|
import sys
|
|
import importlib
|
|
import subprocess # Multiprocessus
|
|
import time
|
|
|
|
###############################################################################
|
|
# twin_plot.py
|
|
# @title: Visualisation des données
|
|
# @project: Blender-EduTech
|
|
# @lang: fr
|
|
# @authors: Philippe Roy <philippe.roy@ac-grenoble.fr>
|
|
# @copyright: Copyright (C) 2023 Philippe Roy
|
|
# @license: GNU GPL
|
|
###############################################################################
|
|
|
|
# UPBGE scene
|
|
scene = bge.logic.getCurrentScene()
|
|
|
|
# Récupérer la configuration du graphique
|
|
system=importlib.import_module(scene.objects['Doc']['system']) # Système
|
|
plot_config = system.get_pin_config()
|
|
|
|
###############################################################################
|
|
# Création du graphique
|
|
###############################################################################
|
|
|
|
def plot(data):
|
|
# subprocess.run([sys.executable, os.path.join(os.getcwd(), "twin_plot.py")], , stdin=subprocess.PIPE) # Process bloquant
|
|
|
|
# pin_config = {
|
|
# 'bp_ext' : [['d','i'],['Bp cote rue','pin'],['o','-', 'blue', 1]],
|
|
# 'bp_int' : [['d','i'],['Bp cote cour','pin'],['o','-', 'darkblue', 1]],
|
|
# 'fdc_o' : [['d','i'],['Microrupteur fdc ouvert','pin'],['o','-', 'violet', 1]],
|
|
# 'fdc_f' : [['d','i'],['Microrupteur fdc ferme','pin'],['o','-', 'darkviolet', 1]],
|
|
# 'mot_o' : [['d','o'],['Moteur','pin_o'],['o','-', 'green', 1]],
|
|
# 'mot_f' : [['d','o'],['Moteur','pin_f'],['o','-', 'darkgreen', 1]],
|
|
# 'gyr' : [['d','o'],['Led','pin'],['o','-', 'orange', 1]],
|
|
# 'ir_emet' : [['d','o'],['Emetteur IR','pin'],['o','-', 'red', 1]],
|
|
# 'ir_recep' : [['d','i'],['Recepteur IR','pin'],['o','-', 'darkred', 1]]}
|
|
|
|
# Terminer le processus précédent
|
|
if scene.objects['System']['plot_proc'] is not None:
|
|
if scene.objects['System']['plot_proc'].poll()==None:
|
|
scene.objects['System']['plot_proc'].terminate()
|
|
scene.objects['System']['plot_draw'] = True
|
|
scene.objects['System']['plot_time'] = 0
|
|
|
|
# Configuration des données
|
|
scene.objects['System']['plot_data'] =[]
|
|
for obj in data:
|
|
scene.objects['System']['plot_data'].append(plot_config[obj][1][0])
|
|
|
|
# Démarrer le processus
|
|
scene.objects['System']['plot_proc'] = subprocess.Popen([sys.executable, os.path.join(os.getcwd(), "twin_plot_qt.py")], stdin=subprocess.PIPE, stdout=subprocess.PIPE, encoding = 'utf8')
|
|
stout, sterr = scene.objects['System']['plot_proc'].communicate() # FIXME : attente du message retour pour lancer l'acquisition
|
|
scene.objects['System']['plot']=True
|
|
|
|
###############################################################################
|
|
# Mise à jour du graphique
|
|
###############################################################################
|
|
|
|
def plot_maj(cont):
|
|
if cont.sensors['Plot'].positive :
|
|
|
|
# Affichage du graphique
|
|
if scene.objects['System']['plot_draw']:
|
|
|
|
# Préparation du message
|
|
# FIXME : ajouter les valeurs réelles et valeurs numériques ('activated_real')
|
|
# msg=str(round(scene.objects['System']['plot_time'], 2))
|
|
msg=format(scene.objects['System']['plot_time'],".2f")
|
|
for obj in scene.objects['System']['plot_data']:
|
|
if scene.objects[obj]['activated']:
|
|
msg = msg+",1"
|
|
else:
|
|
msg = msg+",0"
|
|
msg = msg+"\n"
|
|
|
|
# Envoi (Pipe)
|
|
if scene.objects['System']['plot_proc'].poll()==None:
|
|
# scene.objects['System']['plot_proc'].communicate(input=time_send.encode())[0] # Communication bloquante
|
|
scene.objects['System']['plot_proc'].stdin.write(msg)
|
|
else:
|
|
print ("Stop")
|
|
scene.objects['System']['plot']=False
|
|
scene.objects['System']['plot_draw'] =False
|
|
scene.objects['System']['plot_proc'].terminate()
|
|
|
|
# Arret de l'affichage du graphique
|
|
else :
|
|
if scene.objects['System']['plot_proc'].poll()==None:
|
|
pass
|
|
else:
|
|
print ("Stop")
|
|
scene.objects['System']['plot']=False
|
|
scene.objects['System']['plot_draw'] =False
|
|
scene.objects['System']['plot_proc'].terminate()
|