Forum Programmation.python problème rebond moteur Python 3 COO

Posté par . Licence CC By‐SA.
Étiquettes :
3
14
mar.
2021

Bonjour,
Je suis en train de mettre au point une cablecam ptz pilotée grâce à une Raspberry P4 en Python 3 et commandé via un un server web. J'ai une fonction manuel et auto pour la faire avancer sur le câble. En gros il y a des fins de course qui font repartir la bête à chaque extrémité du câble. Mon soucis c'est que pour avoir un démarrage progressif du moteur j'ai utilisé:

for dc in range(0, 101, 10):
self.V1.ChangeDutyCycle(dc)
time.sleep(self.t)

pour les fonctions de translation, mais dés que j'active la fonction stop j'ai un rebond moteur qui le fait repartir dans le sens inverse pendant 1 sec. Si je retire ces ligne tout fonctionne correctement.
la ligne de code concernée:

 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.initccMan()
 self.loop()
 self.Moteur_status = ""
 def Pwm(self):
 self.V1=GPIO.PWM(self.MoteurOutputPinN, 1000)
 self.V1.start(0) 
 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)
 if 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)
 if ccDir=="ccstop":
 GPIO.output(self.MoteurOutputPinR,GPIO.LOW)
 GPIO.output(self.MoteurOutputPinL,GPIO.LOW)
 def loop(self):
 GPIO.add_event_detect(self.TiltSensorPin, GPIO.FALLING, callback=self.ccMan, bouncetime = 3000)
 GPIO.add_event_detect(self.TiltSensorPin2, GPIO.FALLING, callback=self.ccMan, bouncetime = 3000)

je vous remercie d'avance pour votre aide. j'ai passé quelques heures à chercher et je n'ai rien trouvé. je tiens a préciser que je suis un découvreur de python
yôme

  • # betement

    Posté par . Évalué à 2.

    je dirais que tu "lisses" le depart du moteur,
    mais tu fais un arrêt brutal.

    pourquoi ne pas lisser aussi l'arrêt ?

    • [^] # Re: betement

      Posté par . Évalué à 1.

      Bonsoir,

      Je l'ai fait mais ça crée un boucle plus longue à l'arrêt
      un aller et un retour

    • [^] # Re: betement

      Posté par . Évalué à 1.

      Bonsoir,

      Je l'ai fait mais ça crée un boucle plus longue à l'arrêt
      un aller et un retour

      if ccDir=="ccstop":
       GPIO.output(self.MoteurOutputPinL,GPIO.LOW)
       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)
      • [^] # Re: betement

        Posté par . Évalué à 1. Dernière modification le 14 mars 2021 à 21:36.

        le liens vers la vidéo qui montre en action le moteur avec l'utilisation du moteur avec le script de ralentissement.
        vidéo moteur commande gauche, puis stop et droite

  • # J'ai fini par trouver ;-)

    Posté par . Évalué à 2.

    alors pour ceux qui en auraient besoin
    j'ai séparé la fonction stop et créer une nouvelle définition,
    et modifier l'adresse de la fonction stop dans le serveur

    def ccManStop(self,ccstop=""):
     if ccstop=="ccstop":
     GPIO.output(self.MoteurOutputPinL,GPIO.LOW)
     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)
  • # modification de la fonction stop

    Posté par . Évalué à 1.

    pour que la fonction stop soit réellement opérationnelle et que le moteur ralentisse en s'arrêtant , voici le code complet

    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) 
     if 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=""):
     global 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 and ccstop=="ccstop":
     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) 
     if self.Moteur_status == 0 and ccstop=="ccstop":
     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 = 10000)
     GPIO.add_event_detect(self.TiltSensorPin2, GPIO.FALLING, callback=self.ccMan, bouncetime = 10000)

    je me suis aidé tout seul ;-) mais si ça peut servir à d'autre

Suivre le flux des commentaires

Note : les commentaires appartiennent à celles et ceux qui les ont postés. Nous n’en sommes pas responsables.