Turning at percise right angles.

I have a track based robot powered by a twin gearbox and two dc motors. I want it to move along a preprogramed path and end up back at the same spot, requiring more than a few precise right angle turns. I thought this would be an easy thing to accomplish but it's been mostly frustrating.

I thought I could just use code like this:

digitalWrite(H1,LOW); //H-bridge running Motor 1 forward
digitalWrite(H2,HIGH); //H-bridge running Motor 2 backward
analogWrite (Motor2,100); //motor speed
analogWrite (Motor1,100); //motor speed
delay(1400);  //a smaller number here results in a smaller angle, large in a larger angle

but the result has been spotty at best. If getting the number right wasn't difficult enough, everything from the conditions of the treads to the little imperfections in the driving surface change how the thing turns. Even when working on the flattest and smoothest surface I have, the results are inconsistent and the whole project kind of falls apart if the pathing isn't working properly.

Is there another realistic solution that would provide me anything close to consistent movement?

I think you've just proved to yourself what the limitations of open-loop (dead-reckoning) control are. You might need to consider either or both of line following and position feedback of some sort.

You are experiencing something called SLIP. the tires do not have an absolute grip to the surface they are running on and when you turn and such they slip slightly.

As the previous poster stated - you are running in an open loop configuration with no feedback from the environment. You might try running on a grid with something attaches to you robot that can detect that grid. That would give you some position feedback that you could then use to correct for errors.

Or incorporate a compass unit into your design so it knows what direction it's heading in. But even that won't give perfect resolution - probably a couple of degrees of error. You could fit a beacon (flashing lED ?) at your desired end location and fit the robot with a "eye" so's it can home in on the beacon.