I calibrated a servo for (more or less) exact 0° and 180° position using the min/max timing options when attaching the servo (using the servo library).
When I now move it to 90° it doesn't center but is off by estimated 3°.
I would like to get this more exact as I use it for moving a IR sensor to map the environment. Is there a way to improve this situation or is it simply the inaccuracy of the hardware?
The accuracy by the Arduino is 255 steps. I don't think you can improve that with the functions of the library.
The linearity of the potentionmeter in the servo could be 10% inaccurate for very cheap ones.
Which servo motor do you use ? Can you post a link to it ?
I have not (yet) experimented with the “absolute” positioning accuracy of servos. Consider that they really were meant as part of a system where a human operator constantly adjusts it - not beause of the position the servo has taken, but the effect it has (eg on the model airplane). Absolute or linear accuracy is therefore not needed.
I have had a similar problem driving a big analog meter with PWM. It did not respond linearily (presumably some resonace effect between the coil, the mechancs and the 400Hz PWM). I therefore manualy noted the PWM value that would place it at some points, and when driving it used the values as lookups with a linear interpolation between. Worked for me. You could try the same approach.
You should follow Msquare's method and build a simple calibration table. Linear angular accuracy is not a priority with hobby servos.
Be aware the IR reflectivity varies between materials. IR distance sensors that I have tried are also quite non-linear with a different curve for different materials. The sensor may be a bigger headache than the servo. You may also want to try ultrasonic sensors. Of course a laser rangefinder would be nice