Free Web Hosting by Netfirms
Web Hosting by Netfirms | Free Domain Names by Netfirms

Skippy the Robot

Skippy_16.JPG (119057 bytes)

Note: this data is still a rough draft that has some missing information but I have posted it here as some friends want the data that I had. Check back for revisions!

Make sure you read my homebrew disclaimer before proceeding.

Introduction

I wanted to post some information about "Skippy the robot" that I built as some people that I have spoken (and demonstrated) to have wanted some more details. 

This is some pretty "bare minimum" documentation, hopefully someone may find this site and learn a few things from my research and building efforts. Feel free to re-use any of the information that you find here, giving appropriate credit. The source code is released under GPL.

If you found this information helpful or have suggestions for changes or additions, please let me know at one of these email addresses.

What

Skippy is a small robot, length 18 cm, width 13 cm, height 20 cm, mass less than 1 kg. 

Key features are:

Here are some more robot pictures, click for higher resolution:

Skippy_15.JPG (151242 bytes) Skippy_17.JPG (114304 bytes) Skippy_12.JPG (113369 bytes) Skippy_13.JPG (145618 bytes)

Skippy_14.JPG (127342 bytes) Skippy_18.JPG (151124 bytes)  Skippy_8.JPG (145318 bytes) Skippy_7.JPG (104361 bytes) 

Skippy_6.JPG (120133 bytes)  Skippy_4.JPG (282928 bytes) Skippy_2.JPG (149626 bytes) Skippy_3.JPG (172164 bytes)

Skippy_11.JPG (177557 bytes) Skippy_1.JPG (94210 bytes) Skippy_5.JPG (107472 bytes) Skippy_9.JPG (116791 bytes)  

Skippy_10.JPG (104359 bytes)

Who

Skippy was built by Eric Pierce, old fart geezer geek and radio ham operator, more info than you would ever want to know at www.va3ep.net 

Where

Skippy was born here.

When 

Skippy Rev 1 hardware was started in mid 2004 and finished in early 2005 (low priority project :-) 
A first hack of the SW was doing something interesting in early 2005. May do more updates later.

Why

As you can see from my website, I have hacked and worked with electronics/computers all my life. A while back I built a few ham radio projects ( tinytrak APRS vehicle tracker, rockmite QRP transceiver, morse code iambic keyer ) that used pre-programmed Microchip PICS, and this led me to investigate how to develop sw for them, which resulted in a Microchip PIC presentation "Ham (Amateur) Radio Applications of PIC Single Chip Microcontrollers" which I gave at the local ham club. 

I then started on a project programming a Microchip PIC 18F452 in Microchip C18 Ansi C to send Morse Code practice QSOs (at this point have it sending the International Morse Code alphabet at 15wpm using the Hardware PWM, will get back to it later) but a couple of personal and ham radio friends (Douglas Elliott VA3DAE and Andrew Mitchell VA3WAM who I had "elmered" (ham radio jargon for mentored)) who saw my presentation got off on a tangent building robots (maybe Doug and Andrew will document theirs, Doug is working entirely in PIC assembler and is using stepper motors and they are both using cool infrared sensors for collision). 

So anyway I put the Morse Code project aside and rooted through my junkbox to build a robot. About the only thing that I bought new was the speakjet chip, and some other components. My bottom line goals of building the robot were to: 

I have achieved all of those to a certain extent, but could go a lot further with the software, especially with some behavior based on the light detection circuitry and more precise movement based on wheel position feedback..

Behavior

Skippy's behavior is totally software defined, at this point he flashes his lights, runs around, if he collides with somthing he backs up and heads some other way, monitors the air temp, his voltage, the light in his eyes and talks. He is not doing anything interesting with the light information at this point.

Here is a short video of Skippy the robot in operation:

Hardware Documentation and Schematic

Here is a spreadsheet (done in open office of course, but also xls version for those that are using that "other" spreadsheet) that documents the PIC 18F452 pinouts, and some other design calculations and stuff:

Here is the hardware schematic, both as a ??? xyz file and jpg:

Following is a Circuit Description, please refer to schematic when reading.

Power Distribution

Six AA NiMH cells provide a nominal 7.2 volts of primary power. A battery charger jack across the batteries allows for an external current limited trickle charger to be connected (0.1 amps at 7.2 volts). The primary power switch S1 switches the unregulated +7.2 power bus. There are two LM2940CT low voltage dropout regulators U1 and U2, one which supplies power to the RC servos and the other to the digital logic.  Low dropout voltage regulators allow regulation down to ??? volts on the batteries. Two separate voltage regulators are used as the motors in the RC servos are DC brush type motors, and generate quite a bit of electrical noise due to brush arcing on their supply line, which might interfere with the digital logic if a common regulator was used. Using a separate regulator for the PIC ensures that the PIC regulated voltage is as clean as possible. S2 switches off the power to the RC servos to allow testing and debugging without robot drive taking place (and falling off the workbench). The LM386N-3 audio power amplifier U? is powered directly from the primary 7.2 volts (nominal) which gives on the order of 25% higher output volume to the speaker than if it was powered from regulated 5 volts. There is liberal electrolytic and ceramic capacitor bypassing as per the regulator specs, on the power supply busses and for the PIC, speakjet and MAX232 chips.

