I have tried my hand at writing a PID controller to control a the output power of a laser in response to the measured temperature of some thing. The measurement of the temperature can be very noisy at certain temperature ranges, though the picture below was taken in a less noisy range.
Here is a current view of the PID in action
My current issue is not the oscillation in the command signal to the laser, I have since found some descent parameters that smooth it out nicely. My real issue is the initial drop off to the lower limit of the command signal range then the rise back to appropriate levels.
Some more background. The PID itself works by first using a lookup table to command the laser signal to a "close" value of what it should be to get the initial temperature close for the PID, it does this for X amount of seconds (20-30 has worked well to get it to a stable temperature).
The idea behind this was to hopefully fix the issue we were (are) having of the PID initially wildly oscillation between the minimum and maximum output signal. This is highly undesired and can hurt the thing being heated.
So once the lookup table value command time has expired the PID is then given control, in the image above you can see pretty clearly when this is (the initial sharp drop). Then it relatively quickly rises back to an appropriate signal.
What I think is happening is that the previous error and previous integral terms have not yet accumulated proper values (they start at 0) for the PID to produce the proper command signal at the desired set point.
Is the way to fix this to initialize the previous error and previous integral to values close to what they are when the PID is stable near the end of the graph?