Control
Introduction
Control theory is a branch of mathematics that deals with the control of continuously operating dynamical systems in engineered processes and machines. The objective is to develop a control model for controlling such systems using a control action in an optimum manner without delay or overshoot and ensuring control stability.
To do this, a controller with the requisite corrective behavior is required.
In robotics, control theory is used to design controllers that can make robots perform desired tasks. Using the robot's sensors, the controller can determine the robot's current state and send commands to the robot's actuators to make it perform a desired task.
"Sense, plan, act." - Rodney Brooks
Open-loop vs. Closed-loop Control
There are two main types of control systems: open-loop and closed-loop.
Open-loop Control
In an open-loop control system, the control action from the controller is independent of the process variable. The process variable is the variable that is being controlled. The control action is the output of the controller that is sent to the system.
An example of an open-loop control system is an electric toaster. The toaster is turned on and operates for a predetermined time. The input is the button that is pressed to turn the toaster on, and the output is the amount of time the toaster stays on. There is no sensing of the toast temperature. As a result, the toaster provides the same output for any given input (i.e. the toaster provides the same amount of toasting for each button selection).
When you programmed your robot choreography, you used open-loop control. You programmed the robot to move for a certain amount of time, but the robot did not sense its environment and adjust its motion accordingly.
Closed-loop Control
In a closed-loop control system, the control action from the controller is dependent on feedback from the process in the form of the value of the process variable.
A closed-loop control system is also called a feedback control system.
An example of a closed-loop control system is the cruise control system in an automobile. The cruise control system monitors the car's speed and maintains the set speed without the driver's input. The controller continuously calculates an error signal as the difference between the desired speed (set point) and the actual speed, and applies a control action to reduce the error signal.
When you programmed your robot to follow a line, you used closed-loop control.
PID Control
PID control is a control loop feedback mechanism widely used in industrial control systems and a variety of other applications requiring continuously modulated control. It is one of the most commonly used control strategies in the industry.
A PID controller continuously calculates an error value as the difference between a desired setpoint and a measured process variable and applies a correction based on proportional, integral, and derivative terms (sometimes denoted P, I, and D respectively) which give their name to the controller type.
The first theoretical analysis and practical application was in the field of automatic steering systems for ships.
Mathematically, the PID controller is expressed as:
where:
- is the control signal (output of the controller)
- is the error signal (difference between the desired setpoint and the measured process variable).
- is the proportional gain
- is the integral gain
- is the derivative gain
- is the integral term (sum of the error over time)
- is the derivative term (rate of change of the error)
Proportional Control
The proportional term () makes a change to the output that is proportional to the current error value. The proportional response can be adjusted by multiplying the error by a constant called the proportional gain.
In the case of the line-following robot, the error is the difference between the desired position (the center of the line) and the measured position (the position of the robot relative to the line). The proportional term makes the robot turn proportional to the error. The larger the error, the larger the turn.
In python, the proportional term is implemented as:
Kp = 1.0
error = desired_position - measured_position
proportional = Kp * error
Integral Control
The integral term () makes a change to the output that is proportional to both the magnitude of the error and the duration of the error. The integral response can be adjusted by multiplying the error by a constant called the integral gain.
In the case of the line-following robot, the integral term makes the robot turn proportional to the error and the duration of the error. The larger the error and the longer the error, the larger the turn.
In python, the integral term is implemented as:
Ki = 1.0
error = desired_position - measured_position
error_accumulator += error * dt # dt is the time since the last update
integral = Ki * error_accumulator
Integral Windup
The integral term accumulates the error over time. If the error is large and lasts for a long time, the integral term can become very large. This is called integral windup.
To prevent integral windup, the integral term is often limited to a maximum value.
In the above python code, the integral term is limited to a maximum value of 1.0:
integral = min(Ki * error_accumulator, 1.0)
Derivative Control
The derivative term () makes a change to the output that is proportional to the rate of change of the error. The derivative response can be adjusted by multiplying the error by a constant called the derivative gain.
In the case of the line-following robot, the derivative term makes the robot turn proportional to the rate of change of the error. The larger the rate of change of the error, the larger the turn.
In python, the derivative term is implemented as:
Kd = 1.0
error = desired_position - measured_position
derivative = Kd * (error - previous_error) / dt # dt is the time since the last update
previous_error = error