IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Raspberry Pi Discussion :

[python 3] [Pi 4] Programmation moteur double commande


Sujet :

Raspberry Pi

  1. #1
    Nouveau Candidat au Club
    Homme Profil pro
    directeur technique association
    Inscrit en
    Mars 2021
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 55
    Localisation : France, Côtes d'Armor (Bretagne)

    Informations professionnelles :
    Activité : directeur technique association
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Mars 2021
    Messages : 2
    Points : 1
    Points
    1
    Par défaut [python 3] [Pi 4] Programmation moteur double commande
    Bonjour,
    Je met au point une cablecam autour d'une raspberry et j'ai des soucis de rebond avec le moteur de translation.
    Cette camera et d'autre, ont pour but d'enregistrer des groupes de musique dans des sessions live
    Le moteur à une double commande:
    1°) via un server web une commande gauche droite et stop
    2°) via 2 fin de courses (des capteurs à effet hall) aux extrémités du câble
    Nom : photo2.jpg
Affichages : 308
Taille : 60,3 Ko
    mon soucis c'est que j'ai des fonctionnements aléatoires ou le moteur fait l'inverse de qu'on lui demande
    voici la partie du code concernée
    Code python : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
     
    class PiTZ:
        MoteurOutputPinL=24
        MoteurOutputPinR=23
        MoteurOutputPinN=18
        TiltSensorPin = 19
        TiltSensorPin2 = 16
        Moteur_status = ""
        t=0.05
     
    def __init__(self):
            GPIO.setmode(GPIO.BCM)
            GPIO.setwarnings(False)
            GPIO.setup(self.MoteurOutputPinL, GPIO.OUT)
            GPIO.setup(self.MoteurOutputPinR, GPIO.OUT)
            GPIO.setup(self.MoteurOutputPinN, GPIO.OUT)
            GPIO.setup(self.TiltSensorPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
            GPIO.setup(self.TiltSensorPin2, GPIO.IN, pull_up_down=GPIO.PUD_UP)
            self.Pwm()
            self.loop()
            self.configCall("default")
            self.initPan()
            self.initTilt()
            self.initZoom()
            self.initFocus()
            self.initIrCut()
            self.initIMG()
            self.initccMan()
     
    def Pwm(self):
            self.V1=GPIO.PWM(self.MoteurOutputPinN, 1000)
            self.V1.start(0)     
    def initccMan(self):
            self.ccMan()
            self.ccManStop()
     
    def ccMan(self,ccDir=""):    
            global Moteur_status
            self.Moteur_status = not self.Moteur_status
            GPIO.output(self.MoteurOutputPinL, self.Moteur_status)
            GPIO.output(self.MoteurOutputPinR, self.Moteur_status)
            GPIO.output(self.MoteurOutputPinN, self.Moteur_status)
     
            if self.Moteur_status == 1 or ccDir=="ccleft":
                GPIO.output(self.MoteurOutputPinL,GPIO.HIGH)
                GPIO.output(self.MoteurOutputPinR,GPIO.LOW)
                GPIO.output(self.MoteurOutputPinN,GPIO.HIGH)  
                for dc in range(0, 101, 10):
                    self.V1.ChangeDutyCycle(dc)
                    time.sleep(self.t)
     
            elif self.Moteur_status == 0 or ccDir=="ccright":
                GPIO.output(self.MoteurOutputPinL,GPIO.LOW)
                GPIO.output(self.MoteurOutputPinR,GPIO.HIGH)
                GPIO.output(self.MoteurOutputPinN,GPIO.HIGH)
                for dc in range(0, 101, 10):
                    self.V1.ChangeDutyCycle(dc)
                    time.sleep(self.t)
     
        def ccManStop(self,ccstop=""):
     
            if ccstop=="ccstop" and self.Moteur_status == 1:
                GPIO.output(self.MoteurOutputPinL,GPIO.HIGH)
                GPIO.output(self.MoteurOutputPinR,GPIO.LOW)
                GPIO.output(self.MoteurOutputPinN,GPIO.HIGH)
                for dc in range(100, -1, -10):
                    self.V1.ChangeDutyCycle(dc)
                    time.sleep(self.t)
     
            elif ccstop=="ccstop" and self.Moteur_status == 0:
                GPIO.output(self.MoteurOutputPinL,GPIO.LOW)
                GPIO.output(self.MoteurOutputPinR,GPIO.HIGH)
                GPIO.output(self.MoteurOutputPinN,GPIO.HIGH)
                for dc in range(100, -1, -10):
                    self.V1.ChangeDutyCycle(dc)
                    time.sleep(self.t)
     
        def loop(self):
            GPIO.add_event_detect(self.TiltSensorPin, GPIO.FALLING, callback=self.ccMan, bouncetime = 5000)
            GPIO.add_event_detect(self.TiltSensorPin2, GPIO.FALLING, callback=self.ccMan, bouncetime = 5000)

    j'espère que vous pourrez m'aider
    merci

  2. #2
    Nouveau Candidat au Club
    Homme Profil pro
    directeur technique association
    Inscrit en
    Mars 2021
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 55
    Localisation : France, Côtes d'Armor (Bretagne)

    Informations professionnelles :
    Activité : directeur technique association
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Mars 2021
    Messages : 2
    Points : 1
    Points
    1
    Par défaut précision
    mon soucis, c'est que pour un moteur j'ai six commandes différentes.
    La première fonction fait aller le moteur dans les 2 sens, changeant l'état de 2 ports GPIO.output de LOW à HIGH.
    Pour avoir une accélération progressive j'utilise la fonction "for range" sur le port GPIO.PWM
    La 2ème fonction, fait intervenir les fin de courses avec des capteurs à effet Hall, qui inverse le sens de rotation du moteur et modifie l'état des ports GPIO.ouput
    Dans un premier temps je gérais 2 états pour chaque capteur, mais de façon aléatoire pour des raisons inconnues l'état changer et passer de 1 à 0
    et inverser le sens de rotation.
    Pour éviter les fantômes j'ai finalement séparer les fonctions avant et arrière et ne gère qu'un état pour chaque capteur. J'ai aussi affilié un seul capteur par fonction.
    La 3éme fonction est la fonction stop. Et là j'ai encore un soucis que je n'arrive pas résoudre. Pour éviter les à-coups à l'arrêt j'ai besoin d'utiliser la fonction "For range".
    Je dois pouvoir m'arrêter doucement quelque soit le sens du moteur et quelque soit la fonction utilisée au préalable. Si je n'utilise pas la fonction "For Range" tout fonctionne. dans le cas contraire je retrouve mes fantômes et de façon aléatoire la fonction arrêt inverse le sens de rotation avant de s'arrêter. j'ai fini par refaire le code d'une façon non s'satisfaisante mais la moins pire mettant tout les ports GPIO sur HIGH .
    voici le code modifié
    Code python : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
     
    def ccMan(self,ccDir2=""):    
            global Moteur_status2
            self.Moteur_status2 = 0
            GPIO.output(self.MoteurOutputPinL, self.Moteur_status2)
            GPIO.output(self.MoteurOutputPinR, self.Moteur_status2)
            GPIO.output(self.MoteurOutputPinN, self.Moteur_status2)
     
            if ccDir2=="ccleft" or self.Moteur_status2 == 0:
                self.Moteur_status2=0
                GPIO.output(self.MoteurOutputPinL,GPIO.HIGH)
                GPIO.output(self.MoteurOutputPinR,GPIO.LOW)
                GPIO.output(self.MoteurOutputPinN,GPIO.HIGH)
                for dc in range(0, 101, 10):
                    self.V1.ChangeDutyCycle(dc)
                    time.sleep(self.t)
     
        def ccMan2(self,ccDir=""):
            global Moteur_status
            self.Moteur_status = 1
            GPIO.output(self.MoteurOutputPinL, self.Moteur_status)
            GPIO.output(self.MoteurOutputPinR, self.Moteur_status)
            GPIO.output(self.MoteurOutputPinN, self.Moteur_status)
     
            if ccDir=="ccright" or self.Moteur_status == 1:
                self.Moteur_status=1
                GPIO.output(self.MoteurOutputPinL,GPIO.LOW)
                GPIO.output(self.MoteurOutputPinR,GPIO.HIGH)
                GPIO.output(self.MoteurOutputPinN,GPIO.HIGH)
                for dc in range(0, 101, 10):
                    self.V1.ChangeDutyCycle(dc)
                    time.sleep(self.t)
     
        def ccManStop(self,ccstop=""):
            if ccstop=="ccstop":
                GPIO.output(self.MoteurOutputPinL,GPIO.HIGH)
                GPIO.output(self.MoteurOutputPinR,GPIO.HIGH)
                GPIO.output(self.MoteurOutputPinN,GPIO.HIGH)
                for dc in range(100, -1, -10):
                    self.V1.ChangeDutyCycle(dc)
                    time.sleep(self.t)
     
        def loop(self):
            GPIO.add_event_detect(self.TiltSensorPin, GPIO.FALLING, callback=self.ccMan)
            GPIO.add_event_detect(self.TiltSensorPin2, GPIO.FALLING, callback=self.ccMan2)

    J'attend de vos nouvelles et vous dis merci

Discussions similaires

  1. Programme Arduino de commande de moteur+encodeur.
    Par loquet38 dans le forum Arduino
    Réponses: 7
    Dernier message: 15/03/2018, 20h20
  2. ouverture d'un programme par double clic sur un fichier
    Par zieg18 dans le forum Visual C++
    Réponses: 6
    Dernier message: 12/07/2006, 10h02
  3. probleme de programmation de la commande locate
    Par louve_garoute dans le forum C
    Réponses: 8
    Dernier message: 29/05/2006, 22h24
  4. programmer un panier / commande
    Par ddeee dans le forum ASP
    Réponses: 8
    Dernier message: 16/02/2006, 14h33
  5. Réponses: 7
    Dernier message: 22/09/2005, 10h09

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo