Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

FUZZY LOGIC for Automatic Braking System

OUTPUT
Code Explanation:
 Importing Libraries:
 numpy is imported as np for numerical operations.
 The necessary modules from skfuzzy are imported for fuzzy logic
control.
 Defining Antecedent and Consequent:
 distance is the antecedent (input) representing the distance to an
obstacle, with linguistic terms: near, medium, and far.
 brake_force is the consequent (output) representing the brake force,
with linguistic terms: low, medium, and high.
 Membership Functions:
 Triangular membership functions are defined for both distance and
brake_force.
 fuzz.trimf is used to create triangular membership functions with
specified parameters.
 Rules:
 Three rules are defined to map the distance values to brake force
values.
 Rule 1: If distance is near, then brake force is high.
 Rule 2: If distance is medium, then brake force is medium.
 Rule 3: If distance is far, then brake force is low.

 Control System:
 braking_ctrl is a control system created using the defined rules.
 Control System Simulation:
 braking is a simulation object for the control system.
 The input distance is set to 6 (sample distance), and the simulation is
computed.
 The output brake force is then printed.
 Visualization:
 Membership functions for distance and brake_force are plotted
using distance.view() and brake_force.view().
Fuzzy Logic Explanation:
In Fuzzy logic is used to control the brake force of a vehicle based on the
distance to an obstacle. Here's how the fuzzy logic system works:
 Fuzzification (Input):
 The distance input is fuzzified into three linguistic terms: near,
medium, and far. Triangular membership functions are used to
assign degrees of membership to these terms based on the current
distance.
 Fuzzification (Output):
 The brake_force output is fuzzified into three linguistic terms:
low, medium, and high. Triangular membership functions are used
to represent the degrees of membership in these output terms.
 Rules and Inference:
 Three fuzzy rules define the relationship between the input and
output. These rules capture the decision-making process based on
the distance to the obstacle. For instance, if the distance is near,
the brake force should be high.
 Control System and Aggregation:
 The control system aggregates the rules and determines the
overall brake force output based on the input distance. The
aggregation is typically done using methods like minimum,
maximum, or average.
 Defuzzification (Output):
 The fuzzy output obtained from the aggregation process is
defuzzified to obtain a crisp value for the brake force. This
represents the system's decision on the appropriate brake force to
apply.
 Simulation and Output:
 The simulation applies a specific distance value (6 in this case) to
the fuzzy logic system. The system computes the degree of
membership of the input in each fuzzy set, evaluates the rules,
aggregates the results, and provides a crisp output value for
brake_force. The printed output represents the recommended
brake force.
 Visualization:
 The membership functions are visualized to understand how the
input and output values are fuzzified and defuzzified. This helps in
interpreting the fuzzy logic system's reasoning and decision-
making process.
In summary, this code demonstrates a simple fuzzy logic system for
controlling brake force based on the distance to an obstacle. The linguistic
rules capture the qualitative relationship between distance and brake force,
providing a flexible and intuitive approach for decision-making in a braking
system.

You might also like