Cool idea to use one of the Sharp IR rangefinders as feedback to position your linear motor. What are you trying to do in this project? I’m imagining that you’re trying to control some non-contact offset distance between your linear servo and obstacles around it. Be careful though, if something gets closer than about 3cm to your sensor, it could command the servo to ram right into it! Look at the feedback vs distance graph on the datasheet: http://www.acroname.com/robotics/parts/GP2D120_SS.pdf.
Before you start playing with the PID coefficients, you might want to check if the jittering is caused by instability in the feedback signal from your rangefinder. These fluctuations could be too small to show up on a multimeter. If you use a fixed voltage as your feedback signal, say by using a potentiometer as a voltage divider, or even just two resistors, does the motor still jitter? If not, there’s your problem, and you can smooth out your signal with a capacitor between the signal line and ground (or an RC filter as Jan suggests, I see just now that he’s responded too). Even if this only helps a little, you should use a stable signal when tuning your PID values.
If you do need to change the control loop values there isn’t any real formula for the correct values. That’s a lie, there are people who get PHD’s in systems and controls by working out exactly these kinds of problems, but it would involve characterization of the motor, the loads you are applying to it, and controller. I don’t think you really want to do that.
Instead you can determine good values experimentally by making small changes to the coefficients one at a time. The user guide briefly mentions a very good way to do this:
Start with the integral and differential terms set to zero, and test different values of the proportional term. If this term set low, the motor will move slowly, and it’s position will not scale linearly with the position command (with a purely proportional controller there will always be an offset from the desired position proportional to that position). As you increase the proportional term, your motor will move to the commanded position more quickly, and the offset will decrease and eventually become negligible, but if there isn’t enough mechanical damping in your system you will start to see oscillations about the commanded position.
If you do see oscillations before the motor speed and final position offset are to your liking, lower the proportional term until you see no oscillations and start to increase the integral term. This part of the loop will try to move the motor to it’s commanded position in response to it sitting in the wrong place for too long. Whereas the proportional term commanded the motor to move with a speed proportional to the position error, the integral term will command increases to the motor speed as it integrates (adds up over time) the error.
As you start to increase the integral term the motor will start to creep towards it’s true commanded position. As you set this term higher to get there faster, it may start to overshoot and cause oscillations again. This is when you can bring in the derivative term. This term will tend to slow the motor down as it approaches the commanded position, to prevent it from overshooting. As you set this term higher it will limit the speed your motor can reach as it approaches the commanded position (too high and it will never get there!).
The main thing is to change values slowly, and one at a time. Setting P or I too high can make the system completely unstable, where the jitters will increase with every oscillation! Also, don’t feel like you need to use both the I and D terms. You may find that P (I=0, D=0), PI (D=0), or PD (I=0) control is sufficient for you.
I see Jan also answered your last question. In general Pololu devices retain those sorts of settings without power (stored in non-volatile memory).
-Adam