PIC Microprocessor

The Microchip PIC 18F452 U3 is the main "brain" if the Robot. A 10 mhz crystal and associated capacitors provides the main clock at pins ?? and ??.

Digital Inputs

"Startup Mode" toggle switches S2, S3, S4 and push button "calibration" switches S5 and S6 are active pull down with discrete external pullups and the resulting logic level applied to ?? ... respectively.

Front left, right and center collision switches S7, S8 and S9 are externally pulled up and applied to ?? ...

Wheel turn magnetic reed switches (activated by magnets mounted on the plastic wheels) S10 and S11 are externally pulled up and applied to ?? ...

Analog inputs

Analog inputs are applied to some of the inputs of the PIC ADC (Analog to Digital) converter for conversion into digital values that the software can makes use of.

The battery voltage is divided by a factor of two by R? and R? and filtered a bit by C? and then applied to ??. For a nominal 7.2 volts battery voltage, the voltage divider applies 3.6 volts to analog inpout ??. The battery voltage could go as high as 10 volts (during fast charging for example) before reaching the maximum value of 5 volts at the PIC input.

Temperature sensor U4 is a LM335 pulled up with R? produces 10 millivolts per degree kelvin that is applied to analog input ??

Left and right light sensor "eyes" LDR1 and LDR2 are pulled up with R? and R? and the voltage inversely propotional to the light incident in the "eye" applies to analog input ?? and ??

Digital Outputs

LED outputs are provided by headlighs LED1 and LED2 on ?? and ?? and taillights LED3 and LED4 on ?? and ??. These are used during operation to create "cute" behaviour, and used as diagnostic indicators during software development and debugging.

The two RC servos (modified for continuous rotation) are driven by TTL level signals from ?? and ??.

RS232 Converter

The level converter U5 converts the transmit and receive TTL levels from ?? and ?? to RS232 with an external connection via a mini stereo jack (RTS and DTS are not connected). This allows for external boot loading, or input and output to a dumb ASCII terminal emulator during software development and testing.

Speech

The Speakjet chip U6 is a preprogrammed PIC that accepts TTL level 8 bit async data representing human speech phonemes (and control codes) and converts this to analog audio. The low pass filer ??... removes the PWM component from pin ?? and passes the analog audio signal through a volume control potentiometer to the LM386N-3 audio power amplifier U7.

Jumpers J1 and J2 are used to configure the Speakjet for normal, test or speed calibrate modes (see Speakjet spec sheet).

A switch S12 is used to isolate the async data from the PIC to the Speakjet when using the RS232 interface for bootloading or debugging, when various ascii or control codes might cause the Speakjet to emit sensless phonems or interpret the data as control codes and go into some sort of state requiring reset.

Software

Here is the current version of the Microchip C18 18F452 Ansi C robot source code sample software, including hex file. Note that there is Ansi C soure code in here for creating speech with the Speakjet chip, which should be easy to strip out. Thanks to Doug Elliot VA3DAE for his symbolic phoneme encoding in Microchip PIC assembler that I used for the C version. Note that the 2 include files have to be in the same project directory as the C source file.

This software is released open source under the GPL, feel free to use all or part of it but please mention the original source, leave in the link to www.va3ep.net and please send any changes and additions to me at one of these email addresses so it can be shared for others. Sorry, not on Sourceforge :-) 

Frequently Asked Questions (FAQs)

My thanks to Doug and Andrew for pre-asking and/or discussing most of these questions during our semi-regular "nerd night" robot, ham radio and associated geekery show and tell get togethers.

General Questions

Q: Where can I get more info about how you did X, Y or Z?

A: Before you send me an email, please use www.google.com (google is your friend) to search for key words and phrases (as it may be a while before I get back by email). There is a TON of stuff out there about building small robots, so read a lot and then just get on with building one. Hands on is the best way to learn. You can buy parts, semi kits and even whole kits from various places.

Q: Any other books or information sources other than googleing around that you recommend.

A: See www.picbook.com for a good text on the Microchip PIC 18F452 (applicable to other 18F chips as well). Thing I like about the book is that it shows a lot of code examples of HOW TO USE the features of the chip. The Micochip spec sheets contain every detail about every feature of the chip, but sometime you wonder "so what can I do with that"? Also has ordering info on a nice little development system you can build to make a target for assembler or C code. The circuit board came free with the first edition of the book, not sure if it still does. The development system could even be used directly as a brain for your robot to avoid that part of the HW building.

