Outils pour utilisateurs

Outils du site


dev:python:asynchrone:tipe

Exemple de programme de TIPE

# -*- coding: utf-8 -*- 
"""
Created on Sun Jan 28 14:45:34 2018
 
@author: arnaudtecher
"""
 
import RPi.GPIO as GPIO
import time 
 
fichier=open("Resultat.csv","a")
 
#Il existe differentes manieres de nommer chaque port du raspberry, on choisi la notation BCM (cf l'annexe)
GPIO.setmode(GPIO.BCM)
 
#on associe à chaque relais un couple de valeurs correspondant a deux port du rapsberry, il faut donx 8 ports au total dont leur identifiant sont les suivants:
liste_relais=(14,15,18,23,24,25,8,7)
#chaque port du raspberry peut prendre la valeur HIGH ou LOW (0 ou 1), on place initialement tous les ports concerné en LOW
GPIO.setup(liste_relais, GPIO.OUT, initial=GPIO.HIGH)
 
#on associe à chaque detecteur une valeur correspondant à un port du raspberry 
liste_detecteur=(4,17,27,22)
#on fait de meme pour les ports liés aux recepteur
GPIO.setup(liste_detecteur, GPIO.IN, pull_up_down=GPIO.PUD_UP)
 
 
#Depart
#bobine 1 en attraction: principe similaire à un vas et viens. 
GPIO.output(liste_relais[0:2],(GPIO.LOW,GPIO.HIGH))
 
 
print("etat debut:",GPIO.input(liste_detecteur[0]), GPIO.input(liste_detecteur[1]), GPIO.input(liste_detecteur[2]), GPIO.input(liste_detecteur[3]))
 
#Etape 1
#Detection du passage de l'aimant dans la premiere bobine:
while GPIO.input(liste_detecteur[0]):
    pass
 
temps_bobine1=time.clock()
#passage de la 1ere bobine en repulsion, 2eme bobibe en attraction 
GPIO.output(liste_relais[0:4],(GPIO.HIGH,
                               GPIO.LOW,
                               GPIO.LOW,
                               GPIO.HIGH))
 
 
 
print("contact au 1",GPIO.input(liste_detecteur[0]),GPIO.input(liste_detecteur[1]), GPIO.input(liste_detecteur[2]), GPIO.input(liste_detecteur[3]))
 
#Etape 2
#Detection du passage de l'aimant dans la 2eme bobine
while GPIO.input(liste_detecteur[1]):
    pass
 
temps_bobine2=time.clock()
#arret 1ere bobine, 2eme bobine en repulsion, 3 eme bobine en attraction
GPIO.output(liste_relais[:6],(GPIO.HIGH,GPIO.HIGH,
                              GPIO.HIGH,GPIO.LOW,
                              GPIO.LOW,GPIO.HIGH))
print("contact au 2",GPIO.input(liste_detecteur[0]),GPIO.input(liste_detecteur[1]), GPIO.input(liste_detecteur[2]), GPIO.input(liste_detecteur[3]))
 
#Etape 3
#detection du passage de l'aimant dans la 3eme bobine
while GPIO.input(liste_detecteur[2]):
    pass
temps_bobine3=time.clock()
#arret 2eme bobine, 3eme bobine en repulsion, 4eme bobine en attraction
GPIO.output(liste_relais[2:8],(GPIO.HIGH,GPIO.HIGH,
                               GPIO.HIGH,GPIO.LOW,
                               GPIO.LOW,GPIO.HIGH))
print("contact au 3",GPIO.input(liste_detecteur[0]),GPIO.input(liste_detecteur[1]), GPIO.input(liste_detecteur[2]), GPIO.input(liste_detecteur[3]))
 
#Etape 4
#detection du passage de l'aimant dans la 4eme bobine
while GPIO.input(liste_detecteur[3]):
    pass
 
temps_bobine4=time.clock()
#arret 3eme bobine, 4eme bobine en propulsion
GPIO.output(liste_relais[4:8],(GPIO.HIGH,GPIO.HIGH,
                               GPIO.HIGH,GPIO.LOW))
print("contact au 4",GPIO.input(liste_detecteur[0]),GPIO.input(liste_detecteur[1]), GPIO.input(liste_detecteur[2]), GPIO.input(liste_detecteur[3]))
#je laisse la bobine 4 en repulsion un certain temps afin qu'lle puisse propulser l'aimant avant la fin du porgramme
time.sleep(2)
 
#reinitialisation des paramètres 
GPIO.cleanup()
 
fichier.write("{};{};{};{};{}".format(time.ctime(),
                                      temps_bobine1,
                                      temps_bobine2,
                                      temps_bobine3,
                                      temps_bobine4))
fichier.write("\n")
fichier.close()
dev/python/asynchrone/tipe.txt · Dernière modification: 2018/05/21 09:59 (modification externe)