Prerequisite:
Experience with electronic circuits/knowledge about basic principals (eg. what do capacitors and resistors do, why they are important, and how you use them). If you do not know basic electronic skills (i.e. you haven't built anything yet), then you should first build some kits to gain some experience both soldering, and learning about electronics. For good introductory kits go to our great WCRG sponsors, www.solarbotics.com or www.jcminventures.com or www.hvwtech.com and pick up a few of their kits to get started with. The reason I say this is because if you don't know how to read the value on a resistor, you will be very unhappy when you start burning out dozens of pricey microprocessors, and not knowing why, then quitting because it is "too hard" (when you are really just jumping into the deep end before you learn how to swim).
Equipment (Hardware):
If you are going to program microprocessors, then you need a microprocessor. There are several types, but here is the 5 most prevalent, and relative to robotics that you will encounter:
- Lego Mindstorms (available from www.lego.com ) - A great introduction to robotics for the person who has zero knowledge about the subject. Lego will first teach you about mechanics (motors, gears (why you can't hook a wheel directly to your motor), and general building stuff). After teaching you how to build things that will stay together and move, it will also teach you very basic programming skills (ex. if left bump sensor is triggered, reverse the motors) (eventually you will want to move on to a better programming language like C, but the Lego brick language is a good starting point to develop logic, program flow, and program layout). And it does all this without you having to have any knowledge about electronics. But due to the simplicity, you will eventually hit the limits of the Mindstorm platform (namely the limited number of sensors, and motor ports), and the relative high cost for each RCX brick.
- BASIC Stamp (available from www.hvwtech.com ) - The BASIC Stamp is one of the best introductory "real" microprocessor kits out there (I would highly recommend going straight for the BASIC Stamp II starter kit). The focus of the BASIC Stamp is to make programming easy (by programming in the BASIC language), and to help you learn how to connect electronic things to the microprocessor in a way that doesn't fry something. The manuals are very good at telling you what components you need, and how to build a circuit in the right way so that your BASIC Stamp has a happy nice warm fuzzy feeling of doing what you want it to do. For example, it shows a couple of different ways that you can connect a button, and how to use a pull up, or pull down resistor to make it work properly. The best feature of the BASIC Stamp is its debugging capability. When you download your program into the BASIC Stamp via the serial cable, you can leave it plugged in, and while your robot is running, you can send debugging messages back to your computer (i.e. when the left touch sensor is triggered, you could have a message come back to the computer informing you on, where your program is in the code, what is happening, what the values of some of the various variables are, and informative messages like "Thar be dragons!" which indicates that you want to back away from that object). This really helps a beginner understand how their code works, and also figure out why their robot behaves the way it does. Usually the BASIC Stamp is sufficient for most people who are interested in robotics to get started, and it is also able to do some intermediate level robotics. Eventually three factors will come into play, speed (the BASIC Stamp runs *relatively* slowly (2000-4000 lines of code per second)), lack of Analog to Digital inputs and special ports like I2C (which prevents you from hooking up more advanced devices), and cost per BASIC Stamp(~$40 a 'chip').
- PIC (kits available from www.hvwtech.com and chips from www.digikey.ca ) - This is one of the most powerful, flexible, fast, and inexpensive microprocessors out there (in fact, the BASIC Stamp is based off a PIC chip). It is also one of the most common microprocessors out in industry. In exchange, you will not have your hand held as you plunge head first into the deep end. A knowledge about electronics is a must, as well as good knowledge about programming. Even for most people who have good knowledge of electronics, and programming will take about three times longer to get an LED light blinking than with a BASIC Stamp, and boy, will you celebrate getting that simple light blinking... as your BASIC Stamp robot circles around you (because it is easier to program, and make things with it). The struggle is long and hard at the beginning, but there are more advantages in the long run like faster program execution (1-8 million instructions per second (a thousand times faster than a BASIC Stamp)), more I/O pins (depends on the model), and much much cheaper (usually most chips are under $10).
- Atmel AVR (available from www.digikey.ca ) - What I like to call a PIC on steroids. It carries all of the advantages of a PIC, with some definite improvements and features, and also it is the "WCRS standard" microprocessor for our group. The AVR runs more efficiently than a PIC (i.e. it will run more instructions per second), runs at a lower power, has more features built into the chip (eg. I2C, UART, multiple A/D I/O, etc.), and all for approximately the same cost of a PIC, or 1 or 2 dollars more. Unfortunately you will still face a fairly monumental learning curve, as you try to find a way to download your program into your AVR, and then make sure things work.
- Embedded Microprocessors or Digital Signal Processors (DSP) - These are extremely powerful processors (usually most of these modern processors run in the hundreds of Mega hertz (much more powerful than the original 486, but less powerful and expensive than your 3+Ghz Dual-Core Intel chip)). The downside of these processors is that they are usually more powerful than we typically need (i.e. like putting a V8 engine in a Pinto), usually much more expensive (running into the hundreds of dollars) then a PIC or an AVR ($2-$20), and they usually have a poor interface to external componets (usually you are limited to serial and possibly USB communication (i.e. not easy interfaces for most robotic components to work with)). Basically, stick with the less expensive PIC's or AVR's, unless you have a specific need for raw processing power.
Software - Programming Languages:
If you have a microprocessor, you will have to eventually download a program of some type into it. What programming language you use, largely depends on knowledge, the type of program you are writing, and personal preference. There are really four main programming languages that you will have to really be concerned with, and their various pros and cons.
- Lego Brick - The Lego brick language is a very simple "language" that uses a simple graphical interface, and interlocking programming "bricks" to create a program. It has the advantage of being very simple to learn, and focuses you on learning program flow and logic, and not on syntax technicalities and compiling issues, etc. The two downsides to it are that it only works for the Lego Mindstorms system, and that due to its simplistic nature, causes it to be hard to create complex programs.
- BASIC - BASIC (Beginner's All-Purpose Symbolic Instruction Code) was designed to be an easy to learn language (hence the acronym). If you use the BASIC Stamp, you will program it with a modified version of the original BASIC language specifically designed for the BASIC Stamp. While it is possible to get BASIC compilers for other microprocessors (although hard to find), the original physical language is not really designed for microprocessors. In general the only time you will use BASIC will be when you are programming the BASIC Stamp, for which it is easy to learn and use. But for other microprocessors, BASIC doesn't work as well.
- Assembly - Assembly language is the lowest level language that you can feasibly go. Every instruction is the lowest level that you can go, so a "for" loop involves you setting up your registers (of which you will quickly realize that you have a limited number of, and always too few), checking the conditions, executing the required code if the conditions are right, and going back to the start, or jumping elsewhere in your code. In general, Assembly language is widely regarded as one of the most difficult languages to master, even though there is only a small fixed number of commands, and variables. What is required is a certain art to program in it, a strong mind for logic, and a certain tyrant egotistical behavior required to command the chip to do your bidding, manipulate bits and bytes, and be able to control every single thing that the chip does, which is what you will have to do. For small programs (blink some LED's), assembly is great, for larger programs (like a complex minesweeper robot), things can get complicated really fast, and make it hard to program.
- C or C++ - C and C++ are essentially the same language, but with C++ having a few more Object Orientated features (like classes). When you are programming a microprocessor, you won't really see much differences other than using a different compiler to compile your code. C/C++ is good for designing large complex code. The downside is that it is not as easy as assembly for controlling the processor (for example manipulating special registers for controlling timers), but with the ability to program very complex stuff (like recursive functions) easily, C/C++is probably the most attractive programming language.