Différences entre versions de « Rasp-Hat-Moteur-Moteurs-Continus »

De MCHobby - Wiki
Sauter à la navigation Sauter à la recherche
Ligne 4 : Ligne 4 :
  
 
== Utiliser des moteurs à courant continu ==
 
== Utiliser des moteurs à courant continu ==
DC motors are used for all sort of robotic projects.
+
Les moteurs continus sont utilisé pour de nombreux types de projets robotiques.
  
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!
+
Le Hat moteur peut piloter jusque 4 moteurs continu bi-directionnel. Cela signifie que vous pouvez contrôler les moteurs en marche avant et en marche arrière. La vitesse peut également varier par incrément de 0.5% en utilisant le contrôleur PWM haute qualité du HAT moteur. Cela signifie que la vitesse peut être modifiée en douceur et que cette dernière restera stable (elle ne variera pas en fonction de la charge processeur sur le Raspberry-Pi)!
  
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!
+
Notez que les puces des pont-H ne sont prévue pour piloter continuellement une charge dépassant 1.2A ou des moteurs ayant des pointes de courant au delà de 3A. Le HAT moteur est donc prévu pour de petits moteurs. Voyez la fiche technique de vos moteurs pour plus d'informations sur leurs caractéristiques afin de savoir s'ils peuvent être utilisés avec le HAT Moteur!
  
 
== Brancher les moteurs ==
 
== Brancher les moteurs ==

Version du 2 septembre 2017 à 15:39


MCHobby investit du temps et de l'argent dans la réalisation de traduction et/ou documentation. C'est un travail long et fastidieux réalisé dans l'esprit Open-Source... donc gratuit et librement accessible.
SI vous aimez nos traductions et documentations ALORS aidez nous à en produire plus en achetant vos produits chez MCHobby.

Utiliser des moteurs à courant continu

Les moteurs continus sont utilisé pour de nombreux types de projets robotiques.

Le Hat moteur peut piloter jusque 4 moteurs continu bi-directionnel. Cela signifie que vous pouvez contrôler les moteurs en marche avant et en marche arrière. La vitesse peut également varier par incrément de 0.5% en utilisant le contrôleur PWM haute qualité du HAT moteur. Cela signifie que la vitesse peut être modifiée en douceur et que cette dernière restera stable (elle ne variera pas en fonction de la charge processeur sur le Raspberry-Pi)!

Notez que les puces des pont-H ne sont prévue pour piloter continuellement une charge dépassant 1.2A ou des moteurs ayant des pointes de courant au delà de 3A. Le HAT moteur est donc prévu pour de petits moteurs. Voyez la fiche technique de vos moteurs pour plus d'informations sur leurs caractéristiques afin de savoir s'ils peuvent être utilisés avec le HAT Moteur!

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 sudo python DCTest.py to watch your motor spin back and forth.

Rasp-Hat-Moteur-Moteurs-Continus-00.jpg
Crédit: AdaFruit Industries www.adafruit.com

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:

#!/usr/bin/python
from Adafruit_MotorHAT import Adafruit_MotorHAT, Adafruit_DCMotor

import time
import atexit

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)

# create a default object, no changes to I2C address or frequency
mh = Adafruit_MotorHAT(addr=0x60)

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.

# 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)

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

myMotor = mh.getMotor(3)

DC motors are simple beasts, you can basically only set the speed and direction.

Fixer la vitesse du moteur

To set the speed, call setSpeed(speed) where speed varies from 0 (off) to 255 (maximum!). This is the PWM duty cycle of the motor

# set the speed to start, from 0 (off) to 255 (max speed)
myMotor.setSpeed(150)

Fixer le sens de rotation

To set the direction, call run(direction) where direction is a constant from one of the following:

  • Adafruit_MotorHAT.FORWARD - DC motor spins forward
  • Adafruit_MotorHAT.BACKWARD - DC motor spins forward
  • Adafruit_MotorHAT.RELEASE - DC motor is 'off', not spinning but will also not hold its place.
while (True):
	print "Forward! "
	myMotor.run(Adafruit_MotorHAT.FORWARD)

	print "\tSpeed up..."
	for i in range(255):
		myMotor.setSpeed(i)
		time.sleep(0.01)

	print "\tSlow down..."
	for i in reversed(range(255)):
		myMotor.setSpeed(i)
		time.sleep(0.01)

	print "Backward! "
	myMotor.run(Adafruit_MotorHAT.BACKWARD)

	print "\tSpeed up..."
	for i in range(255):
		myMotor.setSpeed(i)
		time.sleep(0.01)

	print "\tSlow down..."
	for i in reversed(range(255)):
		myMotor.setSpeed(i)
		time.sleep(0.01)

	print "Release"
	myMotor.run(Adafruit_MotorHAT.RELEASE)
	time.sleep(1.0)

Source: Adafruit DC and Stepper Motor HAT for Raspberry Pi
Créé par LadyAda pour AdaFruit Industries.

Traduction réalisée par Meurisse D pour MCHobby.be.

Toute référence, mention ou extrait de cette traduction doit être explicitement accompagné du texte suivant : «  Traduction par MCHobby (www.MCHobby.be) - Vente de kit et composants » avec un lien vers la source (donc cette page) et ce quelque soit le média utilisé.

L'utilisation commercial de la traduction (texte) et/ou réalisation, même partielle, pourrait être soumis à redevance. Dans tous les cas de figures, vous devez également obtenir l'accord du(des) détenteur initial des droits. Celui de MC Hobby s'arrêtant au travail de traduction proprement dit.

Traduit avec l'autorisation d'AdaFruit Industries - Translated with the permission from Adafruit Industries - www.adafruit.com