# Outer Position Loop to Control Inner Velocity Loop

I'm trying to control the position of a brushless DC gearmotor. To drive the motor, I have a controller box that provides a velocity that is proportional to a 0 to 5 V input. The motor has it's own Hall sensors for measuring velocity. I also have a rotary encoder attached to the motor to measure position.

I'm looking for an algorithm to control absolute position/angle of the motor (i.e. the outer loop in the diagram above). The first thing I tried was a PID loop which supplied a 0 to 5 V signal based on the position error calculated from the encoder. I was not able to tune the loop to go to a position quickly and accurately. And I have my doubts as to whether PID is even suitable for this kind of topology.

The algorithm I'm using now is to use KP only, but as my motor gets close to the setpoint, I lower the KP. I think I lower the KP about 4 times before I come to a complete stop. This algorithm kind of works, but it's highly unusual. It is pretty fast.

I've seen this question but found the answers to not be helpful.

• what is your question? Oct 20 '21 at 0:25
• found the answers to not be helpful ... why were the answers not helpful? Oct 20 '21 at 0:27
• @jstola, My question is: what is a suitable algorithm for controlling position of a motor that already has a velocity controller. As to why the answers weren't helpful. Well, the accepted answer was (to paraphrase) "use a PI loop, be careful with KI term, and also use feedforward". A PI loop. That I can do. But I don't know what to do with feed forward. Oct 20 '21 at 0:42
• @bfris Thanks for your question. Unfortunately reviewing this question I don't think that it's currently worded as a good question for this site. The PID controller that you've stated doesn't work is the most basic algorithm typically used for things like this. There's an art to tuning PID loops for different systems. With three parameters and many different characteristics of the system there's likely ways to tune the different parameters to solve your problem. There could also be ways to improve your system to make it easier to tune the parameters. However your question doesn't provide any o Oct 20 '21 at 7:34
• As I mentioned this question doesn't have enough information to be answerable which is the first requirement for questions here: robotics.stackexchange.com/help/dont-ask It also is kind of a shopping question: stackoverflow.blog/2010/11/23/qa-is-hard-lets-go-shopping and there's very close duplicates which have been pointed to by others. Please consider updating your question to be better by these metrics otherwise it's liable for being closed out. Oct 21 '21 at 17:56