Modifications

Sauter à la navigation Sauter à la recherche
Page créée avec « {{Rasp-Hat-Moteur-NAV}} {{traduction}} == Utiliser des moteurs pas-à-pas == Stepper motors are great for (semi-)precise control, perfect for many robot and CNC projects.... »
{{Rasp-Hat-Moteur-NAV}}

{{traduction}}
== Utiliser des moteurs pas-à-pas ==
Stepper motors are great for (semi-)precise control, perfect for many robot and CNC projects. This HAT supports up to 2 stepper motors. The python library works identically for bi-polar and uni-polar motors

Running a stepper is a little more intricate than running a DC motor but its still very easy

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

== Connecter des moteurs pas-à-pas ==
Pour cette démonstration, utilisé M1 et M2 pour connecter le moteur.

Après avoir raccordé le moteur (voir ci-dessous), rendez vous dans le répertoire {{fname|Adafruit-Motor-HAT-Python/examples}} et exécutez la commande {{sudo python StepperTest.py}} pour voir le moteur pas-à-pas tourner dans un sens puis l'autre.

=== Pour les moteurs unipolaires ===
to connect up the stepper, first figure out which pins connected to which coil, and which pins are the center taps. If its a 5-wire motor then there will be 1 that is the center tap for both coils. [http://learn.adafruit.com/adafruit-motor-shield/resources Theres plenty of tutorials online on how to reverse engineer the coils pinout]. The center taps should both be connected together to the '''GND''' terminal on the Motor HAT output block. then coil 1 should connect to one motor port (say '''M1''' or '''M3''') and coil 2 should connect to the other motor port ('''M2''' or '''M4''').

=== Pour les moteurs bipolaires ===
its just like unipolar motors except theres no 5th wire to connect to ground. The code is exactly the same.

== Contrôler un moteur pas-à-pas ==
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, Adafruit_StepperMotor

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>



Even though this example code does not use DC motors, it's still important to note that 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.

Stepper motors will not continue to move when the Python script quits, but it's still strongly recommend that you keep this 'at exit' code, 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 pas-à-pas ==
OK now that you have the motor HAT object, note that each HAT can control up to 2 steppers. And you can have multiple HATs!

To create the actual Stepper motor object, you can request it from the MotorHAT object you created above with '''getStepper(steps, portnum)''' where steps is how many steps per rotation for the stepper motor (usually some number between 35 - 200) ith a value between 1 and 2. Port #1 is '''M1''' and '''M2''', port #2 is '''M3''' and '''M4'''

<syntaxhighlight lang="python">
myStepper = mh.getStepper(200, 1) # 200 steps/rev, motor port #1
</syntaxhighlight>

Next, if you are planning to use the 'blocking' '''step()''' function to take multiple steps at once you can set the speed in RPM. If you end up using oneStep() then this step isn't necessary. Also, the speed is approximate as the Raspberry Pi can't do precision delays the way an Arduino would. Anyways, we wanted to keep the Arduino and Pi versions of this library similar so we kept '''setSpeed()''' in:

<syntaxhighlight lang="python">
myStepper.setSpeed(30) # 30 RPM
</syntaxhighlight>

== Les pas ==
Stepper motors differ from DC motors in that the controller (in this case, Raspberry Pi) must tick each of the 4 coils in order to make the motor move. Each two 'ticks' is a step. By alternating the coils, the stepper motor will spin all the way around. If the coils are fired in the opposite order, it will spin the other way around.

If the python code or Pi crashes or stops responding, the motor will no longer move. Compare this to a DC motor which has a constant voltage across a single coil for movement.

[[Fichier:Rasp-Hat-Moteur-Moteurs-pas-a-pas-01.gif]]<br />[http://commons.wikimedia.org/wiki/File:StepperMotor.gif#mediaviewer/File:StepperMotor.gif "StepperMotor" par Wapcaplet; Teravolt.]

There are four essential types of steps you can use with your Motor HAT. All four kinds will work with any unipolar or bipolar stepper motor
#

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

modifications

Menu de navigation