Autonomous Robots FAQ


This page offers answers to frequently asked questions about autonomous robots. Whenever the word robot is used, I am refering to autonomous robots specifically. This FAQ is a work in progress. Please send corrections to dubel at ufl dot edu.


Table of Contents:

What is an autonomous robot?
How can I make a robot autonomous?
What powers a robot? What is NiCad, NiMH, and LiIon?
How does a robot move around?
What are servos?
What kind of motors should I use?
What is a motor driver?
What is an H-Bridge?
What does RC stand for?
What is PWM?
What is TTL?
What is a microcontroller?
What microcontroller should I use?
What language should I program in?
How do I program my microcontroller?
What is a makefile?
How do I download my program to my microcontroller?
What is ISP, ICSP, and JTAG?
What is a bootloader?
How do I build a robot?
What is a PCB?
How do I make printed circuit boards?
Where do I order parts?
How do I interface an LCD screen?
What sensors should my robot have?
How much do robots cost?
What is I2C and TWI?
What is RS232?
How do I use the SRF-04 Ultrasonic Range Finder?
What is a CCD?
How can I follow lines with my robot?
Can I control other devices with my microcontroller?
How do I use a transistor to switch larger loads?
How do I use a relay?

Answers:

What is an autonomous robot?

An autonomous robot is a robot that functions under its own control. Autonomous robots react to their environment based on sensor information, instead of following pre-programmed instructions or working under direct control of a human. Radio control cars, "BattleBots", and industrial manufacturing robots are not autonomous, but could be made autonomous by adding sensors and intelligent behavior.

How can I make a robot autonomous?

Add sensors and intelligent behavior to the robot. There are many types of sensors that are  useful to robots, such as vision, touch, and light sensors. To process information from a sensor, a microcontroller is typically used. A microcontroller is usually the brains of an autonomous robot, but there are other ways to process information.

What powers a robot? What is NiCad, NiMH, and LiIon?

Most robots are powered by rechargeable batteries. Solar powered robots exist, but for most applications they are not practical. Nickel-Cadmium (NiCad), NiMH (Nickel-Metal Hydride), and Lithium Ion (LiIon) are all popular chemistries. I don't recommend NiCad because they are not environmentally friendly. NiMH batteries are a great low cost choice for robots. They have higher charge densities than NiCad, and come in all the same shapes, sizes and voltages. Finally LiIon (and also Lithium Polymer) offer the highest charge densities for the smallest and most demanding robots. LiIon batteries are most expensive. You'll need a charger for your batteries, and the charger must support your specific chemistry.

Most small robots are powered by 7.2 V or 9.6 V battery packs. These numbers represent the nominal voltage of the battery pack. Each NiCad or NiMH cell is 1.2 V nominal, and each LiPoly cell is 3.6 V or 3.7 V nominal. So six cells of NiMH or two cells of LiPoly give you a nominal voltage of 7.2 V. Fully charged the voltage is higher than the nominal. And discharged, the cell voltage is lower than nominal. To provide the constant voltage required for electronics, a voltage regulator is used. I recommend NiMH batteries until you understand the differences because LiPoly batteries require special precautions.

Usually the motors and driver circuitry determine the minimum voltage of your power supply. Check the voltage requirements of your motor drivers, as some require 12 V or higher to function properly.

How does a robot move around?

Robots may use legs or wheels to move around. Legged robots usually make use of servos for actuation. Wheeled robots typically use geared DC motors, but can also use modified (hacked) servos as a less expensive option.  The components found in a servo are cheaper than what you would ideally use to drive your robot.

Picture of typical robot platform goes here (Caption: Tank Style driving)

What are servos?

Servos have a geared DC motor, a motor driver, and a feedback element all contained in a small box suitable for RC applications. When hacked for continuous motion, the feedback element is bypassed. RC Servos have three electrical connections: Ground, Power (5V) and a signal line. The signal line carries a PWM signal that determines the angular displacement of the servo. For example, a 1 ms pulse width causes a servo to rotate -45 degrees from center. A 2 ms pulse width causes an angular displacement of +45 degrees from center. A 1.5 ms pulse width centers the servo. The PWM signal should have a frequency of about 50 Hz. When servos are modified for continuous rotation, pulse widths of greater than 1.5 ms move the servo clockwise, where widths less than 1.5 ms move the servo counter clockwise.

Picture of servo goes here

What kind of motors should I use?

The best types of motors to move your robot along are geared DC motors. They should be geared for a final output RPM of between 150 RPM and 400 RPM, depending on how fast you want your robot to go. Choose motors that operate from 6 VDC to 12 VDC. Stall current is important too - it tells you what the maximum current the motor will draw when stalled. This can happen if your robot runs into something or gets stuck. Your motor drivers must be able to handle the stall current of your motors. 2 Amps is a typical stall current. Note that it is possible for the motor to draw more than its stall current when switching directions. If your motor driver can't handle current in excess of the motors stall current, you can first stop the motor before reversing directions with a delay to avoid burning your motor driver. Another specification to consider is torque. Larger robots need more torque. How much torque? It's possible to calculate this, but you'll probably resort to trial and error in the end. Most small robots are driven just fine with your typical 200 RPM geared DC motor at 7.2 V.

What is a motor driver?

You need a motor driver to provide enough current to your motors (to make them move). A microcontroller cannot provide sufficient current to drive a motor. Servos have motor drivers built in so if you use those then you won't need a seperate motor driver board.

Some motor drivers are more expensive than others. For a complete dual RC motor driver _board_ you should expect to pay $25 to $60, though cheaper ones exist. You will need not only the motor driver chip(s), but also support capacitors and resistors so that your microcontroller only needs to
send a PWM signal (and possibly a direction signal) to the motor drivers to control your motors. The datasheets for motor driver chips usually provide schematics for motor driving applications.

You could make your own board and save a good bit of money. Check out my motor driver page.

In progress...

What is an H-Bridge?

An H-Bridge is a configuration of four transistors, typically MOSFETS, that allow current to be switched in either direction through a load. The load is often a DC motor, but the same configuration is used for a (single) bipolar stepper motor winding. The 'H' in the name references the shape of the transistor configuration. <include picture of circuit diagram> If you wish to control DC motors on your robot, you will need an H-Bridge. To be answered...

What does RC stand for?

RC has two common meanings in robotics. The first is an abbreviation for radio control, signifying that a component is compatible with typical radio control systems. For the robotic hobbyist, this means that a component such as a motor driver or servo uses the same PWM signals that are used by a typical radio control receiver. This PWM signal is usually around 50 Hz, with a pulse width (high time) of 0.5 to 2.5 ms. The width of the pulse can control a motor driver or a servo, for example. The second is shorthand for resistor-capacitor, which is used in filtering applications and to model many types of loads.

What is PWM?

Pulse Width Modulation, or PWM, is a type of signal modulation used to transmit an analog signal on a binary channel. The PWM signals in this document use standard RC servo ranges.

What is TTL?

TTL stands for transistor-transistor logic, but is used to describe voltage levels of 0 V and 5 V, with threshold values at 0.8 V and 2 V. Another popular standard is LVTTL which use voltage levels of 0 V and 3.3 V but are compatible with TTL thresholds. CMOS has a range of voltages with the thresholds at around 50%. Care must be taken when mixing logic levels because it's possible to burn out a lower voltage chip. Also, some technologies may not provide sufficient current sourcing ability to properly drive others, for example TTL and CMOS. Note: In the networking domain, TTL has a different meaning: time-to-live.

What is a microcontroller?

A microcontroller is a microprocessor that has inputs and outputs designed to interface more than just memory. Typically the program memory and RAM are integrated on the microcontroller, instead of accessed externally. You will usually find that I/O on a microcontroller can sink or source 15 mA or more. Advanced microcontrollers such as the PIC16F877A and the ATmega8 also feature communication interfaces such as a UART, SPI or I2C, analog to digital conversion, and PWM generation.

What microcontroller should I use?

You should use an Atmel or a Microchip... Please visit my ATmega128 resources page. I recommend Atmel since the ATmege series of microcontrollers can be programmed in C using the free GCC compiler.

Beginners can use a Stamp from www.parallax.com. A stamp is basically a small microcontroller, BASIC interpreter, EEPROM, clock, regulator, and I/O all on a single 24 pin chip! Very cool and you don't even need a programmer. It will cost you $50 though, probably making the controller the most expensive component on your robot.

What language should I program in?

Great question, so many valid choices with no right answer. I think you should program in C, but it is of course up to you. Here are some advantages and disadvantages of popular languages:

Assembly is available (assemblers are almost always free) for all microcontrollers. In theory, it can be the most efficient language you can use. In practice, many C compilers produce machine code just as efficient as you might code in assembly. Assembly is really bad for group projects. Assembly is probably best for small projects or sections of timing critical code that might otherwise be coded in C or another language. On a scale of 1 (easy) to 5 (difficult), assembly is probably a 5.

BASIC is very popular because it is designed to be easy to use. BASIC lacks some of the modularity of other languages such as C and Java. You usually don't have access to interrupts when using BASIC. This usually means that your microcontroller will have a hard time doing more than a few things at a time, and you will be polling a lot. Also, as far as performance goes, BASIC is the worst. It is usually interpreted (such as on the BASIC stamp) and orders of magnitude slower than compiled or assembled code. There is no BASIC "standard" with microcontrollers - each compiler seems to have their own variation, and BASIC interpreters/compilers are not available for all microcontrollers. I give basic a 1 (easy) out of 5 on my difficulty scale.

Java is a language that is gaining popularity with microcontrollers, but still requires an interpreter and more expensive microcontrollers. Java offers a nice standard language base and promotes modular and object oriented programming. It is a great language for group projects. There are few microcontrollers that have Java runtime environments available. The few that I am aware of either run a proprietary byte code (such as the Javelin) or run on variants of the 8051, such as the Tini.

C is last but not least on my list, as I have already recommended that you code in C. C offers most of the capabilities of assembly while shielding you from the processor specifics. Unfortunately, in a microcontroller that's not entirely true since you will still need to directly write to many hardware registers to use the microcontroller's special features. And while the language itself is standard, the special features of different microcontrollers are not, so usually microntroller code written in C (or any language) is not portable across different brands of microcontrollers. The good news is that C compilers are available for most popular microcontrollers - even the most simple and memory limited microcontrollers. C is also good for group projects. What about C++? Well, it turns out that the small size of most microcontroller projects undermines most of the benefits of object oriented programming. Currently there are not too many C++ compilers for microcontrollers. This may change as microcontrollers get bigger and more powerful.

How do I program my microcontroller?

ISP, device programmer, bootloader, etc... To be answered...

What is a makefile?

When you compile source code and link the resulting object files for your microcontroller, you are building an executable program. In general, a makefile is a user created or edited file that is used by the make program typically to build an application. Using make with a predefined makefile simplifies the build (compile and linking) process by performing all the actions you describe in your makefile when you execute make, so that you don't have to execute each step on the command line seperately. Some IDEs (Integrated Development Environment) handle this convenience for you, automatically compiling and linking all of the necessary files from your project when you build your project. Other environments rely on make (and a customized makefile) to build your application. There are several sample make files for the Atmel series at http://www.avrfreaks.com that you can customize for your projects. To be answered...

How do I download my program to my microcontroller?

Microcontrollers can be programmed directly with a device programmer, as well as in circuit using methods such as ICSP and JTAG, or a bootloader. To be answered...

What is ISP, ICSP, and JTAG?

ISP and ICSP stand for In Circuit Serial Programming. JTAG stands for Joint Test Action Group, but usually refers to a programming and debugging interface used on many integrated circuits such as microcontrollers and FPGAs. To be answered...

What is a bootloader?

A bootloader is microcontroller code that can write to its own program memory. These are usually used to allow new programs to be loaded into its program area without a special device programmer.

How do I build a robot?

The simplest robots are made from ABS plastic, but you can cut your parts from wood, polycarbonate, or acrylic. I find that 1/8" material is great for most projects. When using wood, be sure to buy the 5-ply birch aircraft grade, or else your robot may not be rigid.

For the body of your robot, polycarbonate is an excellent choice, you can cut it with machine tools or a dremel. It's stronger than Plexiglas (acrylic), and lasts longer than wood (looks nicer too), and a lot easier to cut than metal. Only drawback I know of with polycarbonate is that it scratches easier than acrylic. I try to design my robots so that no glue is necessary, and everything is screwed together. If you do use glue, be sure to get the correct type. Poly-Zap from Pacer works well on polycarbonate. Other CA glues work great for wood. Using the wrong glue can cause your plastics to haze or crack.

To have the Polycarbonate pieces cut, I used to go through Lynxmotion but they no longer offer the service on their website. I've found another company, Pololu, that offers the same cutting service. Unfortunately, their neighbors complained about the odor caused by cutting polycarbonate so they only offer ABS plastic now. They also offer some robotics parts as well, but I have yet to order from them. If you order through them, let me know how it goes. A small "sumo" size robot costs about $40 to cut, including the material, which is usually 0.116" Lexan (Polycarbonate).

Update: Another company offering laser cutting is Filener. They appear to offer polycarbonate as well! Please let me know if you order from them; I'd like to know how it turns out.

What is a PCB?

A printed circuit board, or PCB, is a permanent circuit etched or cut out of a copper clad board. Because it’s permanent, it’s less likely that a connection would be inadvertently broken. Typically, a circuit design is developed in a CAD application where the required parts are laid out and (net) connections are routed. The final board layout can be printed or saved as design files used to create the physical PCB. There are several ways to produce a PCB from design files, from chemically preparing at home to ordering professional manufactured boards online.

How do I make printed circuit boards?

I use one of three different methods (other methods exist though):

a) Send the (gerber/excellon drill) design files out to be manufactured professionally.
2 layer boards with silkscreen and solder mask costs roughly $33 a board. If you are a student you can order as few as one board. The board house I recommend is Advanced Circuits, but there are many companies to choose from. The promotions vary so you'll want to shop around. You can use as many layers as you can afford. If you are intimidated by the special gerber files needed by the popular boarding houses, you can try ExpressPCB. The have a free software that allows you to design a board and upload it directly for manufacture. The catch is that they cost a little more for boards and the software is proprietary (you must buy the boards from them).

b) Isolate a board based on your design files using a CNC routing machine.
Many universities and engineering companies have access to such machines. Usually the process is limited to 1 or 2 layers, and you won't get a silkscreen or solder mask. You must manually make connections between top and bottom layers as necessary. Furthermore, isolated boards are typically harder to solder, because they are not pre-tinned and the isolation process usually leaves the unused copper which you must avoid while soldering. The cost is around $5 a board for materials.

c) Chemically develop the boards (at home).
I buy most of my chemicals and materials online at Electronix Express. The materials come with instructions, but here's a rundown so you know what you will need to buy and what to expect:
First you print a positive 1:1 image of your circuit on celephane (transparency material). I use inkjet transparencies with success. Laser gives you better resolution. It's important to use laser type for laser printers, and inkjet type for inkjet printers. If you are using an inkjet, make sure it's a really sharp printer. I've used both inkjet and laser with success, but I've found some printers don't print dark enough unless adjusted properly. If the image is not opaque enough, you may need to increase the ink settings or double up on the transparency.

You'll then need a copper clad board pre-sensitized by a photosensitive material. The boards are made of a type of fiberglass, FR4. For your first boards, use single sided - you'll find later that double sided are usually more trouble than it's worth. In the dark, you will remove a protective tape from the board and use a picture frame to hold the transparency against the pre-sensitized copper board. Make sure the image is placed so that text is readable - not backwards. Note: Some nicer picture frames have a UV protective coating - that may slow down the exposure process.

With the transparency and board in place, use a 200 Watt light bulb (or a special UV light) to transfer the image to the photosensitive material. The process takes about 8 minutes with your light source a distance of 8 inches from the board.

You then use a positive developer solution diluted with water to wash away the developed areas of the photosensitive material. This takes about 20 seconds. Rinse the board with cold water. You can turn on the lights now. You are left with green photosensitive material protecting your copper clad board where you want
your traces to go.

