I am building my own motor controller that has feedback from the motors, to maintain a constant speed.
The current equation I have for the control system is as follows
if (tempclicks > (speed_req + (DEAD_BAND / 2)))
{
power-= ((tempclicks - speed_req) / SPEED_CONTROL_GAIN);
if (power < 0)
power = 0;
}
if (tempclicks < (speed_req - (DEAD_BAND / 2)))
{
power+= ((speed_req - tempclicks) / SPEED_CONTROL_GAIN);
if (power > 255)
power = 255;
}
Where speed-req is the goal, and temp clicks is the actual measure from the encoder. The control loop operates at 35Hz. The dead band is 6 and the speed controller gain is 7 right now. power is a duty cycle of pwm to the h bridge, 255 is 100% duty cycle.
I am no good with control systems, and this model is creating damped oscillations when recovering from a step response (holding the motor to make it work harder and then releasing to let it free spin). It will oscillate twice before settling on the requested speed.
Can someone point me in the right direction of a better control system?