I’m using an Arduino to control the position of a linear motor that has a built in optical encoder for feedback. Additionally, i’m using a motor driver so that I can run the motor off of a 24 VDC system. I’ve been using the PID Library description to help walk me through writing the code for a PID loop. As of now I have it running and it will go to the right set point (usually). However, at some set points I get a lot of steady state oscillation. If I let the controller send the full power of 255 to the motor then it has way too much over shoot and just oscillates, also the optical encoder can’t register the position because it’s moving too fast. I’ve reduced the max velocity to 130 and that helps some. Also, if I alter the delays in between the changing PWM signals that seems to make a difference as well. So I guess what I’m asking is there any material out there that involves honing in on the best velocities and delays or is it just a game of trial and error?
I’m picking up on a project where someone else left off and I’m fairly new to Arduino, so if something I say doesn’t make any sense I apologize.
I’ve attached the code for reference.
PID_application_v2.ino (9.08 KB)