-
Notifications
You must be signed in to change notification settings - Fork 1
PID Reference
this program uses this PID library: https://playground.arduino.cc/Code/PIDLibrary/
here's an explanation of this library by the author of it
P is for Proportional. The farther from target, the stronger the output trying to correct.
I is for Integral. Summing up all error, if it's continuing to not quite reach the target, the error sum adds up and gives an extra boost to get the error to zero.
D is for Derivative. Reacts against quickly changing input, a damper, or friction.
Start tuning by adjusting P. Too little, and it doesn't respond enough (floppy). Too much and it oscillates back and forth (shaky). A well tuned P is usually the majority of the PID loop, there's usually little I or D compared to P.
Using some I term may be helpful for the speed loop to counter the robot not sticking to the set speed.
Using some D term for the angle loop may help minimize oscillations, but a small amount can quickly bring in a lot of jitter, so use sparingly.
The following values worked for a version of URSA, they're not perfect but could be used as a starting point (and to see the scale of the numbers:
PA=0.09074
IA=0.0
DA=0.00648
PS=0.01852
IS=0.00046
DS=0.0
For one PID loop (PIDA for angle), the input is pitch angle calculated from a gyro board, the output is what acceleration to change the speed of turning the motors at, and the setpoint is the angle that the robot should try to get to. Acceleration changes angle, maintaining a tip angle requires acceleration.
For the second PID loop (PIDS for speed), the input is the speed the motors are turning, the setpoint is the speed the robot should move at, and the output is the angle to tip the robot to fed to PIDA. The speed the robot can be told to go should only be a part of how fast it can actually go so there is some reserve to stay balanced.
This all may seem like a strange almost circular reference, but I think that's because tipping forwards or backwards changes how much a robot needs to accelerate to remain at the same angle (angle is the change in speed, and while moving at a constant speed, it should stand balanced). The speed required for self balancing can be sent to each motor, and steering can be done with a small offset for each motor.