Skip to content

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

πŸŽ›οΈ Advanced PID Controller System

A comprehensive, production-ready PID (Proportional-Integral-Derivative) control system with real-time visualization, safety monitoring, and automated tuning capabilities. Designed for educational purposes and drone control applications.

🌟 Features

Core Control System

  • Advanced PID Implementation: Full PID controller with configurable parameters
  • Noise-Robust Control: Enhanced PID with filtering and disturbance rejection
  • Auto-Tuning: Automatic parameter optimization using system identification
  • Output Limiting: Configurable saturation and anti-windup protection
  • Component Analysis: Real-time monitoring of P, I, D terms

Safety & Monitoring

  • Real-Time Safety Monitor: Continuous system health checking
  • Emergency Stop: Instant system shutdown capability
  • Performance Metrics: Settling time, overshoot, steady-state error tracking
  • Alert System: Automated warnings for system anomalies

Data Management

  • Comprehensive Logging: Automatic flight data recording
  • Log Management: Intelligent cleanup and storage optimization
  • Performance Analytics: Historical data analysis and reporting
  • Export Capabilities: CSV and JSON data export

User Interface

  • Professional GUI: Modern dark-theme interface with CustomTkinter
  • Real-Time Visualization: 6-panel dashboard with live plotting
  • Flight Modes: Pre-configured settings for different scenarios
  • Interactive Controls: Intuitive parameter adjustment and system control

πŸš€ Quick Start

Prerequisites

  • Python 3.8 or higher
  • Windows, macOS, or Linux

Installation

  1. Clone or download this repository

  2. Install dependencies:

    pip install -r requirements.txt

Running the Application

For the complete integrated experience:

python integrated_pid_system.py

For basic PID functionality:

python pid_controller.py

πŸ“ Project Structure

PID-Controller/
β”œβ”€β”€ πŸ“± Core Application
β”‚   β”œβ”€β”€ integrated_pid_system.py    # Main integrated application
β”‚   β”œβ”€β”€ pid_controller.py           # Core PID controller class
β”‚   └── pid_gui_app.py             # Basic GUI application
β”‚
β”œβ”€β”€ πŸ”§ Advanced Features
β”‚   β”œβ”€β”€ noise_robust_pid.py        # Enhanced PID with filtering
β”‚   β”œβ”€β”€ system_identification.py   # Auto-tuning algorithms
β”‚   β”œβ”€β”€ flight_mode_manager.py     # Flight mode presets
β”‚   └── system_validation.py       # System validation tools
β”‚
β”œβ”€β”€ πŸ›‘οΈ Safety & Monitoring
β”‚   β”œβ”€β”€ safety_monitor.py          # Real-time safety monitoring
β”‚   └── data_logger.py            # Data logging and management
β”‚
β”œβ”€β”€ πŸ§ͺ Testing & Validation
β”‚   β”œβ”€β”€ test_pid.py                # Comprehensive unit tests
β”‚   └── logs/                      # Flight data storage
β”‚
└── πŸ“š Documentation
    β”œβ”€β”€ README.md                  # This file
    β”œβ”€β”€ FLIGHT_MODES_GUIDE.md      # Flight mode documentation
    β”œβ”€β”€ requirements.txt           # Python dependencies
    └── LICENSE                    # MIT License

🎯 Usage Guide

Basic Operation

  1. Launch the Application

    python integrated_pid_system.py
  2. Start the System

    • Click ▢️ Start System to begin simulation
    • Monitor the real-time dashboard
  3. Configure Parameters

    • Adjust Kp, Ki, Kd values manually
    • Or use 🎯 Auto-Tune for automatic optimization
  4. Monitor Performance

    • Watch the 6-panel real-time visualization
    • Check safety status indicators
    • Review performance metrics
  5. Emergency Controls

    • Use πŸ›‘ EMERGENCY STOP for immediate shutdown
    • Reset system with πŸ”„ Reset button

Flight Modes

The system includes pre-configured flight modes:

  • 🚁 Stable Hover: Gentle, stable flight
  • 🎯 Precision: High-accuracy positioning
  • ⚑ Sport: Fast, responsive control
  • πŸ“Έ Camera: Smooth movements for filming
  • πŸŒͺ️ Windy: Enhanced disturbance rejection

Auto-Tuning Process

  1. Select appropriate flight mode
  2. Click 🎯 Auto-Tune
  3. System automatically identifies plant characteristics
  4. Optimal PID parameters calculated and applied
  5. Performance validated and reported

πŸ”§ API Reference

PIDController Class

from pid_controller import PIDController

# Initialize controller
pid = PIDController(
    kp=1.0,           # Proportional gain
    ki=0.1,           # Integral gain  
    kd=0.05,          # Derivative gain
    setpoint=0.0,     # Target value
    output_limits=(-100, 100)  # Output saturation
)

# Update controller
output = pid.update(current_value, dt=0.01)

