diff --git a/monte_charge/montchg.py b/monte_charge/montchg.py index 2b9e91d..2162e05 100644 --- a/monte_charge/montchg.py +++ b/monte_charge/montchg.py @@ -52,6 +52,12 @@ def init(cont): scene.objects['Moteur pignon']['init_rx']=scene.objects['Moteur pignon'].worldOrientation.to_euler().x scene.objects['Moteur pignon']['init_ry']=scene.objects['Moteur pignon'].worldOrientation.to_euler().y scene.objects['Moteur pignon']['init_rz']=scene.objects['Moteur pignon'].worldOrientation.to_euler().z + + # Description des composants sensibles + scene.objects['Bp niveau 0']['description']="Bouton poussoir appel niveau 0 : ba_0()" + scene.objects['Bp niveau 1']['description']="Bouton poussoir appel niveau 1 : ba_1()" + scene.objects['Microrupteur niveau 0']['description']="Capteur présence cabine niveau 0 : pc_0()" + scene.objects['Microrupteur niveau 1']['description']="Capteur présence cabine niveau 1 : pc_1()" system_init() # Initialisation du système diff --git a/monte_charge/montchg_cmd.py b/monte_charge/montchg_cmd.py index 8a8d66d..79facad 100644 --- a/monte_charge/montchg_cmd.py +++ b/monte_charge/montchg_cmd.py @@ -42,6 +42,8 @@ brochage={} def commandes(): + jumeau() + # Ecrire votre code ici ... while True: voy_0(True) diff --git a/monte_charge/montchg_lib.py b/monte_charge/montchg_lib.py index d5e225d..c6e4d68 100644 --- a/monte_charge/montchg_lib.py +++ b/monte_charge/montchg_lib.py @@ -1,6 +1,6 @@ import bge # Bibliothèque Blender Game Engine (UPBGE) -from twin_threading import thread_cmd_start, thread_cmd_stop, fin # Multithreading -from twin_serial import jumeau # Liaison série +from twin_threading import thread_cmd_start, thread_cmd_stop, thread_cmd_end # Multithreading +import twin_serial # Liaison série import time ############################################################################### @@ -9,7 +9,7 @@ import time # @project: Blender-EduTech # @lang: fr # @authors: Philippe Roy -# @copyright: Copyright (C) 2022 Philippe Roy +# @copyright: Copyright (C) 2022-2023 Philippe Roy # @license: GNU GPL ############################################################################### @@ -77,8 +77,28 @@ def ba_1 (): return scene.objects['Bp niveau 1']['activated'] ############################################################################### -# Temporisation +# Jumeau ############################################################################### +def jumeau (): + twin_serial.open() + +############################################################################### +# Cycle +############################################################################### + +# Temporisation def tempo (duree): time.sleep(duree) + +# Fin +def end(): + if scene.objects['System']['twins']: + twin_serial.close() + thread_cmd_end() + +def fin(): + end() + +def quit(): + end() diff --git a/monte_charge/monte_charge-4.blend b/monte_charge/monte_charge-4.blend index 2c41718..d2ca68e 100644 Binary files a/monte_charge/monte_charge-4.blend and b/monte_charge/monte_charge-4.blend differ diff --git a/portail_coulissant/porcou.py b/portail_coulissant/porcou.py index 82ffb24..5159cce 100644 --- a/portail_coulissant/porcou.py +++ b/portail_coulissant/porcou.py @@ -47,6 +47,14 @@ def init(cont): scene.objects['Engrenage']['init_rx']=scene.objects['Engrenage'].worldOrientation.to_euler().x scene.objects['Engrenage']['init_ry']=scene.objects['Engrenage'].worldOrientation.to_euler().y scene.objects['Engrenage']['init_rz']=scene.objects['Engrenage'].worldOrientation.to_euler().z + + # Description des composants sensibles + scene.objects['Bp cote cour']['description']="Bouton poussoir coté cour : bp_int()" + scene.objects['Bp cote rue']['description']="Bouton poussoir coté rue : bp_ext()" + scene.objects['Microrupteur fdc ouvert']['description']="Capteur fin de course portail ouvert : fdc_o()" + scene.objects['Microrupteur fdc ferme']['description']="Capteur fin de course portail fermé : fdc_f()" + scene.objects['Emetteur IR']['description']="Capteur barrage IR (absence d\"obstacle) : ir_recep()" + scene.objects['Recepteur IR']['description']="Capteur barrage IR (absence d\"obstacle) : ir_recep()" system_init() # Initialisation du système diff --git a/portail_coulissant/porcou_cmd.py b/portail_coulissant/porcou_cmd.py index 5834daa..720c0f9 100644 --- a/portail_coulissant/porcou_cmd.py +++ b/portail_coulissant/porcou_cmd.py @@ -42,7 +42,9 @@ brochage={} def commandes(): # Ecrire votre code ici ... + # jumeau() gyr(True) # Activer le gyrophare + # ir_emet(True) while True: pass diff --git a/portail_coulissant/porcou_lib.py b/portail_coulissant/porcou_lib.py index 921c57e..b71426c 100644 --- a/portail_coulissant/porcou_lib.py +++ b/portail_coulissant/porcou_lib.py @@ -1,6 +1,6 @@ import bge # Bibliothèque Blender Game Engine (UPBGE) -from twin_threading import thread_cmd_start, thread_cmd_stop, fin # Multithreading -from twin_serial import jumeau # Liaison série +from twin_threading import thread_cmd_start, thread_cmd_stop, thread_cmd_end # Multithreading +import twin_serial # Liaison série import time ############################################################################### @@ -9,7 +9,7 @@ import time # @project: Blender-EduTech # @lang: fr # @authors: Philippe Roy -# @copyright: Copyright (C) 2020-2022 Philippe Roy +# @copyright: Copyright (C) 2020-2023 Philippe Roy # @license: GNU GPL ############################################################################### @@ -98,8 +98,28 @@ def bp_int (): return scene.objects['Bp cote cour']['activated'] ############################################################################### -# Temporisation +# Jumeau ############################################################################### +def jumeau (): + twin_serial.open() + +############################################################################### +# Cycle +############################################################################### + +# Temporisation def tempo (duree): time.sleep(duree) + +# Fin +def end(): + if scene.objects['System']['twins']: + twin_serial.close() + thread_cmd_end() + +def fin(): + end() + +def quit(): + end() diff --git a/portail_coulissant/portail_coulissant-17.blend b/portail_coulissant/portail_coulissant-17.blend index 99148a0..d791e55 100644 Binary files a/portail_coulissant/portail_coulissant-17.blend and b/portail_coulissant/portail_coulissant-17.blend differ diff --git a/twin.py b/twin.py index e60f110..86bb47a 100644 --- a/twin.py +++ b/twin.py @@ -197,7 +197,6 @@ def cmd_hl(cont): "About-cmd": "A propos"} scene.objects['Cmd-text']['modal']= False scene.objects['Cmd-text']['Text']= text_hl[obj.name] - print (obj.name) if scene.objects['Doc']['page_chap']== "" and obj.name =="Doc-cmd-colbox" : scene.objects['Cmd-text']['Text']= "Chargement de la documentation ..." if scene.objects['Doc']['page_chap']!= "" and obj.name =="Doc-cmd-colbox" : @@ -547,7 +546,6 @@ def cycle_end (cont): def cycle_hl(cont): obj = cont.owner - # name=obj.name # Passif if "active" in obj.getPropertyNames(): @@ -559,15 +557,15 @@ def cycle_hl(cont): if cont.sensors['MO'].status == JUST_ACTIVATED and scene.objects['System']['run']: obj.color = color_hl obj['mo'] = True - # scene.objects[name].color = color_hl - # scene.objects[name]['mo'] = True + if obj['description'] is not None: + scene.objects['Cmd-text']['Text']=obj['description'] + scene.objects['Cmd-text'].setVisible(True,True) # Désactivation - if cont.sensors['MO'].status == JUST_RELEASED: + if cont.sensors['MO'].status == JUST_RELEASED and scene.objects['System']['run']: obj.color = color_active obj['mo'] = False - # scene.objects[name].color = color_active - # scene.objects[name]['mo'] = False + scene.objects['Cmd-text']['Text']="" ## # Click sur les éléments cliquables du systèmes (activation numérique) @@ -587,7 +585,6 @@ def cycle_click(cont): # Activation if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive and scene.objects['System']['manip_mode']==0: obj.color = color_activated - # scene.objects[name].color = color_activated obj['activated'] = True obj['click'] = True # Modele 3d -> Arduino : FIXME @@ -599,7 +596,5 @@ def cycle_click(cont): # Modele 3d -> Arduino : FIXME if cont.sensors['MO'].positive: obj.color = color_hl - # scene.objects[name].color = color_hl else: obj.color = color_active - # scene.objects[name].color = color_active diff --git a/twin_config.xml b/twin_config.xml index 5fc687a..7500901 100644 --- a/twin_config.xml +++ b/twin_config.xml @@ -1,7 +1,7 @@ - 1280 - 720 + 1411 + 794 1 \ No newline at end of file diff --git a/twin_serial.py b/twin_serial.py index 202300c..3a7e87e 100644 --- a/twin_serial.py +++ b/twin_serial.py @@ -1,5 +1,6 @@ import bge # Bibliothèque Blender Game Engine (UPBGE) import numpy as np +import time import serial # Liaison série import pyfirmata # Protocole Firmata @@ -18,11 +19,13 @@ from serial.tools.list_ports import comports # Détection du port automatique # UPBGE scene scene = bge.logic.getCurrentScene() +board = None + ## # Recherche automatique du port ## -def serial_autoget_port(): +def autoget_port(): # USB Vendor ID, USB Product ID board_dict={'microbit' :[3368, 516], 'uno' :[9025, 67], @@ -59,7 +62,7 @@ def serial_init(port,speed): # Affiche la liste des cartes (communication série) ## -def serial_devices(): +def devices(): for com in comports(): print ("Name : "+str(com.name)+"\n" +" Device : "+str(com.device)+"\n" @@ -78,16 +81,16 @@ def serial_devices(): # pyfirmata : baudrate=57600 ## -def jumeau(pins): +# def jumeau(pins): +def open(): global board - # global gyr_pin # UI : étape 1 scene.objects['Twins-text']['Text'] = "Connection en cours ..." # Mise en place de la carte speed = 57600 - [device,board_name] =serial_autoget_port() # Recherche automatique du port + [device,board_name] =autoget_port() # Recherche automatique du port if device is None: scene.objects['System']['twins'] = False scene.objects['Twins-text']['Text'] = "Aucune connection disponible : jumeau réel débranché." @@ -110,7 +113,7 @@ def jumeau(pins): scene.objects['Twins-text']['Text'] = "Connection ouverte : "+device+" - "+str(speed)+" baud." else: scene.objects['Twins-text']['Text'] = "Connection ouverte : "+board_name+" sur "+device+" à "+str(speed)+" baud." - tempo (0.1) + time.sleep(0.1) # Déclaration des entrées - sorties # for pin in pins: @@ -138,16 +141,23 @@ def jumeau(pins): # Fermeture de la communication série ## -def jumeau_close(): +def close(): global board - # twins_serial.close() # Fermer proprement le port série + scene.objects['Twins-text']['Text'] = "Connection fermée." board.exit() # Fermer proprement la communication avec la carte scene.objects['System']['twins'] = False - scene.objects['Twins-text']['Text'] = "Connection fermée." + +# def jumeau_close(): +# global board +# scene.objects['Twins-text']['Text'] = "Connection fermée." +# print ("Connection fermée.") +# # twins_serial.close() # Fermer proprement le port série +# board.exit() # Fermer proprement la communication avec la carte +# scene.objects['System']['twins'] = False # Configuration manuelle du port # FIXME -def jumeau_config(port, speed): +def config(port, speed): pass # global board # global twins_serial diff --git a/twin_threading.py b/twin_threading.py index c8a887c..d5b6415 100644 --- a/twin_threading.py +++ b/twin_threading.py @@ -3,6 +3,7 @@ import threading # Multithreading import trace import sys import time +import twin_serial # Liaison série ############################################################################### # twin_threading.py @@ -64,6 +65,7 @@ def thread_start(threads, type_txt, fct): if (debug_thread): print ("Thread",type_txt, "#", len(threads)-1, "open.") +# Stop des threads def thread_stop(threads, type_txt): i=0 zombie_flag=False @@ -94,27 +96,21 @@ def thread_stop(threads, type_txt): print ("There are zombies threads",type_txt, ".") return False +############################################################################### +# Fonctions utilisateur +############################################################################### + def thread_cmd_start(fct): thread_start(threads_cmd, "commands", fct) def thread_cmd_stop(): + if scene.objects['System']['twins']: + twin_serial.close() thread_stop(threads_cmd, "commands") -def end(): - - # Jumeau numérique - # if scene.objects['System']['twins']: - # jumeau_close() - - # Thread +def thread_cmd_end(): if (debug_thread): print ("Thread commands is arrived.") time.sleep(0.125) scene.objects['System']['thread_cmd']=False time.sleep(0.125) - -def fin(): - end() - -def quit(): - end() diff --git a/volet_roulant/volet_roulant-17.blend b/volet_roulant/volet_roulant-17.blend index 47ccb99..d10925c 100644 Binary files a/volet_roulant/volet_roulant-17.blend and b/volet_roulant/volet_roulant-17.blend differ diff --git a/volet_roulant/volrou.py b/volet_roulant/volrou.py index d400bed..9d9ed5e 100644 --- a/volet_roulant/volrou.py +++ b/volet_roulant/volrou.py @@ -38,6 +38,15 @@ def init(cont): twin.manip_init() # Manipulation du modèle 3D twin.cmd_init() # Commandes + + # Description des composants sensibles + scene.objects['Bp monter']['description']="Bouton poussoir monter volet : bp_m()" + scene.objects['Bp descendre']['description']="Bouton poussoir descendre volet : bp_d()" + scene.objects['Bp arret']['description']="Bouton poussoir arrêt volet : bp_a()" + scene.objects['Bp auto']['description']="Bouton poussoir mode automatique : bp_auto()" + scene.objects['Microrupteur haut']['description']="Capteur fin de course volet en haut : fdc_h()" + scene.objects['Microrupteur bas']['description']="Capteur fin de course volet en bas : fdc_b()" + scene.objects['Recepteur LDR']['description']="Capteur de luminosité (LDR) : lum()" system_init() # Initialisation du système diff --git a/volet_roulant/volrou_cmd.py b/volet_roulant/volrou_cmd.py index 0184e29..f16e1c3 100644 --- a/volet_roulant/volrou_cmd.py +++ b/volet_roulant/volrou_cmd.py @@ -45,6 +45,7 @@ brochage={} def commandes(): # Ecrire votre code ici ... + jumeau() voy_auto(True) # Activer le gyrophare while True: pass diff --git a/volet_roulant/volrou_lib.py b/volet_roulant/volrou_lib.py index 7fb599d..9984818 100644 --- a/volet_roulant/volrou_lib.py +++ b/volet_roulant/volrou_lib.py @@ -1,6 +1,6 @@ import bge # Bibliothèque Blender Game Engine (UPBGE) -from twin_threading import thread_cmd_start, thread_cmd_stop, fin # Multithreading -from twin_serial import jumeau # Liaison série +from twin_threading import thread_cmd_start, thread_cmd_stop, thread_cmd_end # Multithreading +import twin_serial # Liaison série import time ############################################################################### @@ -93,8 +93,28 @@ def bp_auto (): return scene.objects['Bp auto']['activated'] ############################################################################### -# Temporisation +# Jumeau ############################################################################### +def jumeau (): + twin_serial.open() + +############################################################################### +# Cycle +############################################################################### + +# Temporisation def tempo (duree): time.sleep(duree) + +# Fin +def end(): + if scene.objects['System']['twins']: + twin_serial.close() + thread_cmd_end() + +def fin(): + end() + +def quit(): + end()