Not sure if this is the correct place to put this question but here it is.
I am building a simple isosceles bard door star tracker. I have worked out the rate at which a stepper motor would have to step to turn a threaded rod to open the barn door. I find tat that rate that I am always lagging, and for some reason about 5 times slower than needed.
I decided to use an ADXL335 accelerometer to measure the angle of the barn door and then use its data as feedback to adjust the speed of stepping the motor and suddenly I found myself in the world of PID controllers.
My first attempt was using my own interpretation of the error and had my code running pretty well, but it would overshoot its target and then run backwards to correct for it and then overshoot again.
Then I found the Arduino PID library by Brett Beauregard and downloaded it and implemented it with my code. It seems to run, but it too overshoots and then sits idle until the computed value, or SP (its my phiS variable in my code), of where the tracker needs to be exceeds the PV (phi in my code)and then it reacts to catch up and overshoot again. wR, in my code is the output variable that I am trying to control, which is the stepper motor rate that gets sent to AccelStepper to run my stepper.
I have tired many different variations of the Kp, Ki and Kd and no luck in getting the tracker to steadily track with the expected PV.
With low Kp values it takes too long for the tracker to catch up to the PV. With high values, the higher the better it seems for my system, but then it overshoots to quickly and then sit idle for quite a while, about 100 seconds, I cant have the tracker sit idle for longer than about 15 secs or the stars will streak. If I add any Ki, it just delays the overshoot even longer. When I add Kd to the system, it tends to over predict and keeps the overshoot almost like an offset. Then I tried a Ki less than 1, like 0.1 and 0.01, but it does not seem to alter anything.
Any help would be greatly appreciated.
Here is my code as an attachment
sketch_oct05a_StarTracker_V3a.ino (7.3 KB)