NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

PID Optimization Using Lagrangian Mechanics

Ethan Kou, Majid MoghadamarXiv 2023 · DOI · OpenReview

TL;DR

This paper presents a method for simulating an inverted pendulum on a cart using Lagrangian mechanics, enabling efficient PID controller tuning without physical hardware. They demonstrate both manual and optimization-based tuning, showing that optimization can yield superior performance for balancing the pendulum.

What Problem Does This Paper Address?

Tuning control systems, particularly Proportional-Integral-Derivative (PID) controllers, for physical systems can be a time-consuming and iterative process, often hindering development progress. The authors aim to address this by creating a physics-based simulation of an inverted pendulum on a cart. This simulation allows for rapid experimentation and tuning of PID controllers, making the process more manageable and efficient. The inverted pendulum on a cart is a classic control problem due to its inherent instability, requiring precise control to maintain balance.

Methods

The core of the paper lies in deriving the equations of motion for the inverted pendulum on a cart system using Lagrangian Mechanics. This approach focuses on the kinetic and potential energies of the system rather than forces directly, which the authors found to be a more straightforward derivation for this scenario.

  1. Lagrangian Derivation: They define the kinetic energy (KE) of the cart and the pendulum bob, and the potential energy (PE) of the bob. The Lagrangian (L = KE - PE) is then formulated.
  2. Euler-Lagrange Equations: The Euler-Lagrange equations are applied to derive the differential equations governing the system's motion, specifically solving for the acceleration of the cart ($\ddot{x}$) and the angular acceleration of the rod ($\ddot{\theta}$).
  3. PID Controller Implementation: A standard PID controller is implemented, where the control action $u(t)$ is a function of the error in the rod's angle $e(t)$, its integral, and its derivative, weighted by proportional ($K_p$), integral ($K_i$), and derivative ($K_d$) gains, respectively.
  4. Manual Tuning: The authors describe a step-by-step manual tuning process, starting with the proportional gain ($K_p$) to achieve basic balance, then adjusting the derivative gain ($K_d$) to reduce oscillations, and finally the integral gain ($K_i$) to eliminate steady-state error.
  5. Optimization-Based Tuning: An objective function is defined as the sum of squared errors of the rod angle over a simulation period, plus a small penalty on the magnitude of the gain coefficients. This function is then minimized using scipy.optimize.minimize to find optimal PID gains.

Datasets

Not discussed in the paper. The paper focuses on simulating a physical system and tuning a controller, rather than training on pre-existing datasets.

Key Insights and Ideas

  • Lagrangian Mechanics for Simulation: Using Lagrangian mechanics provides a systematic way to derive the complex dynamics of the inverted pendulum on a cart, which is crucial for creating an accurate simulation.
  • Simulation as a Tuning Sandbox: The simulation environment significantly accelerates the PID tuning process compared to working with a physical system, allowing for rapid iteration and exploration of different gain values.
  • Manual Tuning Strategy: The described manual tuning approach (Kp -> Kd -> Ki) is a practical heuristic that effectively addresses different aspects of control performance (stability, oscillation, steady-state error).
  • Optimization for Superior Performance: While manual tuning yields decent results, optimization-based tuning can discover PID gains that lead to faster convergence and better overall performance, especially in minimizing error and oscillations.
  • Gain Penalization in Optimization: Including a penalty for large gain coefficients in the objective function is a smart way to encourage controllers that are less "aggressive" and potentially more energy-efficient, without sacrificing too much performance.

Key Results

  • Successful Simulation: The paper successfully derives and implements a simulation of the inverted pendulum on a cart using Lagrangian mechanics.
  • Manual Tuning Achieves Balance: Manual tuning of the PID controller, following the described strategy, successfully balances the pendulum, though with some residual oscillation or steady-state error depending on the stage of tuning.
  • Optimized PID Outperforms: The optimization-based tuning method, using a sum of squared errors and gain penalty objective function, yields PID gains that result in significantly faster error reduction and better long-term stability compared to manual tuning. For example, one optimized PID achieved an error that "quickly decreases to zero and stays at 0."
  • Robustness to Initial Conditions: The optimized PID controller demonstrates robustness, performing well even when starting from different initial rod angles (e.g., $\theta = \pi/6$ instead of $\theta = \pi/4$).

Limitations and Future Work

  • Limited Scope of Optimization: The optimization was performed using a specific objective function (sum of squared errors + gain penalty). Other objective functions or optimization algorithms might yield different results.
  • No Real-World Validation: The paper focuses solely on simulation. The performance of the tuned controllers on a physical inverted pendulum on a cart is not demonstrated.
  • Future Work Suggestions:
    • Comparison with Other Controllers: Explore and compare the performance of more advanced control strategies like Linear Quadratic Regulator (LQR) or Model Predictive Control (MPC).
  • Learning-Based Controllers: Investigate the use of imitation learning or reinforcement learning for PID tuning or direct control.
  • Simulation vs. Real-World Physics: Bridge the gap between simulation physics and real-world physics, potentially using optimization or system identification techniques to refine the simulation model.
  • MAE vs. RMSE: While MAE was explored as an alternative objective function, further analysis could be beneficial. The paper notes MAE takes longer to converge but yields similar performance.

Summary updated

BibTeX
@misc{kou2023pid,
  author = {Ethan Kou and Majid Moghadam},
  title = {{PID Optimization Using Lagrangian Mechanics}},
  year = {2023},
  eprint = {2310.00016},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2310.00016},
}
Figure