mirror of
https://forge.apps.education.fr/blender-edutech/jumeaux-numeriques.git
synced 2024-01-27 06:56:18 +01:00
Ajout de la boucle principale
This commit is contained in:
parent
c6b7021737
commit
fdd0729f66
@ -40,12 +40,18 @@ def init(cont):
|
||||
twin.cmd_init() # Commandes
|
||||
|
||||
# Mémorisation de la position et orientation des composants du système au départ
|
||||
# scene.objects['Cabine']['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
|
||||
scene.objects['Cabine']['init_lx']=scene.objects['Cabine'].worldPosition.x
|
||||
scene.objects['Cabine']['init_ly']=scene.objects['Cabine'].worldPosition.y
|
||||
scene.objects['Cabine']['init_lz']=scene.objects['Cabine'].worldPosition.z
|
||||
scene.objects['Contrepoids']['init_lx']=scene.objects['Contrepoids'].worldPosition.x
|
||||
scene.objects['Contrepoids']['init_ly']=scene.objects['Contrepoids'].worldPosition.y
|
||||
scene.objects['Contrepoids']['init_lz']=scene.objects['Contrepoids'].worldPosition.z
|
||||
scene.objects['Moteur vis sans fin']['init_rx']=scene.objects['Moteur vis sans fin'].worldOrientation.to_euler().x
|
||||
scene.objects['Moteur vis sans fin']['init_ry']=scene.objects['Moteur vis sans fin'].worldOrientation.to_euler().y
|
||||
scene.objects['Moteur vis sans fin']['init_rz']=scene.objects['Moteur vis sans fin'].worldOrientation.to_euler().z
|
||||
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
|
||||
|
||||
system_init() # Initialisation du système
|
||||
|
||||
@ -53,22 +59,6 @@ def init(cont):
|
||||
# Actionneurs
|
||||
###############################################################################
|
||||
|
||||
##
|
||||
# Action du simulateur pour le clignotant
|
||||
##
|
||||
|
||||
# def sml_clignotant (cont):
|
||||
# if scene.objects['System']['run']:
|
||||
# obj = cont.owner
|
||||
# if obj['actif'] and scene.objects['Led allumee'].visible == False:
|
||||
# scene.objects['Led allumee'].setVisible(True,False)
|
||||
# scene.objects['Led'].setVisible(False,False)
|
||||
# # print ("Clignotant allumée")
|
||||
# if obj['actif']==False and scene.objects['Led allumee'].visible == True:
|
||||
# scene.objects['Led'].setVisible(True,False)
|
||||
# scene.objects['Led allumee'].setVisible(False,False)
|
||||
# # print ("Clignotant éteint")
|
||||
|
||||
##
|
||||
# Action du simulateur pour le moteur
|
||||
##
|
||||
@ -147,70 +137,6 @@ def init(cont):
|
||||
# if obj_microrupteur['MO'] == False and obj_microrupteur.color !=couleur_orange:
|
||||
# obj_microrupteur.color =couleur_orange
|
||||
|
||||
# ##
|
||||
# # Forçage capteur fin de course avec la souris
|
||||
# ##
|
||||
|
||||
# def sml_microrupteur (cont):
|
||||
# if scene.objects['System']['run'] :
|
||||
# system_click(cont, cont.owner)
|
||||
|
||||
# ###############################################################################
|
||||
# # Capteur barrage
|
||||
# ###############################################################################
|
||||
|
||||
# ##
|
||||
# # Emetteur IR
|
||||
# ##
|
||||
|
||||
# def sml_emet_ir (cont):
|
||||
# if scene.objects['System']['run'] :
|
||||
# obj = cont.owner
|
||||
# obj_emetteur_ir=scene.objects['Emetteur IR']
|
||||
# obj_recepteur_ir=scene.objects['Recepteur IR']
|
||||
# if obj['actif'] and scene.objects['Emetteur IR Led allumee'].visible == False:
|
||||
# scene.objects['Emetteur IR Led allumee'].setVisible(True,False)
|
||||
# scene.objects['Emetteur IR Led'].setVisible(False,False)
|
||||
# obj_emetteur_ir.color = couleur_orange
|
||||
# obj_recepteur_ir.color = couleur_orange
|
||||
# if obj['actif']==False and scene.objects['Emetteur IR Led allumee'].visible == True:
|
||||
# scene.objects['Emetteur IR Led'].setVisible(True,False)
|
||||
# scene.objects['Emetteur IR Led allumee'].setVisible(False,False)
|
||||
# obj_emetteur_ir.color = couleur_magenta
|
||||
# obj_recepteur_ir.color = couleur_magenta
|
||||
|
||||
# ##
|
||||
# # Récepteur IR
|
||||
# ##
|
||||
|
||||
# def sml_recep_ir (cont):
|
||||
# if scene.objects['System']['run'] and scene.objects['Module emetteur IR']['actif'] :
|
||||
# obj = cont.owner
|
||||
# system_click(cont, scene.objects['Module recepteur IR'])
|
||||
# if scene.objects['Module recepteur IR']['actif']==True :
|
||||
# scene.objects['Emetteur IR'].color = couleur_jaune
|
||||
# scene.objects['Recepteur IR'].color = couleur_jaune
|
||||
|
||||
# ###############################################################################
|
||||
# # Boutons poussoirs
|
||||
# ###############################################################################
|
||||
|
||||
# ##
|
||||
# # Bouton pousssoir coté rue
|
||||
# ##
|
||||
|
||||
# def sml_bp_rue (cont):
|
||||
# if scene.objects['System']['run'] :
|
||||
# system_click(cont, scene.objects['Module bouton cote rue'])
|
||||
|
||||
# ##
|
||||
# # Bouton pousssoir coté cour
|
||||
# ##
|
||||
|
||||
# def sml_bp_cour (cont):
|
||||
# if scene.objects['System']['run'] :
|
||||
# system_click(cont, scene.objects['Module bouton cote cour'])
|
||||
|
||||
###############################################################################
|
||||
# Système
|
||||
###############################################################################
|
||||
@ -237,9 +163,12 @@ def system_reset ():
|
||||
|
||||
# Cabine
|
||||
# # applyRotationTo(scene.objects['System'], 0, 0, 0)
|
||||
# scene.objects['Portail'].worldPosition.x = scene.objects['Portail']['init_lx']
|
||||
# scene.objects['Portail'].worldPosition.y = scene.objects['Portail']['init_ly']
|
||||
# scene.objects['Portail'].worldPosition.z = scene.objects['Portail']['init_lz']
|
||||
scene.objects['Cabine'].worldPosition.x = scene.objects['Cabine']['init_lx']
|
||||
scene.objects['Cabine'].worldPosition.y = scene.objects['Cabine']['init_ly']
|
||||
scene.objects['Cabine'].worldPosition.z = scene.objects['Cabine']['init_lz']
|
||||
scene.objects['Contrepoids'].worldPosition.x = scene.objects['Contrepoids']['init_lx']
|
||||
scene.objects['Contrepoids'].worldPosition.y = scene.objects['Contrepoids']['init_ly']
|
||||
scene.objects['Contrepoids'].worldPosition.z = scene.objects['Contrepoids']['init_lz']
|
||||
|
||||
# # Moteur à l'état initial
|
||||
# rres=0.001 # resolution rotation
|
||||
@ -272,24 +201,64 @@ def system_run ():
|
||||
# serial_msg=""
|
||||
# return
|
||||
|
||||
# Position cabine numérique
|
||||
print ("serial_msg : ", serial_msg)
|
||||
roll_txt = txt_extrac(serial_msg,"Roll (Rx): ", " Pitch")
|
||||
# pitch_txt= txt_extrac(serial_msg,"Pitch (Ry): ", " \\r\\n")
|
||||
pitch_txt = txt_extrac(serial_msg,"Pitch (Ry): ", " bt_a_m:")
|
||||
if roll_txt !="" and pitch_txt !="" :
|
||||
obj1=scene.objects['Plateau']
|
||||
roll=float(roll_txt)/57.3
|
||||
pitch=float(pitch_txt)/57.3
|
||||
# print ("Roll : ", roll, " Pitch : ", pitch)
|
||||
applyRotationTo(scene.objects['Plateau'], roll,0, 0)
|
||||
applyRotationTo(scene.objects['Plateau'], roll,pitch, 0)
|
||||
scene.objects['Plateau']['roll']=roll
|
||||
scene.objects['Plateau']['pitch']=pitch
|
||||
# Voyant niveau 0
|
||||
# Modele 3d -> Arduino : FIXME
|
||||
# Arduino -> Modele 3d : FIXME
|
||||
if scene.objects['Led niveau 0']['activated']==True 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 scene.objects['Led niveau 0']['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)
|
||||
|
||||
# Capteurs numériques
|
||||
# Voyant niveau 1
|
||||
# Modele 3d -> Arduino : FIXME
|
||||
# Arduino -> Modele 3d : FIXME
|
||||
if scene.objects['Led niveau 1']['activated']==True 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 scene.objects['Led niveau 1']['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)
|
||||
|
||||
|
||||
# Moteur et cabine
|
||||
# Modele 3d -> Arduino : FIXME
|
||||
# Arduino -> Modele 3d : FIXME
|
||||
obj = cont.owner
|
||||
pas_rot = math.pi/7 # z = 14
|
||||
pas = 2.35619/0.3 # pas echelle 1:1 = 2.35619 -> pas à l'échelle de la maquette (0,3) : 2.35619/0.3 = 7,85396
|
||||
vitesse = 0.05
|
||||
obj_moteur = scene.objects['Moteur']
|
||||
obj_vissansfin = scene.objects['Moteur vis sans fin']
|
||||
obj_pignon = scene.objects['Moteur pignon']
|
||||
obj_cabine = scene.objects['Cabine']
|
||||
obj_contrepoids = scene.objects['Contrepoids']
|
||||
obj_cable = scene.objects['Cable']
|
||||
if obj_moteur['up']:
|
||||
# print (scene.objects['Portail'].worldPosition.x)
|
||||
obj_cabine.applyMovement((0, 0, pas*vitesse), True)
|
||||
# engrenage_obj.applyRotation((0, 0, -pas_rot*vitesse), True)
|
||||
# else:
|
||||
if obj_moteur['down']:
|
||||
# print (scene.objects['Portail'].worldPosition.x)
|
||||
obj_cabine.applyMovement((0, 0, -pas*vitesse), True)
|
||||
# engrenage_obj.applyRotation((0, 0, pas_rot*vitesse), True)
|
||||
|
||||
# print ("serial_msg : ", serial_msg)
|
||||
# roll_txt = txt_extrac(serial_msg,"Roll (Rx): ", " Pitch")
|
||||
# # pitch_txt= txt_extrac(serial_msg,"Pitch (Ry): ", " \\r\\n")
|
||||
# pitch_txt = txt_extrac(serial_msg,"Pitch (Ry): ", " bt_a_m:")
|
||||
# if roll_txt !="" and pitch_txt !="" :
|
||||
# obj1=scene.objects['Plateau']
|
||||
# roll=float(roll_txt)/57.3
|
||||
# pitch=float(pitch_txt)/57.3
|
||||
# # print ("Roll : ", roll, " Pitch : ", pitch)
|
||||
# applyRotationTo(scene.objects['Plateau'], roll,0, 0)
|
||||
# applyRotationTo(scene.objects['Plateau'], roll,pitch, 0)
|
||||
# scene.objects['Plateau']['roll']=roll
|
||||
# scene.objects['Plateau']['pitch']=pitch
|
||||
|
||||
# Capteurs
|
||||
# Modele 3d -> Arduino : FIXME
|
||||
# Arduino -> Modele 3d : FIXME
|
||||
|
||||
@ -307,33 +276,16 @@ def system_run ():
|
||||
# bp_phy('Bp Cm', bt_c_m_txt)
|
||||
# bp_phy('Bp Cd', bt_c_d_txt)
|
||||
|
||||
# # Voyants aux états initiaux
|
||||
# scene.objects['Led niveau 0'].setVisible(True,False)
|
||||
# scene.objects['Led niveau 0-on'].setVisible(False,False)
|
||||
# scene.objects['Led niveau 1'].setVisible(True,False)
|
||||
# scene.objects['Led niveau 1-on'].setVisible(False,False)
|
||||
|
||||
# Cabine
|
||||
# # applyRotationTo(scene.objects['System'], 0, 0, 0)
|
||||
# scene.objects['Portail'].worldPosition.x = scene.objects['Portail']['init_lx']
|
||||
# scene.objects['Portail'].worldPosition.y = scene.objects['Portail']['init_ly']
|
||||
# scene.objects['Portail'].worldPosition.z = scene.objects['Portail']['init_lz']
|
||||
|
||||
# # Moteur à l'état initial
|
||||
# rres=0.001 # resolution rotation
|
||||
# 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)
|
||||
|
||||
# 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 1']['activated']=False
|
||||
# scene.objects['Microrupteur niveau 0']['activated']=False
|
||||
# scene.objects['Microrupteur niveau 1']['activated']=False
|
||||
# # 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
|
||||
|
||||
###############################################################################
|
||||
# Interface
|
||||
@ -377,77 +329,3 @@ def click(cont):
|
||||
scene.objects[name].color = color_hl
|
||||
else:
|
||||
scene.objects[name].color = color_active
|
||||
|
||||
##
|
||||
# Activation réel
|
||||
##
|
||||
|
||||
# FIXME
|
||||
|
||||
# obj = cont.owner
|
||||
# if cont.sensors['MO'].status == JUST_ACTIVATED :
|
||||
# obj.color = couleur_blanc
|
||||
# obj['MO']=True
|
||||
# if cont.sensors['Click'].status == JUST_ACTIVATED and scene.objects['System']['manip_mode']==0:
|
||||
# if obj['MO']:
|
||||
# obj_activation['actif'] = True
|
||||
# obj.color = couleur_jaune
|
||||
# if cont.sensors['MO'].status == JUST_RELEASED :
|
||||
# obj['MO']=False
|
||||
# if cont.sensors['Click'].status == ACTIVATE :
|
||||
# obj.color = couleur_jaune
|
||||
# else:
|
||||
# obj.color = couleur_orange
|
||||
# if cont.sensors['Click'].status == JUST_RELEASED:
|
||||
# obj_activation['actif'] = False
|
||||
# obj.color = couleur_blanc
|
||||
# if cont.sensors['MO'].status != ACTIVATE :
|
||||
# obj.color = couleur_orange
|
||||
|
||||
# ###############################################################################
|
||||
# # Boutons poussoirs
|
||||
# ###############################################################################
|
||||
|
||||
# # Activation numérique des boutons
|
||||
# def bp_num(cont):
|
||||
# if scene.objects['Systeme']['run'] :
|
||||
# obj = cont.owner
|
||||
# # print(obj.name, "obj.name")
|
||||
# if cont.sensors['MO'].status == JUST_ACTIVATED :
|
||||
# obj.color = couleur_blanc
|
||||
# obj['MO']=True
|
||||
# if cont.sensors['Click'].status == JUST_ACTIVATED and scene.objects['Systeme']['manip_mode']==0:
|
||||
# if obj['MO']:
|
||||
# obj['actif_num'] = True
|
||||
# # print(obj.name, "activé")
|
||||
# obj.color = couleur_jaune
|
||||
# serial_msg = obj.name+"\n"
|
||||
# serial_comm.write(serial_msg.encode()) # Communication série : modele 3d -> arduino
|
||||
# if cont.sensors['MO'].status == JUST_RELEASED :
|
||||
# if obj['MO']:
|
||||
# obj['MO']=False
|
||||
# if cont.sensors['Click'].status == ACTIVATE :
|
||||
# obj.color = couleur_jaune
|
||||
# else:
|
||||
# obj.color = couleur_orange
|
||||
# if cont.sensors['Click'].status == JUST_RELEASED:
|
||||
# if obj['actif_num']:
|
||||
# obj['actif_num'] = False
|
||||
# # print(obj.name, "desactivé")
|
||||
# obj.color = couleur_blanc
|
||||
# serial_msg = obj.name+" R\n"
|
||||
# # serial_msg = "RELEASED"+"\n"
|
||||
# serial_comm.write(serial_msg.encode()) # Communication série : modele 3d -> arduino
|
||||
# if cont.sensors['MO'].status != ACTIVATE :
|
||||
# obj.color = couleur_orange
|
||||
|
||||
# # 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
|
||||
|
@ -42,7 +42,7 @@ def commandes():
|
||||
print ("Ok go !!")
|
||||
|
||||
# Ecrire votre code ici ...
|
||||
# voy_0(True) # Activer le voyant du niveau 0
|
||||
voy_0(True) # Activer le voyant du niveau 0
|
||||
while True:
|
||||
pass
|
||||
|
||||
|
@ -153,12 +153,12 @@ def quit():
|
||||
# Ordre pour le voyant 0
|
||||
def voy_0 (order):
|
||||
scene.objects['Led niveau 0']['activated']=order
|
||||
if order:
|
||||
scene.objects['Led niveau 0-on'].setVisible(True,False)
|
||||
scene.objects['Led niveau 0'].setVisible(False,False)
|
||||
else:
|
||||
scene.objects['Led niveau 0'].setVisible(True,False)
|
||||
scene.objects['Led niveau 0-on'].setVisible(False,False)
|
||||
# if order:
|
||||
# scene.objects['Led niveau 0-on'].setVisible(True,False)
|
||||
# scene.objects['Led niveau 0'].setVisible(False,False)
|
||||
# else:
|
||||
# scene.objects['Led niveau 0'].setVisible(True,False)
|
||||
# scene.objects['Led niveau 0-on'].setVisible(False,False)
|
||||
# global gyr_pin
|
||||
# if scene.objects['System']['twins'] :
|
||||
# if ordre :
|
||||
@ -169,12 +169,12 @@ def voy_0 (order):
|
||||
# Ordre pour le voyant 1
|
||||
def voy_1 (order):
|
||||
scene.objects['Led niveau 1']['activated']=order
|
||||
if order:
|
||||
scene.objects['Led niveau 1-on'].setVisible(True,False)
|
||||
scene.objects['Led niveau 1'].setVisible(False,False)
|
||||
else:
|
||||
scene.objects['Led niveau 1'].setVisible(True,False)
|
||||
scene.objects['Led niveau 1-on'].setVisible(False,False)
|
||||
# if order:
|
||||
# scene.objects['Led niveau 1-on'].setVisible(True,False)
|
||||
# scene.objects['Led niveau 1'].setVisible(False,False)
|
||||
# else:
|
||||
# scene.objects['Led niveau 1'].setVisible(True,False)
|
||||
# scene.objects['Led niveau 1-on'].setVisible(False,False)
|
||||
|
||||
# Ordre pour le moteur phase monter
|
||||
def mot_m (order):
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user