Bu proje, bir top-cubuk (ball-beam) sisteminin bulanik mantik tabanli kontrolunu gerceklestirmektedir. Iki farkli bulanik kontrolor tasarlanmis ve gercek zamanli simulasyon ortaminda karsilastirilmistir.
This project implements fuzzy logic-based control of a ball-beam system. Two different fuzzy controllers have been designed and compared in a real-time simulation environment.
Fuzzy_Logic/
├── codes/
│ ├── config.py # Fiziksel parametreler / Physical parameters
│ ├── fuzzy_controllers.py # Bulanik kontrolor siniflari / Fuzzy controller classes
│ ├── ball_beam_system.py # Fizik modeli / Physics model
│ ├── performance_metrics.py # Performans analizi / Performance analysis
│ ├── visualization.py # Gorsellestirme / Visualization
│ ├── main.py # Ana program / Main program
│ └── Simulation.py # Eski monolitik versiyon / Old monolithic version (reference)
├── requirements.txt
├── KURULUM.md
└── README.md
Top-cubuk sistemi, bir cubuk uzerindeki topun konumunu kontrol etmeye dayanan klasik kontrol problemidir. Cubuk belirli bir aci ile egilerek topun cubuk uzerindeki konumu sifir noktasina (merkeze) getirilmeye calisilir.
The ball-beam system is a classic control problem based on controlling the position of a ball on a beam. The beam is tilted at a certain angle to drive the ball towards the zero position (center) on the beam.
Sistemde kullanilan fiziksel parametreler (config.py dosyasinda tanimlidir):
Physical parameters used in the system (defined in config.py):
| Parametre / Parameter | Deger / Value | Aciklama / Description |
|---|---|---|
| Yercekimi / Gravity | 9.81 m/s^2 | Yercekimi ivmesi / Gravitational acceleration |
| Zaman adimi / Time step | 0.02 s | Simulasyon adimi / Simulation step |
| Top yaricapi / Ball radius | 0.05 m | Topun yaricapi / Radius of the ball |
| Cubuk uzunlugu / Beam half-length | 1.0 m | Cubugun yari uzunlugu / Half-length of the beam |
Bu kontrolor, uyelik fonksiyonlari ve kurallar deneme-yanilma yontemiyle elle belirlenerek tasarlanmistir.
This controller is designed by manually determining the membership functions and rules through trial and error.
-
Ucgen (triangular) uyelik fonksiyonlari kullanir
-
5 konum etiketi (NB, NS, Z, PS, PB), 3 hiz etiketi (N, Z, P) ve 5 aci etiketi (NB, NS, Z, PS, PB) vardir
-
Toplam 15 kural iceren bir kural tabani bulunur
-
Uses triangular membership functions
-
Has 5 position labels (NB, NS, Z, PS, PB), 3 velocity labels (N, Z, P), and 5 angle labels (NB, NS, Z, PS, PB)
-
Contains a rule base of 15 rules in total
Bu kontrolor, Gauss uyelik fonksiyonlari ve matris tabanli kural tablosu kullanilarak sistematik bir sekilde olusturulmustur.
This controller is systematically created using Gaussian membership functions and a matrix-based rule table.
-
Gauss (Gaussian) uyelik fonksiyonlari kullanir
-
Ayni etiket sayilarina sahiptir ancak farkli uyelik fonksiyonu sekilleri vardir
-
Kural matrisi uzerinden otomatik olarak 15 kural uretilir
-
Uses Gaussian membership functions
-
Has the same number of labels but different membership function shapes
-
15 rules are automatically generated through a rule matrix
Asagidaki tablo her iki kontrolorde ortak olan mantik yapisini gostermektedir:
The following table shows the logic structure common to both controllers:
| Konum / Hiz | N | Z | P |
|---|---|---|---|
| NB | PB | PB | PS |
| NS | PB | PS | Z |
| Z | PS | Z | NS |
| PS | Z | NS | NB |
| PB | NS | NB | NB |
Tum fiziksel sabitler, sistem sinirlari, gurultu parametreleri ve baslangic kosullari bu dosyada tutulur. Parametreleri degistirerek farkli simulasyon senaryolari olusturulabilir.
All physical constants, system limits, noise parameters, and initial conditions are stored in this file. Different simulation scenarios can be created by changing these parameters.
SezgiselBulanikKontrolor ve OtomatikBulanikKontrolor adli iki sinif icerir. Her ikisi de scikit-fuzzy kutuphanesini kullanarak uyelik fonksiyonlarini tanimlar, kurallarini olusturur ve hesapla() metoduyla kontrol ciktisi uretir. Kontrolor hesaplama hata verirse PD tipi bir geri donus (fallback) mekanizmasi mevcuttur.
Contains two classes: SezgiselBulanikKontrolor and OtomatikBulanikKontrolor. Both use the scikit-fuzzy library to define membership functions, create rules, and produce control output through the hesapla() method. A PD-type fallback mechanism is available if the controller computation fails.
BallBeamSystem sinifi sistemin fiziksel modelini icerir. Her simulasyon adiminda topun konum ve hizini gunceller, aktuator dinamigini uygular, gurultu ve bozucu etkilerini hesaplar. Olcum gurultusu ve fiziksel gurultu bagimsiz olarak acilip kapatilabilir. Cubuga ani darbe uygulanabilir.
The BallBeamSystem class contains the physical model of the system. At each simulation step, it updates the ball's position and velocity, applies actuator dynamics, and calculates noise and disturbance effects. Measurement noise and physical noise can be toggled independently. An impulse can be applied to the beam.
Simulasyon sonuclarini degerlendirmek icin metrikler hesaplar: MSE (ortalama karesel hata), maksimum hata, salinim sayisi, asim miktari ve kararlilik. Bu metriklere gore performans iyi, orta veya kotu olarak siniflandirilir.
Calculates metrics to evaluate simulation results: MSE (mean squared error), maximum error, oscillation count, overshoot, and stability. Based on these metrics, performance is classified as good, moderate, or poor.
BallBeamVisualization sinifi matplotlib kullanarak gercek zamanli animasyon, buton kontrolleri, performans grafikleri, uyelik fonksiyonu gorselleri ve karsilastirmali analiz ekranlari olusturur. Kullanici simulasyon sirasinda kontroller arasinda gecis yapabilir, gurultu ekleyebilir ve darbe uygulayabilir.
The BallBeamVisualization class uses matplotlib to create real-time animation, button controls, performance graphs, membership function visuals, and comparative analysis screens. During simulation, users can switch between controllers, add noise, and apply impulses.
Programin giris noktasidir. Sistemi ve kontrolorleri baslatir, gorsellestirme ortamini hazirlar ve simulasyonu calistirir. KontrolorYonetici sinifi araciligiyla kontroller arasinda gecis yapilir.
This is the entry point of the program. It initializes the system and controllers, sets up the visualization environment, and runs the simulation. Controller switching is handled through the KontrolorYonetici class.
- Iki farkli bulanik kontrolor tasarimi ve karsilastirmasi / Two different fuzzy controller designs and comparison
- Gercek zamanli top-cubuk animasyonu / Real-time ball-beam animation
- MSE, asim, salinim, kararlilik gibi performans metrikleri / Performance metrics such as MSE, overshoot, oscillation, stability
- Olcum gurultusu ve fiziksel bozucu etki simülasyonlari / Measurement noise and physical disturbance simulations
- Uyelik fonksiyonlarinin gorsellestirilmesi / Visualization of membership functions
- Kontrolorler arasi karsilastirmali analiz / Comparative analysis between controllers
- Cubuga ani darbe uygulama ve toparlanma testi / Impulse application to beam and recovery testing
Detayli kurulum talimatlari icin KURULUM.md dosyasina bakiniz.
For detailed installation instructions, see the KURULUM.md file.
# Virtual environment olustur / Create a virtual environment
python3 -m venv venv
# Aktif et / Activate
source venv/bin/activate # macOS/Linux
# venv\Scripts\activate # Windows
# Bagimliliklar / Dependencies
pip install -r requirements.txt
# Calistir / Run
python3 codes/main.py- Python 3.8+
- numpy >= 1.20.0
- matplotlib >= 3.3.0
- scikit-fuzzy >= 0.4.2
- scipy >= 1.7.0
- networkx >= 2.5
Program calistirildiktan sonra bir animasyon penceresi acilir. Bu pencerede asagidaki butonlar bulunur:
After running the program, an animation window opens. The following buttons are available in this window:
- Kontrolor: Sezgisel ve otomatik kontroller arasinda gecis yapar / Switches between intuitive and automatic controllers
- Darbe: Cubuga ani bir darbe uygulayarak kontrolorun toparlanmasini test eder / Applies an impulse to the beam to test controller recovery
- Olcum Gurultusu: Konum ve hiz olcumlerine gurultu ekler/kaldirir / Adds/removes noise to position and velocity measurements
- Fiziksel Gurultu: Sistemdeki fiziksel bozuculari acar/kapatir / Toggles physical disturbances in the system
- Sifirla: Sistemi baslangic durumuna dondurur / Resets the system to initial state
- Performans: Anlık performans metriklerini ve grafikleri gosterir / Shows current performance metrics and graphs
- Uyelik Fonk.: Kullanilan uyelik fonksiyonlarini gorsellestirir / Visualizes the membership functions used
- Karsilastirma: Iki kontrolorun performansini yan yana karsilastirir / Compares the performance of two controllers side by side