Now use ferric chloride acid to etch away the unprotected copper. This takes about 45 mins, depending on the strength of your solution. You can reuse the etching solution until it is saturated with copper. It will turn opaque black when saturated, but you'll know because it will start to take too long to etch your circuit. You can make the stuff last longer (and boards faster to etch) if you leave copper around your traces instead of removing all unused copper (called copper-pouring in most CAD software). In this picture you can see a small amount of copper pouring. The less copper to remove, the faster the etching works.

Clean the board using alcohol to remove the remaining photosensitive material. Optionally, you can also use a tinning solution to protect the copper from further oxidation (after tinning, use ammonia to neutralize the reaction).
Finally, drill any holes you need using a Dremmel or press with a .031" and .040" drill bit where necessary.

This process costs you around $10 per board or less, depending on the quantity you do. As with the CNC router, you are limited to 1 or 2 layers, and won't get a solder mask or silkscreen. A positive with this process is that excess copper is removed and a tinning solution is available. Here are some additional tips:

1. When printing the 1:1 image from your CAD software, have the software not print where the drill holes should go. In other words, traces should have a little hole where pins will be soldered. If you don't do this, it's more difficult to drill in the center where you need holes, since the drill bit wants to slide around and off the copper trace. You can see the holes I am describing here.

2. Ferric Chloride stains... don't let it get on anything! It will also eat away at certain types of plumbing.

