FuzzyAutoBrakePlayground is an interactive SwiftUI application that demonstrates a fuzzy logic-based automotive braking system. The project simulates how a car's automatic braking system can use fuzzy logic to determine appropriate braking intensity based on variables like vehicle speed and distance to obstacles.
I created this project to dive deeper into fuzzy logic beyond what I learned in class. It's a fun way to see how the theory works in real life, letting me play around with different settings and see the results instantly. This hands-on approach helps me understand the concepts better and explore new ideas in a practical, engaging way.
Screenshot 1 | Screenshot 2 |
---|---|
Fuzzy logic provides a way to handle imprecise data and make decisions based on "degrees of truth" rather than the strict true/false values of classical logic. In automotive braking systems, fuzzy logic can help create more natural and smooth braking behaviors that mimic human decision-making.
-
Fuzzy Variables: The system uses three main variables:
- Speed: The current vehicle speed
- Distance: Distance to the obstacle ahead
- Brake: The output variable representing braking intensity
-
Membership Functions: Each variable has multiple membership functions that describe linguistic terms (e.g., "slow," "medium," "fast" for speed).
-
Fuzzy Rules: Rules that connect input variables to outputs (e.g., "If speed is fast AND distance is close, THEN brake is hard").
-
Defuzzification: The process of converting fuzzy output values into a precise braking intensity value.
-
Core/: Contains the core functionality of the application
- Fuzzy/: Implements the fuzzy logic system
FuzzyVariable.swift
: Defines fuzzy variables and their propertiesFuzzyMembershipFunction.swift
: Implements different membership function shapesFuzzyRule.swift
: Defines the structure for fuzzy inference rulesFuzzyLogicEngine.swift
: Main engine that processes rules and calculates outputs
- Simulation/: Contains the simulation logic
SimulationEngine.swift
: Manages the simulation state and controls
- Fuzzy/: Implements the fuzzy logic system
-
Views: Contains UI components
- Components: Reusable UI elements
- Fuzzy: UI for fuzzy logic visualization and configuration
- Simulations: Components for the simulation view
- Objects: Visual elements for the simulation
- Components: Reusable UI elements
-
MyApp.swift: The application entry point
-
ContentView.swift: The main view of the application
The playground interface allows you to:
- Adjust vehicle speed and distance to obstacles
- Modify membership functions for each variable
- Create and edit fuzzy inference rules
- Choose different defuzzification methods
- Observe the resulting brake intensity in real-time simulation