2022-12-18 22:46:19 +01:00
|
|
|
import bge # Bibliothèque Blender Game Engine (UPBGE)
|
2023-01-28 17:39:15 +01:00
|
|
|
import twin_threading # Multithreading (multitâches)
|
2023-02-03 05:58:20 +01:00
|
|
|
from twin_serial import jumeau, jumeau_stop, serial_close, jumeau_mode_system, jumeau_mode_object # Liaison série
|
2023-01-21 06:56:54 +01:00
|
|
|
from twin_daq import get, daq, csv_generate, plot, plot_generate # Acquisition des données
|
2022-12-18 22:46:19 +01:00
|
|
|
import time
|
|
|
|
|
|
|
|
###############################################################################
|
2022-12-19 17:28:29 +01:00
|
|
|
# volrou_lib.py
|
2022-12-18 22:46:19 +01:00
|
|
|
# @title: Bibliothèque utilisateur du volet roulant
|
|
|
|
# @project: Blender-EduTech
|
|
|
|
# @lang: fr
|
|
|
|
# @authors: Philippe Roy <philippe.roy@ac-grenoble.fr>
|
2023-01-01 17:34:01 +01:00
|
|
|
# @copyright: Copyright (C) 2022-2023 Philippe Roy
|
2022-12-18 22:46:19 +01:00
|
|
|
# @license: GNU GPL
|
|
|
|
###############################################################################
|
|
|
|
|
2023-01-08 19:55:18 +01:00
|
|
|
# Récupérer la scène UPBGE
|
2022-12-18 22:46:19 +01:00
|
|
|
scene = bge.logic.getCurrentScene()
|
|
|
|
|
|
|
|
# UPBGE constants
|
|
|
|
JUST_ACTIVATED = bge.logic.KX_INPUT_JUST_ACTIVATED
|
|
|
|
JUST_RELEASED = bge.logic.KX_INPUT_JUST_RELEASED
|
|
|
|
ACTIVATE = bge.logic.KX_INPUT_ACTIVE
|
|
|
|
# JUST_DEACTIVATED = bge.logic.KX_SENSOR_JUST_DEACTIVATED
|
|
|
|
|
2023-01-28 17:39:15 +01:00
|
|
|
# Threads de commandes
|
|
|
|
threads_cmd=[]
|
|
|
|
|
|
|
|
# Threads de visualisation de données
|
|
|
|
threads_plot=[]
|
|
|
|
|
2022-12-18 22:46:19 +01:00
|
|
|
###############################################################################
|
2022-12-23 14:30:13 +01:00
|
|
|
# Voyant
|
2022-12-18 22:46:19 +01:00
|
|
|
###############################################################################
|
|
|
|
|
2022-12-23 14:30:13 +01:00
|
|
|
# Ordre pour allumer le voyant témoin mode automatique
|
|
|
|
def voy_auto (order):
|
|
|
|
scene.objects['Led auto']['activated']=order
|
2022-12-18 22:46:19 +01:00
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# Actionneurs
|
|
|
|
###############################################################################
|
|
|
|
|
2022-12-23 14:30:13 +01:00
|
|
|
# Ordre pour le moteur pour monter le volet
|
|
|
|
def mot_m (order):
|
|
|
|
scene.objects['Moteur']['up']=order
|
|
|
|
|
|
|
|
# Ordre pour le moteur pour descendre le volet
|
|
|
|
def mot_d (order):
|
|
|
|
scene.objects['Moteur']['down']=order
|
2022-12-18 22:46:19 +01:00
|
|
|
|
2023-01-20 18:31:51 +01:00
|
|
|
# Réglage de la vitesse du moteur numérique
|
2023-02-04 13:28:28 +01:00
|
|
|
def mot_vitesse (speed=125.6):
|
|
|
|
scene.objects['Moteur']['speed_setting']=speed # Vitesse du moteur numérique : 125.6 rad /s ( 20 tr / s )
|
2023-01-20 18:31:51 +01:00
|
|
|
|
2022-12-18 22:46:19 +01:00
|
|
|
###############################################################################
|
|
|
|
# Capteurs
|
2023-02-15 17:56:49 +01:00
|
|
|
# Priorité à l'activation (binaire) ou la valeur la plus grande (numérique)
|
2022-12-18 22:46:19 +01:00
|
|
|
###############################################################################
|
|
|
|
|
2022-12-23 14:30:13 +01:00
|
|
|
# Compte-rendu du capteur fin de course volet en haut
|
|
|
|
def fdc_h ():
|
2023-01-08 19:55:18 +01:00
|
|
|
if scene.objects['Microrupteur haut']['activated'] or scene.objects['Microrupteur haut']['activated_real']:
|
|
|
|
return True
|
2023-02-04 13:28:28 +01:00
|
|
|
return False
|
2022-12-18 22:46:19 +01:00
|
|
|
|
2022-12-23 14:30:13 +01:00
|
|
|
# Compte-rendu du capteur fin de course volet en bas
|
2023-01-01 17:34:01 +01:00
|
|
|
def fdc_b():
|
2023-01-08 19:55:18 +01:00
|
|
|
if scene.objects['Microrupteur bas']['activated'] or scene.objects['Microrupteur bas']['activated_real']:
|
|
|
|
return True
|
2023-02-04 13:28:28 +01:00
|
|
|
return False
|
2022-12-18 22:46:19 +01:00
|
|
|
|
2022-12-24 03:10:30 +01:00
|
|
|
# Compte-rendu du capteur de luminosité
|
|
|
|
def lum():
|
2023-02-15 17:56:49 +01:00
|
|
|
if scene.objects['Recepteur LDR']['value'] > scene.objects['Recepteur LDR']['value_real']:
|
|
|
|
return (scene.objects['Recepteur LDR']['value'])
|
|
|
|
return (scene.objects['Recepteur LDR']['value_real'])
|
2022-12-24 03:10:30 +01:00
|
|
|
|
2022-12-18 22:46:19 +01:00
|
|
|
###############################################################################
|
|
|
|
# Boutons poussoirs
|
|
|
|
###############################################################################
|
|
|
|
|
2022-12-23 14:30:13 +01:00
|
|
|
# Compte-rendu du bouton monter volet
|
|
|
|
def bp_m ():
|
2023-01-08 19:55:18 +01:00
|
|
|
if scene.objects['Bp monter']['activated'] or scene.objects['Bp monter']['activated_real']:
|
|
|
|
return True
|
2023-02-04 13:28:28 +01:00
|
|
|
return False
|
2022-12-23 14:30:13 +01:00
|
|
|
|
|
|
|
# Compte-rendu du bouton arrêt volet
|
|
|
|
def bp_a ():
|
2023-01-08 19:55:18 +01:00
|
|
|
if scene.objects['Bp arret']['activated'] or scene.objects['Bp arret']['activated_real']:
|
|
|
|
return True
|
2023-02-04 13:28:28 +01:00
|
|
|
return False
|
2022-12-23 14:30:13 +01:00
|
|
|
|
|
|
|
# Compte-rendu du bouton descendre volet
|
|
|
|
def bp_d ():
|
2023-01-08 19:55:18 +01:00
|
|
|
if scene.objects['Bp descendre']['activated'] or scene.objects['Bp descendre']['activated_real']:
|
|
|
|
return True
|
2023-02-04 13:28:28 +01:00
|
|
|
return False
|
2022-12-18 22:46:19 +01:00
|
|
|
|
2023-02-11 23:52:07 +01:00
|
|
|
# Compte-rendu du bouton poussoir mode automatique
|
2022-12-23 14:30:13 +01:00
|
|
|
def bp_auto ():
|
2023-02-04 13:28:28 +01:00
|
|
|
if scene.objects['Bp auto']['activated'] or scene.objects['Bp auto']['activated_real']:
|
|
|
|
return True
|
|
|
|
return False
|
2022-12-18 22:46:19 +01:00
|
|
|
|
2023-02-11 23:52:07 +01:00
|
|
|
# Compte-rendu du bouton à glissière mode automatique
|
|
|
|
def bg_auto ():
|
|
|
|
if scene.objects['Bg auto']['activated'] or scene.objects['Bg auto']['activated_real']:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2023-02-03 05:58:20 +01:00
|
|
|
###############################################################################
|
|
|
|
# Jumelage
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
# Mode de jumelage (règles d'activation)
|
|
|
|
def jumeau_mode (input_real=True, input_digital=True, output_real=True, output_digital=True):
|
2023-02-11 23:52:07 +01:00
|
|
|
input_objs = ['Bp monter', 'Bp arret', 'Bp descendre', 'Bp auto', 'Bg auto', 'Microrupteur haut', 'Microrupteur bas', 'Recepteur LDR']
|
2023-02-03 05:58:20 +01:00
|
|
|
output_objs = ['Moteur', 'Led auto']
|
|
|
|
jumeau_mode_system (input_objs, output_objs, input_real, input_digital, output_real, output_digital)
|
|
|
|
|
2023-01-06 21:23:44 +01:00
|
|
|
###############################################################################
|
|
|
|
# Cycle
|
2022-12-18 22:46:19 +01:00
|
|
|
###############################################################################
|
|
|
|
|
2023-01-21 06:56:54 +01:00
|
|
|
##
|
2023-01-06 21:23:44 +01:00
|
|
|
# Temporisation
|
2023-01-21 06:56:54 +01:00
|
|
|
##
|
|
|
|
|
2022-12-18 22:46:19 +01:00
|
|
|
def tempo (duree):
|
|
|
|
time.sleep(duree)
|
2023-01-06 21:23:44 +01:00
|
|
|
|
2023-01-21 06:56:54 +01:00
|
|
|
##
|
2023-01-18 06:06:15 +01:00
|
|
|
# t (temps)
|
2023-01-21 06:56:54 +01:00
|
|
|
##
|
2023-01-18 06:06:15 +01:00
|
|
|
|
|
|
|
def get_t ():
|
2023-01-20 18:31:51 +01:00
|
|
|
# return truncate(scene.objects['System']['time'], 3)
|
|
|
|
return round(scene.objects['System']['time'], 3)
|
2023-01-18 06:06:15 +01:00
|
|
|
|
|
|
|
def set_t (date):
|
|
|
|
scene.objects['System']['time']=date
|
|
|
|
|
|
|
|
def reset_t ():
|
|
|
|
scene.objects['System']['time']=0
|
|
|
|
|
2023-01-28 17:39:15 +01:00
|
|
|
##
|
|
|
|
# Départ
|
|
|
|
##
|
|
|
|
|
|
|
|
def start(fct):
|
|
|
|
twin_threading.start(threads_cmd, "commands", fct)
|
|
|
|
|
2023-02-11 23:52:07 +01:00
|
|
|
##
|
|
|
|
# Variante
|
|
|
|
#
|
2023-02-13 16:43:13 +01:00
|
|
|
# Variante 1 : Le mode automatique s'active avec le bouton poussoir bp_auto et se désactive avec l'appui sur bp_m, bp_a ou bp_d.
|
2023-02-13 16:39:18 +01:00
|
|
|
# Variante 2 : Le mode automatique s'active et se désactive avec le bouton à glissière bg_auto.
|
2023-02-11 23:52:07 +01:00
|
|
|
#
|
|
|
|
# La variante 1 correspond à la maquette réelle de 4A technologie.
|
|
|
|
#
|
|
|
|
# Configuration des variantes du modèle 3D -> variant_dict :
|
|
|
|
# 'nom de l'objet 3D' : liste des variantes où l'objet est présent.
|
|
|
|
# Par défaut les objets sont présents quelque soit la variante sélectionnée.
|
|
|
|
##
|
|
|
|
|
2023-02-12 00:34:37 +01:00
|
|
|
def variant(variant_num):
|
|
|
|
if variant_num != scene.objects['System']['variant']:
|
|
|
|
print ("Variante de la maquette numérique:", variant_num)
|
|
|
|
scene.objects['System']['variant']=variant_num
|
2023-02-14 00:06:50 +01:00
|
|
|
variant_dict = {'Bp auto':[1], 'Bg auto':[2], 'Bg auto-on':[2]}
|
|
|
|
variant_list = list(variant_dict)
|
|
|
|
for name in variant_list:
|
|
|
|
if variant_num in variant_dict[name]:
|
|
|
|
scene.objects[name].setVisible(True,True)
|
|
|
|
scene.objects[name].restorePhysics()
|
|
|
|
else:
|
|
|
|
scene.objects[name].setVisible(False,True)
|
|
|
|
scene.objects[name].suspendPhysics()
|
2023-02-11 23:52:07 +01:00
|
|
|
|
2023-01-21 06:56:54 +01:00
|
|
|
##
|
2023-01-08 19:55:18 +01:00
|
|
|
# Arrêt
|
2023-01-21 06:56:54 +01:00
|
|
|
##
|
|
|
|
|
2023-01-08 19:55:18 +01:00
|
|
|
def stop():
|
2023-01-28 17:39:15 +01:00
|
|
|
|
2023-01-20 18:31:51 +01:00
|
|
|
# Jumeau
|
2023-01-08 19:55:18 +01:00
|
|
|
if scene.objects['System']['twins']:
|
2023-01-09 05:54:31 +01:00
|
|
|
serial_close(scene.objects['System']['board'])
|
2023-01-08 19:55:18 +01:00
|
|
|
time.sleep(1)
|
2023-01-20 18:31:51 +01:00
|
|
|
|
|
|
|
# Suivi de données
|
2023-01-21 06:56:54 +01:00
|
|
|
if scene.objects['System']['daq']:
|
2023-01-20 18:31:51 +01:00
|
|
|
csv_generate()
|
2023-01-21 06:56:54 +01:00
|
|
|
if scene.objects['System']['plot']:
|
2023-01-28 17:39:15 +01:00
|
|
|
plot_generate(threads_plot)
|
2023-01-21 06:56:54 +01:00
|
|
|
|
|
|
|
# Thread
|
2023-01-28 17:39:15 +01:00
|
|
|
twin_threading.stop(threads_cmd, "commands")
|
2023-01-08 19:55:18 +01:00
|
|
|
|
2023-01-21 06:56:54 +01:00
|
|
|
##
|
2023-01-08 19:55:18 +01:00
|
|
|
# Fin naturelle
|
2023-01-21 06:56:54 +01:00
|
|
|
##
|
|
|
|
|
2023-01-06 21:23:44 +01:00
|
|
|
def end():
|
2023-01-28 17:39:15 +01:00
|
|
|
fin()
|
2023-01-06 21:23:44 +01:00
|
|
|
|
|
|
|
def fin():
|
2023-01-28 17:39:15 +01:00
|
|
|
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)
|