Modifications

Sauter à la navigation Sauter à la recherche
Ligne 20 : Ligne 20 :     
== Contrôle de moteurs continus ==
 
== Contrôle de moteurs continus ==
Here's a walkthru of the code which shows you everything the MotorHAT library can do and how to do it.
+
Nous allons réviser le contenu du code que nous allons réviser pour vous montrer comment fonctionne la bibliothèque MotorHAT library can do and how to do it.
    
Start with importing at least these libraries:
 
Start with importing at least these libraries:
Ligne 32 : Ligne 32 :  
</syntaxhighlight>
 
</syntaxhighlight>
   −
The MotorHAT library contains a few different classes, one is the MotorHAT class itself which is the main PWM controller. You'll always need to create an object, and set the address. By default the address is 0x60 (see the stacking HAT page on why you may want to change the address)
+
La bibliothèque MotorHAT contient quelques classes dont une classe MotorHAT qui est le contrôleur PWM principal (la carte HAT moteur inclus un controleur PWM). Vous aurez toujours besoin de créer un objet et de configurer l'adresse. L'adresse par défaut est 0x60 (Voyez la [[Rasp-Hat-Moteur-Empiler-les-Hats|concernant l'empilement des HATs]]  où il sera nécessaire de changer l'adresse)
    
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
# create a default object, no changes to I2C address or frequency
+
# Créer un objet par défaut, pas de changement d'adresse I2C ou de Fréquence PWM
 
mh = Adafruit_MotorHAT(addr=0x60)
 
mh = Adafruit_MotorHAT(addr=0x60)
 
</syntaxhighlight>
 
</syntaxhighlight>
   −
The PWM driver is 'free running' - that means that even if the python code or Pi linux kernel crashes, the PWM driver will still continue to work. This is good because it lets the Pi focus on linuxy things while the PWM driver does its PWMy things. '''But it means that the motors DO NOT STOP when the python code quits'''
+
Le contrôleur PWM est autonome (fonctionne seul) - cela signifie qu'il continuera à fonctionner même si votre programme Python plante (ou crash du noyau Linux). C'est une bonne chose en soit car elle permet au Raspberry-Pi de se concentrer sur la gestion de l'OS pendant que le contrôleur PWM du HAT s'occupe de gérer les signaux PWM. '''Mais cela signifie également que les moteurs NE VONT PAS S'ARRETER lorsque le programme Python s'arrête''' (sauf si cela est spécifiquement prit en compte par le programme python).
   −
'''For that reason, we strongly recommend this 'at exit' code''' when using DC motors, it will do its best to shut down all the motors.
+
'''C'est pour cette raison qu'il est fortement recommandé d'utiliser une section de code {{fname|at exit}}''' lorsque des moteurs continus sont utilisés. {{fname|at exit}} fera de son mieux pour arrêter tous les moteurs.
    
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
# recommended for auto-disabling motors on shutdown!
+
# Recommandé pour auro-désactiver les moteurs lors d'un arrêt programme!
 
def turnOffMotors():
 
def turnOffMotors():
 
mh.getMotor(1).run(Adafruit_MotorHAT.RELEASE)
 
mh.getMotor(1).run(Adafruit_MotorHAT.RELEASE)
29 917

modifications

Menu de navigation