Ligne 80 : |
Ligne 80 : |
| | | |
| 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 | | 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 |
− | # | + | # '''Single Steps''' - this is the simplest type of stepping, and uses the least power. It uses a single coil to 'hold' the motor in place, as seen in the animated GIF above |
| + | # '''Double Steps''' - this is also fairly simple, except instead of a single coil, it has two coils on at once. For example, instead of just coil #1 on, you would have coil #1 and #2 on at once. This uses more power (approx 2x) but is stronger than single stepping (by maybe 25%) |
| + | # '''Interleaved Steps''' - this is a mix of Single and Double stepping, where we use single steps interleaved with double. It has a little more strength than single stepping, and about 50% more power. What's nice about this style is that it makes your motor appear to have 2x as many steps, for a smoother transition between steps |
| + | # '''Microstepping''' - this is where we use a mix of single stepping with PWM to slowly transition between steps. It's slower than single stepping but has much higher precision. We recommend 8 microstepping which multiplies the # of steps your stepper motor has by 8. |
| + | |
| + | <syntaxhighlight lang="python"> |
| + | while (True): |
| + | print("Single coil steps") |
| + | myStepper.step(100, Adafruit_MotorHAT.FORWARD, Adafruit_MotorHAT.SINGLE) |
| + | myStepper.step(100, Adafruit_MotorHAT.BACKWARD, Adafruit_MotorHAT.SINGLE) |
| + | print("Double coil steps") |
| + | myStepper.step(100, Adafruit_MotorHAT.FORWARD, Adafruit_MotorHAT.DOUBLE) |
| + | myStepper.step(100, Adafruit_MotorHAT.BACKWARD, Adafruit_MotorHAT.DOUBLE) |
| + | print("Interleaved coil steps") |
| + | myStepper.step(100, Adafruit_MotorHAT.FORWARD, Adafruit_MotorHAT.INTERLEAVE) |
| + | myStepper.step(100, Adafruit_MotorHAT.BACKWARD, Adafruit_MotorHAT.INTERLEAVE) |
| + | print("Microsteps") |
| + | myStepper.step(100, Adafruit_MotorHAT.FORWARD, Adafruit_MotorHAT.MICROSTEP) |
| + | myStepper.step(100, Adafruit_MotorHAT.BACKWARD, Adafruit_MotorHAT.MICROSTEP) |
| + | </syntaxhighlight> |
| + | |
| + | == step() - fonction bloquante == |
| + | As you can see above, you can step mulitple steps at a time with '''step()''' |
| + | |
| + | step(number_de_pas, direction, type) |
| + | |
| + | Where ''nombre_de_pas'' is the number of steps to take, ''direction'' is either FORWARD or BACKWARD and ''type'' is SINGLE, DOUBLE, INTERLEAVE or MICROSTEP |
| + | |
| + | {{ambox|text=Note that INTERLEAVE will move half the distance of SINGLE or DOUBLE because there are twice as many steps. And MICROSTEP will move 1/8 the distance because each microstep counts as a step!}} |
| + | |
| + | This is the easiest way to move your stepper but is '''blocking''' - that means that the Python program is completely busy moving the motor. If you have two motors and you call these two procedures in a row: |
| + | |
| + | <syntaxhighlight lang="python"> |
| + | stepper1.step(100, Adafruit_MotorHAT.FORWARD, Adafruit_MotorHAT.SINGLE) |
| + | stepper2.step(100, Adafruit_MotorHAT.BACKWARD, Adafruit_MotorHAT.SINGLE) |
| + | </syntaxhighlight> |
| + | |
| + | Then the first stepper will move 100 steps, stop, and then the second stepper will start moving. |
| + | |
| + | Chances are you'd like to have your motors moving at once! |
| + | |
| + | For that, you'll need to take advantage of Python's ability to multitask with threads which you can see in '''DualStepperTest.py''' |
| + | |
| + | The key part of the DualStepperTest example code is that we define a function that will act as a 'wrapper' for the {{fname|step()}} procedure: |
| + | |
| + | <syntaxhighlight lang="python"> |
| + | def stepper_worker(stepper, numsteps, direction, style): |
| + | #print("Steppin!") |
| + | stepper.step(numsteps, direction, style) |
| + | #print("Done") |
| + | </syntaxhighlight> |
| + | |
| + | We have some commented-out print statements in case you want to do some debugging. |
| + | |
| + | Then, whenever you want to make the first stepper move, you can call: |
| + | |
| + | <syntaxhighlight lang="python"> |
| + | st1 = threading.Thread(target=stepper_worker, args=(myStepper1, numsteps, direction, stepping_style)) |
| + | st1.start() |
| + | </syntaxhighlight> |
| + | |
| + | Which will spin up a background thread to move Stepper1 and will return immediately. You can then do the same with the second stepper: |
| + | |
| + | <syntaxhighlight lang="python"> |
| + | st2 = threading.Thread(target=stepper_worker, args=(myStepper2, numsteps, direction, stepping_style)) |
| + | st2.start() |
| + | </syntaxhighlight> |
| + | |
| + | You can tell when the stepper is done moving because the stepper thread you created will 'die' - test it with '''st2.isAlive()''' or '''st2.isAlive()''' - if you get '''True''' that means the stepper is still moving. |
| + | |
| + | == oneStep() - fonction non bloquante == |
| | | |
| {{Rasp-Hat-Moteur-TRAILER}} | | {{Rasp-Hat-Moteur-TRAILER}} |