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:
- 16C73A - PIC microcontroller. Chosen because it has hardware PWM. Click http://www.seattlerobotics.org/encoder/sep99/pwmmail.html to find out more about hardware PWM. Go to www.microchip.com for documents that describe the 16C73A. www.atmel.com also makes a similar chip (AT90S4433). You could use other chips like the Atmel AT90S8515 or PIC 16F87X series. The Atmel series does not use the same code/compiler as the PIC series so the code in this project won't work on them. And, of course, you could use a Motorola MCU - most of which have hardware PWM also. You can pick up PIC chips from Digikey - but you will need a programmer and a UV light source to complete your PIC kit. You might want to get a friend who has all this to help with your first shot at it.
- Globe DC Motor - Chosen because it is small and has built-in shaft encoders. It seems to be popular right now on the surplus market and can be gotten from a number of sources. It simplifies the motor feedback. You can use wheel encoders or any other feedback method, but this example uses the Globe Motors for simplicity. See the bottom of this page for some examples of other feedback methods. You can get a Globe motor from: http://www.gatewayelex.com/motors.htm The Globe motor shaft encoder gives 2 pulses per revolution of the motor, which equates to about 240 pulses per revolution of the drive shaft.
- 12 Volt power. You can get a 12 volt Gel Cell from a battery store for less than $20 (1.4 amp hour is fine - cost me $15 retail). You could use a variety of battery packs including one of the RC model car Ni-Cads (7.2 volt). Also, you could just use a 12 - 13 volt bench supply. The Globe motors are rated at 24 volts but seem to like just about anything from a few volts on up. If you use a higher voltage ( > 12 volts), you might have to heat sink the motor control chip and your power supply chip.
- Pic Basic Pro. Basic was chosen because it is like psuedo code. You can code your project in any language once you know how it all goes together. Basic is a well understood language and it is very easy to read. You can get PBPro from http://www.melabs.com. It is somewhat expensive, but makes prototyping very easy. Remember, you don't have to use the language used in this example, you can develop this in assembler (which is free for the PIC, Atmel, and Motorola chips).
- A 74HCT04 hex inverter for inverting one channel of the motor drive. The remaining inverters on the chip (you only use one of the six) will be useful if you expand the project to control two motors - or to use it as an inverter to serially communicate to your PC (or both). For a simple block diagram of how the inverter is used, see pulses.html. You can get the inverter chip from Radio Shack or Jameco (www.jameco.com)
- An SN754410 motor controller. You can get them from www.acroname.com They are a substitute for the L293D controller. They handle more current and are a bit better (a tad more expensive). Since the Globe motors are a little current hungry, the upgraded chip was used. If you use L293D chips, then be sure to put them on a good heat sink.
- A solderless breadboard. A Jameco JE23 is fine (see picture below) www.jameco.com
- A 7805 voltage regulator - or other 5 volt power source for the PIC and other chips. Get them at Radio Shack or cheaper through Jameco.
- A 20 mHz crystal (you can use just about anything, but the 20 mHz gives you a great deal of flexibility if you decide to build on to the project and actually make a useful controller.) Again, go to Jameco/Digikey/etc.
- Various caps and hookup wire. Get them from your junk box or from the Shack.
Limitations Of This Experiment
- Proportional feedback only. Proportional is all you need for most small robot applications. However, the other two types of feedback are explained at PID.htm. Refer to this document if you want to implement a more elegant version. See http://188.8.131.52/robots/skinny.html for a more complete implementation example.
- Single channel only. This is a tutorial and as such it is probably not functional for anything, but it should show you how to do it all. You should be able to add a second channel (second motor) to this example very easily. You are only a few smoke releases away from a working example! 8-)
- Locked anti-phase for the motor controller. Anti-phase is the easiest to hook up. For a discussion of the difference between locked anti-phase and sign magnitude (the two basic types) see National Semiconductor Note AN-694 (AN-694). When using locked anti-phase, the frequency of the PWM should be relatively high so that the motor coils can act as a filter to turn the pulses into an average DC output. Try to run the PWM at 19 kHz or higher when starting and then adjust to see how it works.
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 here mogotut.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.