jumeaux-numeriques/monte_charge/montchg_lib.py

112 lines
3.5 KiB
Python

import bge # Bibliothèque Blender Game Engine (UPBGE)
from twin_threading import thread_cmd_start, thread_cmd_stop, thread_cmd_end # Multithreading
from twin_serial import jumeau, jumeau_stop, serial_close # Liaison série
import time
###############################################################################
# montchg_lib.py
# @title: Bibliothèque utilisateur du monte-charge
# @project: Blender-EduTech
# @lang: fr
# @authors: Philippe Roy <philippe.roy@ac-grenoble.fr>
# @copyright: Copyright (C) 2022-2023 Philippe Roy
# @license: GNU GPL
###############################################################################
# Récupérer la scène UPBGE
scene = bge.logic.getCurrentScene()
# UPBGE constants
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
###############################################################################
# Voyants
###############################################################################
# Ordre pour allumer le voyant niveau 0
def voy_0 (order):
scene.objects['Led niveau 0']['activated']=order
# Ordre pour allumer le voyant niveau 1
def voy_1 (order):
scene.objects['Led niveau 1']['activated']=order
###############################################################################
# Actionneurs
###############################################################################
# Ordre pour le moteur phase monter
def mot_m (order):
scene.objects['Moteur']['up']=order
# Ordre pour le moteur phase descendre
def mot_d (order):
scene.objects['Moteur']['down']=order
###############################################################################
# Capteurs
###############################################################################
# Compte-rendu du capteur de présence cabine niveau 0
def pc_0 ():
if scene.objects['Microrupteur niveau 0']['activated'] or scene.objects['Microrupteur niveau 0']['activated_real']:
return True
else:
return False
# Compte-rendu du capteur de présence cabine niveau 0
def pc_1 ():
if scene.objects['Microrupteur niveau 1']['activated'] or scene.objects['Microrupteur niveau 1']['activated_real']:
return True
else:
return False
###############################################################################
# Boutons poussoirs
###############################################################################
# Compte-rendu du bouton pousssoir appel niveau 0
def ba_0 ():
if scene.objects['Bp niveau 0']['activated'] or scene.objects['Bp niveau 0']['activated_real']:
return True
else:
return False
# Compte-rendu du bouton pousssoir appel niveau 1
def ba_1 ():
if scene.objects['Bp niveau 1']['activated'] or scene.objects['Bp niveau 1']['activated_real']:
return True
else:
return False
###############################################################################
# Cycle
###############################################################################
# Temporisation
def tempo (duree):
time.sleep(duree)
# Arrêt
def stop():
if scene.objects['System']['twins']:
serial_close(scene.objects['System']['board'])
time.sleep(1)
thread_cmd_stop()
# Fin naturelle
def end():
if scene.objects['System']['twins']:
serial_close(scene.objects['System']['board'])
time.sleep(1)
thread_cmd_end()
def fin():
end()
def quit():
end()