2022-12-05 14:07:17 +01:00
|
|
|
|
import bge # Bibliothèque Blender Game Engine (UPBGE)
|
2022-12-13 02:42:31 +01:00
|
|
|
|
import twin # Bibliothèque de l'environnement 3D des jumeaux numériques
|
2022-12-05 14:07:17 +01:00
|
|
|
|
import math
|
|
|
|
|
import time
|
|
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
|
# porcou.py
|
|
|
|
|
# @title: Commandes pour le portail coulissant
|
|
|
|
|
# @project: Blender-EduTech
|
|
|
|
|
# @lang: fr
|
|
|
|
|
# @authors: Philippe Roy <philippe.roy@ac-grenoble.fr>
|
|
|
|
|
# @copyright: Copyright (C) 2020-2022 Philippe Roy
|
|
|
|
|
# @license: GNU GPL
|
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
|
|
# Récupérer la scène UPBGE
|
|
|
|
|
scene = bge.logic.getCurrentScene()
|
|
|
|
|
|
|
|
|
|
# Couleurs
|
2022-12-22 08:11:43 +01:00
|
|
|
|
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
|
2022-12-05 14:07:17 +01:00
|
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
2022-12-11 15:50:38 +01:00
|
|
|
|
###############################################################################
|
2022-12-13 02:42:31 +01:00
|
|
|
|
# Initialisation de la scène
|
2022-12-11 15:50:38 +01:00
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
|
|
def init(cont):
|
2022-12-16 00:37:11 +01:00
|
|
|
|
if cont.sensors['Init'].positive == False: # 1 seule fois
|
|
|
|
|
return False
|
|
|
|
|
|
2022-12-11 15:50:38 +01:00
|
|
|
|
twin.manip_init() # Manipulation du modèle 3D
|
|
|
|
|
twin.cmd_init() # Commandes
|
2022-12-30 05:13:11 +01:00
|
|
|
|
twin.manip_init() # Cacher les objets de l'aide
|
2022-12-11 15:50:38 +01:00
|
|
|
|
|
|
|
|
|
# Mémorisation de la position et orientation des composants du système
|
|
|
|
|
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
|
2023-01-06 21:23:44 +01:00
|
|
|
|
|
|
|
|
|
# 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()"
|
2022-12-11 15:50:38 +01:00
|
|
|
|
|
|
|
|
|
system_init() # Initialisation du système
|
|
|
|
|
|
|
|
|
|
###############################################################################
|
2022-12-05 14:07:17 +01:00
|
|
|
|
# Actionneurs
|
|
|
|
|
###############################################################################
|
|
|
|
|
|
2022-12-13 02:42:31 +01:00
|
|
|
|
##
|
2022-12-22 08:11:43 +01:00
|
|
|
|
# Gyrophare
|
|
|
|
|
# Modele 3d -> Arduino : FIXME
|
|
|
|
|
# Arduino -> Modele 3d : FIXME
|
2022-12-13 02:42:31 +01:00
|
|
|
|
##
|
|
|
|
|
|
2022-12-22 08:11:43 +01:00
|
|
|
|
def gyr (cont):
|
2022-12-11 15:50:38 +01:00
|
|
|
|
if scene.objects['System']['run']:
|
2022-12-05 14:07:17 +01:00
|
|
|
|
obj = cont.owner
|
2022-12-22 08:11:43 +01:00
|
|
|
|
if obj['activated'] and scene.objects['Led-on'].visible == False:
|
|
|
|
|
scene.objects['Led-on'].setVisible(True,False)
|
2022-12-05 14:07:17 +01:00
|
|
|
|
scene.objects['Led'].setVisible(False,False)
|
2022-12-22 08:11:43 +01:00
|
|
|
|
if obj['activated']==False and scene.objects['Led-on'].visible == True:
|
2022-12-05 14:07:17 +01:00
|
|
|
|
scene.objects['Led'].setVisible(True,False)
|
2022-12-22 08:11:43 +01:00
|
|
|
|
scene.objects['Led-on'].setVisible(False,False)
|
2022-12-05 14:07:17 +01:00
|
|
|
|
|
2022-12-13 02:42:31 +01:00
|
|
|
|
##
|
2022-12-22 08:11:43 +01:00
|
|
|
|
# Moteur et portail
|
|
|
|
|
# Modele 3d -> Arduino : FIXME
|
|
|
|
|
# Arduino -> Modele 3d : FIXME
|
2022-12-13 02:42:31 +01:00
|
|
|
|
##
|
|
|
|
|
|
2022-12-22 08:11:43 +01:00
|
|
|
|
def mot (cont):
|
2022-12-11 15:50:38 +01:00
|
|
|
|
if scene.objects['System']['run']:
|
2022-12-05 14:07:17 +01:00
|
|
|
|
obj = cont.owner
|
|
|
|
|
vitesse = 0.05
|
2022-12-22 08:11:43 +01:00
|
|
|
|
pas_portail = 2.35619/0.3 # pas echelle 1:1 = 2.35619 -> pas à l'échelle de la maquette (0,3) : 2.35619/0.3 = 7,85396
|
|
|
|
|
pas_engrenage = math.pi/7 # z = 14
|
|
|
|
|
obj_engrenage = scene.objects['Engrenage']
|
|
|
|
|
obj_portail = scene.objects['Portail']
|
|
|
|
|
obj_portail['x']= scene.objects['Portail'].localPosition.x # Affichage de la position du portail
|
|
|
|
|
if obj['open']:
|
|
|
|
|
obj_engrenage.applyRotation((0, 0, -pas_engrenage*vitesse), True)
|
|
|
|
|
obj_portail.applyMovement((-pas_portail*vitesse, 0, 0), True)
|
|
|
|
|
# else: # Pas de priorité
|
|
|
|
|
if obj['close']:
|
|
|
|
|
obj_engrenage.applyRotation((0, 0, pas_engrenage*vitesse), True)
|
|
|
|
|
obj_portail.applyMovement((pas_portail*vitesse, 0, 0), True)
|
2022-12-05 14:07:17 +01:00
|
|
|
|
|
2022-12-11 15:50:38 +01:00
|
|
|
|
###############################################################################
|
2022-12-05 14:07:17 +01:00
|
|
|
|
# Capteurs fin de course
|
|
|
|
|
###############################################################################
|
|
|
|
|
|
2022-12-13 02:42:31 +01:00
|
|
|
|
##
|
2022-12-05 14:07:17 +01:00
|
|
|
|
# Etat capteur fin de course portail ouvert
|
2022-12-22 08:11:43 +01:00
|
|
|
|
# Modele 3d -> Arduino : FIXME
|
|
|
|
|
# Arduino -> Modele 3d : FIXME
|
2022-12-13 02:42:31 +01:00
|
|
|
|
##
|
|
|
|
|
|
2022-12-22 08:11:43 +01:00
|
|
|
|
def fdc_o (cont):
|
2022-12-11 15:50:38 +01:00
|
|
|
|
if scene.objects['System']['run'] :
|
2022-12-05 14:07:17 +01:00
|
|
|
|
obj = cont.owner
|
2022-12-22 08:11:43 +01:00
|
|
|
|
|
2022-12-05 14:07:17 +01:00
|
|
|
|
# Etat capteur en fonction de la grille : worldPosition.x : 0 -> 65.5 et localPosition.x : 0 -> 218
|
2022-12-22 08:11:43 +01:00
|
|
|
|
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
|
|
|
|
|
|
2022-12-22 05:02:33 +01:00
|
|
|
|
# Couleurs
|
2022-12-22 08:11:43 +01:00
|
|
|
|
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
|
2022-12-13 02:42:31 +01:00
|
|
|
|
|
|
|
|
|
##
|
2022-12-05 14:07:17 +01:00
|
|
|
|
# Etat capteur fin de course portail fermé
|
2022-12-22 08:11:43 +01:00
|
|
|
|
# Modele 3d -> Arduino : FIXME
|
|
|
|
|
# Arduino -> Modele 3d : FIXME
|
2022-12-13 02:42:31 +01:00
|
|
|
|
##
|
|
|
|
|
|
2022-12-22 08:11:43 +01:00
|
|
|
|
def fdc_f (cont):
|
2022-12-11 15:50:38 +01:00
|
|
|
|
if scene.objects['System']['run'] :
|
2022-12-05 14:07:17 +01:00
|
|
|
|
obj = cont.owner
|
2022-12-22 08:11:43 +01:00
|
|
|
|
|
2022-12-05 14:07:17 +01:00
|
|
|
|
# Etat capteur en fonction de la grille : worldPosition.x : 0 -> 65.5 et localPosition.x : 0 -> 218
|
2022-12-22 08:11:43 +01:00
|
|
|
|
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
|
2022-12-05 14:07:17 +01:00
|
|
|
|
|
2022-12-22 08:11:43 +01:00
|
|
|
|
# Forçage (click)
|
|
|
|
|
if obj['click'] == True:
|
|
|
|
|
obj['activated'] = True
|
2022-12-13 02:42:31 +01:00
|
|
|
|
|
2022-12-22 08:11:43 +01:00
|
|
|
|
# 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
|
2022-12-05 14:07:17 +01:00
|
|
|
|
|
2022-12-11 15:50:38 +01:00
|
|
|
|
###############################################################################
|
2022-12-13 02:42:31 +01:00
|
|
|
|
# Capteur barrage
|
2022-12-05 14:07:17 +01:00
|
|
|
|
###############################################################################
|
|
|
|
|
|
2022-12-13 02:42:31 +01:00
|
|
|
|
##
|
2022-12-05 14:07:17 +01:00
|
|
|
|
# Emetteur IR
|
2022-12-13 02:42:31 +01:00
|
|
|
|
##
|
|
|
|
|
|
2022-12-22 08:11:43 +01:00
|
|
|
|
def ir_emet (cont):
|
2022-12-11 15:50:38 +01:00
|
|
|
|
if scene.objects['System']['run'] :
|
2022-12-05 14:07:17 +01:00
|
|
|
|
obj = cont.owner
|
2022-12-31 16:48:54 +01:00
|
|
|
|
|
|
|
|
|
# Passif
|
|
|
|
|
if obj['active'] == False and obj.color !=color_passive:
|
|
|
|
|
obj.color =color_passive
|
2022-12-05 14:07:17 +01:00
|
|
|
|
scene.objects['Emetteur IR Led'].setVisible(True,False)
|
2022-12-22 08:11:43 +01:00
|
|
|
|
scene.objects['Emetteur IR Led-on'].setVisible(False,False)
|
2022-12-31 16:48:54 +01:00
|
|
|
|
scene.objects['Recepteur IR']['active'] = False
|
|
|
|
|
|
|
|
|
|
# Active
|
|
|
|
|
if obj['active']:
|
|
|
|
|
|
|
|
|
|
# Allumage
|
|
|
|
|
if scene.objects['Emetteur IR Led-on'].visible == False:
|
|
|
|
|
scene.objects['Emetteur IR Led-on'].setVisible(True,False)
|
|
|
|
|
scene.objects['Emetteur IR Led'].setVisible(False,False)
|
|
|
|
|
obj.color = color_active
|
|
|
|
|
scene.objects['Recepteur IR']['active'] = True
|
|
|
|
|
|
|
|
|
|
# Forçage (click)
|
|
|
|
|
if obj['click'] == True:
|
|
|
|
|
obj['activated'] = True
|
|
|
|
|
scene.objects['Recepteur IR']['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
|
|
|
|
|
|
|
|
|
|
##
|
|
|
|
|
# Récepteur IR
|
|
|
|
|
##
|
|
|
|
|
|
|
|
|
|
def ir_recep (cont):
|
|
|
|
|
if scene.objects['System']['run'] :
|
|
|
|
|
obj = cont.owner
|
|
|
|
|
|
|
|
|
|
# Passif
|
|
|
|
|
if obj['active'] == False and obj.color !=color_passive:
|
|
|
|
|
obj.color =color_passive
|
|
|
|
|
|
|
|
|
|
# Active
|
|
|
|
|
if obj['active']:
|
|
|
|
|
|
|
|
|
|
# Forçage (click)
|
|
|
|
|
if obj['click'] == True:
|
|
|
|
|
obj['activated'] = True
|
|
|
|
|
scene.objects['Emetteur IR']['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
|
|
|
|
|
|
2022-12-05 14:07:17 +01:00
|
|
|
|
|
2022-12-11 15:50:38 +01:00
|
|
|
|
###############################################################################
|
2022-12-22 08:11:43 +01:00
|
|
|
|
# Boutons
|
2022-12-05 14:07:17 +01:00
|
|
|
|
###############################################################################
|
|
|
|
|
|
2022-12-22 08:11:43 +01:00
|
|
|
|
# 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
|
2022-12-05 14:07:17 +01:00
|
|
|
|
|
2022-12-11 15:50:38 +01:00
|
|
|
|
###############################################################################
|
|
|
|
|
# Système
|
2022-12-05 14:07:17 +01:00
|
|
|
|
###############################################################################
|
|
|
|
|
|
2022-12-13 02:42:31 +01:00
|
|
|
|
##
|
2022-12-11 15:50:38 +01:00
|
|
|
|
# Initialisation du système
|
2022-12-05 14:07:17 +01:00
|
|
|
|
# Le moteur est géré en continue.
|
2022-12-13 02:42:31 +01:00
|
|
|
|
##
|
|
|
|
|
|
2022-12-11 15:50:38 +01:00
|
|
|
|
def system_init ():
|
2022-12-22 08:11:43 +01:00
|
|
|
|
system_reset()
|
2022-12-05 14:07:17 +01:00
|
|
|
|
|
2022-12-13 02:42:31 +01:00
|
|
|
|
##
|
2022-12-11 15:50:38 +01:00
|
|
|
|
# Réinitialisation du système
|
2022-12-13 02:42:31 +01:00
|
|
|
|
##
|
|
|
|
|
|
2022-12-11 15:50:38 +01:00
|
|
|
|
def system_reset ():
|
2022-12-05 14:07:17 +01:00
|
|
|
|
|
2022-12-11 15:50:38 +01:00
|
|
|
|
# Grille à l'état initial
|
2022-12-29 10:08:55 +01:00
|
|
|
|
scene.objects['Portail'].worldPosition.x = scene.objects['Portail']['init_lx']-scene.objects['System']['init_lx']+scene.objects['System'].worldPosition.x
|
|
|
|
|
scene.objects['Portail'].worldPosition.y = scene.objects['Portail']['init_ly']-scene.objects['System']['init_ly']+scene.objects['System'].worldPosition.y
|
|
|
|
|
scene.objects['Portail'].worldPosition.z = scene.objects['Portail']['init_lz']-scene.objects['System']['init_lz']+scene.objects['System'].worldPosition.z
|
2022-12-05 14:07:17 +01:00
|
|
|
|
|
2022-12-11 15:50:38 +01:00
|
|
|
|
# Moteur à l'état initial
|
2022-12-05 14:07:17 +01:00
|
|
|
|
rres=0.001 # resolution rotation
|
2022-12-11 15:50:38 +01:00
|
|
|
|
obj1=scene.objects['Engrenage']
|
|
|
|
|
while (obj1.localOrientation.to_euler().y) > 1.1*rres :
|
|
|
|
|
obj1.applyRotation((0, 0, -rres), True)
|
|
|
|
|
while (obj1.localOrientation.to_euler().y) < -1.1*rres :
|
|
|
|
|
obj1.applyRotation((0, 0, rres), True)
|
2022-12-05 14:07:17 +01:00
|
|
|
|
|
2022-12-22 08:11:43 +01:00
|
|
|
|
# Gyrophare à l'état initial
|
2022-12-11 15:50:38 +01:00
|
|
|
|
scene.objects['Led'].setVisible(True,False)
|
2022-12-22 08:11:43 +01:00
|
|
|
|
scene.objects['Led-on'].setVisible(False,False)
|
2022-12-05 14:07:17 +01:00
|
|
|
|
|
2022-12-11 15:50:38 +01:00
|
|
|
|
# Capteur barrage IR
|
|
|
|
|
scene.objects['Emetteur IR Led'].setVisible(True,False)
|
2022-12-22 08:11:43 +01:00
|
|
|
|
scene.objects['Emetteur IR Led-on'].setVisible(False,False)
|
|
|
|
|
scene.objects['Emetteur IR'].color = color_passive
|
|
|
|
|
scene.objects['Recepteur IR'].color = color_passive
|
2022-12-05 14:07:17 +01:00
|
|
|
|
|
2022-12-11 15:50:38 +01:00
|
|
|
|
# I/O à l'état initial
|
2022-12-22 08:11:43 +01:00
|
|
|
|
scene.objects['Led']['activated']=False
|
|
|
|
|
scene.objects['Moteur']['open']=False
|
|
|
|
|
scene.objects['Moteur']['close']=False
|
|
|
|
|
scene.objects['Microrupteur fdc ouvert']['activated']=False
|
|
|
|
|
scene.objects['Microrupteur fdc ferme']['activated']=False
|
|
|
|
|
scene.objects['Bp cote cour']['activated'] =False
|
|
|
|
|
scene.objects['Bp cote rue']['activated'] =False
|
|
|
|
|
scene.objects['Emetteur IR']['activated'] =False
|
|
|
|
|
scene.objects['Emetteur IR']['active'] =False
|
|
|
|
|
scene.objects['Recepteur IR']['activated'] =False
|
|
|
|
|
scene.objects['Recepteur IR']['active'] =False
|