jumeaux-numeriques/portail_coulissant/porcou_cmd.py

112 lines
3.3 KiB
Python

from porcou_lib import * # Bibliothèque utilisateur du portail coulissant
###############################################################################
# porcou_cmd.py
# @title: Commandes du portail coulissant
###############################################################################
###############################################################################
# Instructions élémentaires pour le portail coulissant
#
# Actions (ordre = True ou False) :
# - Gyrophare : gyr(True | False)
# - Ouvrir le portail (moteur sens trigo) : mot_o(True | False)
# - Fermer le portail (moteur sens horaire) : mot_f(True | False)
# - Emetteur pour le capteur barrage IR : ir_emet(True | False)
#
# Capteurs (valeur retournée = True ou False) :
# - Capteur fin de course portail ouvert : fdc_o()
# - Capteur fin de course portail fermé : fdc_f()
# - Capteur barrage IR (absence d'obstacle) : ir_recep()
#
# Consignes du pupitre (valeur retournée = True ou False) :
# - Bouton poussoir coté rue : bp_ext()
# - Bouton poussoir coté cour : bp_int()
#
# Gestion du temps :
# - Temporisation en seconde : tempo(duree)
#
###############################################################################
# Brochage du portail coulissant
brochage={}
###############################################################################
# Fonctions
###############################################################################
###############################################################################
# Commandes
###############################################################################
def commandes():
# # Mise en place : Fermeture
# print ("Version sans sécurité : sans réouverture")
# print ("Mise en place : Fermeture")
# while fdc_f() ==False :
# gyr(True)
# mot_o(False)
# mot_f(True)
# mot_f(False)
# gyr(False)
# Init
while fdc_o() ==False :
gyr(True)
mot_f(False)
mot_o(True)
mot_o(False)
gyr(False)
# Fermeture
tf_d= get_t()
xf_d= get('portail_x')
while fdc_f() ==False :
gyr(True)
mot_o(False)
mot_f(True)
print (get('portail_x'), get('mot_angle'), get('mot_vitesse'))
mot_f(False)
gyr(False)
tf_f = get_t()
xf_f= get('portail_x')
print ("Fermeture : "+str(round(tf_f-tf_d,3)) +" s - distance : " +str(round(xf_f-xf_d,3))+" m")
# Ouverture
to_d= get_t()
xo_d= get('portail_x')
while fdc_o() ==False :
gyr(True)
mot_f(False)
mot_o(True)
print (get('portail_x'), get('mot_angle'), get('mot_vitesse'))
mot_o(False)
gyr(False)
to_f = get_t()
xo_f= get('portail_x')
print ("Ouverture : "+str(round(to_f-to_d,3)) +" s - distance : " +str(round(xf_f-xf_d,3))+" m")
# plot(['gyr'])
# plot(['bp_ext'])
# plot(['gyr', 'bp_ext', 'bp_int'])
# while True:
# print (get_t())
# gyr(True)
# tempo(0.25)
# gyr(False)
# tempo(0.25)
fin() # A garder
###############################################################################
# En: External call << DONT CHANGE THIS SECTION >>
# Fr: Appel externe << NE PAS MODIFIER CETTE SECTION >>
###############################################################################
if __name__=='start':
thread_cmd_start(commandes)
if __name__=='stop':
stop()