Skip to content
Alex Schendel edited this page Jul 18, 2020 · 16 revisions

This wiki discusses the various motors on the robot and how we interface with them. These problems were all implemented in the Arduino Code previously, so if you don't mind reading the Arduino C++, that could help you also see some more examples.

Stepper Motors

Stepper motors are special, brushless DC motors. Inside they have coils which pull the rotor along. They are called stepper motors because every time the next coil turns on, one step is performed which turns the rotor a consistent distance. To control these directly would be quite challenging, so instead we use stepper motor controllers which are like the Sabertooth, but for stepper motors. It is worth noting that we have a few different motor controllers for our stepper motors, but they still all work the same.

So how do we control the stepper motor controllers? The main part is Pulse Frequency Modulation. Big words aside, we need to tell the motor controller when to turn the motor, so we do that by sending it a pulse (just setting the "PUL" pin to HIGH). But now what? It turned one step which we couldn't even see because it's so tiny and then it stopped! So we have to set it back to LOW and then we can set it to HIGH again to get another step. Just keep doing that HIGH LOW HIGH LOW and you've got it turning! Except we can't send those pulses too fast or else the motor controller won't even know what to do, so we need to add some delay. It depends on the way the motor controller is setup, but I tend to have good luck with a 500 μs delay. If you want to go slower, make the delay longer. If you want to go faster, make the delay shorter, but do note that if you start with to high of a frequency, the motor can sleep and make the worst sound you've ever heard. Trust me, I've only heard it about a hundred times ☹️. If you want to go faster but you can't manage it without the motor slipping, ramp up the speed. Start out with a long delay and every few pulses decrement the delay until you reach the desired speed. The rest of the control of the stepper motor controller is the ENA(enable) pin and the DIR(direction) pin. Basically, the enable pin just lets the controller know whether we want it to actively hold its position (can waste energy and make the motors heat up though). Also, NOTE THAT ENA IS ACTIVE-LOW (set it to LOW to enable the motor). The direction pin is there because the pulse pin can't tell the controller which way we want to turn, just when and how quickly. Therefore, we set the direction pint to HIGH to make it go one way and LOW to make it go the other way (you'll have to figure out which is CW and which is CCW through trial and error).

Basically it looks like this:

pulse = DigitalOutputDevice(PUL_PIN)#This assumes you have constants named PUL_PIN, ENA_PIN, and DIR_PIN going to the correct pins on a stepper motor controller
enable = DigitalOutputDevice(ENA_PIN, active_high=False)#active_high=False means that enable is set to run as active-low, so we don't have to worry about inverting the enable every time
direction = DigitalOutputDevice(DIR_PIN)
enable.on()
direction.on()#we don't really know which way it'll turn now... Fun surprises!
for i in range(3000):#run for 3000 steps
    pulse.on()
    sleep(500 / 1000000)#divide by 1000000 to convert to μs
    pulse.off()
    sleep(500 / 1000000)

TODO: Make a library for this!

Clone this wiki locally