The www.piclist.com is a good source as well, but look out for DATED information that may not be "true" or "best" anymore. 

There are a lot of robot books out there too, but I found enough information and websites that I did not get any robot books.

Q: I think I am doing the right thing, but X or Y does not work and I can't figure it out, I'm really stuck, what can I do?

A: I would recommend that you try to link up with a local friend or two or more that are into building robots for mutual show and tell sessions (face to face, phone, icq, ham radio, email). If you can find people that have complementary skills this is really helpful, for example maybe you are a Ansi C programming guru, and a friend is a real electronic hardware hacker, you can really help each other. Maybe your school or university or city has a robotics group or club where you can meet like minded people. Don't dismiss people before you get to know them if they are older or younger than you, I know lots of retired geeks that enjoy sharing their knowlege, and lots of high school people who know and have done a lot. Nobody knows everything (or nothing)!

Often when you get together, something that is not obvious to any of you will suddenly become clear to your collective thinking. The other benefit is that you can subdivide R&D and share efforts, for example one of you can research stepper motors and the other can research RC servos, then you can share what you have learned. You can share code segments that or hardware hacks that you do. This brings back memories of the fun days of the "Homebrew computer clubs" in the 70's when the hackers were doing personal computers from scratch and the suits did not have a clue yet (still don't, sometimes). 


Q: Any other good Robot building links that you have found?

A: Here are some:

Hardware Questions

Q: Why did you use drawer pull doorknobs instead of casters?

A: By placing the wheels in the center I can turn 360 degrees "on the spot" but I read some material on the net about people having trouble with swiveling casters (like on your furnature) getting "stuck", and read somewhere else about someone using doorknobs, so tried that. You have to make sure that there is a bit of clearance (when wheels on ground, robot can rock back and forth a bit) so that the robot does not get "hung up" on a rough surface. Very simple and cheap, but limits you to fairly smooth surfaces. Does not do stairs at all well, either.


Q: What is the main robot chassis made out of.

