Modifications

Sauter à la navigation Sauter à la recherche
3 179 octets ajoutés ,  30 août 2017 à 20:12
Page créée avec « {{Rasp-Hat-Moteur-NAV}} {{traduction}} == Utiliser des moteurs à courant continu == DC motors are used for all sort of robotic projects. The Motor HAT can drive up to... »
{{Rasp-Hat-Moteur-NAV}}

{{traduction}}

== Utiliser des moteurs à courant continu ==
DC motors are used for all sort of robotic projects.

The Motor HAT can drive up to 4 DC motors bi-directionally. That means they can be driven forwards and backwards. The speed can also be varied at 0.5% increments using the high-quality built in PWM. This means the speed is very smooth and won't vary!

Note that the H-bridge chip is not meant for driving continuous loads over 1.2A or motors that peak over 3A, so this is for small motors. Check the datasheet for information about the motor to verify its OK!

== Brancher les moteurs ==
To connect a motor, simply solder two wires to the terminals and then connect them to either the '''M1''', '''M2''', '''M3''', or '''M4'''. If your motor is running 'backwards' from the way you like, just swap the wires in the terminal block

For this demo, please connect it to '''M3'''

Now go into the Adafruit-Motor-HAT-Python/examples folder and run {{fname|sudo python DCTest.py}} to watch your motor spin back and forth.

{{ADFImage|Rasp-Hat-Moteur-Moteurs-Continus-00.jpg|640px}}

== 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.

Start with importing at least these libraries:

<syntaxhighlight lang="python">
#!/usr/bin/python
from Adafruit_MotorHAT import Adafruit_MotorHAT, Adafruit_DCMotor

import time
import atexit
</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)

<syntaxhighlight lang="python">
# create a default object, no changes to I2C address or frequency
mh = Adafruit_MotorHAT(addr=0x60)
</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'''

'''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.

<syntaxhighlight lang="python">
# recommended for auto-disabling motors on shutdown!
def turnOffMotors():
mh.getMotor(1).run(Adafruit_MotorHAT.RELEASE)
mh.getMotor(2).run(Adafruit_MotorHAT.RELEASE)
mh.getMotor(3).run(Adafruit_MotorHAT.RELEASE)
mh.getMotor(4).run(Adafruit_MotorHAT.RELEASE)

atexit.register(turnOffMotors)
</syntaxhighlight>

== Créer un objet moteur ==
OK now that you have the motor HAT object, note that each HAT can control up to 4 motors. And you can have multiple HATs!

To create the actual DC motor object, you can request it from the MotorHAT object you created above with '''getMotor(num)''' with a value between 1 and 4, for the terminal number that the motor is attached to

<syntaxhighlight lang="python">
myMotor = mh.getMotor(3)
</syntaxhighlight>

{{Rasp-Hat-Moteur-TRAILER}}
29 922

modifications

Menu de navigation