I already had my controller connected to the motor driver and to the motor. What was missing was the position feedback, and with my encoder fitted, the first test with feedback was ready.
I'd already written most of the controller code including the quadrature decoding necessary to understand the encoder's output. I patched in the encoder's lines to the controller, and set a low voltage for the motor driver. Setup done... I gingerly switched it on.
Nothing happened. So, I bumped the shaft and the motor took off. I had considered the possibility that I would get the encoder's output and the motor's input reversed. Knowing this, I reversed the motor leads.
Nothing happened. I bumped the shaft...nothing happened. I tried to turn the shaft... I couldn't. Success! I connected a shifter to the shaft and turned it. The motor pushed back. Considering the PID controller had no tuning, I was quite surprised by the initial response.
This static system was a little uninteresting, so I added a simple increment in to a timed routine to give it some movement. The results were very rewarding, and raised a couple of areas of concern.
Cogging. This demonstration makes the cogging extremely visible. The controller pushes through the natural attraction to one "cog" position, and once it reaches the influence of the next, it races toward it (and then the controller slowly recovers).
Large deviations from the desired position (like an idiot pushing a shifter on the shaft) recover very quickly, but the smaller ones are very slow at the moment. At this point, it's important to remember that the PID parameters have not been tuned at all. In fact, you can see the effect of the default (1) values in this situation:
Proportional - The further away from the desired position the more power applied - gets results quicker
Integral - The longer it's away from the desired position the more power applied - overcomes a constant opposing force (cogging torque, rubber band)
Derivative - The quicker it's approaching the desired position the more power removed - dampening to help stop overshoot
Tuning, tuning, tuning! The key to success here is tuning the unit. Just one problem, the tuning is specific to the circumstance of the unit. For example, in current no-load conditions the parameters would need to be set to respond quickly enough to over come the cogging jolts. But at its final destination, there will be pulleys, belts, shafts and screws attached. All of these components will add inertia and friction, greatly changing the characteristics of the system. The cogging torque may well be irrelevant when lifting a 100kg machining head with a badly lubricated screw. Irrespective of what is relevant where... I do need to devise and document a simple and repeatable tuning method for this controller.
I dream of a single button...