import bge # Bibliothèque Blender Game Engine (UPBGE) import twin # Bibliothèque de l'environnement 3D des jumeaux numériques import math import time ############################################################################### # volrou.py # @title: Commandes pour le volet roulant # @project: Blender-EduTech # @lang: fr # @authors: Philippe Roy # @copyright: Copyright (C) 2022 Philippe Roy # @license: GNU GPL ############################################################################### # Récupérer la scène UPBGE scene = bge.logic.getCurrentScene() # Couleurs color_passive = (0.800, 0.005, 0.315,1) # bouton non activable : magenta color_active = (0.799, 0.130, 0.063,1) # bouton activable : orange color_hl = (0.8, 0.8, 0.8, 1) # bouton focus : blanc color_activated = (0.8, 0.619, 0.021, 1) # bouton activé : jaune # Constantes UPBGE 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 ############################################################################### # Initialisation de la scène ############################################################################### def init(cont): if cont.sensors['Init'].positive == False: # 1 seule fois return False twin.manip_init() # Manipulation du modèle 3D twin.cmd_init() # Commandes # Mémorisation de la position et orientation des composants du système # FIXME : animation par keyframe # scene.objects['Portail']['init_lx']=scene.objects['Portail'].worldPosition.x # scene.objects['Portail']['init_ly']=scene.objects['Portail'].worldPosition.y # scene.objects['Portail']['init_lz']=scene.objects['Portail'].worldPosition.z # 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 system_init() # Initialisation du système ############################################################################### # Voyants ############################################################################### ## # Etat voyant mode automatique # Modele 3d -> Arduino : FIXME # Arduino -> Modele 3d : FIXME ## def voy_auto (cont): if scene.objects['System']['run']: obj = cont.owner if obj['activated'] and scene.objects['Led auto-on'].visible == False: scene.objects['Led auto-on'].setVisible(True,False) scene.objects['Led auto'].setVisible(False,False) if obj['activated']==False and scene.objects['Led auto-on'].visible == True: scene.objects['Led auto'].setVisible(True,False) scene.objects['Led auto-on'].setVisible(False,False) ############################################################################### # Actionneurs ############################################################################### ## # Moteur et volet # Modele 3d -> Arduino : FIXME # Arduino -> Modele 3d : FIXME ## def mot (cont): if scene.objects['System']['run']: obj = cont.owner print (obj['frame']) # Monter if obj['up']: start = 1 end = 100 layer = 0 priority = 1 blendin = 1.0 mode = bge.logic.KX_ACTION_MODE_PLAY layerWeight = 0.0 ipoFlags = 0 speed = 0.5 scene.objects['Axe enrouleur'].playAction('Axe enrouleur-Up', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) scene.objects['Axe fdc'].playAction('Axe fdc-Up', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) scene.objects['Lame volet 1'].playAction('Lame volet 1-Up', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) scene.objects['Lame volet 2'].playAction('Lame volet 2-Up', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) scene.objects['Lame volet 3'].playAction('Lame volet 3-Up', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) scene.objects['Lame volet 4'].playAction('Lame volet 4-Up', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) scene.objects['Lame volet 5'].playAction('Lame volet 5-Up', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) scene.objects['Lame volet 6'].playAction('Lame volet 6-Up', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) scene.objects['Lame volet 7'].playAction('Lame volet 7-Up', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) scene.objects['Lame volet 8'].playAction('Lame volet 8-Up', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) scene.objects['Lame volet 9'].playAction('Lame volet 9-Up', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) scene.objects['Lame volet 10'].playAction('Lame volet 10-Up', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) scene.objects['Lame volet 11'].playAction('Lame volet 11-Up', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) scene.objects['Lame volet 12'].playAction('Lame volet 12-Up', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) scene.bjects['Lame volet 13'].playAction('Lame volet 13-Up', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) time.sleep(0.125) obj['up']= False # FIXME : Touner sans fin # Descendre if obj['down']: start = 1 end = 100 layer = 0 priority = 1 blendin = 1.0 mode = bge.logic.KX_ACTION_MODE_PLAY layerWeight = 0.0 ipoFlags = 0 speed = 0.5 scene.objects['Axe enrouleur'].playAction('Axe enrouleur-Down', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) scene.objects['Axe fdc'].playAction('Axe fdc-Down', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) scene.objects['Lame volet 1'].playAction('Lame volet 1-Down', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) scene.objects['Lame volet 2'].playAction('Lame volet 2-Down', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) scene.objects['Lame volet 3'].playAction('Lame volet 3-Down', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) scene.objects['Lame volet 4'].playAction('Lame volet 4-Down', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) scene.objects['Lame volet 5'].playAction('Lame volet 5-Down', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) scene.objects['Lame volet 6'].playAction('Lame volet 6-Down', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) scene.objects['Lame volet 7'].playAction('Lame volet 7-Down', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) scene.objects['Lame volet 8'].playAction('Lame volet 8-Down', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) scene.objects['Lame volet 9'].playAction('Lame volet 9-Down', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) scene.objects['Lame volet 10'].playAction('Lame volet 10-Down', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) scene.objects['Lame volet 11'].playAction('Lame volet 11-Down', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) scene.objects['Lame volet 12'].playAction('Lame volet 12-Down', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) scene.bjects['Lame volet 13'].playAction('Lame volet 13-Down', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) time.sleep(0.125) obj['down']= False # FIXME : Touner sans fin ############################################################################### # Capteurs fin de course ############################################################################### ## # Etat capteur fin de course volet en haut # Modele 3d -> Arduino : FIXME # Arduino -> Modele 3d : FIXME ## def fdc_h (cont): if scene.objects['System']['run'] : obj = cont.owner # Etat capteur en fonction de la grille : worldPosition.x : 0 -> 65.5 et localPosition.x : 0 -> 218 # FIXME : animation par keyframe # if scene.objects['Portail'].localPosition.x <= 0 and obj['activated'] == False : # obj['activated'] = True # if scene.objects['Portail'].localPosition.x > 0 and obj['activated'] == True : # obj['activated'] = False # Forçage (click) if obj['click'] == True: obj['activated'] = True # Couleurs if obj['activated'] == True and obj.color !=color_activated: obj.color =color_activated if obj['activated'] == False : if obj['mo'] == True and obj.color !=color_hl: obj.color =color_hl if obj['mo'] == False and obj.color !=color_active: obj.color =color_active ## # Etat capteur fin de course volet en bas # Modele 3d -> Arduino : FIXME # Arduino -> Modele 3d : FIXME ## def fdc_b (cont): if scene.objects['System']['run'] : obj = cont.owner # Etat capteur en fonction de la grille : worldPosition.x : 0 -> 65.5 et localPosition.x : 0 -> 218 # FIXME : animation par keyframe # if scene.objects['Portail'].localPosition.x >= 218 and obj['activated'] == False : # obj['activated'] = True # if scene.objects['Portail'].localPosition.x < 218 and obj['activated'] == True : # obj['activated'] = False # Forçage (click) if obj['click'] == True: obj['activated'] = True # Couleurs if obj['activated'] == True and obj.color !=color_activated: obj.color =color_activated if obj['activated'] == False : if obj['mo'] == True and obj.color !=color_hl: obj.color =color_hl if obj['mo'] == False and obj.color !=color_active: obj.color =color_active ############################################################################### # Boutons ############################################################################### # Modele 3d -> Arduino : FIXME # Arduino -> Modele 3d : FIXME # Arduino -> numérique # bt_a_m_txt = txt_extrac_bool(serial_msg,"bt_a_m: ") # bt_a_d_txt = txt_extrac_bool(serial_msg,"bt_a_d: ") # bt_b_m_txt = txt_extrac_bool(serial_msg,"bt_b_m: ") # bt_b_d_txt = txt_extrac_bool(serial_msg,"bt_b_d: ") # bt_c_m_txt = txt_extrac_bool(serial_msg,"bt_c_m: ") # bt_c_d_txt = txt_extrac_bool(serial_msg,"bt_c_d: ") # bp_phy('Bp Am', bt_a_m_txt) # bp_phy('Bp Ad', bt_a_d_txt) # bp_phy('Bp Bm', bt_b_m_txt) # bp_phy('Bp Bd', bt_b_d_txt) # bp_phy('Bp Cm', bt_c_m_txt) # bp_phy('Bp Cd', bt_c_d_txt) # # Affichage de l'activation physique des boutons # def bp_phy(obj_name, bp_phy_sig): # obj=scene.objects[obj_name] # if bp_phy_sig =="0": # obj['actif_phy'] = True # obj.color = couleur_jaune # else: # if obj['actif_phy']: # obj['actif_phy'] = False # obj.color = couleur_orange ############################################################################### # Système ############################################################################### ## # Initialisation du système # Le moteur est géré en continue. ## def system_init (): # Voyants statiques scene.objects['Led capteur courant'].setVisible(True,False) scene.objects['Led capteur courant-on'].setVisible(False,False) scene.objects['Led moteur'].setVisible(True,False) scene.objects['Led moteur-on'].setVisible(False,False) scene.objects['Led alimentation'].setVisible(True,False) scene.objects['Led alimentation-on'].setVisible(False,False) system_reset() ## # Réinitialisation du système ## def system_reset (): # Voyants aux états initiaux scene.objects['Led auto'].setVisible(True,False) scene.objects['Led auto-on'].setVisible(False,False) # Volet # FIXME : animation par keyframe # I/O à l'état initial scene.objects['Led auto']['activated']=False scene.objects['Bp monter']['activated']=False scene.objects['Bp arret']['activated']=False scene.objects['Bp descendre']['activated']=False scene.objects['Bp auto']['activated']=False scene.objects['Microrupteur haut']['activated']=False scene.objects['Microrupteur bas']['activated']=False scene.objects['Moteur']['up']=False scene.objects['Moteur']['down']=False scene.objects['Recepteur LDR']['activated']=False