3. Place text on your circuit board so you can verify the orientation of the film after printing (make sure it's not upside down). Text should be readable.

4. The exposure time varies with the light source and distance. I recommend running a test with a small board:
Peel a centimeter of the protective tape back (against the board) and place the board under the light source:
Wait 2 minutes
Peel the protective tape back another centimeter:
Expose for another 2 minutes
Repeat the process peeling back a cm further and exposing 2 mins each time until you have about 12 mins total exposure time.
Remove the remaining tape and place the exposed board in the developer solution for about 20 to 30 seconds allowing the developer to rinse the developed sections off.
This should give you a good indication of how much time you will need given your light source and distance. Use the earliest time in which your image is fully developed. If you try to develop an image too long, the area underneath the traces will receive some exposure as well - and your traces will have little gaps and holes in them.

5. A small amount of light (such as from a candle) should not affect the development process. In otherwords, it doesn't have to be pitch black while you set up the transparency on the board for the image transfer. However, a small amount of sunlight can affect the process - so you want no outside light! You want a room without windows.

No matter what process you use to fabricate your board, I recommend CadSoft's EAGLE application to design your board. They have a free version that is limited to 2 layer designs.

Where do I order parts?

Just about all parts can be purchased from www.digikey.com. Their online ordering system is the best I've seen, given that they sell millions of items. The only things you'll need to go elsewhere for are for tools, some hardware, and servos. Jameco offers lower prices on some products, but their online search tool is useless - you will need to request a catalog.

How do I interface an LCD screen?

The most popular type of LCD screen used in robotics is based off of the Hitachi HD44780 controller. The instruction set of the HD44780 is well know and you will find many code examples to interface a display based on this controller. You can find some sample code on my Atmel resource page.

What sensors should my robot have?

Some popular sensors include IR phototransistors, ultrasonic range finders, microphones, CDS cells, cameras, bump sensors (limit switches), and pressure sensors. To be answered...

How much do robots cost?

Prepare to cash out a couple hundred bucks in parts and tools for your first robot, a lot more if it's your first project in general.

The biggest expense in building a robot is your time. If it takes you 5 hours to track down parts for your robot, you just spent at least $100 of your time. It doesn't make sense to save on materials by building your own hinges if it takes you an hour to do it. Order it, and use your time for the stuff you can't buy, like designing or programming your robot. Also you can get free samples of almost any component just by requesting. Not sure if that custom serial port is going to fit correctly? Try to get a sample before you cash out $10. I found that anything that the regular consumer will have no use for, like an 8bit data register or 99.9% pure glycerin, is available as a sample somewhere.

The resourceful student can build an obstacle avoidance robot for under $100, but most people will spend much more.

What is I2C and TWI?

I2C (pronounced “eye squared see”) is a synchronous serial protocol that operates on TTL levels and has provision for bi-directional communication between up to 127 (with 7 bit addressing) devices. It requires an SCL (clock) and SDA (data/address) line, as well as a ground connection. The bus is externally pulled high via a resistor. TWI stands for Two-Wire Interface. To be continued...

What is RS232?

RS232 is a recommended standard for serial communications, and at one time was found on most desktop computers. It defines a signal that uses between –25 V and –3 V for a logic 1 transmission, and between +3 V and +25 V for logic 0. It is a legacy standard that is usually deviated from in robotics. At a minimum it requires separate TX and RX lines, as well as a ground connection.

How do I use the SRF-04 Ultrasonic Range Finder?

Information gathered from the datasheet: You assert the init line high (on the SRF-04) then release it. A “ping” is sent. Another line (in response) goes high and stays high until the “echo” is received. The time that this echo line is high is linearly equivalent to the round trip distance. Longer times equal longer distances. Since sound travels about 343 m/s (at STP), you can easily calculate the distance given time. Of course, we are talking about centimeters and microseconds here, but you see it’s pretty simple.

Better yet, who needs to convert anyway, as the robot doesn’t know what a centimeter is anyway. I usually time (in 50usec) intervals the length of the pulse, and I get a value from about 3 to 255 equating to about 1 cm to about 3.5 meters. You’ll find the resolution to be about 50 usec anyway from the sonar. I also assume 255 to be overflow (pulse never received). That number fits nicely in a byte, and that’s a quantity your
robot will easily understand.

Here is some code that works on my PICs from the interrupt service routing (ISR), but you should just treat it as ‘pseudocode’. Note that it is a state machine designed to run every 50 usec in the ISR from a TIMER interrupt:

static char SRFWaiting, deadTime = 4; //deadtime is the wait for Echo

if (!INIT && !SRFWaiting)
{
    // start the pulse (INIT line), Advance to next state
    INIT = 1;   
}
// if in the middle of a pulse, turn off and wait for echo
else if (INIT)
{
       INIT = 0;    // pulse finished
       SRFWaiting = 1;   // Advance to next state
       SRFDist = 0;      // reset distance measured
}
// if waiting for an echo
else
{
    // if not echo returned and not overflow yet, increment
    if (deadTime)
       
//wait for the echo pulse to go high (about 212us)       
        deadTime--;
    else if (ECHO && SRFDist<255)
        SRFDist++;
    else   // we aren't waiting anymore, turn off GO indicator
    {
        SRFWaiting = 0;   // reset state machine
        SRFGo = 0; // this was my flag to exit the ISR
        deadTime = 4; // reset deadTime
    }
}


Also define this outside your ISR somehere:

unsigned char SRFGo, SRFDist;

unsigned char read_SRF()
{
    USoundGo = 1;
    while (SRFGo);    // wait for SRF04
    delay_ms(1);
    return SRFDist;
}


Then you can call read_SRF() in your program to get an accurate distance. If accuracy is not critical, you can use a much simpler routine without using a timer.

What is a CCD?

CCD stands for charge-coupled device, but is used to describe a standard imaging chip used in most low cost cameras. Many web cams, digital cameras, and camcorders make use of a CCD. CMOS sensors is becoming more popular in imaging devices, and are typically found in lower power, lower cost devices.

How can I follow lines with my robot?

I have a nice paper devoted to this topic: Reliable Line Tracking

Can I control other devices with my microcontroller?

By other devices I assume you mean devices that require a little more than the typical source or sink current capabilities of your microcontroller. Typical microcontrollers claim to source or sink as much as 25 mA, but in my own testing I've found that 10 mA is a more reasonable expectation - especially if you are sinking or sourcing from multiple pins. To switch more than 10 mA of direct current, I recommend a transistor. If you need to switch more than 1 Amp of current, or need to switch AC loads, you should use a transistor along with a relay. Note that using PWM with relays is not recommended because relays tend to fail after a limited number of switches. The number is high, but easy to exceed if pulsing the load.

How do I use a transistor?

To be answered...

How do I use a relay?

To be answered...


2005.07.27 William Summerfield Dubel IV