2022-12-18 22:46:19 +01:00
import bge # Bibliothèque Blender Game Engine (UPBGE)
import twin # Bibliothèque de l'environnement 3D des jumeaux numériques
import math
import time
2023-02-12 00:34:37 +01:00
import runpy # Exécution de script Python légère (sans import)
2022-12-18 22:46:19 +01:00
###############################################################################
2022-12-19 17:28:29 +01:00
# volrou.py
2022-12-18 22:46:19 +01:00
# @title: Commandes pour le volet roulant
# @project: Blender-EduTech
# @lang: fr
# @authors: Philippe Roy <philippe.roy@ac-grenoble.fr>
2023-01-01 17:34:01 +01:00
# @copyright: Copyright (C) 2022-2023 Philippe Roy
2022-12-18 22:46:19 +01:00
# @license: GNU GPL
###############################################################################
# Récupérer la scène UPBGE
scene = bge . logic . getCurrentScene ( )
2023-01-18 18:21:12 +01:00
# Configuration des variables publiques
# 'nom_variable' :
2023-01-31 11:15:21 +01:00
# - Objet 3D : [nom de l'objet 3D, propriété associée à la valeur (activate ou activated_real), type de la valeur ('d' (digital, binary), 'a', (analog) ou 'n' (numeric)), échelle (1 si ommis)]
2023-02-03 05:58:20 +01:00
# - Configuration de la broche : [nom de la propriété stockant l'object broche (pyfirmata),
# type de broche par défaut : 'd' (digital), 'a' (analog) ou 'p' (pwm)), mode de la broche par défaut : 'i' (input) ou 'o' (output)]
# - Configuration du graphique : ['marque', 'type de ligne', 'couleur', linewidth]] (Codification de Matplotlib)
2023-01-18 18:21:12 +01:00
#
# 'nom_variable_r' est la valeur réelle de la variable (valeur numérique) 'nom_variable' issue du jumelage numérique.
# Dans ce cas, il n'y a pas configuration de broche car elle est présente sur la variable 'nom_variable'.
2023-02-03 05:58:20 +01:00
# Ce distinguo ne concerne que les entrées, car les sorties sont pilotées par le numérique.
2023-01-18 18:21:12 +01:00
public_vars = {
2023-01-31 14:06:34 +01:00
' t ' : [ [ ' System ' , ' time ' , ' a ' ] , [ ] , [ ] ] ,
' fdc_h ' : [ [ ' Microrupteur haut ' , ' activated ' , ' d ' ] , [ ' pin ' , ' d ' , ' i ' ] , [ ] ] ,
' fdc_h_r ' : [ [ ' Microrupteur haut ' , ' activated_real ' , ' d ' ] , [ ] , [ ] ] ,
' fdc_b ' : [ [ ' Microrupteur bas ' , ' activated ' , ' d ' ] , [ ' pin ' , ' d ' , ' i ' ] , [ ] ] ,
' fdc_b_r ' : [ [ ' Microrupteur bas ' , ' activated_real ' , ' d ' ] , [ ] , [ ] ] ,
' bp_m ' : [ [ ' Bp monter ' , ' activated ' , ' d ' ] , [ ' pin ' , ' d ' , ' i ' ] , [ ] ] ,
' bp_m_r ' : [ [ ' Bp monter ' , ' activated_real ' , ' d ' ] , [ ] , [ ] ] ,
' bp_d ' : [ [ ' Bp descendre ' , ' activated ' , ' d ' ] , [ ' pin ' , ' d ' , ' i ' ] , [ ] ] ,
' bp_d_r ' : [ [ ' Bp descendre ' , ' activated_real ' , ' d ' ] , [ ] , [ ] ] ,
' bp_a ' : [ [ ' Bp arret ' , ' activated ' , ' d ' ] , [ ' pin ' , ' d ' , ' i ' ] , [ ] ] ,
' bp_a_r ' : [ [ ' Bp arret ' , ' activated_real ' , ' d ' ] , [ ] , [ ] ] ,
' mot_m ' : [ [ ' Moteur ' , ' up ' , ' d ' ] , [ ' pin_up ' , ' d ' , ' o ' ] , [ ] ] ,
' mot_d ' : [ [ ' Moteur ' , ' down ' , ' d ' ] , [ ' pin_down ' , ' d ' , ' o ' ] , [ ] ] ,
' mot_angle ' : [ [ ' Moteur ' , ' alpha ' , ' a ' ] , [ ] , [ ] ] ,
' mot_vitesse ' : [ [ ' Moteur ' , ' speed ' , ' a ' ] , [ ] , [ ] ] ,
' mot_pas ' : [ [ ' Moteur ' , ' step ' , ' a ' ] , [ ] , [ ] ] ,
' bp_auto ' : [ [ ' Bp auto ' , ' activated ' , ' d ' ] , [ ' pin ' , ' d ' , ' i ' ] , [ ] ] ,
' bp_auto_r ' : [ [ ' Bp auto ' , ' activated_real ' , ' d ' ] , [ ] , [ ] ] ,
2023-02-11 23:52:07 +01:00
' bg_auto ' : [ [ ' Bg auto ' , ' activated ' , ' d ' ] , [ ' pin ' , ' d ' , ' i ' ] , [ ] ] ,
' bg_auto_r ' : [ [ ' Bg auto ' , ' activated_real ' , ' d ' ] , [ ] , [ ] ] ,
2023-01-31 14:06:34 +01:00
' voy_auto ' : [ [ ' Led auto ' , ' activated ' , ' d ' ] , [ ' pin ' , ' d ' , ' o ' ] , [ ] ] ,
2023-02-15 17:56:49 +01:00
' lum ' : [ [ ' Recepteur LDR ' , ' value ' , ' a ' ] , [ ' pin ' , ' a ' , ' i ' ] , [ ] ] ,
' lum_r ' : [ [ ' Recepteur LDR ' , ' value_real ' , ' a ' ] , [ ] , [ ] ] }
2023-01-08 19:55:18 +01:00
2022-12-18 22:46:19 +01:00
# Couleurs
2022-12-22 05:02:33 +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
2023-01-07 18:01:03 +01:00
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
2022-12-18 22:46:19 +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
###############################################################################
# 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
2023-01-06 21:23:44 +01:00
2023-01-08 19:55:18 +01:00
# Brochage
2023-01-18 18:21:12 +01:00
for pin in public_vars :
if public_vars [ pin ] [ 1 ] != [ ] :
scene . objects [ public_vars [ pin ] [ 0 ] [ 0 ] ] [ public_vars [ pin ] [ 1 ] [ 0 ] ] = None
2023-01-08 19:55:18 +01:00
2023-01-11 22:09:10 +01:00
# Groupe de focus pour les actionneurs
twin . cycle_def_focusgroup ( [ [ " Moteur " , " blue " ] ,
[ " Capuchon moteur " , " blue " ] ,
[ " Arriere moteur " , " blue " ] ,
[ " Moteur axe-1 " , " blue " ] ,
[ " Moteur coupleur " , " blue-dark " ] ,
[ " Moteur vis1 " , " grey " ] ,
[ " Moteur vis2 " , " grey " ] ] , " Moteur : mot_m(True | False), mot_d(True | False) " )
twin . cycle_def_focusgroup ( [ [ " Led auto " , " led_yellow " ] ] , " Voyant témoin mode automatique : voy_auto(True | False) " )
2023-02-11 23:52:07 +01:00
# twin.cycle_def_focusgroup([["Bg auto", "color_active"],
# ["Bg auto-on", "color_active"]], "Voyant témoin mode automatique : voy_auto(True | False)")
2023-01-11 22:09:10 +01:00
2023-01-06 21:23:44 +01:00
# Description des composants sensibles
scene . objects [ ' Bp monter ' ] [ ' description ' ] = " Bouton poussoir monter volet : bp_m() "
scene . objects [ ' Bp descendre ' ] [ ' description ' ] = " Bouton poussoir descendre volet : bp_d() "
scene . objects [ ' Bp arret ' ] [ ' description ' ] = " Bouton poussoir arrêt volet : bp_a() "
scene . objects [ ' Bp auto ' ] [ ' description ' ] = " Bouton poussoir mode automatique : bp_auto() "
2023-02-11 23:52:07 +01:00
scene . objects [ ' Bg auto ' ] [ ' description ' ] = " Bouton à glissière mode automatique : bg_auto() "
scene . objects [ ' Bg auto-on ' ] [ ' description ' ] = " Bouton à glissière mode automatique : bg_auto() "
2023-01-06 21:23:44 +01:00
scene . objects [ ' Microrupteur haut ' ] [ ' description ' ] = " Capteur fin de course volet en haut : fdc_h() "
scene . objects [ ' Microrupteur bas ' ] [ ' description ' ] = " Capteur fin de course volet en bas : fdc_b() "
scene . objects [ ' Recepteur LDR ' ] [ ' description ' ] = " Capteur de luminosité (LDR) : lum() "
2023-02-12 00:34:37 +01:00
# Initialisation du système
system_init ( )
2022-12-18 22:46:19 +01:00
2023-01-18 18:21:12 +01:00
def get_public_vars ( ) :
return public_vars
2023-01-09 05:54:31 +01:00
2022-12-23 14:30:13 +01:00
###############################################################################
# Actionneurs
###############################################################################
2022-12-18 22:46:19 +01:00
##
2022-12-23 14:30:13 +01:00
# Moteur et volet
2022-12-18 22:46:19 +01:00
##
2022-12-23 14:30:13 +01:00
def mot ( cont ) :
2022-12-18 22:46:19 +01:00
if scene . objects [ ' System ' ] [ ' run ' ] :
obj = cont . owner
2022-12-26 19:16:30 +01:00
layer = 0
2023-01-11 22:09:10 +01:00
2022-12-26 18:10:17 +01:00
# Monter
if obj [ ' up ' ] :
2023-01-08 19:55:18 +01:00
2023-02-03 05:58:20 +01:00
# Physique du modèle 3D
if obj [ ' prior ' ] :
# Physique (sens horaire -> négatif)
obj [ ' step ' ] = abs ( scene . objects [ ' Axe enrouleur ' ] . worldOrientation . to_euler ( ) . x - scene . objects [ ' Axe enrouleur ' ] [ ' last_alpha ' ] )
obj [ ' alpha ' ] = obj [ ' last_alpha ' ] - obj [ ' step ' ]
if scene . objects [ ' System ' ] [ ' time ' ] != obj [ ' last_time ' ] :
obj [ ' speed ' ] = - obj [ ' step ' ] / ( scene . objects [ ' System ' ] [ ' time ' ] - obj [ ' last_time ' ] )
# print (obj['speed'], obj['step'],scene.objects['System']['time']-obj['last_time'], scene.objects['System']['time'], obj['last_time'])
# Animation
if obj [ ' frame_down ' ] < 105 : # Volet pas cassé
if obj [ ' frame_up ' ] < 0 : # Réinit entre 0 et -4
obj [ ' frame_up ' ] = 0
if obj [ ' frame_up ' ] < 110 : # Cycle normal de 0 à 100 (butée en 110)
start = obj [ ' frame_up ' ]
end = 111
priority = 1
blendin = 1.0
mode = bge . logic . KX_ACTION_MODE_PLAY
layerWeight = 0.0
ipoFlags = 0
speed = 0.4 # FIXME
scene . objects [ ' Axe enrouleur ' ] . playAction ( ' Axe enrouleur-Up ' , start , 135 , layer , priority , blendin , mode , layerWeight , ipoFlags , speed )
scene . objects [ ' Axe fdc ' ] . playAction ( ' Axe fdc-Up ' , start , 135 , 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 . objects [ ' Lame volet 13 ' ] . playAction ( ' Lame volet 13-Up ' , start , end , layer , priority , blendin , mode , layerWeight , ipoFlags , speed )
obj [ ' frame_up ' ] = scene . objects [ ' Axe enrouleur ' ] . getActionFrame ( layer )
else : # Tourner sans fin
# vitesse = 0.015
vitesse = 0.03
pas_axe_enrouleur = 0.5
pas_axe_fdc = 0.5 / 3
# scene.objects['Axe enrouleur'].applyRotation((pas_axe_enrouleur*vitesse, 0, 0), True)
scene . objects [ ' Axe fdc ' ] . stopAction ( layer )
scene . objects [ ' Axe fdc ' ] . applyRotation ( ( - pas_axe_fdc * vitesse , 0 , 0 ) , True )
if obj [ ' frame_up ' ] == 170 : # Réinit
obj [ ' frame_up ' ] = 110
start = obj [ ' frame_up ' ]
end = 171
priority = 1
blendin = 1.0
mode = bge . logic . KX_ACTION_MODE_PLAY
layerWeight = 0.0
ipoFlags = 0
speed = 0.4 # FIXME
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 . objects [ ' Lame volet 13 ' ] . playAction ( ' Lame volet 13-Up ' , start , end , layer , priority , blendin , mode , layerWeight , ipoFlags , speed )
obj [ ' frame_up ' ] = scene . objects [ ' Axe enrouleur ' ] . getActionFrame ( layer )
obj [ ' frame_down ' ] = 100 - obj [ ' frame_up ' ]
# Physique après mouvement (last_*)
scene . objects [ ' Axe enrouleur ' ] [ ' last_alpha ' ] = scene . objects [ ' Axe enrouleur ' ] . worldOrientation . to_euler ( ) . x
obj [ ' last_time ' ] = scene . objects [ ' System ' ] [ ' time ' ]
obj [ ' last_alpha ' ] = obj [ ' alpha ' ]
2023-01-20 18:31:51 +01:00
2023-01-08 19:55:18 +01:00
# Modele 3D -> Arduino
2023-02-03 05:58:20 +01:00
if scene . objects [ ' System ' ] [ ' twins ' ] and obj [ ' prior_real ' ] :
2023-02-14 00:06:50 +01:00
if scene . objects [ ' Moteur ' ] [ ' pin_up ' ] is not None :
if scene . objects [ ' Moteur ' ] [ ' pin_down ' ] is not None :
scene . objects [ ' Moteur ' ] [ ' pin_down ' ] . write ( 0 )
scene . objects [ ' Moteur ' ] [ ' pin_up ' ] . write ( 1 )
2023-01-08 19:55:18 +01:00
2022-12-26 18:10:17 +01:00
# Descendre
if obj [ ' down ' ] :
2023-01-08 19:55:18 +01:00
2023-02-03 05:58:20 +01:00
# Physique du modèle 3D
if obj [ ' prior ' ] :
# Physique (sens trigo -> positif)
obj [ ' step ' ] = abs ( scene . objects [ ' Axe enrouleur ' ] . worldOrientation . to_euler ( ) . x - scene . objects [ ' Axe enrouleur ' ] [ ' last_alpha ' ] )
obj [ ' alpha ' ] = obj [ ' last_alpha ' ] + obj [ ' step ' ]
if scene . objects [ ' System ' ] [ ' time ' ] != obj [ ' last_time ' ] :
obj [ ' speed ' ] = obj [ ' step ' ] / ( scene . objects [ ' System ' ] [ ' time ' ] - obj [ ' last_time ' ] )
# print (round(obj['last_alpha'], 3), round(obj['step'], 3), round(obj['alpha'], 3), round(obj['speed'], 3),
# round(scene.objects['Axe enrouleur']['last_alpha'],3), round(scene.objects['Axe enrouleur'].worldOrientation.to_euler().x,3))
# Animation
if obj [ ' frame_up ' ] < 105 : # Volet pas cassé
if obj [ ' frame_down ' ] < 0 : # Réinit entre 0 et -4
obj [ ' frame_down ' ] = 0
if obj [ ' frame_down ' ] < 135 : # Cycle normal de 0 à 100 (butée en 135)
start = obj [ ' frame_down ' ]
end = 136
layer = 0
priority = 1
blendin = 1.0
mode = bge . logic . KX_ACTION_MODE_PLAY
layerWeight = 0.0
ipoFlags = 0
speed = 0.4 # FIXME
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 . objects [ ' Lame volet 13 ' ] . playAction ( ' Lame volet 13-Down ' , start , end , layer , priority , blendin , mode , layerWeight , ipoFlags , speed )
obj [ ' frame_down ' ] = scene . objects [ ' Axe enrouleur ' ] . getActionFrame ( layer )
else : # Tourner sans fin et volet cassé
scene . objects [ ' Axe enrouleur ' ] . stopAction ( layer )
scene . objects [ ' Axe fdc ' ] . stopAction ( layer )
scene . objects [ ' Lame volet 1 ' ] . stopAction ( layer )
scene . objects [ ' Lame volet 2 ' ] . stopAction ( layer )
scene . objects [ ' Lame volet 3 ' ] . stopAction ( layer )
scene . objects [ ' Lame volet 4 ' ] . stopAction ( layer )
scene . objects [ ' Lame volet 5 ' ] . stopAction ( layer )
scene . objects [ ' Lame volet 6 ' ] . stopAction ( layer )
scene . objects [ ' Lame volet 7 ' ] . stopAction ( layer )
scene . objects [ ' Lame volet 8 ' ] . stopAction ( layer )
scene . objects [ ' Lame volet 9 ' ] . stopAction ( layer )
scene . objects [ ' Lame volet 10 ' ] . stopAction ( layer )
scene . objects [ ' Lame volet 11 ' ] . stopAction ( layer )
scene . objects [ ' Lame volet 12 ' ] . stopAction ( layer )
scene . objects [ ' Lame volet 13 ' ] . stopAction ( layer )
vitesse = 0.03 # FIXME
# vitesse = 0.015
pas_axe_enrouleur = 0.5
pas_axe_fdc = 0.5 / 3
pas_volet = 10
scene . objects [ ' Axe enrouleur ' ] . applyRotation ( ( - pas_axe_enrouleur * vitesse , 0 , 0 ) , True )
scene . objects [ ' Axe fdc ' ] . applyRotation ( ( pas_axe_fdc * vitesse , 0 , 0 ) , True )
scene . objects [ ' Lame volet 1 ' ] . applyMovement ( ( 0 , 0 , - pas_volet * vitesse ) , False )
scene . objects [ ' Lame volet 2 ' ] . applyMovement ( ( 0 , 0 , - pas_volet * vitesse ) , False )
scene . objects [ ' Lame volet 3 ' ] . applyMovement ( ( 0 , 0 , - pas_volet * vitesse ) , False )
scene . objects [ ' Lame volet 4 ' ] . applyMovement ( ( 0 , 0 , - pas_volet * vitesse ) , False )
scene . objects [ ' Lame volet 5 ' ] . applyMovement ( ( 0 , 0 , - pas_volet * vitesse ) , False )
scene . objects [ ' Lame volet 6 ' ] . applyMovement ( ( 0 , 0 , - pas_volet * vitesse ) , False )
scene . objects [ ' Lame volet 7 ' ] . applyMovement ( ( 0 , 0 , - pas_volet * vitesse ) , False )
scene . objects [ ' Lame volet 8 ' ] . applyMovement ( ( 0 , 0 , - pas_volet * vitesse ) , False )
scene . objects [ ' Lame volet 9 ' ] . applyMovement ( ( 0 , 0 , - pas_volet * vitesse ) , False )
scene . objects [ ' Lame volet 10 ' ] . applyMovement ( ( 0 , 0 , - pas_volet * vitesse ) , False )
scene . objects [ ' Lame volet 11 ' ] . applyMovement ( ( 0 , 0 , - pas_volet * vitesse ) , False )
scene . objects [ ' Lame volet 12 ' ] . applyMovement ( ( 0 , 0 , - pas_volet * vitesse ) , False )
scene . objects [ ' Lame volet 13 ' ] . applyMovement ( ( 0 , 0 , - pas_volet * vitesse ) , False )
obj [ ' frame_down ' ] + = 1
obj [ ' frame_up ' ] = 100 - obj [ ' frame_down ' ]
# Physique après mouvement (last_*)
scene . objects [ ' Axe enrouleur ' ] [ ' last_alpha ' ] = scene . objects [ ' Axe enrouleur ' ] . worldOrientation . to_euler ( ) . x
obj [ ' last_time ' ] = scene . objects [ ' System ' ] [ ' time ' ]
obj [ ' last_alpha ' ] = obj [ ' alpha ' ]
# Modele 3D -> Arduino
if scene . objects [ ' System ' ] [ ' twins ' ] and obj [ ' prior_real ' ] :
2023-02-14 00:06:50 +01:00
if scene . objects [ ' Moteur ' ] [ ' pin_down ' ] is not None :
if scene . objects [ ' Moteur ' ] [ ' pin_up ' ] is not None :
scene . objects [ ' Moteur ' ] [ ' pin_up ' ] . write ( 0 )
scene . objects [ ' Moteur ' ] [ ' pin_down ' ] . write ( 1 )
2023-02-03 05:58:20 +01:00
# Arrêt
if obj [ ' up ' ] == False and obj [ ' down ' ] == False :
# Physique du modèle 3D
if obj [ ' prior ' ] :
obj [ ' speed ' ] = 0
scene . objects [ ' Axe enrouleur ' ] [ ' last_alpha ' ] = scene . objects [ ' Axe enrouleur ' ] . worldOrientation . to_euler ( ) . x
obj [ ' last_time ' ] = scene . objects [ ' System ' ] [ ' time ' ]
obj [ ' last_alpha ' ] = obj [ ' alpha ' ]
# Animation
if scene . objects [ ' Axe enrouleur ' ] . isPlayingAction ( layer ) :
2022-12-28 14:16:14 +01:00
scene . objects [ ' Axe enrouleur ' ] . stopAction ( layer )
scene . objects [ ' Axe fdc ' ] . stopAction ( layer )
scene . objects [ ' Lame volet 1 ' ] . stopAction ( layer )
scene . objects [ ' Lame volet 2 ' ] . stopAction ( layer )
scene . objects [ ' Lame volet 3 ' ] . stopAction ( layer )
scene . objects [ ' Lame volet 4 ' ] . stopAction ( layer )
scene . objects [ ' Lame volet 5 ' ] . stopAction ( layer )
scene . objects [ ' Lame volet 6 ' ] . stopAction ( layer )
scene . objects [ ' Lame volet 7 ' ] . stopAction ( layer )
scene . objects [ ' Lame volet 8 ' ] . stopAction ( layer )
scene . objects [ ' Lame volet 9 ' ] . stopAction ( layer )
scene . objects [ ' Lame volet 10 ' ] . stopAction ( layer )
scene . objects [ ' Lame volet 11 ' ] . stopAction ( layer )
scene . objects [ ' Lame volet 12 ' ] . stopAction ( layer )
scene . objects [ ' Lame volet 13 ' ] . stopAction ( layer )
2022-12-26 19:16:30 +01:00
2023-01-08 19:55:18 +01:00
# Modele 3D -> Arduino
2023-02-03 05:58:20 +01:00
if scene . objects [ ' System ' ] [ ' twins ' ] and obj [ ' prior_real ' ] :
2023-02-14 00:06:50 +01:00
if scene . objects [ ' Moteur ' ] [ ' pin_down ' ] is not None :
if scene . objects [ ' Moteur ' ] [ ' pin_up ' ] is not None :
scene . objects [ ' Moteur ' ] [ ' pin_up ' ] . write ( 0 )
scene . objects [ ' Moteur ' ] [ ' pin_down ' ] . write ( 0 )
2023-01-08 19:55:18 +01:00
2022-12-18 22:46:19 +01:00
###############################################################################
# Capteurs fin de course
###############################################################################
##
2022-12-23 14:30:13 +01:00
# Etat capteur fin de course volet en haut
2022-12-18 22:46:19 +01:00
##
2022-12-23 14:30:13 +01:00
def fdc_h ( cont ) :
2022-12-18 22:46:19 +01:00
if scene . objects [ ' System ' ] [ ' run ' ] :
obj = cont . owner
2023-01-08 19:55:18 +01:00
# Arduino -> Modele 3D
2023-02-03 05:58:20 +01:00
if scene . objects [ ' System ' ] [ ' twins ' ] and obj [ ' prior_real ' ] :
2023-01-08 19:55:18 +01:00
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
2022-12-28 14:16:14 +01:00
# Etat capteur en fonction du volet
2022-12-28 18:15:42 +01:00
scene . objects [ ' Axe fdc ' ] [ ' rx ' ] = scene . objects [ ' Axe fdc ' ] . localOrientation . to_euler ( ) . x * ( 180 / math . pi )
2023-02-03 05:58:20 +01:00
if scene . objects [ ' Axe fdc ' ] [ ' rx ' ] > = - 175 and scene . objects [ ' Axe fdc ' ] [ ' rx ' ] < = - 155 and obj [ ' activated ' ] == False and obj [ ' prior ' ] :
2022-12-28 14:16:14 +01:00
obj [ ' activated ' ] = True
2023-02-03 05:58:20 +01:00
if scene . objects [ ' Axe fdc ' ] [ ' rx ' ] < - 175 or scene . objects [ ' Axe fdc ' ] [ ' rx ' ] > - 155 and obj [ ' activated ' ] == True and obj [ ' prior ' ] :
2022-12-28 14:16:14 +01:00
obj [ ' activated ' ] = False
2022-12-28 18:15:42 +01:00
2023-01-08 19:55:18 +01:00
# Forçage par clic
2023-02-03 05:58:20 +01:00
if obj [ ' click ' ] == True and obj [ ' prior ' ] :
2022-12-23 14:30:13 +01:00
obj [ ' activated ' ] = True
2022-12-18 22:46:19 +01:00
2022-12-23 14:30:13 +01:00
# Couleurs
2023-01-08 19:55:18 +01:00
twin . cycle_sensitive_color ( obj )
2022-12-18 22:46:19 +01:00
##
2022-12-23 14:30:13 +01:00
# Etat capteur fin de course volet en bas
2022-12-18 22:46:19 +01:00
##
2022-12-23 14:30:13 +01:00
def fdc_b ( cont ) :
2022-12-18 22:46:19 +01:00
if scene . objects [ ' System ' ] [ ' run ' ] :
obj = cont . owner
2023-01-08 19:55:18 +01:00
# Arduino -> Modele 3D
2023-02-03 05:58:20 +01:00
if scene . objects [ ' System ' ] [ ' twins ' ] and obj [ ' prior_real ' ] :
2023-01-08 19:55:18 +01:00
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
2022-12-28 14:16:14 +01:00
# Etat capteur en fonction du volet
2023-02-03 05:58:20 +01:00
if scene . objects [ ' Axe fdc ' ] [ ' rx ' ] > = - 10 and scene . objects [ ' Axe fdc ' ] [ ' rx ' ] < = 10 and obj [ ' activated ' ] == False and obj [ ' prior ' ] :
2022-12-28 14:16:14 +01:00
obj [ ' activated ' ] = True
2023-02-03 05:58:20 +01:00
if scene . objects [ ' Axe fdc ' ] [ ' rx ' ] < - 10 or scene . objects [ ' Axe fdc ' ] [ ' rx ' ] > 10 and obj [ ' activated ' ] == True and obj [ ' prior ' ] :
2022-12-28 14:16:14 +01:00
obj [ ' activated ' ] = False
2022-12-23 14:30:13 +01:00
2023-01-08 19:55:18 +01:00
# Forçage par clic
2023-02-03 05:58:20 +01:00
if obj [ ' click ' ] == True and obj [ ' prior ' ] :
2022-12-23 14:30:13 +01:00
obj [ ' activated ' ] = True
# Couleurs
2023-01-08 19:55:18 +01:00
twin . cycle_sensitive_color ( obj )
2022-12-18 22:46:19 +01:00
###############################################################################
# Système
###############################################################################
##
# Initialisation du système
# Le moteur est géré en continue.
##
def system_init ( ) :
2022-12-23 14:30:13 +01:00
# 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 ( )
2022-12-18 22:46:19 +01:00
##
# Réinitialisation du système
##
def system_reset ( ) :
2023-02-12 00:34:37 +01:00
# Mise en place de la variante
runpy . run_path ( scene . objects [ ' System ' ] [ ' script ' ] , run_name = ' init ' )
2023-02-03 05:58:20 +01:00
# Entrées à l'état initial
2023-02-15 17:56:49 +01:00
objs = [ ' Bp monter ' , ' Bp arret ' , ' Bp descendre ' , ' Bp auto ' , ' Bg auto ' , ' Microrupteur haut ' , ' Microrupteur bas ' ]
2023-02-03 05:58:20 +01:00
for obj in objs :
scene . objects [ obj ] [ ' activated ' ] = False
scene . objects [ obj ] [ ' activated_real ' ] = False
2023-02-15 17:56:49 +01:00
scene . objects [ ' Recepteur LDR ' ] [ ' value ' ] = 0
scene . objects [ ' Recepteur LDR ' ] [ ' value_real ' ] = 0
2023-02-11 23:52:07 +01:00
scene . objects [ ' Bg auto-on ' ] . setVisible ( False , False )
2023-02-03 05:58:20 +01:00
2022-12-23 14:30:13 +01:00
# Voyants aux états initiaux
2023-02-03 05:58:20 +01:00
scene . objects [ ' Led auto ' ] [ ' activated ' ] = False
2022-12-23 14:30:13 +01:00
scene . objects [ ' Led auto ' ] . setVisible ( True , False )
scene . objects [ ' Led auto-on ' ] . setVisible ( False , False )
2022-12-18 22:46:19 +01:00
2023-02-03 05:58:20 +01:00
# Volet et moteur
scene . objects [ ' Moteur ' ] [ ' up ' ] = False
scene . objects [ ' Moteur ' ] [ ' down ' ] = False
scene . objects [ ' Moteur ' ] [ ' alpha ' ] = 0
scene . objects [ ' Moteur ' ] [ ' last_alpha ' ] = 0
scene . objects [ ' Moteur ' ] [ ' speed ' ] = 0
scene . objects [ ' Moteur ' ] [ ' speed_setting ' ] = 125.6 # Vitesse du moteur numérique : 125.6 rad /s ( 20 tr / s )
scene . objects [ ' Moteur ' ] [ ' step ' ] = 0
scene . objects [ ' Axe enrouleur ' ] [ ' last_alpha ' ] = scene . objects [ ' Axe enrouleur ' ] . worldOrientation . to_euler ( ) . x
2022-12-28 14:16:14 +01:00
obj = scene . objects [ ' Moteur ' ]
start = 49
end = 50
priority = 1
layer = 0
blendin = 1.0
mode = bge . logic . KX_ACTION_MODE_PLAY
layerWeight = 0.0
ipoFlags = 0
speed = 0.4
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 . objects [ ' Lame volet 13 ' ] . playAction ( ' Lame volet 13-Up ' , start , end , layer , priority , blendin , mode , layerWeight , ipoFlags , speed )
obj [ ' frame_up ' ] = scene . objects [ ' Axe enrouleur ' ] . getActionFrame ( layer )
obj [ ' frame_down ' ] = 100 - obj [ ' frame_up ' ]
2022-12-18 22:46:19 +01:00
2023-02-03 05:58:20 +01:00
# Priorités activées
2023-02-11 23:52:07 +01:00
objs = [ ' Bp monter ' , ' Bp arret ' , ' Bp descendre ' , ' Bp auto ' , ' Bg auto ' , ' Microrupteur haut ' , ' Microrupteur bas ' , ' Recepteur LDR ' ,
2023-02-03 05:58:20 +01:00
' Moteur ' , ' Led auto ' ]
for obj in objs :
scene . objects [ obj ] [ ' prior ' ] = True
scene . objects [ obj ] [ ' prior_real ' ] = True