mirror of
https://forge.apps.education.fr/blender-edutech/jumeaux-numeriques.git
synced 2024-01-27 06:56:18 +01:00
Jumelage numérique du portail (hors IR)
This commit is contained in:
parent
e968972cbe
commit
61c2ddf819
@ -30,7 +30,11 @@ from montchg_lib import * # Bibliothèque portail coulissant
|
||||
###############################################################################
|
||||
|
||||
# Brochage du monte-charge
|
||||
brochage={}
|
||||
brochage={
|
||||
'pc_0' : 2,'pc_1' : 3,
|
||||
'ba_0' : 4,'ba_1' : 5,
|
||||
'mot_m' : 6,'mot_d' : 7,
|
||||
'voy_0' : 8, 'voy_1' : 9}
|
||||
|
||||
###############################################################################
|
||||
# Fonctions
|
||||
@ -42,9 +46,8 @@ brochage={}
|
||||
|
||||
def commandes():
|
||||
|
||||
jumeau()
|
||||
|
||||
# Ecrire votre code ici ...
|
||||
jumeau(brochage)
|
||||
while True:
|
||||
voy_0(True)
|
||||
voy_1(False)
|
||||
@ -64,4 +67,4 @@ def commandes():
|
||||
if __name__=='start':
|
||||
thread_cmd_start(commandes)
|
||||
if __name__=='stop':
|
||||
thread_cmd_stop()
|
||||
stop()
|
||||
|
Binary file not shown.
@ -20,7 +20,9 @@ scene = bge.logic.getCurrentScene()
|
||||
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
|
||||
color_activated = (0.8, 0.619, 0.021, 1) # bouton activé numériquement uniquement : jaune
|
||||
color_activated_real = (0.799, 0.031, 0.038, 1) # élément activé physiquement uniquement : rouge (hors clic)
|
||||
color_activated_dbl = (0.246, 0.687, 0.078, 1) # élément activé physiquement et numériquement : vert clair
|
||||
|
||||
# Constantes UPBGE
|
||||
JUST_ACTIVATED = bge.logic.KX_INPUT_JUST_ACTIVATED
|
||||
@ -40,6 +42,17 @@ def init(cont):
|
||||
twin.cmd_init() # Commandes
|
||||
twin.manip_init() # Cacher les objets de l'aide
|
||||
|
||||
# Brochage
|
||||
scene.objects['Bp cote cour']['pin'] = None
|
||||
scene.objects['Bp cote rue']['pin'] = None
|
||||
scene.objects['Microrupteur fdc ouvert']['pin'] = None
|
||||
scene.objects['Microrupteur fdc ferme']['pin'] = None
|
||||
scene.objects['Moteur']['pin_o'] = None
|
||||
scene.objects['Moteur']['pin_f'] = None
|
||||
scene.objects['Led']['pin'] = None
|
||||
scene.objects['Emetteur IR']['pin'] = None
|
||||
scene.objects['Recepteur IR']['pin'] = None
|
||||
|
||||
# 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
|
||||
@ -64,24 +77,34 @@ def init(cont):
|
||||
|
||||
##
|
||||
# Gyrophare
|
||||
# Modele 3d -> Arduino : FIXME
|
||||
# Arduino -> Modele 3d : FIXME
|
||||
##
|
||||
|
||||
def gyr (cont):
|
||||
if scene.objects['System']['run']:
|
||||
obj = cont.owner
|
||||
|
||||
# Activation
|
||||
if obj['activated'] and scene.objects['Led-on'].visible == False:
|
||||
scene.objects['Led-on'].setVisible(True,False)
|
||||
scene.objects['Led'].setVisible(False,False)
|
||||
|
||||
# Modele 3D -> Arduino
|
||||
if scene.objects['System']['twins']:
|
||||
if scene.objects['Led']['pin'] is not None:
|
||||
scene.objects['Led']['pin'].write(1)
|
||||
|
||||
# Désactivation
|
||||
if obj['activated']==False and scene.objects['Led-on'].visible == True:
|
||||
scene.objects['Led'].setVisible(True,False)
|
||||
scene.objects['Led-on'].setVisible(False,False)
|
||||
|
||||
# Modele 3D -> Arduino
|
||||
if scene.objects['System']['twins']:
|
||||
if scene.objects['Led']['pin'] is not None:
|
||||
scene.objects['Led']['pin'].write(0)
|
||||
|
||||
##
|
||||
# Moteur et portail
|
||||
# Modele 3d -> Arduino : FIXME
|
||||
# Arduino -> Modele 3d : FIXME
|
||||
##
|
||||
|
||||
def mot (cont):
|
||||
@ -93,75 +116,104 @@ def mot (cont):
|
||||
obj_engrenage = scene.objects['Engrenage']
|
||||
obj_portail = scene.objects['Portail']
|
||||
obj_portail['x']= scene.objects['Portail'].localPosition.x # Affichage de la position du portail
|
||||
|
||||
# Ouvrir
|
||||
if obj['open']:
|
||||
obj_engrenage.applyRotation((0, 0, -pas_engrenage*vitesse), True)
|
||||
obj_portail.applyMovement((-pas_portail*vitesse, 0, 0), True)
|
||||
|
||||
# Modele 3D -> Arduino
|
||||
if scene.objects['System']['twins']:
|
||||
if scene.objects['Moteur']['pin_o'] is not None:
|
||||
if scene.objects['Moteur']['pin_f'] is not None:
|
||||
scene.objects['Moteur']['pin_f'].write(0)
|
||||
scene.objects['Moteur']['pin_o'].write(1)
|
||||
|
||||
# Fermer
|
||||
# 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)
|
||||
|
||||
# Modele 3D -> Arduino
|
||||
if scene.objects['System']['twins']:
|
||||
if scene.objects['Moteur']['pin_f'] is not None:
|
||||
if scene.objects['Moteur']['pin_o'] is not None:
|
||||
scene.objects['Moteur']['pin_o'].write(0)
|
||||
scene.objects['Moteur']['pin_f'].write(1)
|
||||
|
||||
# Arrêrer
|
||||
if obj['open']== False and obj['close'] == False :
|
||||
|
||||
# Modele 3D -> Arduino
|
||||
if scene.objects['System']['twins']:
|
||||
if scene.objects['Moteur']['pin_f'] is not None:
|
||||
if scene.objects['Moteur']['pin_o'] is not None:
|
||||
scene.objects['Moteur']['pin_o'].write(0)
|
||||
scene.objects['Moteur']['pin_f'].write(0)
|
||||
|
||||
|
||||
###############################################################################
|
||||
# Capteurs fin de course
|
||||
###############################################################################
|
||||
|
||||
##
|
||||
# Etat capteur fin de course portail ouvert
|
||||
# Modele 3d -> Arduino : FIXME
|
||||
# Arduino -> Modele 3d : FIXME
|
||||
##
|
||||
|
||||
def fdc_o (cont):
|
||||
if scene.objects['System']['run'] :
|
||||
obj = cont.owner
|
||||
|
||||
# Arduino -> Modele 3D
|
||||
if scene.objects['System']['twins']:
|
||||
if obj['pin'] is not None:
|
||||
if obj['pin'].read()==True and obj['activated_real'] == False :
|
||||
obj['activated_real'] = True
|
||||
if obj['pin'].read()==False and obj['activated_real'] == True :
|
||||
obj['activated_real'] = False
|
||||
|
||||
# Etat capteur en fonction de la grille : worldPosition.x : 0 -> 65.5 et localPosition.x : 0 -> 218
|
||||
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)
|
||||
# Forçage par clic
|
||||
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
|
||||
twin.cycle_sensitive_color(obj)
|
||||
|
||||
##
|
||||
# Etat capteur fin de course portail fermé
|
||||
# Modele 3d -> Arduino : FIXME
|
||||
# Arduino -> Modele 3d : FIXME
|
||||
##
|
||||
|
||||
def fdc_f (cont):
|
||||
if scene.objects['System']['run'] :
|
||||
obj = cont.owner
|
||||
|
||||
# Arduino -> Modele 3D
|
||||
if scene.objects['System']['twins']:
|
||||
if obj['pin'] is not None:
|
||||
if obj['pin'].read()==True and obj['activated_real'] == False :
|
||||
obj['activated_real'] = True
|
||||
if obj['pin'].read()==False and obj['activated_real'] == True :
|
||||
obj['activated_real'] = False
|
||||
|
||||
# Etat capteur en fonction de la grille : worldPosition.x : 0 -> 65.5 et localPosition.x : 0 -> 218
|
||||
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)
|
||||
# Forçage par clic
|
||||
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
|
||||
twin.cycle_sensitive_color(obj)
|
||||
|
||||
###############################################################################
|
||||
# Capteur barrage
|
||||
@ -182,6 +234,11 @@ def ir_emet (cont):
|
||||
scene.objects['Emetteur IR Led-on'].setVisible(False,False)
|
||||
scene.objects['Recepteur IR']['active'] = False
|
||||
|
||||
# Modele 3D -> Arduino
|
||||
if scene.objects['System']['twins']:
|
||||
if scene.objects['Emetteur IR']['pin'] is not None:
|
||||
scene.objects['Emetteur IR']['pin'].write(0)
|
||||
|
||||
# Active
|
||||
if obj['active']:
|
||||
|
||||
@ -192,7 +249,12 @@ def ir_emet (cont):
|
||||
obj.color = color_active
|
||||
scene.objects['Recepteur IR']['active'] = True
|
||||
|
||||
# Forçage (click)
|
||||
# Modele 3D -> Arduino
|
||||
if scene.objects['System']['twins']:
|
||||
if scene.objects['Emetteur IR']['pin'] is not None:
|
||||
scene.objects['Emetteur IR']['pin'].write(1)
|
||||
|
||||
# Forçage par clic
|
||||
if obj['click'] == True:
|
||||
obj['activated'] = True
|
||||
scene.objects['Recepteur IR']['activated'] = True
|
||||
@ -235,46 +297,12 @@ def ir_recep (cont):
|
||||
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 ():
|
||||
@ -314,10 +342,16 @@ def system_reset ():
|
||||
scene.objects['Moteur']['open']=False
|
||||
scene.objects['Moteur']['close']=False
|
||||
scene.objects['Microrupteur fdc ouvert']['activated']=False
|
||||
scene.objects['Microrupteur fdc ouvert']['activated_real']=False
|
||||
scene.objects['Microrupteur fdc ferme']['activated']=False
|
||||
scene.objects['Microrupteur fdc ferme']['activated_real']=False
|
||||
scene.objects['Bp cote cour']['activated'] =False
|
||||
scene.objects['Bp cote cour']['activated_real'] =False
|
||||
scene.objects['Bp cote rue']['activated'] =False
|
||||
scene.objects['Bp cote rue']['activated_real'] =False
|
||||
scene.objects['Emetteur IR']['activated'] =False
|
||||
scene.objects['Emetteur IR']['activated_real'] =False
|
||||
scene.objects['Emetteur IR']['active'] =False
|
||||
scene.objects['Recepteur IR']['activated'] =False
|
||||
scene.objects['Recepteur IR']['active'] =False
|
||||
scene.objects['Recepteur IR']['activated_real'] =False
|
||||
|
@ -29,13 +29,12 @@ from porcou_lib import * # Bibliothèque portail coulissant
|
||||
###############################################################################
|
||||
|
||||
# Brochage du portail coulissant
|
||||
carte = None
|
||||
brochage={
|
||||
'bp_ext' : 2,'bp_int' : 3,
|
||||
'fdc_o' : 4,'fdc_f' : 5,
|
||||
'mot_o' : 6,'mot_f' : 7,
|
||||
'gyr' : 8,
|
||||
'ir_emett' : 9,'ir_recept' : 10}
|
||||
'ir_emet' : 9,'ir_recep' : 10}
|
||||
|
||||
###############################################################################
|
||||
# Fonctions
|
||||
@ -47,14 +46,46 @@ brochage={
|
||||
|
||||
def commandes():
|
||||
|
||||
# jumeau(carte, brochage)
|
||||
jumeau(brochage)
|
||||
gyr(True)
|
||||
while True:
|
||||
pass
|
||||
|
||||
fin() # A garder
|
||||
|
||||
# Mise en place : Fermeture
|
||||
print ("Version sans sécurité : sans réouverture")
|
||||
print ("Mise en place : Fermeture")
|
||||
while fdc_f() ==False :
|
||||
gyr(True)
|
||||
mot_o(False)
|
||||
mot_f(True)
|
||||
mot_f(False)
|
||||
gyr(False)
|
||||
|
||||
# Fonctionnement normal
|
||||
print ("Attente")
|
||||
while True :
|
||||
|
||||
# Ouverture
|
||||
if bp_int() or bp_ext() :
|
||||
print ("Ouverture")
|
||||
while fdc_o() ==False:
|
||||
gyr(True)
|
||||
mot_f(False)
|
||||
mot_o(True)
|
||||
gyr(False)
|
||||
mot_o(False)
|
||||
|
||||
print ("Temporisation")
|
||||
tempo(2) # Temporisation
|
||||
|
||||
# Fermeture
|
||||
print ("Fermeture")
|
||||
while fdc_f() ==False:
|
||||
gyr(True)
|
||||
mot_o(False)
|
||||
mot_f(True)
|
||||
gyr(False)
|
||||
mot_f(False)
|
||||
print ("Attente")
|
||||
|
||||
fin() # A garder
|
||||
|
||||
###############################################################################
|
||||
# En: External call << DONT CHANGE THIS SECTION >>
|
||||
|
@ -1,8 +1,6 @@
|
||||
import bge # Bibliothèque Blender Game Engine (UPBGE)
|
||||
from twin_threading import thread_cmd_start, thread_cmd_stop, thread_cmd_end # Multithreading
|
||||
# rom twin_serial import open, close # Liaison série
|
||||
import twin_serial # Liaison série
|
||||
# import twin_serial # Liaison série
|
||||
import time
|
||||
|
||||
###############################################################################
|
||||
@ -17,20 +15,17 @@ import time
|
||||
|
||||
scene = bge.logic.getCurrentScene()
|
||||
|
||||
# Carte du jumeau numérique
|
||||
# board = None
|
||||
# board_it = None # Iterator (input)
|
||||
|
||||
# Brochage du jumeau numérique
|
||||
# bp_int_pin = None
|
||||
# bp_ext_pin = None
|
||||
# fdc_o_pin = None
|
||||
# fdc_f_pin = None
|
||||
# ir_emett_pin = None
|
||||
# ir_recept_pin = None
|
||||
# mot_o_pin = None
|
||||
# mot_f_pin = None
|
||||
# gyr_pin = None
|
||||
# Brochage du jumeau réel
|
||||
pin_config = {
|
||||
'bp_ext' : ['d','i'],
|
||||
'bp_int' : ['d','i'],
|
||||
'fdc_o' : ['d','i'],
|
||||
'fdc_f' : ['d','i'],
|
||||
'mot_o' : ['d','o'],
|
||||
'mot_f' : ['d','o'],
|
||||
'gyr' : ['d','o'],
|
||||
'ir_emet' : ['d','o'],
|
||||
'ir_recep' : ['d','i']}
|
||||
|
||||
# UPBGE constants
|
||||
JUST_ACTIVATED = bge.logic.KX_INPUT_JUST_ACTIVATED
|
||||
@ -44,13 +39,7 @@ ACTIVATE = bge.logic.KX_INPUT_ACTIVE
|
||||
|
||||
# Ordre pour allumer le gyrophare
|
||||
def gyr (order):
|
||||
# global gyr_pin
|
||||
scene.objects['Led']['activated']=order
|
||||
# if scene.objects['System']['twins'] :
|
||||
# if ordre :
|
||||
# gyr_pin.write(1)
|
||||
# else:
|
||||
# gyr_pin.write(0)
|
||||
|
||||
###############################################################################
|
||||
# Actionneurs
|
||||
@ -74,15 +63,22 @@ def ir_emet(order):
|
||||
|
||||
# Compte-rendu du capteur fin de course portail ouvert
|
||||
def fdc_o ():
|
||||
return scene.objects['Microrupteur fdc ouvert']['activated']
|
||||
if scene.objects['Microrupteur fdc ouvert']['activated'] or scene.objects['Microrupteur fdc ouvert']['activated_real']:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
# Compte-rendu du capteur fin de course portail ouvert
|
||||
# Compte-rendu du capteur fin de course portail fermé
|
||||
def fdc_f ():
|
||||
return scene.objects['Microrupteur fdc ferme']['activated']
|
||||
if scene.objects['Microrupteur fdc ferme']['activated'] or scene.objects['Microrupteur fdc ferme']['activated_real']:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
# Compte-rendu du capteur barrage IR
|
||||
def ir_recep ():
|
||||
if scene.objects['Recepteur IR']['activated']:
|
||||
if scene.objects['Recepteur IR']['activated'] or scene.objects['Recepteur IR']['activated_real']==False:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
@ -93,19 +89,53 @@ def ir_recep ():
|
||||
|
||||
# Compte-rendu du bouton pousssoir coté rue
|
||||
def bp_ext ():
|
||||
return scene.objects['Bp cote rue']['activated']
|
||||
if scene.objects['Bp cote rue']['activated'] or scene.objects['Bp cote rue']['activated_real']:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
# Compte-rendu du bouton pousssoir coté cour
|
||||
def bp_int ():
|
||||
return scene.objects['Bp cote cour']['activated']
|
||||
if scene.objects['Bp cote cour']['activated'] or scene.objects['Bp cote cour']['activated_real']:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
###############################################################################
|
||||
# Jumeau
|
||||
###############################################################################
|
||||
|
||||
def jumeau (brochage):
|
||||
scene.objects['System']['board']=twin_serial.open()
|
||||
print ("jumeau : ", scene.objects['System']['board'])
|
||||
# Créer une broche
|
||||
def jumeau_get_pin(board, name, brochage):
|
||||
for pin in brochage :
|
||||
if pin ==name:
|
||||
# print (pin_config[pin][0]+':'+str(brochage[pin])+':'+pin_config[pin][1])
|
||||
return board.get_pin(pin_config[pin][0]+':'+str(brochage[pin])+':'+pin_config[pin][1])
|
||||
return None
|
||||
|
||||
# Activer le jumelage
|
||||
def jumeau (brochage=None):
|
||||
|
||||
# Carte
|
||||
board =twin_serial.open()
|
||||
scene.objects['System']['board']=board
|
||||
# print ("jumeau : ", scene.objects['System']['board'])
|
||||
|
||||
# Brochage
|
||||
if brochage is not None:
|
||||
scene.objects['Bp cote cour']['pin'] = jumeau_get_pin(board, 'bp_int', brochage)
|
||||
scene.objects['Bp cote rue']['pin'] = jumeau_get_pin(board, 'bp_ext', brochage)
|
||||
scene.objects['Microrupteur fdc ouvert']['pin'] =jumeau_get_pin(board, 'fdc_o', brochage)
|
||||
scene.objects['Microrupteur fdc ferme']['pin'] =jumeau_get_pin(board, 'fdc_f', brochage)
|
||||
scene.objects['Moteur']['pin_o'] = jumeau_get_pin(board, 'mot_o', brochage)
|
||||
scene.objects['Moteur']['pin_f'] = jumeau_get_pin(board, 'mot_f', brochage)
|
||||
scene.objects['Led']['pin'] = jumeau_get_pin(board, 'gyr', brochage)
|
||||
scene.objects['Emetteur IR']['pin'] = jumeau_get_pin(board, 'ir_emet', brochage)
|
||||
scene.objects['Recepteur IR']['pin'] = jumeau_get_pin(board, 'ir_recep', brochage)
|
||||
|
||||
# Désactiver le jumelage
|
||||
def jumeau_stop ():
|
||||
twin_serial.close(scene.objects['System']['board'])
|
||||
|
||||
###############################################################################
|
||||
# Cycle
|
||||
@ -119,14 +149,14 @@ def tempo (duree):
|
||||
def stop():
|
||||
if scene.objects['System']['twins']:
|
||||
twin_serial.close(scene.objects['System']['board'])
|
||||
time.sleep(0.5)
|
||||
time.sleep(1)
|
||||
thread_cmd_stop()
|
||||
|
||||
# Fin naturelle
|
||||
def end():
|
||||
if scene.objects['System']['twins']:
|
||||
twin_serial.close(scene.objects['System']['board'])
|
||||
time.sleep(0.5)
|
||||
time.sleep(1)
|
||||
thread_cmd_end()
|
||||
|
||||
def fin():
|
||||
|
Binary file not shown.
50
twin.py
50
twin.py
@ -42,7 +42,9 @@ color_cmd_hl = (0.8, 0.619, 0.021, 1) # Jaune
|
||||
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
|
||||
color_activated = (0.8, 0.619, 0.021, 1) # bouton activé numériquement uniquement : jaune
|
||||
color_activated_real = (0.799, 0.031, 0.038, 1) # élément activé physiquement uniquement : rouge (hors clic)
|
||||
color_activated_dbl = (0.246, 0.687, 0.078, 1) # élément activé physiquement et numériquement : vert clair
|
||||
|
||||
# Constantes
|
||||
JUST_ACTIVATED = bge.logic.KX_INPUT_JUST_ACTIVATED
|
||||
@ -542,7 +544,7 @@ def cycle_end (cont):
|
||||
scene.objects['Run'].restorePhysics()
|
||||
|
||||
##
|
||||
# Highlight sur les éléments cliquables du systèmes
|
||||
# Highlight sur les éléments cliquable du systèmes
|
||||
##
|
||||
|
||||
def cycle_hl(cont):
|
||||
@ -569,7 +571,7 @@ def cycle_hl(cont):
|
||||
scene.objects['Cmd-text']['Text']=""
|
||||
|
||||
##
|
||||
# Click sur les éléments cliquables du systèmes (activation numérique)
|
||||
# Click sur les éléments cliquables du système (activation numérique)
|
||||
##
|
||||
|
||||
def cycle_click(cont):
|
||||
@ -599,3 +601,45 @@ def cycle_click(cont):
|
||||
obj.color = color_hl
|
||||
else:
|
||||
obj.color = color_active
|
||||
|
||||
##
|
||||
# Couleurs sur les éléments sensibles du système
|
||||
##
|
||||
|
||||
def cycle_sensitive_color(obj):
|
||||
if obj['mo'] == True and obj['click'] == False and obj.color !=color_hl:
|
||||
obj.color =color_hl
|
||||
elif scene.objects['System']['twins']:
|
||||
if obj['activated_real'] ==False and obj['activated']==False and obj.color !=color_active:
|
||||
obj.color =color_active
|
||||
elif obj['activated_real'] and obj['activated'] and obj.color !=color_activated_dbl:
|
||||
obj.color =color_activated_dbl
|
||||
elif obj['activated_real'] and obj['activated']==False and obj.color !=color_activated_real:
|
||||
obj.color =color_activated_real
|
||||
elif obj['activated_real'] ==False and obj['activated'] and obj.color !=color_activated:
|
||||
obj.color =color_activated
|
||||
elif obj['activated_real'] ==False and obj['activated']==False and obj.color !=color_activated:
|
||||
obj.color =color_active
|
||||
else:
|
||||
if obj['activated'] == True and obj.color !=color_activated:
|
||||
obj.color =color_activated
|
||||
elif obj['activated'] == False and obj.color !=color_active:
|
||||
obj.color =color_active
|
||||
|
||||
##
|
||||
# Gestion des boutons
|
||||
##
|
||||
|
||||
def cycle_bp(cont):
|
||||
obj = cont.owner
|
||||
|
||||
# Arduino -> Modele 3D
|
||||
if scene.objects['System']['twins']:
|
||||
if obj['pin'] is not None:
|
||||
if obj['pin'].read()==True and obj['activated_real'] == False :
|
||||
obj['activated_real'] = True
|
||||
if obj['pin'].read()==False and obj['activated_real'] == True :
|
||||
obj['activated_real'] = False
|
||||
|
||||
# Couleurs
|
||||
cycle_sensitive_color(obj)
|
||||
|
@ -1,7 +1,7 @@
|
||||
<data>
|
||||
<screen>
|
||||
<width>1318</width>
|
||||
<height>741</height>
|
||||
<width>1573</width>
|
||||
<height>884</height>
|
||||
<quality>1</quality>
|
||||
</screen>
|
||||
</data>
|
@ -19,10 +19,6 @@ from serial.tools.list_ports import comports # Détection du port automatique
|
||||
# UPBGE scene
|
||||
scene = bge.logic.getCurrentScene()
|
||||
|
||||
# Carte du jumeau numérique
|
||||
# board = None
|
||||
# board_it = None # Iterator (input)
|
||||
|
||||
##
|
||||
# Recherche automatique du port
|
||||
##
|
||||
@ -83,7 +79,6 @@ def devices():
|
||||
# pyfirmata : baudrate=57600
|
||||
##
|
||||
|
||||
# def jumeau(pins):
|
||||
def open():
|
||||
|
||||
# UI : étape 1
|
||||
@ -115,49 +110,21 @@ def open():
|
||||
else:
|
||||
scene.objects['Twins-text']['Text'] = "Connection ouverte : "+board_name+" sur "+device+" à "+str(speed)+" baud."
|
||||
time.sleep(0.1)
|
||||
|
||||
# Déclaration des entrées - sorties
|
||||
# for pin in pins:
|
||||
# print (pin)
|
||||
# if
|
||||
# bp_ext_pin = board_io('d:'+str(es_dict['bp_ext'])+':i') # Bouton poussoir coté rue
|
||||
# bp_int_pin = board_io('d:'+str(es_dict['bp_int'])+':i') # Bouton poussoir coté cour
|
||||
# fdc_o_pin = board_io('d:'+str(es_dict['fdc_o'])+':i') # Capteur fin de course portail ouvert
|
||||
# fdc_f_pin = board_io('d:'+str(es_dict['fdc_f'])+':i') # Capteur fin de course portail fermé
|
||||
# ir_recept_pin = board_io('d:'+str(es_dict['ir_recept'])+':i') # Recepteur pour le capteur barrage IR
|
||||
|
||||
# gyr_pin = board_io('d:'+str(es_dict['gyr'])+':o') # Gyrophare
|
||||
# mot_o_pin = board_io('d:'+str(es_dict['mot_o'])+':o') # Ouvrir le portail (moteur sens trigo)
|
||||
# mot_f_pin = board_io('d:'+str(es_dict['mot_f'])+':o') # Fermer le portail (moteur sens horaire
|
||||
# ir_emett_pin = board_io('d:'+str(es_dict['ir_emett'])+':o') # Emetteur pour le capteur barrage IR
|
||||
return (board)
|
||||
# return True
|
||||
|
||||
# def board_io(da,pin,io):
|
||||
# if pin_def is not None:
|
||||
# return board.get_pin(da+':'+pin_def)
|
||||
# else:
|
||||
# print ("Définition entrée-sortie non trouvée : "+pin_def)
|
||||
|
||||
##
|
||||
# Fermeture de la communication série
|
||||
##
|
||||
|
||||
def close(board):
|
||||
scene.objects['Twins-text']['Text'] = "Connection fermée."
|
||||
board.exit() # Fermer proprement la communication avec la carte
|
||||
scene.objects['System']['twins'] = False
|
||||
|
||||
# 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
|
||||
if scene.objects['System']['twins']:
|
||||
scene.objects['Twins-text']['Text'] = "Connection fermée."
|
||||
board.exit() # Fermer proprement la communication avec la carte
|
||||
time.sleep(0.1)
|
||||
scene.objects['System']['twins'] = False
|
||||
|
||||
# Configuration manuelle du port
|
||||
# FIXME
|
||||
# FIXME : plus tard
|
||||
def config(port, speed):
|
||||
pass
|
||||
# global board
|
||||
@ -180,6 +147,7 @@ def config(port, speed):
|
||||
|
||||
##
|
||||
# Envoi d'un message vers la communication série
|
||||
# FIXME : plus tard
|
||||
##
|
||||
|
||||
# def serie_msg(text):
|
||||
@ -190,6 +158,7 @@ def config(port, speed):
|
||||
|
||||
##
|
||||
# Mise en écoute de jumeau numérique (figeage de la scène)
|
||||
# FIXME : plus tard
|
||||
##
|
||||
|
||||
# def twins_listen(cont):
|
||||
@ -209,6 +178,7 @@ def config(port, speed):
|
||||
|
||||
##
|
||||
# Réception d'un message de la communication série
|
||||
# FIXME : plus tard
|
||||
##
|
||||
|
||||
# def serie_rcpt():
|
||||
|
Binary file not shown.
@ -32,7 +32,11 @@ from volrou_lib import * # Bibliothèque volet roulant
|
||||
###############################################################################
|
||||
|
||||
# Brochage du volet roulant
|
||||
brochage={}
|
||||
brochage={
|
||||
'fdc_h' : 2,'fdc_b' : 3,
|
||||
'bp_m' : 4,'bp_d' : 5, 'bp_a' : 6,
|
||||
'mot_m' : 7,'mot_d' : 8,
|
||||
'bp_auto' : 9, 'voy_auto' : 10, 'lum' : 11}
|
||||
|
||||
###############################################################################
|
||||
# Fonctions
|
||||
@ -45,7 +49,7 @@ brochage={}
|
||||
def commandes():
|
||||
|
||||
# Ecrire votre code ici ...
|
||||
jumeau()
|
||||
jumeau(brochage)
|
||||
voy_auto(True) # Activer le gyrophare
|
||||
while True:
|
||||
pass
|
||||
@ -61,4 +65,4 @@ def commandes():
|
||||
if __name__=='start':
|
||||
thread_cmd_start(commandes)
|
||||
if __name__=='stop':
|
||||
thread_cmd_stop()
|
||||
stop()
|
||||
|
Loading…
Reference in New Issue
Block a user