Jumelage numérique du monte-charge (point d'étape)

This commit is contained in:
Philippe Roy 2023-01-07 18:01:03 +01:00
parent e144bc3bbb
commit a43fd2d547
8 changed files with 191 additions and 85 deletions

View File

@ -16,11 +16,24 @@ import time
# Récupérer la scène UPBGE
scene = bge.logic.getCurrentScene()
# Configuration du brochage du jumeau réel
pin_config = {
'voy_0' : [['d','o'],['Led niveau 0','pin']],
'voy_1' : [['d','o'],['Led niveau 1','pin']],
'pc_0' : [['d','i'],['Microrupteur niveau 0','pin']],
'pc_1' : [['d','i'],['Microrupteur niveau 1','pin']],
'ba_0' : [['d','i'],['Bp niveau 0','pin']],
'ba_1' : [['d','i'],['Bp niveau 1','pin']],
'mot_m' : [['d','o'],['Moteur','pin_m',]],
'mot_d' : [['d','o'],['Moteur','pin_d']]}
# 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
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
@ -39,6 +52,11 @@ def init(cont):
twin.manip_init() # Manipulation du modèle 3D
twin.cmd_init() # Commandes
# Brochage
for pin in pin_config:
# print (pin_config[pin][1][0], pin_config[pin][1][1])
scene.objects[pin_config[pin][1][0]][pin_config[pin][1][1]] = None
# Mémorisation de la position et orientation des composants du système au départ
scene.objects['Cabine']['init_lx']=scene.objects['Cabine'].worldPosition.x
scene.objects['Cabine']['init_ly']=scene.objects['Cabine'].worldPosition.y
@ -71,15 +89,24 @@ def init(cont):
# Arduino -> Modele 3d : FIXME
##
def voy_0 (cont):
if scene.objects['System']['run']:
obj = cont.owner
if obj['activated'] and scene.objects['Led niveau 0-on'].visible == False:
scene.objects['Led niveau 0-on'].setVisible(True,False)
scene.objects['Led niveau 0'].setVisible(False,False)
if obj['activated']==False and scene.objects['Led niveau 0-on'].visible == True:
scene.objects['Led niveau 0'].setVisible(True,False)
scene.objects['Led niveau 0-on'].setVisible(False,False)
# def voy_0 (cont):
# if scene.objects['System']['run']:
# obj = cont.owner
# # Activation
# if obj['activated'] and scene.objects['Led niveau 0-on'].visible == False:
# scene.objects['Led niveau 0-on'].setVisible(True,False)
# scene.objects['Led niveau 0'].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 niveau 0-on'].visible == True:
# scene.objects['Led niveau 0'].setVisible(True,False)
# scene.objects['Led niveau 0-on'].setVisible(False,False)
##
# Etat voyant 1
@ -87,15 +114,15 @@ def voy_0 (cont):
# Arduino -> Modele 3d : FIXME
##
def voy_1 (cont):
if scene.objects['System']['run']:
obj = cont.owner
if obj['activated'] and scene.objects['Led niveau 1-on'].visible == False:
scene.objects['Led niveau 1-on'].setVisible(True,False)
scene.objects['Led niveau 1'].setVisible(False,False)
if obj['activated']==False and scene.objects['Led niveau 1-on'].visible == True:
scene.objects['Led niveau 1'].setVisible(True,False)
scene.objects['Led niveau 1-on'].setVisible(False,False)
# def voy_1 (cont):
# if scene.objects['System']['run']:
# obj = cont.owner
# if obj['activated'] and scene.objects['Led niveau 1-on'].visible == False:
# scene.objects['Led niveau 1-on'].setVisible(True,False)
# scene.objects['Led niveau 1'].setVisible(False,False)
# if obj['activated']==False and scene.objects['Led niveau 1-on'].visible == True:
# scene.objects['Led niveau 1'].setVisible(True,False)
# scene.objects['Led niveau 1-on'].setVisible(False,False)
###############################################################################
# Actionneurs
@ -120,11 +147,22 @@ def mot (cont):
obj_cabine['z']= scene.objects['Cabine'].localPosition.z # Affichage de l'altitude de la cabine
obj_contrepoids = scene.objects['Contrepoids']
obj_cable = scene.objects['Cable'] # FIXME : plus tard
# Monter
if obj['up']:
obj_vissansfin.applyRotation((0, 0, pas_vissansfin*vitesse), True)
obj_pignon.applyRotation((pas_pignon*vitesse, 0, 0), True)
obj_cabine.applyMovement((0, 0, pas_cabine*vitesse), True)
obj_contrepoids.applyMovement((0, 0, -pas_cabine*vitesse), True)
# Modele 3D -> Arduino
if scene.objects['System']['twins']:
if scene.objects['Moteur']['pin_m'] is not None:
if scene.objects['Moteur']['pin_d'] is not None:
scene.objects['Moteur']['pin_d'].write(0)
scene.objects['Moteur']['pin_m'].write(1)
# Descendre
# else: # Pas de priorité
if obj['down']:
obj_vissansfin.applyRotation((0, 0, -pas_vissansfin*vitesse), True)
@ -132,99 +170,92 @@ def mot (cont):
obj_cabine.applyMovement((0, 0, -pas_cabine*vitesse), True)
obj_contrepoids.applyMovement((0, 0, pas_cabine*vitesse), True)
# Arrêter
if obj['up']== False and obj['down'] == False :
# Modele 3D -> Arduino
if scene.objects['System']['twins']:
if scene.objects['Moteur']['pin_d'] is not None:
if scene.objects['Moteur']['pin_m'] is not None:
scene.objects['Moteur']['pin_m'].write(0)
scene.objects['Moteur']['pin_d'].write(0)
###############################################################################
# Capteurs
###############################################################################
##
# Etat capteur présence cabine niveau 0
# Modele 3d -> Arduino : FIXME
# Arduino -> Modele 3d : FIXME
##
def pc_0 (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 position de la cabine : localPosition.z entre -40 et -42
if scene.objects['Cabine'].localPosition.z <-40 and scene.objects['Cabine'].localPosition.z >-42 and obj['activated'] == False :
obj['activated'] = True
if (scene.objects['Cabine'].localPosition.z > -40 or scene.objects['Cabine'].localPosition.z <-42) 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)
# 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 présence cabine niveau 1
# Modele 3d -> Arduino : FIXME
# Arduino -> Modele 3d : FIXME
##
def pc_1 (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 position de la cabine : localPosition.z entre 0 et -2
if scene.objects['Cabine'].localPosition.z <0 and scene.objects['Cabine'].localPosition.z >-2 and obj['activated'] == False :
obj['activated'] = True
if (scene.objects['Cabine'].localPosition.z > 0 or scene.objects['Cabine'].localPosition.z <-2) 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
###############################################################################
# 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
twin.cycle_sensitive_color(obj)
# 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
###############################################################################
# Système
@ -259,14 +290,18 @@ def system_reset ():
scene.objects['Contrepoids'].worldPosition.z = scene.objects['Contrepoids']['init_lz']-scene.objects['System']['init_lz']+scene.objects['System'].worldPosition.z
# Moteur à l'état initial : pas utile
# I/O à l'état initial
scene.objects['Led niveau 0']['activated']=False
scene.objects['Led niveau 1']['activated']=False
scene.objects['Bp niveau 0']['activated']=False
scene.objects['Bp niveau 0']['activated_real']=False
scene.objects['Bp niveau 1']['activated']=False
scene.objects['Bp niveau 1']['activated_real']=False
scene.objects['Microrupteur niveau 0']['activated']=False
scene.objects['Microrupteur niveau 0']['activated_real']=False
scene.objects['Microrupteur niveau 1']['activated']=False
scene.objects['Microrupteur niveau 1']['activated_real']=False
scene.objects['Moteur']['up']=False
scene.objects['Moteur']['down']=False

View File

@ -13,14 +13,23 @@ import time
# @license: GNU GPL
###############################################################################
# Récupérer la scène UPBGE
scene = bge.logic.getCurrentScene()
# Carte du jumeau numérique
board = None
board_it = None # Iterator (input)
# Récupérer le brochage du jumeau réel
from montchg import pin_config
# system=importlib.import_module('montchg') # Système
# pin_config = system.get_pin_config()
# Brochage du jumeau numérique
# FIXME
# pin_config = {
# 'voy_0' : [['d','o'],['Led niveau 0','pin']],
# 'voy_1' : [['d','o'],['Led niveau 1','pin']],
# 'pc_0' : [['d','i'],['Microrupteur niveau 0','pin']],
# 'pc_1' : [['d','i'],['Microrupteur niveau 0','pin']],
# 'ba_0' : [['d','i'],['Bp niveau 0','pin']],
# 'ba_1' : [['d','i'],['Bp niveau 1','pin']],
# 'mot_m' : [['d','o'],['Moteur','pin_m']],
# 'mot_d' : [['d','o'],['Moteur','pin_d']]}
# UPBGE constants
JUST_ACTIVATED = bge.logic.KX_INPUT_JUST_ACTIVATED
@ -80,8 +89,30 @@ def ba_1 ():
# Jumeau
###############################################################################
def jumeau ():
twin_serial.open()
# Créer une broche
def jumeau_get_pin(board, name, brochage):
for pin in brochage :
if pin ==name:
# print (pin_config[pin][0][0]+':'+str(brochage[pin])+':'+pin_config[pin][0][1])
return board.get_pin(pin_config[pin][0][0]+':'+str(brochage[pin])+':'+pin_config[pin][0][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:
for pin in pin_config :
scene.objects[pin_config[pin][1][0]][pin_config[pin][1][1]] = jumeau_get_pin(board, pin, brochage)
# Désactiver le jumelage
def jumeau_stop ():
twin_serial.close(scene.objects['System']['board'])
###############################################################################
# Cycle
@ -91,10 +122,18 @@ def jumeau ():
def tempo (duree):
time.sleep(duree)
# Fin
# Arrêt
def stop():
if scene.objects['System']['twins']:
twin_serial.close(scene.objects['System']['board'])
time.sleep(1)
thread_cmd_stop()
# Fin naturelle
def end():
if scene.objects['System']['twins']:
twin_serial.close()
twin_serial.close(scene.objects['System']['board'])
time.sleep(1)
thread_cmd_end()
def fin():

Binary file not shown.

32
twin.py
View File

@ -627,7 +627,7 @@ def cycle_sensitive_color(obj):
obj.color =color_active
##
# Gestion des boutons
# Comportement standard des boutons
##
def cycle_bp(cont):
@ -643,3 +643,33 @@ def cycle_bp(cont):
# Couleurs
cycle_sensitive_color(obj)
##
# Comportement standard des voyants
##
def cycle_voy(cont):
obj = cont.owner
obj_on=scene.objects[obj.name+"-on"]
if scene.objects['System']['run']:
# Activation
if obj['activated'] and obj_on.visible == False:
obj_on.setVisible(True,False)
obj.setVisible(False,False)
# Modele 3D -> Arduino
if scene.objects['System']['twins']:
if obj['pin'] is not None:
obj['pin'].write(1)
# Désactivation
if obj['activated']==False and obj_on.visible == True:
obj.setVisible(True,False)
obj_on.setVisible(False,False)
# Modele 3D -> Arduino
if scene.objects['System']['twins']:
if obj['pin'] is not None:
obj['pin'].write(0)

View File

@ -1,7 +1,7 @@
<data>
<screen>
<width>1573</width>
<height>884</height>
<width>1368</width>
<height>769</height>
<quality>1</quality>
</screen>
</data>

Binary file not shown.

View File

@ -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