PID Control

The overall control function as presented on wikipedia

https://wikimedia.org/api/rest_v1/media/math/render/svg/4037a97c29467502e1dc6b4ed81d561b661a2eb1

You really dont have to know all of the advanced math to implement this as we will be doing it all in code as an approximation. The starting point is to understand that we will be using this equation to calculate a speed so here $speed = u(t)$ this speed will be calculated based on something we call error in this case $error = e(t)$. Error is calculated as:

$$ error = target-position $$

depending on our application position could be the distance the robot has traveled for example $x$. or the angle the robot is facing in degrees which we call $heading$

Developing PID Using GyroTurn Example

We will develop PID using Gyroturn function as an example. The gyroTurn function will make the robot turn to a target that is a specified number of degrees. The basic process is this:

The concept of the gyroTurn function

Start with a specified target and maximum speed, reset the gyro rotation sensor.

The control loop is then:

The above is pseudocode just showing the steps the code needs to take.

gyroTurn Function

https://gist.github.com/gkirkman/d04530afe161a5fb98591de95addb1b9

Turn the Robot