Robot circuit notes:
Operating System: Linux 2.4.11 + rtai-24.1.9
Programs: test.c (kernel module), robot.c (user program)
Serial port: uses rtcom part of rtai to communicate 115200 bits/sec to circuit on protoboard (on robot). Instructions are 2 bytes.
I have changed the circuit to now use 2 PICs. PIC0 sends 8 data lines (PORTB) and PIC1 sends 8 address lines. PIC0 PORTA pin 2 sends a 1 byte address at 115200 to PIC1. This lets me use 8 bits of data for 8-bit buffers (not 6) and 1 more 4-16 decoder/demultiplexor.
Instructions take the form
a7 a6 a5 a4 a3 a2 a1 a0 d7 d6 d5 d4 d3 d2 d1 d0
x x x x x io a3 a2 a1 a0 d5 d4 d3 d2 d1 d0)
d0-d5 = 6 data lines
a0-a3 = 4 address lines
io = input or output bit (not sure if I still use this)
x = unused
future: I eventually want to be using a computer with 2 separate USB hubs, that is the only way to get images from two cameras at one time, plus I may be moving to a microcase pc for a low cost faster CPU (perhaps dual CPUs for all the image and sound processing).
I want to communicate to the robot circuit using realtime USB or IEEE 1638 (Firewire)
How it works:
The laptop/computer sends 2 byte instructions (see above for format)
The pic program (link) gets the 2 byte command, sends the 4 address bits to the 4 address lines, sends the 6 data bits to the 6 data lines (and may send back 1 byte of data, if command was for a "get").
The 4 address lines from the PIC go to the 4-16 decoder/demultiplexor to select from 16 various enable lines. Only 1 of these 16 lines can be 0 at one time. So using 4 bits of address in the instruction sent from the computer, 16 different 8-bit ports can be accessed. I doubt I will need more than 16 8-bit ports for this robot in the first years. Each of these 16 lines goes to an 8-bit (or octal) 3-state (or tri-state) latch (or port) "output enable" pin or is inverted and connected to a "latch enable" pin.
The OE is for input ports and the LE is for output ports. The input ports input is always enabled, but the outputs should be high impedence when not being read. The output ports are almost the opposite, the output must stay the same (for example a motor may be turning even if the port is not getting an instruction/latch enabled). The LE needs to be inverted from the 4-16.
That is the basic idea. This circuit can be used for a number of various robots, or circuits. This is basically a way to turn motors and get inputs (like buttons, accelerometers, etc...)
In the picture of the circuit, I have only drawn 2 8-bit latches, 1 for inputs and 1 for outputs.
Update: I am now using 2 pic16f84a. The top pic0 to use 8 bits of data on PORTB and then pic1 to use 8 bits to 2 4-16 decoder chips as address lines (32 address bits). I need to update the circuit image, but the changes are very simple. I use one of the pins on PORTA of pic0 to send a byte in 115200 bps to pic1.
I am finding that I need to have a tilt sensor on each segment of each leg (lower leg+upper leg*2) and also the torso (the feet have buttons on the bottom that should show if the foot is flat on the ground). This makes a total of 5 tilt sensors x 2 (for each dimension [x,y]) = 10 tilt readings.
There are two methods I am using to balance the robot:
ADXL202 - acceleromters made by Analog
+sensitive tilt reading (I can only use 5 or 6 bits, but could be more)
-need 3 chips to read 2 axes (=5 PICS and 10 8-bit ports)
(-)need to mount surface mount chips on copper etch board
Mercury Tilt Switches
+only need 1 chip for 2 axes (4 bits, =0 PICS, and 5 8-bit ports)
-contains mercury that may cause some kind of problems not sure
-is only a binary 0 or 1 tilt reading (not 5 or more bits like ADXL202)
+Mercury liquid very interesting and pretty, good atom group to keep supply of.
I am currently exploring better ways to make use of these chips, but for my current simple unfunded experiments I think I may turn to mercury switches as being more simple. I have the code I am using picadxl.asm that can be used for any adxl202 application. I started with a program that used a 10ms adxl202 wavelength/cycle. Each 0x31 reads would be totaled each 107us for the 115200 serial port to read, total and calculate tilt, but now I have a better method. I am using a 1ms adxl202 wavelength/cycle (actually more like .6ms) to calculate the tilt reading in the PIC. The PIC reads the adxl202 every 5.2us (~200 reads - enough to fit in 8bits, otherwise I would have to use 16bits, 2 PIC 8-bit registers), then puts the tilt info on 6 bits of PORTB and all 5 bits of PORTA. I could use up to 12 bits to describe the tilt reading, but that would take 2 8-bit buffer chips and 1 PIC for each adxl axis.
The people at analog.com have been very kind in sending me a number of sample chips for free! (This chip sells for $20). These chips are surface mount and need to be glued onto an etched copper board. I have to drill tiny holes in to the board to support the resistor and 3 capacitors needed to filter the signal from the adxl202. I finally stumbled on a better way of connecting the 4 wires (+5,0,datax,datay), by using crimp connectors. I will crimp the 4 wires to pins, put the pins in a plastic connector, glue the female plastic part on to the copper etch board and so pulling on the wires will not separate the tiny soldered connections to the tiny ADXL202 chip.
I tried experimenting with non liquid (the metal ball) tilt switches, but friction can cause unpredictable results. Some times a metal ball will be stuck even if there should be enough gravity to pull the ball to the two wire contacts.
The human skin is covered with millions of touch sensors or buttons. A good robot will need to have similar touch data/skills.
H-Bridge (Motor Control/Motor Driver)
I must have spent a solid year and went thru 4 or 5 different designs, and hundreds of irf9530 and irf530 transistors before finally using this final design. I decided that the reason the irf530 and irf9530 transistors kept exploding was because the motors were pulling too much current. How to measure the current (number of electrons, that are probably groups of photons) for an electric motor is to get the motor to "stall" or be "jammed", an electric motor, when held by an unmovable resistence will move the most current possible. Measuring more than 1 amp of current is beyond the $5 volt/amp meters that people with low income can buy. One thing I did to measure this current is to use 1ohm (and lower) power resistors (these are white ceremic [i guess] resistors available at radio shack, mouser.com, etc...). By measuring the voltage drop, or voltage lost over the resistor, the amount of current/amount of electrons can be measure by using the V=IR equation (Ohm's Law). For example 12 Volts dropped over a 1 ohm resistor = 12 amps. The one problem is figuring out the resistance of the motor. This resistance changes when the motor is running, and I was not sure if my voltage reading was correct. I finally decided that the most amps this car winshield motor could use was ~ 13amps at 24 volts (the ad at meci.com says 3amps).
Getting back to the H-Bridge, I finally decided that the motors were simply drawing more current than the irf9530 (and even irf9540!) could handle. I decided to spend more money and get the irf4905 and irfz48n. I did also explore the idea of connecting a capacitor to the 24 volt power source on each H-bridge circuit. Because of Robot Wars there is more information on the web describing building robots and this is extremely helpful, the team nightmare, and hassocks hog robots are both good web pages. Plus I moved the H-Bridge circuit off of the protoboard and on to a soldered copper etched board (this may have also been my problem, because after 2 or three exploded transistors, some of the metal in the protoboard may have shorted). moving the H-bridge on to a separate circuit board and next to the motor was a good idea I think.
In addition to the 2 irf4905 and 2 irfz48n power transistors, I use 2 2n2222 n-type transistors to turn on and off each half of the h-bridge. I also use 4 300ohm reisistors.
serial port cable: Finding how to put together this cable is one more part of the secret story of basic electronics and science. The best source for this cable (already crimped and put together) is www.phanderson.com:
9-pin Serial with 10-terminal wire-wrap header - $7.00.
For making this cable by hand my best guess is:
1) 10 pin 28awg ribbon cable (like Jameco #103481)
2) 9 pin db9 ribbon cable connector male crimpable (standard serial port connector) on one end of the cable (you will have to figure out what wire to not include in the crimp header - I think using the non red wire [used for pin 0?] may be a good idea) to connect to the laptop serial port.
3) a crimp tool for db type headers/connectors (although you probably could use a vise...but should have the correct tool)
4) a 10 pin IDC female ribbon cable socket connector on the other end of the cable .100 inch standard pitch (this is the space between the pins on a standard protoboard and most IC chips) [I found SC-10-BA at www.web-tronics.com]
I guess you could actually buy a serial port cable (with at least 1 male side) and cut one side off and crimp the header
1) Straight Lead wire wrap 10 pin header (I actually found this needle in the haystack at digikey.com part#CHW10G-ND $2.08 [10=$1.58])
Connecting "power" (electron source) to robotI use 24 volts, 2 12 volt 17 amp-hour batteries I bought from meci.com and/or allelectronics. One thing I learned is to use crimp connectors/terminals (sometimes listed as "quick" connector/terminals). I will have to show an image of these here. This makes connecting the battery to the robot and wires to the motors not permanent and more fast to use. Another thing I learned is to connect "terminals", a plastic piece with 2 rows of screws to connect wires on, to the robot. This is a good idea for any robot, to have a secure (not on protoboard) location for the higher 24 volts (no where on the circuit board is the 24 volts needed so better to keep the 24V wires off the protoboard). I also have a 30amp, 50v fuse in a fuse holder from Radio Shack [I also made a pcb with 2 fuse holder clips for a fuse I can use)
Plus, of course you need a switch. I think I am using a max of 15-18 amps/motor, using 2 motors at full force is more than a house circuit (15 amps)! (but not a problem for the batteries). So I need a switch that can handle ~30 amps or more, I have melted switches by accident (with a soldering iron, and also by too much current). I am using 2 low cost average 15 amp room switches. One switch turns on 12 volts (connected to the protoboard and lowered to 5 volts on the protoboard- I was surprised to realize that I do not have to lower the entire 24V, only 12V! - I learned that after trying series zener diodes and various voltage regulator chips), and the other switch turns on the 24V (adding in the 12V from the 2nd battery).
Using cameras is a very important part of robots. Cameras are awesome. Most cameras capture photons moving with frequencies that are visible, detected by a human eye (and brain). I use low cost USB web cams, logitech quickcams, and IBM cams because there are drivers for Linux for these two cameras. Creative Labs 3 cameras may be another option. The resolution on these cameras 320x240 is perhaps 100x less than the human eye, so the best robots using these cameras will appear to have poor eyesight (at least compared to an average human).
I may have more than 2 cameras, to put cameras on the back of the robot head may be useful. (I some times think eyes on the back of a head may be a useful evolution, or contribute to survival in a small way, the early eye evolved in the earth oceans more than 1 billion years before now and clearly provided an advantage to those easly species and the fish, amphibians, reptiles, and mammals later). Using two cameras a person can detect depth (also x and y position - even with 1 camera this can be done) by measuring the distance between some recognized object in each of the 2 images.
Measuring Depth with 1 or more cameras
Depth of some object (or pixel) can be measured by comparing the location of the pixel from two different locations. Using one camera and moving the camera back and forth between two locations is one complex method that involved 1 motor, an easier method is using two cameras. In the 2 or 3 experiments I tried with 1 camera, I could only detect a difference of 3 or 4 pixels for the nearest objects (the nearer the object the more the change in apparent location in each of the 2 cameras). This hints to me that measuring the depth of distant objects with 320x240 web cameras may be more difficult than I thought. I am thinking now, that perhaps the x and y locations, and detecting objects hidden behind other objects may help in providing a depth. Another idea is using sonar or radar to measure depth of objects. Perhaps higher resolution cameras (and smaller pixel) will provide better depth measurements in the future.
Here are the basic steps that I want to do with cameras:
1) Separate an image in to objects of the same color (possibly use changes in color to find object boundaries)
a) save file indicating name and position or each object in a chronological group of saved jpg images to search and match later
b) or save images of actual objects to search and match later
c) store the location (a 3 value location [possibly adding a time value] in a universe of space, where (0,0,0) could be some defined local point - for example where the robot first starts. Later the robot should recognize the last time the robot saw some object, the object was "in bedroom 1 nearest to closet 3" at location (49838,203928,59381).
2) Try to match new objects to objects in images saved in the past (recognize an object...for example taking a 2d image of an orange and matching with all other all orange objects- drawing these objects in a separate window)
Microphones (and in fact all input sensors) have some things in common:
1) record/remember input values (may want to remember how an object felt to touch buttons, or what the camera or a microphone recorded on 4/2/53 at 16:32:05.232)
2) recognize current data with data from past (has the image, sound, feel happened before?)
Mircophones can be of use in recording sounds around the place you live. If there are sounds, the lights and cameras can be used to get more data.
Another thing that humans do is try to match sounds from lungs-throat-mouth with sounds heard/remembered in brain. I want a robot to do this too.
I need to use a linear (like a rack and pinion) gear to open a cloth a plastic air bag. I need to make electric motors control the volume of air and frequency of vibration.