2022-12-18 17:33:23 +01:00
|
|
|
import bge # Bibliothèque Blender Game Engine (UPBGE)
|
2023-01-06 21:23:44 +01:00
|
|
|
from twin_threading import thread_cmd_start, thread_cmd_stop, thread_cmd_end # Multithreading
|
2023-01-09 05:54:31 +01:00
|
|
|
from twin_serial import jumeau, jumeau_stop, serial_close # Liaison série
|
2022-12-23 23:29:17 +01:00
|
|
|
import time
|
2022-12-18 17:33:23 +01:00
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# montchg_lib.py
|
|
|
|
# @title: Bibliothèque utilisateur du monte-charge
|
|
|
|
# @project: Blender-EduTech
|
|
|
|
# @lang: fr
|
|
|
|
# @authors: Philippe Roy <philippe.roy@ac-grenoble.fr>
|
2023-01-06 21:23:44 +01:00
|
|
|
# @copyright: Copyright (C) 2022-2023 Philippe Roy
|
2022-12-18 17:33:23 +01:00
|
|
|
# @license: GNU GPL
|
|
|
|
###############################################################################
|
|
|
|
|
2023-01-07 18:01:03 +01:00
|
|
|
# Récupérer la scène UPBGE
|
2022-12-18 17:33:23 +01:00
|
|
|
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
|
|
|
|
|
|
|
|
###############################################################################
|
2022-12-22 05:02:33 +01:00
|
|
|
# Voyants
|
2022-12-18 17:33:23 +01:00
|
|
|
###############################################################################
|
|
|
|
|
2022-12-23 14:30:13 +01:00
|
|
|
# Ordre pour allumer le voyant niveau 0
|
2022-12-21 19:01:21 +01:00
|
|
|
def voy_0 (order):
|
|
|
|
scene.objects['Led niveau 0']['activated']=order
|
|
|
|
|
2022-12-23 14:30:13 +01:00
|
|
|
# Ordre pour allumer le voyant niveau 1
|
2022-12-21 19:01:21 +01:00
|
|
|
def voy_1 (order):
|
|
|
|
scene.objects['Led niveau 1']['activated']=order
|
2022-12-22 05:02:33 +01:00
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# Actionneurs
|
|
|
|
###############################################################################
|
2022-12-18 17:33:23 +01:00
|
|
|
|
2022-12-21 19:01:21 +01:00
|
|
|
# Ordre pour le moteur phase monter
|
|
|
|
def mot_m (order):
|
2022-12-22 05:02:33 +01:00
|
|
|
scene.objects['Moteur']['up']=order
|
2022-12-21 19:01:21 +01:00
|
|
|
|
|
|
|
# Ordre pour le moteur phase descendre
|
|
|
|
def mot_d (order):
|
2022-12-22 05:02:33 +01:00
|
|
|
scene.objects['Moteur']['down']=order
|
2022-12-18 17:33:23 +01:00
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# Capteurs
|
|
|
|
###############################################################################
|
|
|
|
|
2022-12-21 19:01:21 +01:00
|
|
|
# Compte-rendu du capteur de présence cabine niveau 0
|
|
|
|
def pc_0 ():
|
2023-01-07 18:22:03 +01:00
|
|
|
if scene.objects['Microrupteur niveau 0']['activated'] or scene.objects['Microrupteur niveau 0']['activated_real']:
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
2022-12-18 17:33:23 +01:00
|
|
|
|
2022-12-21 19:01:21 +01:00
|
|
|
# Compte-rendu du capteur de présence cabine niveau 0
|
|
|
|
def pc_1 ():
|
2023-01-07 18:22:03 +01:00
|
|
|
if scene.objects['Microrupteur niveau 1']['activated'] or scene.objects['Microrupteur niveau 1']['activated_real']:
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
2022-12-18 17:33:23 +01:00
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# Boutons poussoirs
|
|
|
|
###############################################################################
|
|
|
|
|
2022-12-21 19:01:21 +01:00
|
|
|
# Compte-rendu du bouton pousssoir appel niveau 0
|
|
|
|
def ba_0 ():
|
2023-01-07 18:22:03 +01:00
|
|
|
if scene.objects['Bp niveau 0']['activated'] or scene.objects['Bp niveau 0']['activated_real']:
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
2022-12-18 17:33:23 +01:00
|
|
|
|
2022-12-21 19:01:21 +01:00
|
|
|
# Compte-rendu du bouton pousssoir appel niveau 1
|
|
|
|
def ba_1 ():
|
2023-01-07 18:22:03 +01:00
|
|
|
if scene.objects['Bp niveau 1']['activated'] or scene.objects['Bp niveau 1']['activated_real']:
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
2022-12-18 17:33:23 +01:00
|
|
|
|
2023-01-06 21:23:44 +01:00
|
|
|
###############################################################################
|
|
|
|
# Cycle
|
2022-12-18 17:33:23 +01:00
|
|
|
###############################################################################
|
|
|
|
|
2023-01-06 21:23:44 +01:00
|
|
|
# Temporisation
|
2022-12-18 17:33:23 +01:00
|
|
|
def tempo (duree):
|
|
|
|
time.sleep(duree)
|
2023-01-06 21:23:44 +01:00
|
|
|
|
2023-01-18 06:06:15 +01:00
|
|
|
# t (temps)
|
|
|
|
def truncate(n, decimals=0):
|
|
|
|
multiplier = 10**decimals
|
|
|
|
return int(n* multiplier)/multiplier
|
|
|
|
|
|
|
|
def get_t ():
|
|
|
|
return truncate(scene.objects['System']['time'], 3)
|
|
|
|
|
|
|
|
def set_t (date):
|
|
|
|
scene.objects['System']['time']=date
|
|
|
|
|
|
|
|
def reset_t ():
|
|
|
|
scene.objects['System']['time']=0
|
|
|
|
|
2023-01-07 18:01:03 +01:00
|
|
|
# Arrêt
|
|
|
|
def stop():
|
|
|
|
if scene.objects['System']['twins']:
|
2023-01-09 05:54:31 +01:00
|
|
|
serial_close(scene.objects['System']['board'])
|
2023-01-07 18:01:03 +01:00
|
|
|
time.sleep(1)
|
2023-01-18 06:06:15 +01:00
|
|
|
scene.objects['System']['plot_draw']=False
|
2023-01-07 18:01:03 +01:00
|
|
|
thread_cmd_stop()
|
|
|
|
|
|
|
|
# Fin naturelle
|
2023-01-06 21:23:44 +01:00
|
|
|
def end():
|
|
|
|
if scene.objects['System']['twins']:
|
2023-01-09 05:54:31 +01:00
|
|
|
serial_close(scene.objects['System']['board'])
|
2023-01-07 18:01:03 +01:00
|
|
|
time.sleep(1)
|
2023-01-18 06:06:15 +01:00
|
|
|
scene.objects['System']['plot_draw']=False
|
2023-01-06 21:23:44 +01:00
|
|
|
thread_cmd_end()
|
|
|
|
|
|
|
|
def fin():
|
|
|
|
end()
|
|
|
|
|
|
|
|
def quit():
|
|
|
|
end()
|
2023-01-18 06:06:15 +01:00
|
|
|
|