A: It is made entirely from pieces of scrap aluminum from my "interesting pieces of metal scarp" junk box (I think the main structural base is the heat sink from a high voltage section of a 26" color TV, was the right size and already had 2 bends on the ends), some nuts and bolts and hex standoffs (all from another junkbox). The only tools used were hacksaw, hand drill, file, small vise and various sized pliers (and it shows). The chassis is built in "decks": drive deck that RC servos, sensors and toggle switches are on, battery deck (thin piece of aluminum, battery holders held on with velcro), then circuit board deck all held apart with standoffs and screws. I did a lot of visualizing and "dry fitting" to see how the decks would come together before cutting and drilling. Make sure there is enough clearance between the decks so you don't get shorts.


Q: How do you get the batteries out for charging?

A: I don't. There is a power connector on an "L" bracket on the back of the circuit board that is in parallel with the batteries (before the power switch) so with the power off (or on for that matter) I can apply the voltage from the variable DC bench power supply and crank up the voltage until I get about 100 ma of charge current - a good safe trickle charge current. One should really use a sophiticated NiMH charger, but this works. CAUTION - I read somewhere you can fast charge NiMH at up to 1*C (where "C" is their amp hour rating) so I tried to charge them at 1 amp for a while. The springs in the cheap plastic battery holders heated up so much that they melted right throught the ends of the plastic holders! So all I do now is trickle charge.


Q: How did you make the circuit board? Can I get a copy?

A: No fancy etched board, the circuit is built on a standard ?? mm by ?? mm prototyping board, with random point to point wiring. All the chips are socketed. I have a 40 Pin ZIF socket plugged into the 40 pin PIC socket to speed programming in early revs. I started out trying to use a bootloader, but had some HW glitches (was running TTL signals too far) so put the ZIF socket in so I could use an external programmer. Now that I have an onboard RS223 converter using MAX232 I could go back to a bootloader, but have not got around to it.


Q: Anything special to watch out for in building the electronic circuit?

A: Use lots of BYPASS CAPACITORS. I have separate LM2940CT-5 5 volt low dropout voltage regulator supplies for the logic and motors, with a number of 1000+ electolytic uf caps around the board. Also a 0.1 uf ceramic capacitor close to the supply of each chip (read here if you do not know why). Also watch the layout low signal level audio level connections from the speakjet to the LM386 audio amp, keep leads short and away from other circuits to avoid noise pickup. Leave enough wire length in joining the chassis wiring to the circuit board that you can fold them apart for service or mods. Use some strain relief (like very small rat tails) to keep wires from flexing and breaking off where they are connected when the boards are moved around. Coil wires up carefully when the boards are sandwhched together and make sure they don't get pinched anywhere. 


Q: What type of Radio Controlled Servos are you using?

A: Believe it or not they are a couple of 20+ year old Heathkit Servos that I picked up for a couple of bucks at a ham flea market (don't worry heathkit collectors, the mods are reversable and I have 3 that I did not touch), but the servos you can buy today off the shelf will work as they are about the same size and use the same control signals. Servos are great little drive motors as a single 5 volt TTL level digital pulse between 1.5 and 2.5 msec wide every 20 msec controls them. All the hard drive electroincs, motor, gear and axle stuff is done for you. They have to be modified for continuous rotation. You can get pre modified ones here ??? and even wheels to go on them if you want to spend the $$ instead of eating 2 jars of peanut butter. There are also heavier duty RC servos with bronze bushings or ball bearing axles that will last longer, the regular servos are not designed to rotate continuosuly for long periods with a large side load like in this application. This is really the reasing for about 1 kg (2 pound or so) weight limit for RC drive robots.


Q: Why didn't you use a PIC 16F84, 16F628 or other PIC for the robot?

A: The 16F84 costs ??, the 16F628 ?? and the 18F452 costs ??? at this writing (and dropping all the time). For all the extra power, memory and speed of development using Microchip C18 Ansi C compiler, why bother using a smaller chip to save ??. If I was manufacturing these robots as toys or products in 100K or million quantities for commercial sale, then using the smallest chip to save even a few cents makes sense as it goes right to the profit line, but when you are doing a "one of" it does not make sense (to me, anyway) to save a few cents on the PIC. 

When googleing around there is a ton of references and books for code on the 16F84, but this chip is pretty old now (I think not even recommended for new designs by Microchip), I would personally recommend starting with the 18F452.


Q: Any other hardware and software building or debugging tips?

A: Do things in INCREMENTAL steps. My #1 rule of thumb is to NEVER be debugging hardware and software at the SAME TIME. 

Therefore:

Q: Where can you buy parts.

A: Great place for ICs and discrete components is www.glitchbuster.com - low prices, cheap shipping and fast personal service.
I got my speakjet chip from ???????. Most of the other parts were from my junk box or local electronics store.

For robot and RC control parts, google around!

Q: Where can I get more information or schematics for the speakjet speach synthesizer

A: See www.speakjet.com and the yahoo group ????? 
The reference speakjet and LM??? amplifier schemtics are in the yahoo group files area.

Q: How do I test the electronic components in the Robot if I am having problems?

It is a good idea to check discrete components with your multimeter before you solder them in! The resistors should read the correct number of ohms (within their percentage tolerance) and capacitors should read infinity ohms after an initial lower and then increasing resistance as they charge up (watch the polarity of electrolytics, positive to positive on the multimeter, and when in the circuit). No inductors in this project, but they should read a very low number of ohms. 

The chips are socketed so you can swap in a known good part, but BE SURE to check the power supply, ground and signal pins for legal levels (as per spec sheet) or you just may blow another part if there is a problem.

Q: How do the magnetic reed switch RC drive wheel rotation sensors work?

A: Each magnetic reed switch (there is one for each wheel) is activated by 2 magnets (broken off from the flat ceramic magnet from a pancake motor from an old vcr) that are glued to the inside of the skippy peanut butter jar lid wheels. The reed switches are supported with loops of solid wire that are bent to get the switches in the right place. You have to experiment with the switch positioning a bit to get just one reed switch closure per magnet pass. Each switch closes to ground, and has a pullup to 5 volts, see schematic. Note that there are commercial sensors out there that provide higher resolution (more pulses per rotation).
The reason that they are there is that when using modified servos, you have no way of knowing exactly how fast the servo is going for a given pulse witdth control signal. In an unmodifed servo there is feedback so that the ??? to ??? pulse width causes ± 90 rotation (more or less). When the feedback loop is opened, the ??? to ??? pulse causes it to go full speed one way or the other, but due to electronic component and mechanical component tolerance makes the full speed setting non exact. When I send the "full speed" pulse width to my servos, one goes slightly faster than the other, causing Skippy to veer to the right as he goes. The "right thing" to do here is to read the switches to figure out the exact time between closures for 1/2 a rotation, then adjust the signal to the faster motor to compensate. You can also do very exact turns by measuring switch opening and closing. NOTE: the current rev of the software does not do anything except echo the switch closures to the tail lights for some forward movement routines. May get to in a future software rev. 

Q: How do the light sensor "eyes" work.

A: This is a very simple design that I saw somewhere many years ago (I think in the back of a Scientific American "science fair" column). This shows up in the pictures, but in the way of a descripion the two LDR's (light dependant resistors) are mounted facing forward on a vertical flat surface (a piece of perf board) parallel to left right axis. They are a little bit apart from side to side. Between them pointing forward and on a vertical axis is glued an opaque reflective barrier (piece of tin cut from a can). When a light source is directly in front of the robot, then the voltage measured in a voltage divider with the LDR and a fixed resistor (see schematic) is equal. If the robot turns a bit to the side the opaque barrier "shades" one of the LDRs causing the signal from that side to go down, the more it turns away from the light and is shaded the more the signal goes down (due to the wiring the voltage actually goes up when the light level goes down, this is inverted in the SW). I will probably need to use a bit of black cardboard as a hat and side shades to cut our extranious light. NOTE: In the current rev the SW just reads and speaks out the light level, the plan is to do something more elaborate with the information like be able to go the the brightest light in the room, or track a flashlight.

I used LDRs because I they were cheap and easy to get, phototransistors should work as well with the appropriate anaolg circuitry.

Q: Why is the LM??? audio power amplifier powered directly from the battery and not regulated 5 volts (see schematic)?

A: As the LM??? is AC coupled (with a capacitor) to the speakjet audio signal (but using a common ground), it can operate at a power supply voltage different than the speakjet (up to its maximum of ??? volts). Powering it at 7.2 volts (nominal) gives me on the order of 25% higher output audio volume to the speaker.

Q: Why didn't you use stepper motors for the robot drive?

A: Basically because I had the RC servos in my junk box, and did not have 2 matching stepper motors. The other nice things about servos is that they only need +5 volts, and a TTL logic level pulse directly from the PIC to drive them forward/back. Modifying them for continuous rotation is a bit tricky, but not hard. Stepper motors have the advantage of allowing very precise movement commands, i.e. the software says give me N steps, and unless the motors are held back with too much drag, you get N steps. Downside is that they cannot be driven directly by the PIC and need some discrete transistors or drive ICs to do it. Other downside is most surplus stepper motors have small gears on the shaft for which you have to find mating gears and then build some sort of mechanism with the gears to drive the wheels. Doug Elliot found 2 identical steppers in a piece of scrap electroics (dot matrix printer I think, old laser printers usually have some in too) that were fastended to a gearing mechanism that he was able to hack out and fasten the wheels to to make the mechanical work easier.

Q: Why did you use two 5 volt regulators?

A: The motors in the RC servos are DC brush type motors, and generate quite a bit of electrical noise due to brush arcing on their supply line. By using a separate regulator for the PIC, I was being conservative to ensure that the PIC regulated voltage is as clean as possible. It is probably not absolutely necessary if you used lots of electrolytic and ceramic capacitor bypassing for the PIC, speakjet and MAX232.

Q: How do you get a such a well stocked junk box?

A: Ah, the joy of junk! It is amazing the amount of great electronic and mechanical components that you can from electronic equipment that businesses and households throw out all the time. Snarf it from the dumpster area from where you work, or the side of the road on garbage day (wear a disguise if you must).

Every piece of junk electronic gear with have lots of stuff inside like wire of various sizes and colors, connectors, nuts, bolts, washers, screws, interesting pieces of aluminum (easier to work than thin sheet steel), etc. You can extract useful parts like resistors, capacitors, inductors, transformers, transistors, voltage regulators, etc. from the circuit boards inside using a soldering iron, solder sucker or heavy duty hot air heat gun (tip from Doug E.). Older equipment is actually better as it has larger discrete components, modern stuff has tiny surface mount components. Don't try to get all the parts, just the stuff with longer leads that comes off easily. In addition to what is alreay mentioned above, specifically you can find:
- computers cases: disk drives/floppy drives with small stepper motors, CD drives with DC motors (you can build a cool retractable coffee mug holder for your desk with the drawer retraction mechanism, control it with a PIC and make it voice activated), leds, switches, wire (going to front controls), ribbon cable
- computer mother boards: pretty hard to get parts off, but usually a voltage regulator or two and some large capacitors from older ones
- computer power supplies: large diodes and bridge rectifiers, large resistors and capacitors, heavy wire, heat sinks, heavy toroid inductors, stripped boxes make good "project boxes"
- computer monitors: large resistors and capacitors, heavy wire, heat sinks
- dot matrix / laser printers: stepper motors, neat mechanical drive assemblies
- VCRs: esp older ones, motors, mechanical gears and doodads, sensors, IR remotes and sensors
- Casette Tape decks - nice DC motors, wire
- TVs (esp older console models): nice wiring harnesses connecting different subassemblies, large heat sinks, potentiometers and switches
- Wall Warts: lots of gear has these little transformers that plug into the 110VAC wall socket and produce a low AC or DC voltage, some even tell the voltage on the outside. NOTE that if these are dc, they are usually unregulated and the open circuit voltage may be much higher than the "nominal" marked in them. The DC ones need at least extra filtering and regulation to power logic, i.e. use a 12 volt one with a large (1000 uf or higher) capacitor across it (watch the polarity) and a 3 terminal 5 volt regulator like a ??? to power a PIC. The AC ones need a bridge rectifier before the cap.

You get the idea. Note that there is a tradeoff, things that are cheap like resistors are probably not worth the effort of trying to get out, as they have short leads. IC's are not worth the trouble if they are soldered in, you will probably destroy them getting them out. On the other hand, I have a large supply of 3 terminal voltage regulators, and capacitors, as they are easy to get out and usually have longer leads. One other tip, unless you have a lot or storage space, you do not want to stockpile this stuff. I only grab what I have time to dismantle in a day or 2, reducing it to a small pile of "good stuff" and the rest for recycling. I never spend much more than 10 minutes or so dismantling a single item, as much more time usually provides diminishing returns. At this point, I am stocked up for quite a while!
Another intersting point is that dismantling electronic junk is very educational, you get to see how stuff is fabricated and it gives you lots of ideas how to lay things out when you build them from scratch. The other thing that you learn is component recognition, most parts have some sort of written or color bar code that tells you what they are, you can google around and find tables to decrypt them and spec sheets for the marked semiconductors. You should also invest in a good digital multimeter that in addition to voltage and current, can measure ohms (for resistors), farads (for capacitors) and henries (for inductors) to test every component before re-using as they may not be good (that may be the reason the equipment did not work :-) or you burned it up getting it out.

WARNING: hacking apart electonics can be dangerous, make sure the power cord is not connected (don't laugh, once I diked through a power cord on a piece of junk that was still plugged in the wall from testing to see if it worked at all, created an interesting fireworks display), power has been turned off for a few hours to let all power supply capacitors discharge, wear eye protecion and gloves as appropriate, and dispose of the remains in an environmentally friendly manner. Be especially careful working with and disposing the picture tubes of Monitors and TVs. 

Q: What tools do I need to build a robot and/or dismantle junked electronics?

A: First of all, I do not recommend cheap tools, get at least medium grade or better. Bare minimum is:
- small and medium needle nose pliers (reserve the small ones for cutting fine wire as they are easily nicked)
- small and medium side cutters
- medium slip joint pliers
- small, medium and large flat screwdriver
- small, medium and large phillips screwdriver
Next on the list is:
- small and medium crescent wrenches
- jewlers scredriver set
- small nut drivers (english and metric)
- set of small allen keys (english and metric)
For parts salvage from junk:
- solder "sucker" 
- larger soldering gun (for those big connections)
- heat gun (capable of melting solder)
For simple metal working:
- small power hand drill and bits
- small hacksaw
- small or medium vise
- small and medium flat, triangular and round files

Q: What are the "Startup Mode" toggle switches S2, S3, S4 used for?

A: I like to design very incrementally. The first thing that the SW does (see source code and comments) on power up or reset (after initialization) is to read the 3 bits represented by S2,3 and 4 and convert this binary value to a decimal between 0 and 7. I then use a "case" statement to dispatch off to 1 of 8 different routines. In early (and current) versions many of these routines are simple to more complex "diagnostics", like echo the switches to the leds, output ADC values in ascii to the RS232 port to look at on a terminal emulator, etc. This allows me to change one or two routines on each build, and always be able to execute older proven code as a confidence check. 

Q: What are "calibration" switches S5 and S6 used for?

A: Early in the development I found that sending a nominal ??? wide pulse, which should have caused no rotation, to the RC servos actually did not cause them to come to a complete stop (due to electrical tolerance variations in the RC servo electronics). I had to "tune" the value up or down to get a full stop - I did this by making a routine that when selected by my mode switches allowed me to increment the value for the left and right wheels up and down to get a full stop. I echoed this value to the RS232 port to see on the dumb terminal and then on the next build, coded these values in as DEFINES in the program header. I later found out (thanks Andrew!) that if you send NO pulse to the RC servo control input (just a 0 volt fixed level) that the RC servo just stops completely. According to reading on the web most RC servos go into a low power "sleep" mode when this happens. Although there are no brakes, there is enough drag due to the down gearing from the motor to keep the robot from rolling away freely on an incline. 

Q: What was the hardest to troubleshoot hardware problem that you had?

A: I don't mean to brag, but due to my very incremental hardware build, double visual check and electrical check of every connection, I did not have any major ones. I crossed over the wiring to the left and right headlights, but this was easily swapped in software.

Q: Do you have any other ideas for motion bases?

A: I picked up a rather beat up radio controlled 4 wheel drive truck at a ham flea market that I am going to (eventually) use for my next robot, that will be able to go outdoors and negotiate more rugged terrain. Think I'll call him ATVBOT - for not only "All Terrain Vehicle roBot" but as well "Amateur TeleVision roBOT, which I want to put on board.

Q: What other input/output ideas are possible for the robot?

A: For Skippy I wanted to keep it simple, so stuck with physical switches for the collision detect, led outputs and other simple things. I have pretty much reached the limit for Skippy (weight limit for RC servos, space on circuit board), but here are some other ideas that I am thinking of for ATVBOT:
- LCD display for output (Doug has one on his)
- sound detection, although real speech recogntion would be too much for a regular PIC, you could probably do it with a dsPIC if you are into writing DSP software. A simple hand clap detector would be doable: electret mic, amplifier, rectifier/clipper, integrator, into PIC ADC (might be able to squeeze this onto skippy)
- infrared proximity sensors, Doug is using ??? (using physical scanning with an RC servo, cool) and Andrew is using ???
- GPS input to pic to detect position
- electronic compass
- speech output over wireless FM transmitter, could pick up on portable FM radio
- speech output over ham radio as audio to ham radio HT
- ham packet radio digital, to save re-inventing wheel could use APRS for position / telemetry downlink, send messages with imbedded commands uplink, there is code already written for generating/decoding APRS packets, or you can use an off the shelf KISS TNC. Could use pocket sized radio like ???? as the tranmitter/receiver (anyone doing this, please contact me!) 
- ham radio fast scan TV downlink
NOTE: you have to have a ham radio license to transmit on the ham (amateur) radio bands, but it is pretty easy to get now (no more morse code, unless you really want to), see www.arrl.org or www.rac.ca

Q: What electronic test equipment do I need to build a robot?

A: You could theoretically do it with nothing, assuming all the parts are good when you start, you make no errors and there are no failures to troubleshoot. In my opinion the bare minimum is a good digital multimeter (sometimes called a VOM for volt ohm meter or DVM for Digital VoltMeter) that can at least measure volts, (milli)amps and ohms to do basic tests and troubleshooting. Some models have the ability to measure (micro)farads (for capacitors) and (milli)henries (for inductors) which is very handy, and some can measure frequency in Hz. 
Next on the list is a logic probe that can measure hi, low, pulse single shot or repetative (you can build from scratch or kit).
Other handy equipment:
- assorted test leads with alligator clips on both ends
- test leads with banna plug on one end, test probe or alligator in the other for connecting test equipment
- solderless breadboard for prototyping
- small power supply, at least 5 volts at one amp. One with +5, +12 and -12 and a 0 to +12 variable is nice. You can buy commercial (used even) or build from scratch or a kit.
- function generator to generate digital square wave and analog since wave signals in "audio" range, 100-20000 hz. You can buy commercial (used even) or build from scratch or a kit.
- audio signal tracer for troubleshooting audio circuits, a set of cheap amplified computer speakers with a homemade test probes works for this
- Frequency counter, you can buy commercial (used even) or build from scratch or a kit
- Oscilloscope, a tool for seeing the value of one or two voltages graphed as a function of time, very handy for troubleshooting and design. Should have DC vertical coupling and triggered sweep, with frequency response at least 10 times the highest frequency you are working with, 100 Mhz is good, but lower is better than nothing. You can find these used at ham flea markets or eBay, but be careful, it might not be working correctly. Best it to buy one that you can test, or get someone to help you test to be sure. Note that there is SW around to turn your PC into an oscilliscope.

Lastly, you should read the manuals, articles and books on how to USE the pieces of test gear you have, and set up simple circuits on the breadboard to practice measuring volts, amps, waveforms, etc. When you are trying to troubleshoot it is not the time to be learning how to use your tools - you will not be sure if you are seeing real problems, or having "finger trouble" trying to use your test gear.

Q: What electronic test equipment do you use

A: Everything I have I bought used (except the DVM, it was new old surplus stock on eBay). Most of this stuff has been out of manufacture for a long time, but works for me:
Fluke 77 DVM
B&K ??? LCR meter
Phillips ??? frequency counter
Heathkit ??? function / audio generator (have two of these for testing stereos :-) 
HP ??? 100 Mhz oscilloscope

I also have an HP ??? and Boontown ??? RF signal generator and some other RF test gear for ham work, but this is not needed for building robots!

Software Questions

Q: Is building a Robot a good way to learn to program in Ansi C?

A: Probably not. In my opinion "C" is a great language in that it is about as close the the hardware as you can get without using assembler BUT has the advantage of being (mostly) portable between different chip architecures. The down side of "C" is that there is NO RUNTIME checking and you can write code very easliy that will go into the weeds and you will not have a clue why, and can be hard to debug.

If you want to learn "C" from scratch, I recommend you get the open great source compiler ??? and this book ??? and do all the text examples on your PC first. There are lots of other books and tutorials on the net on learning ANSI C (make sure the book is not ancient, you want to learn "ANSI C", not "pre ANSI" C). Once you get some C software going on the PC you can then test algoritms on the PC first (using simple standard i/o) before porting to the PIC. Just watch out for machine differences and C18 extensions or non compliance to Ansi C standards. 

Q: What software tools are you using?

A: I am using Microchip's great FREE MPLAB ide (integrated development environment) and their great FREE C18 compiler student version. Note that the student version is full function for ?? days, then all you loose is extended mode and procedural abstraction optimization - your code will still compile and run (just a tiny bit bigger, maybe). Before you ask, yes I do use open source Linux (and Mozilla and Firefox and OpenOffice), and there ARE some Microchip development tools for Linux, but my main system is dual boot with Micro$oft Windows XP (as I have some photo, video, GPS, ham and other tools that are not available for Linux) as I find the Microchip MPLAB tools are (for me, personally, don't want a flame war here) a faster end to the goal of getting PIC code working. 

Q: Do I have to know Microchip PIC assembler to program a robot?

A: In my opinion, you may not need to be able to write big complex programs in assembler but you DO have to be able to read and understand assembler (and C) program examples in Microchip PIC spec sheets and application notes and to understand how program and data memory, I/O registers, on chip devices and interrupts work, and how information represented at binary, hex or decimal is moved around. Books like www.picbook.com will help, as will reading all the examples of PIC assembler and C that you can find (especially if it has resonable comments). You can't learn it all at once, start with simple programs like "flash a led" and work up.

Q: What was the hardest to troubleshoot software problem that you had?

A: I had two that are not really resolved.
1) MPLAB (version 7.? on XP, all the latest XP patches) sometimes crashes while in the editor, BOOM and it dies, you loose any unsaved work. This SEEMS to be related to the use of the wheel on the wheel mouse, if I avoid it it seems not to do it (or at least much less often), maybe related to speed of mouse event handling. The workaround is to save your work OFTEN after every line change, and not use the wheel mouse.
2) I made a SINGLE line change and EVERYTHING in my Microchip C18 Ansi C source code on the PIC 18F452 stoped working in the code, executing any routine (even previously good) would cause a hard PIC reset every second or so. I isolated it to ONE line in the source that I could comment in and out, in and it broke, out and everything worked (really strange as the line did not have to be on the executing code path). After some experimenting I found that if I changed from the "small" to "large" stack model for the compile that the code would work. The strange thing is that I did not change the associated linker script to allocate more stack space as recommened in the C18 document, so I am not 100% confident that it is really stack related. A very strong reminder that there is NO runtime checking with C, and you have to understand what resources (ROM, RAM, stack) are being used unless you want your code to do weird things.

