|
1 | 1 |  |
| 2 | +PD Parameter Optimizer for Robotics |
| 3 | +Overview |
| 4 | + |
| 5 | +This Python package optimizes Proportional-Derivative (PD) controller parameters for robotic systems by comparing policy output actions with actual executed actions. It uses sampling data from various PD parameter combinations to find optimal values that minimize tracking error. |
| 6 | + |
| 7 | +Key features: |
| 8 | + |
| 9 | + Loads and validates PD sampling data from CSV files |
| 10 | + |
| 11 | + Calculates weighted tracking errors (position, velocity, acceleration) |
| 12 | + |
| 13 | + Optimizes parameters using gradient-based methods |
| 14 | + |
| 15 | + Performs performance analysis (settling time, overshoot, steady-state error) |
| 16 | + |
| 17 | + Generates comprehensive visualizations |
| 18 | + |
| 19 | + Saves optimization results in JSON format |
| 20 | + |
| 21 | +Requirements |
| 22 | + |
| 23 | + Python 3.7+ |
| 24 | + Required packages: |
| 25 | + bash |
| 26 | + numpy |
| 27 | + pandas |
| 28 | + matplotlib |
| 29 | + scipy |
| 30 | + scikit-learn |
| 31 | + |
| 32 | +Installation |
| 33 | + |
| 34 | + Clone the repository: |
| 35 | + bash |
| 36 | + |
| 37 | +git clone https://github.com/yourusername/pd-parameter-optimizer.git |
| 38 | +cd pd-parameter-optimizer |
| 39 | + |
| 40 | +Install dependencies: |
| 41 | +bash |
| 42 | + |
| 43 | + pip install -r requirements.txt |
| 44 | + |
| 45 | +Usage |
| 46 | +Data Preparation |
| 47 | + |
| 48 | + Create a folder for your sampling data (e.g., ./pd_sampling_data) |
| 49 | + |
| 50 | + Save CSV files with the naming format: pd_p{P value}_d{D value}.csv |
| 51 | + |
| 52 | + Example: pd_p10.0_d0.5.csv |
| 53 | + |
| 54 | + Each CSV file should contain these columns: |
| 55 | + |
| 56 | + timestamp |
| 57 | + |
| 58 | + policy_action |
| 59 | + |
| 60 | + actual_action |
| 61 | + |
| 62 | + position |
| 63 | + |
| 64 | + velocity (optional) |
| 65 | + |
| 66 | + acceleration (optional) |
| 67 | + |
| 68 | + target_velocity (optional) |
| 69 | + |
| 70 | + target_acceleration (optional) |
| 71 | + |
| 72 | +Basic Example |
| 73 | +python |
| 74 | + |
| 75 | +from pd_optimizer import PDParameterOptimizer |
| 76 | + |
| 77 | +# Configuration parameters (optional) |
| 78 | +config = { |
| 79 | + 'file_pattern': '*.csv', |
| 80 | + 'p_range': (0.1, 50.0), |
| 81 | + 'd_range': (0.01, 5.0), |
| 82 | + 'weight_position': 1.0, |
| 83 | + 'weight_velocity': 0.5, |
| 84 | + 'weight_acceleration': 0.3 |
| 85 | +} |
| 86 | + |
| 87 | +# Initialize optimizer |
| 88 | +optimizer = PDParameterOptimizer( |
| 89 | + data_folder='./pd_sampling_data', |
| 90 | + config=config |
| 91 | +) |
| 92 | + |
| 93 | +# Load data |
| 94 | +optimizer.load_sampling_data() |
| 95 | + |
| 96 | +# Analyze existing PD parameters |
| 97 | +analysis_df = optimizer.analyze_pd_performance() |
| 98 | +print("Top performing PD parameters:") |
| 99 | +print(analysis_df.head(5)) |
| 100 | + |
| 101 | +# Optimize parameters |
| 102 | +optimal_p, optimal_d, optimal_error = optimizer.optimize_pd_parameters() |
| 103 | +print(f"\nOptimal parameters: P={optimal_p:.4f}, D={optimal_d:.4f}") |
| 104 | +print(f"Minimum error: {optimal_error:.6f}") |
| 105 | + |
| 106 | +# Generate and save visualizations |
| 107 | +optimizer.plot_results(save_path='optimization_results.png') |
| 108 | + |
| 109 | +# Save full results |
| 110 | +optimizer.save_results('optimization_results.json') |
| 111 | + |
| 112 | +Configuration Options |
| 113 | +Parameter Default Value Description |
| 114 | +file_pattern '*.csv' File pattern for data loading |
| 115 | +p_range (0.1, 200.0) Search range for P parameter |
| 116 | +d_range (0.01, 5.0) Search range for D parameter |
| 117 | +optimization_method 'L-BFGS-B' Optimization algorithm |
| 118 | +max_iterations 1000 Maximum optimization iterations |
| 119 | +tolerance 1e-6 Optimization tolerance |
| 120 | +weight_position 1.0 Weight for position error |
| 121 | +weight_velocity 0.5 Weight for velocity error |
| 122 | +weight_acceleration 0.3 Weight for acceleration error |
| 123 | +Output Visualization |
| 124 | + |
| 125 | +The plot_results() method generates a 2x2 grid of visualizations: |
| 126 | + |
| 127 | + Error Heatmap |
| 128 | + Shows tracking error across different PD parameter combinations |
| 129 | + |
| 130 | + Best Waveform Comparison |
| 131 | + Compares policy actions vs actual actions for optimal PD parameters |
| 132 | + |
| 133 | + PD Parameter Scatter Plot |
| 134 | + Visualizes parameter space with error coloring and marks best point |
| 135 | + |
| 136 | + Performance Metrics Comparison |
| 137 | + Compares overshoot, settling time, and steady-state error for top 5 PD combinations |
| 138 | + |
| 139 | + |
| 140 | +The analyze_pd_performance() method returns a DataFrame with these metrics for each PD combination: |
| 141 | +Metric Description |
| 142 | +Total_Error Weighted composite tracking error |
| 143 | +Settling_Time Time to reach within 2% of target value |
| 144 | +Overshoot Maximum overshoot percentage |
| 145 | +Steady_State_Error Average error in last 10% of trajectory |
| 146 | +Optimization Algorithm |
| 147 | + |
| 148 | +The optimization process: |
| 149 | + |
| 150 | + Uses sampled PD points as starting references |
| 151 | + |
| 152 | + Estimates errors for unsampled points using distance-weighted interpolation |
| 153 | + |
| 154 | + Applies gradient-based optimization (L-BFGS-B by default) to find minimum |
| 155 | + |
| 156 | + Respects parameter boundaries defined in configuration |
| 157 | + |
| 158 | +Contributing |
| 159 | + |
| 160 | +Contributions are welcome! Please submit pull requests for: |
| 161 | + |
| 162 | + Additional optimization algorithms |
| 163 | + Improved interpolation methods |
| 164 | + Enhanced visualization options |
| 165 | + Extended performance metrics |
| 166 | + |
| 167 | +License |
| 168 | + |
| 169 | +This project is licensed under the MIT License - see the LICENSE file for details. |
0 commit comments