Coding PIDs
Worth it.
Last updated
Was this helpful?
Worth it.
Last updated
Was this helpful?
A PID (proportional integral derivative) controller is an advanced coding technique to make the robot's motion consistent, reliable, and efficient.
PIDs are used everywhere in industrial robotics--car factories, robot vacuums, and more. If a robot moves, it likely uses PIDs to move.
But why? PIDs do one thing, and they do it really well. They move a robot from point A to point B:
But how? This is where the PID algorithm comes in. There are three parts to a PID controller, given by the acronym. Each part applies a specific power to the drive motors based on certain factors:
P (Proportional): Update motor power based on the present
I (Integral): Update motor power based on the past
D (Derivative): Update motor power based on the future
The motor power is calculated by the following line of code, which is the heart of the PID algorithm:
That is, each part of the PID is added together to calculate motor power. kP
, kI
, and kD
are constants that determine the relative weights of each portion of the PID.
Error refers to how far the robot is from the target point. If the robot wants to go forward 20 inches, the PID algorithm would calculate the following errors.
Error plays a major factor in the PID algorithm; we'll see how later. If you want some more explanation, here's a good eight-minute video explaining the theory behind PIDs:
Now, let's start by coding your drive PID!