Q: How do you debug software on such limited robot hardware without an ICE (in circuit emulator)?

A: The key is VERY incremental software development, similar to what I described for the hardware eleswhere. The key is to get some simple known good code (based on a Microchip application note or other code from the net) working first. Use the "startup mode" switches as described elsewhere to add new code as an alternate selection to known good code. The first thing that I tried on the hw was a know good assembler led flash program. Then I tried a known good Microchip C18 Ansi C led flash program. Then I echoed the switches to the leds. Then I added an known good Interrupt service routine from an example in the Microchip C18 documentation. And so on, just add one or two things at a time. Using a ZIF socket on your programmer and prototype makes it quick to do a build/program/test cycle. A bootloader makes it quicker. I baselined my source code on almost every build - not sophisitcated, just copied the current skippy.c to skippy_blnnn.c each time, so that I could fallback to the previous build if I broke something and could not fix it. If I really broke a build I named it skippy_blnnnX.c and then started applying the changes that I made to the previous good build more carefully. 

Also, especially when writing interrupt service routines that co-operate with mainline code, do some design work on paper - UML diagrams, state diagrams, pseudo code, variable worksheets, flow charts, whatever works for you to understand exactly what you are trying to do. If you can't explain it on paper or verbally to a friend, you probably can't program it.

You can use the LEDs as effective debugging aids, for example turning one on when entering a routine, and off when you leave, or to reflect the status of certain control lines (I debugged the speakjet buffer half full / talking handshaking this way). Or using 4 leds to represent a binary count as things proceed. If things are happening too fast, you can look at the led signal on the oscilloscope (if you have one) to see when you are entering or leaving a routine, for example. 

It is good to have routines written and tested to echo a character, newline, string, byte, integer and float (if using them) to the RS232 port, you can hook up a terminal emulator like Terraterm or even good old Kermit (runs on ANY old 386/486 laptop from DOS) for a diagnostic terminal, you can print out different messages and values from different checkpoints. You can even build a very simple "command interperter" into your code to accept a character from the terminal to command it to do different things, echoing what it is doing as it proceeds.

One other thing you can do is use the Quickbug on chip loader debugger from www.picbook.com - it has a bootloader and ability to do breakpoints and register examination. NOTE that Quickbug needs a very specific (but cheap) programmer and software to load it the first time on the 18F452! (If you really want to get Quickbug programmed, and don't have a programmer and can't find anyone to do it for you let me know, I might be able to help).

More FAQs as I get them.

Copyright 2005-6 Eric Pierce
www.va3ep.net