Skip to content
Tutorials Center
My learning

Topics

Lesson 22 of 36 ยท Controllers

Tuning Fuzzy Controllers

Learn a practical order for tuning a fuzzy controller: scaling factors, set widths, rule outputs and a small automatic search, with runnable Python experiments.

A first fuzzy controller almost never has the right behavior. The temperature overshoots, or crawls, or the heater chatters. Tuning is the craft of changing a few well-chosen knobs, one family at a time, until the response is right. Because a fuzzy controller has many possible knobs, the order in which you turn them matters more than the cleverness of any single change.

The knobs, from most to least powerful

  1. Scaling factors. Inputs and outputs are multiplied by constants before and after the rule base: ke for the error, kde for the change of error and ku for the output. Changing a scaling factor stretches the whole controller at once. It is the cheapest and most effective tuning.
  2. Set widths and overlap. Narrow zero sets make the controller sensitive near the target; wide ones make it relaxed.
  3. Rule consequents. The numbers (Sugeno) or sets (Mamdani) in the rule table decide how hard each situation is pushed.
  4. Operators and defuzzifier. min versus product for AND, centroid versus weighted average. These change feel slightly but rarely decide success.
  5. The rule structure itself. Adding or removing rules is the last resort.

Tuning order

  1. Scale
ke, kde, ku
  1. Shapes
Width and overlap
  1. Outputs
Rule consequents
  1. Rules
Add or remove last

Change one thing at a time

1 / 2

Scaling factors in code

We reuse the incremental fuzzy thermostat. The fuzzy sets live on normalized universes: error from -1 to 1 and change of error from -1 to 1. A scaling factor converts real units into that range, so the same rule base works on any plant. The output scale ku converts the rule result back into percent power per step.

Python Effect of the output scale ku

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Look at the pattern. With ku=1 the controller is safe but slow (IAE 536). Around ku=3 the response is best (IAE 317, settled at minute 55). From ku=6 upward the overshoot grows from 2.7 to 8.6 degrees and the loop keeps swinging for the whole run (settling time 149 or 150 means it never stayed inside the band), because the 3-minute delay makes big corrections arrive too late. Faster is not always better: the middle value wins on IAE. That trade-off is the heart of tuning.

Hand-tuning three scaling factors gets tedious. A grid search simply tries many combinations and keeps the best score. You define the score yourself, here "IAE plus a penalty for overshoot", so you decide what best means.

Python Grid search over ku and kde

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The search picks ku=4 and kde=0.3. That result depends on the weight 40 in the score. Make it 0 and the search will choose a more aggressive controller that overshoots; make it larger and it will choose a gentler one. Tuning is as much about deciding what you want as about finding it.

A practical checklist

  1. Start with the rule table from the operator's description and symmetric sets covering the universe.
  2. Normalize inputs so the normal operating error fits inside the middle of the universe, not the edge.
  3. Set the output scale so a single rule firing at full strength gives a modest, safe move.
  4. Raise ku until the response is quick; lower the change-of-error scale or widen zero sets if it chatters.
  5. Test a disturbance and a different plant gain (as in the PID comparison) before you stop.
  6. Only then edit rule outputs or sets.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which knob should you try first when a fuzzy controller overshoots?

    Scaling factors change the behavior of the whole controller cheaply and predictably.
  2. 2. What trade-off does increasing the output scale usually create?

    A larger output scale makes every move bigger: quicker, but easier to overshoot.
  3. 3. What defines the best controller in an automatic search?

    The score encodes your priorities (speed, overshoot, effort), so changing it changes the winner.
  4. 4. A heater controller switches power up and down every minute. What is a sensible first fix?

    Chatter means the controller reacts to tiny changes; relaxing the sensitive terms calms it.

Summary

  • Tune in order: scaling factors, set shapes, rule outputs, then rules.
  • Normalized universes let one rule base work on different plants.
  • Output scale trades speed against overshoot.
  • A grid search can automate tuning, but you write the scoring function that defines "best".
  • Always test disturbances and a changed plant before declaring victory.

Next: Knowledge Representation Overview