-
Notifications
You must be signed in to change notification settings - Fork 1
Motors
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.
These are your standard, run-of-the-mill motors that run on Direct Current with their speed varying based on the voltage given to them. However, since our microcontrollers cannot control the output of the pins themselves, they need some help from their motor controller friends. In this case, we chose to use Sabertooth motor controllers to get the job done. They are expensive buy they have some very nice features. As for interfacing with them, lucky for you, we already have an API to show you that!
As for what we use these for, they are all over, most notably the entire drive system, articulation and drive.
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
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!