I am trying to use a PID loop to control a motor. This is my first attempt at creating a PID loop (really just a PI loop). There doesn't exist a model for this system, and I don't know how to create one. All that I mention below may be an incorrect approach, so please guide me on the correct one.
My goal, is to set a percentage velocity, and have the motor run at the velocity.
My only feedback is degrees of movement, which I have correlated to an acceptable input -> output ratio. Meaning, without any resistance, if I have moved 50 degrees in 250mS that is considered 100% velocity. 25 degrees = 50% etc.
As mentioned in another thread here, I've experimented with setting waypoints for the PID controller. That is, if I were moving at 100% velocity, I set a waypoint that is 50 degrees away from the last one, every 250mS. This appears to be working fine under non problematic angles.
The problem is, if I am at a lower speed, such as the 50% velocity. There are certain angles where the proportional gain is not enough, and the motor is stuck. I've tried experimenting with how I modify the waypoints, and modifying Ki and Kp. I could enumerate them here, though I don't think it's worth it, as I think I have some fundamental misunderstanding on how to do this.
So to give an overview of my current structure in pseudo code:
while (1)
{
if firstRun or 250ms elapsed
targetPosition = currentPosition + scaledVelocityValue
if 10mS elapsed
calculatePID()
}
In this case, the currentPosition is not be the previous targetPosition, and therefore the speed is always constant. I've tried using the previous targetPosition, but that creates an unstable system because it's such a large increase.
I hope this makes some sense. Some guidance please.