Dan Creagan (email@example.com)
An Experiment For You To Build Upon
Click HERE for a zip file of this article
Click HERE for just the source code
Motor *Controller*??? Why do we need a fancy motor controller with our robots? Can't we just apply power and let them scoot off chasing the dog or cat? Well ... sure, you can do that. But if you just apply a constant power to each motor on a 'bot, then the poor robot will never be able to maintain a steady speed. It will go slower over carpet, faster over smooth flooring, slower up hill, faster down hill, etc. In fact, it will probably be darn hard to fix it so both motors turn exactly the same speed given any terrain. The usual result is the 'bot does slow curves around the floor because one wheel is getting more power than the other. The other irritating problem with applying fixed power to robot wheels is that it is hard to apply *just a little* power to get the robot to go slow. The wheels only have a limited torque when this is done, and just about anything will stop the robot.
This article explains the basics of how to get your motor to give feedback to a microcontroller and then control the speed of the motor with a good deal of precision (well... good enough for our robots). You can select any speed you want the 'bot to go and it will try to go that speed - even if it runs into difficult terrain. It will apply more power when it senses a slow down and the power will continue to be increased until the wheels turn at the selected speed (or until you run out of battery juice). In fact, it is quite interesting to command the robot to turn at a low rpm and then watch it crawl very slowly across the carpet. If you put your hand on it to stop it, it 'hunkers' down and starts pushing harder until you let it go. It then quickly settles into its slow and straight crawl.
When you use the speed of the motor as feedback and add it into your speed adjustment circuit, you are implementing Proportional Feedback. A spinoff of being able to control the motors with this system is that you can keep track of just how far the motors have traveled. You can then use that information to make precision turns and do dead reckoning navigation. Click HERE for a Real Movie of a motor controller that is based on this experiment taking its robot around a relatively precise square.
These are the basic instructions on how to make a simple DC Motor Controller. They are compiled from my own experiences, and from some really great discussions about the topic on the Seattle Robotics Society's mail list. In addition, Bill Ruehl and I collaborated on a more elaborate controller that this experiment is derived from - so Bill needs to be given credit for his work on this. You can contact him at: Bill Ruehl and you can see some of Bill's robots at Bill Ruehl's Web page .
The experiment described here is just that - an experiment. It is not a completed robot or motor controller, but it should introduce you to how it all works and then you can build your own. This experiment is meant to get your creative juices flowing so that you can create your personal solution for your robot. These instructions use the following configuration - if you don't have this exact equipment, then you are on your own, but if you read on, you should be able to understand what is happening and apply it to your situation:
Limitations Of This Experiment
The basic diagram of the experiment like this:
The layout of the breadboard looks like this (click for larger picture and comments).
And here is a picture of the experiment all hooked up and ready to go (the motor power is coming from a bench supply that is off screen):
The idea behind the coding for this experiment is to select a feedback rate that equates to the speed you want your motors to go. Then sample the encoder feedback to see if the motor is turning that speed. If it isn't, then increase/decrease the PWM duty cycle until the motor comes into the right speed range. The code (PicBasic Pro) to run this experiment is heremogotut.bas. If you decide to use another language to do this coding (or you use an Atmel chip) then let me know. I would like to collect a few different examples so folks would be able to pick and choose.
A more complete controller and an example application using wheel encoders is here: http://188.8.131.52/robots/skinny.html
You will definitely want to experiment with different feedback speeds, sampling times and size, PWM frequencies, and gain of your proportional feedback (if your gain is too high, the motor will oscillate). This is actually quite a bit of fun to play with and it will get you a good deal of experience.
What's next??? Well .. with a little thought, you can see that this is not a very complete experiment. You will want to be able to start and stop the motors and tell them to turn a specific way, keep track of how far they have traveled, etc. We'll leave that code for a future article (or for your own experimentation).
ClickHERE for a zip file of this article