Just thought I'd post an outline of the algorithm I'm using in Weave (my modular obstacle avoidance robot) at the moment. It's not perfectly implemented, but when it's a bit better I'll post a video of it working.
It works like this:
Robot can see if there is an obstacle to the right or the left.
Program has two 8 bit variables, each corresponding to a direction (one for left and right)
During each loop, these variables are incremented if there is no obstacle and decremented if there is an obstacle in their corresponding direction.
After each loop (right and left sensor polled and variables adjusted), motor control works like this:
MSB is treated as a sign, 1=fwds and 0=backwds. The other 7 bits are used to determine the speed, via PWM. If direction bit = 0, the other 7 bits are complimented.
With a delay introduced into the loop, this produces a robot that, starting from still, speeds up until it gets to full speed. If it sees something to the left, the left motor will slow down through the variable decrementing, then when it hits 127 the direction bit changes, and it starts reversing that motor.
This results in a robot that steers in a fairly pleasant and pseudo-intelligent way, not making rapid jerky movements like mine used to.
I can post PIC asm for this if you like, but it's not pretty… :|