Generally you find the PID gain values by structured experimentation, something like this:
- Start with only a P gain (I and D = 0), and make it as high as possible with little or no overshoot.
- Add a little I gain. Make it as high as possible without producing more than just a little ringing.
- Up the P gain a little. This will usually add a little stability now that the I term is there.
- Iterate with the P and I terms to get the fastest settling time with whatever overshoot you can tolerate.
- You can either stop here, or try to add a little D term. The polarity of the D term depends on how exactly you implemented the equations. A little D can add some stability, which allows you to make the P and I terms a bit more aggressive. The point of the D term is basically to say if I'm already heading in the right direction, decrease the drive. However, D is susceptible to noise. Making it too high will cause the output to sortof "vibrate", which is basically amplifying the sensor noise onto the output. A little D can be useful if you need the last bit of performance, but a lot of implementations leave it out.
I notice you plan on doing this all in analog electronics. This makes no sense, especially for something slow like a motor. For efficiency, you will want to drive the motor with PWM. The natural way to do this is the motor speed sensor feeds into a microcontroller A/D. The micro does the PID calculations and uses that to adjust the PWM duty cycle. It can also do the direction changing with the H bridge, guarantee break before make, etc. There are many small and cheap micros with A/D and PWM hardware built in. Some even have H bridge drive PWM outputs. This is such a common problem that there are whole subfamilies of micros optimized for this.
The compute power you need is modest. Back in the late 1990s I used a PIC 16F877 to run two layered PID control loops that drove a DC motor. The inner loop controlled the position of the motor and output PWM to the H bridge. The outer loop controlled the speed of a gasoline engine and output a position value to the inner loop. The PID computations were done in 24 bit floating point. We used 8 ms per iteration, which left a little time to do all the other low priority tasks. That micro was running at its maximum speed of 5 MIPS. That is quite slow by today's standards. Lots of micros are quite capable of doing what you need.
Doing this in analog will take more board space, take more components, be much harder to tweak, and does not provide a convenient interface to the motor driver power stage. It just doesn't make sense.
As always, what is your specification?
If the robot only has to move, and you are not too bothered about exactly how far, or whether in exactly a straight line, then a DC motor on each wheel simply switched on and off, or maybe speed controlled open loop with PWM, will do the job in the cheapest, easiest way. The assumption here is that the driver (human or some imaging computer program) is looking at the robot and correcting the next move command. With good DC motors, speed is well controlled by the terminal voltage, especially at low and balanced loads.
If you want a straight line, or exact distance, or profiled speed control, then you have a choice of DC motors with optical encoders PID closed loop, or stepper motors. Be aware that these only control the amount the wheels turn. If you want accurate wheel position to actually give you to accurate ground position, then your wheels must be perfect, equal diameter, running without slipping on a surface with no contamination.
It may be therefore that PID control of the motors is not sufficient to give a good ground position spec, and some form of geographic position sensing is needed. Once you have that, the need for closed loop on the wheel motors becomes less, unless you are trying to hit a very tight position/speed/time profile specification.
I'm not sure I understand what the phrase 'consistent power' means in this context, or why it should be desirable?
Best Answer
http://robotsforroboticists.com/pid-control/ seems to have a fairly simple PID pseudo code implementation. Also, it has some info into how to tune the gains.
In any type of control you gonna need to vary the input, in the case of DC motors is changing the supply voltage (or PWM). And you need feedback of the output, for motor is a tachometer or encoder, check the motor datasheet if one of the pins from the assembly would provide feedback on the rotation speed.
Transform that feedback into RPM and use that value as, in the PID example above, actual_value. Transform output so it can be used as your PWM bias.
I also suggest using unwinding for the integral error and output. Simply use if/else conditions to avoid those variables to exceed a threshold you defined.
To control the motor you can feed the PWM output into the gate of a N channel MOSFET, and connect negative terminal of the motor and ground throught the mosfet terminals.