Skip to content

Commit 9f2050f

Browse files
committed
Finish introduction to proportional control page
1 parent 812847e commit 9f2050f

2 files changed

Lines changed: 63 additions & 25 deletions

File tree

Lines changed: 63 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,85 @@
11
Introduction to Proportional Control
22
====================================
33

4-
Introduction:
5-
-------------
4+
What is Proportional Control?
5+
-----------------------------
66

7-
While the on-off controller works, there are issues that can be solved using another type of controller.
7+
Imagine you're driving a car and you want to keep at a steady speed. If you're going too slow,
8+
you press the accelerator a bit, and if you're going too fast, you ease off. But instead of
9+
just fully pressing or fully releasing the accelerator (like an on-off switch), you adjust
10+
how hard you press based on how far off you are from your desired speed. That's the basic idea
11+
behind proportional control. The further you are from your target, the harder you try to correct it.
12+
If you're a little off, you make a small adjustment. If you're way off, you make a big one.
813

9-
The on-off controller is a **discrete** controller. This means that the controller has discrete states. It can be "on" or "off". It cannot be "half on" or "half off".
14+
Let's take this analogy further - you decide that the perfect cruising speed for your car ride is 70 mph.
15+
This speed represents your desired value or where you ideally want to be. In control theory, this is
16+
called the **setpoint**.
1017

11-
A **continuous** controller is one that can have any value. For example, the speed of a car is a continuous controller. It is not limited to "on" or "off".
18+
You get on the highway, and as you settle into your drive, you glance at your speedometer. It reads 65 mph,
19+
which is your current value. In control theory, this is called the **process variable**.
1220

13-
Continuous controllers are more effective and offer the user more control over their system, but are also easier to implement.
21+
Naturally, you recognize there's a difference between where you want to be (70 mph) and where you currently are
22+
(65 mph). This difference is the called the **error**, and in this case, it's 5 mph. It's easily calculated by
23+
the formula:
1424

15-
Basic Definitions + Steps of a Proportional Controller
16-
------------------------------------------------------
25+
.. code-block:: python
1726
18-
A proportional controller is the simplest type of continuous controller. It is also known as a P controller.
27+
error = setpoint - process variable
1928
20-
Before implementing one, we need to define some terms and steps.
29+
Knowing the error isn't enough. How should you, the driver, react to it? This is where the concept of Proportional
30+
control comes into play.
2131

22-
**Target Value** - The value that you want to go to. In this example, let's set our target value to 5 cm
32+
Think of P control as your driving instinct. Instead of abruptly flooring the accelerator or immediately slamming the
33+
brakes, you adjust your speed based on your error: how far you are from your desired speed.
2334

24-
**Error** - The difference between the target value and the actual value. For example, if you want to go to 5 cm but you are currently at 3 cm, then the error is 2 cm.
35+
A measure called **control output** tells you much to adjust. It's calculated as:
2536

26-
**Control Effort** - The value that the controller outputs.
37+
.. code-block:: python
2738
28-
**kp** - The constant that you scale the error by to get the control effort. For example, if you want to go to 5 cm but you are currently at 3 cm, then the error is 2 cm. If **kp** is 0.5, then the control effort is 1 (0.5 * 2 cm).
39+
control output = Kp * error
2940
30-
Now that we have defined some terms, let's go over the steps to implement a continuous controller.
41+
where Kp is a constant called the **proportional gain** and acts as a scaling factor for the error.
3142

32-
1. Define your target value
33-
2. Find the error
34-
3. Multiply the error by a constant **kp** to get the control effort
35-
4. Feed the control effort into your system
43+
If Kp is high, it's like you have a heavy foot and you'll accelerate hard even for a small error. You'll get there faster, but
44+
less precisely and you're more likely to overshoot.
45+
46+
On the other hand, if Kp is low, you're more of a cautious driver, gently pressing the accelerator for the same error. You'll
47+
get there more slowly, but at a much smoother pace.
48+
49+
Having the constant Kp allows you to tune your control system to your liking.
50+
51+
Note that this analogy breaks down somewhat. Imagine your current speed is *greater* than your desired speed. In this case,
52+
the error is negative. If you plug this into the control output formula, you'll get a negative control output. This means that
53+
a proportional controller will actually slow you down if you're going too fast, proportional to how far you are from your desired
54+
speed. So, you can imagine that a proportional controller is like a driver who's always trying to get to the speed limit, utilizing
55+
both the accelerator and the brakes.
56+
57+
Tuning Kp
58+
---------
59+
60+
The following graph shows proportional control in action.
61+
62+
.. image:: media/proportional.jpeg
63+
:width: 400
64+
65+
The blue line is the reference, and indicates the desired value. Red, green, and purple lines represent the current value over time
66+
when controlled by a proportional controller with different values of Kp.
67+
68+
With a low Kp, the red line is slow to react to the error, and the controller is sluggish. It takes a long time to reach the desired
69+
value, and it never quite gets there. This is called **underdamped** behavior.
70+
71+
With a high Kp, the purple line is quick to react to the error, and the controller is aggressive. It reaches the desired value quickly,
72+
but overshoots, causing the error to become negative. It then corrects itself, but overshoots again, and so on. This is called **overdamped**
73+
behavior, and results in oscillations around the desired value.
74+
75+
The green line is just right. It reaches the desired value quickly, and doesn't overshoot much. It's an important task to tune Kp so that
76+
the controller approaches the desired value as quickly and smoothly as possible.
77+
78+
Note: You'll find that, even with excellent tuning, a proportional controller often will either oscillate a little bit, or never quite reach
79+
the desired value. More advanced control systems like PID aim to minimize these issues, but they are out of the scope of this course.
3680

37-
Tips on finding "kp"
38-
--------------------
3981

40-
Finding the right value for **kp** is a bit tricky. If **kp** is too small, then the system will not respond fast enough. If **kp** is too large, then the system will overshoot the target value and oscillate around it.
4182

42-
When first finding a **kp** value, you want to "scale" an expected range of errors into an acceptable control signal.
4383

44-
For example, if your expected error ranges from 0-40 but your control signal ranges from 0-1, a "good" starting kp value would be 0.025 (1/40).\
4584

46-
From there, you can adjust the kp value to get the desired response after testing.
4785

34.6 KB
Loading

0 commit comments

Comments
 (0)