# Get component analysis
components = pid.get_components()  # Returns P, I, D terms

NoiseRobustPIDController Class

from noise_robust_pid import NoiseRobustPIDController

# Enhanced PID with filtering
robust_pid = NoiseRobustPIDController(
    kp=1.0, ki=0.1, kd=0.05,
    lpf_cutoff=10.0,    # Low-pass filter frequency
    notch_freq=50.0,    # Notch filter frequency  
    noise_threshold=0.1  # Noise detection threshold
)

Safety Monitor

from safety_monitor import SafetyMonitor

# Create safety monitor
safety = SafetyMonitor(
    max_error=5.0,
    max_output=100.0,
    stability_window=50
)

# Check system safety
is_safe, alerts = safety.check_safety(error, output, dt)

πŸ§ͺ Testing

Running Tests

# Run all tests
python test_pid.py

# Run specific test
python -m unittest test_pid.TestPIDController.test_proportional_only

Test Coverage

  • βœ… PID controller initialization and parameter setting
  • βœ… Proportional, integral, and derivative control
  • βœ… Output limiting and anti-windup
  • βœ… Step response and stability testing
  • βœ… Performance metrics calculation
  • βœ… Safety monitoring functionality

Performance Validation

The system includes automated validation tests:

  • Settling time measurement
  • Overshoot calculation
  • Steady-state error analysis
  • Stability assessment

πŸ“Š Performance Metrics

The system automatically calculates and displays:

  • Settling Time: Time to reach Β±2% of setpoint
  • Overshoot: Maximum deviation beyond setpoint
  • Steady-State Error: Final error after settling
  • Rise Time: Time to reach 90% of setpoint
  • Control Effort: RMS of control signal

πŸ›‘οΈ Safety Features

Real-Time Monitoring

  • Continuous error magnitude checking
  • Output saturation detection
  • System stability analysis
  • Performance degradation alerts

Emergency Procedures

  • Immediate system shutdown capability
  • Safe parameter reset functionality
  • Automatic data preservation
  • Error state recovery

Fail-Safe Mechanisms

  • Parameter limit enforcement
  • Output range protection
  • Integral windup prevention
  • Noise spike filtering

βš™οΈ Configuration

PID Parameters

  • Kp (Proportional): Controls response speed and steady-state error
  • Ki (Integral): Eliminates steady-state error, can cause instability
  • Kd (Derivative): Improves stability, sensitive to noise

System Settings

  • Update Rate: Control loop frequency (default: 100 Hz)
  • Data Logging: Automatic logging with configurable retention
  • Safety Thresholds: Customizable safety limits
  • Visualization: Real-time plotting configuration

πŸ” Troubleshooting

Common Issues

System Oscillation

  • Reduce Kp gain
  • Increase derivative gain (Kd)
  • Check for noise in sensor data

Slow Response

  • Increase Kp gain
  • Verify system is not saturated
  • Check for mechanical limitations

Steady-State Error

  • Increase Ki gain
  • Verify integral term is functioning
  • Check for external disturbances

System Instability

  • Use emergency stop immediately
  • Reduce all gains by 50%
  • Enable noise filtering

Debug Mode

Enable debug logging for detailed analysis:

import logging
logging.basicConfig(level=logging.DEBUG)

🀝 Contributing

We welcome contributions! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Follow PEP 8 coding standards
  4. Add comprehensive tests
  5. Update documentation
  6. Submit a pull request

Development Guidelines

  • Use type hints for all function parameters
  • Include comprehensive docstrings
  • Maintain test coverage above 90%
  • Follow the existing code structure
  • Document any new dependencies

πŸ“‹ Dependencies

Required Packages

  • numpy>=2.3.1: Numerical computations
  • matplotlib>=3.10.3: Plotting and visualization
  • customtkinter>=5.2.2: Modern GUI framework
  • scipy>=1.16.0: Scientific computing (optional)
  • control>=0.10.2: Control systems library

Optional Packages

  • scipy: Required for auto-tuning functionality
  • pandas: Enhanced data analysis capabilities

⚠️ Safety Notice

This software is designed for educational and simulation purposes.

When integrating with real hardware:

  • ⚠️ Always maintain manual override capability
  • πŸ§ͺ Test thoroughly in controlled environments
  • πŸ“‹ Follow all applicable safety regulations
  • πŸ›‘οΈ Implement proper fail-safe mechanisms
  • πŸ“Š Monitor system performance continuously
  • 🚫 Never rely solely on software safety systems

πŸ“ License

MIT License - See LICENSE file for details.

πŸ™ Acknowledgments

  • Control theory implementation based on classical PID design
  • GUI framework powered by CustomTkinter
  • Visualization using Matplotlib
  • Testing framework using Python unittest

🎯 Ready to start? Run python integrated_pid_system.py and experience professional PID control!

For questions, issues, or contributions, please visit our GitHub repository.

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages