Skip to content

Aimed to balance an Inverted Pendulum using a PID controller, focusing on control algorithms and tuning with Python using Matplotlib for simulation and analysis.

Notifications You must be signed in to change notification settings

guptuv/Inverted-Pendulum

Repository files navigation

Inverted-Pendulum

Balancing of inverted pendulum done in colab Credits to CMU Videos For detailed explanations and interactive code, please open the Colab files:

Open in Colab

Google Slides


image


Technical View of PID Algorithm for Balancing an Inverted Pendulum

image


image

PID Control Theory for Balancing an Inverted Pendulum

PID (Proportional-Integral-Derivative) control is a fundamental control theory used in control systems to maintain a desired output, such as speed, position, or temperature, by continuously adjusting inputs based on feedback. A PID controller calculates the error as the difference between a desired setpoint (SP) and a measured process variable (PV). It then applies a correction based on three components: proportional, integral, and derivative terms.

Overview of PID Components

  • Proportional (P): The proportional term responds to the current error. It provides an output directly proportional to the error, allowing the system to correct deviations quickly.
  • Integral (I): The integral term accounts for the accumulation of past errors. It helps to eliminate small errors that may not be fully corrected by the proportional term alone, achieving precise control over time.
  • Derivative (D): The derivative part predicts future error by considering the rate of change of the error. It reduces overshoot and prevents oscillations by slowing down the system as it approaches the desired value.

Applying PID Control to the Inverted Pendulum Problem

In this setup, sensors measure the angle of the pendulum (process variable, PV) relative to the upright position (desired setpoint, SP). The PID controller continuously calculates the error (the difference between SP and PV) and adjusts the force applied to the cart or motor torque that moves the base of the pendulum to keep it upright. The PID controller’s role is to determine the optimal corrective action using three components: Proportional, Integral, and Derivative.

Proportional (P) Component

The proportional term adjusts the corrective force based on the current tilt angle of the pendulum. When the pendulum tilts, the P component applies a force proportional to this tilt, aiming to push the pendulum back toward the upright position. However, relying on the proportional term alone can lead to persistent oscillations and an inability to fully stabilize the pendulum.

Integral (I) Component

The integral term addresses any accumulated tilt (persistent error) by summing up past errors over time. In an inverted pendulum, the integral term can help counteract small imbalances or external disturbances, allowing for precise control by correcting even small deviations that the proportional term might not fully handle. It acts as a correction to any residual tilt that might keep the pendulum from achieving true upright balance.

Derivative (D) Component

The derivative term predicts future tilt by measuring the rate at which the pendulum’s angle is changing. If the pendulum is tilting faster toward one direction, the D component applies a counteracting force proportional to this rate, effectively slowing down the corrective action as the pendulum nears the upright position. This helps to reduce overshoot and dampen oscillations, allowing for smoother and more stable balancing.

Challenges and Tuning PID for an Inverted Pendulum

The inverted pendulum problem requires fine-tuning the PID parameters (Kp, Ki, Kd) to achieve stability. The Proportional gain (Kp) must be large enough to respond quickly to tilting but not so high that it causes excessive oscillations. Integral gain (Ki) must be set to counteract persistent deviations without leading to instability. Finally, Derivative gain (Kd) is critical to dampen oscillations effectively but needs careful tuning, as too high a value can cause excessive sluggishness, and too low can lead to overshooting.

Summary

In PID-controlled inverted pendulum systems, each component of PID has a specific role:

  • P quickly responds to tilt.
  • I corrects minor errors over time.
  • D prevents overshoot by slowing the pendulum near the upright position.

This combination, when well-tuned, enables the controller to keep the pendulum balanced effectively and is commonly used as a foundational example for understanding the power of PID control.



Results:
PController

Flowers

Description of GIF

Description of GIF



PD-Controller
Flowers Description of GIF Description of GIF

About

Aimed to balance an Inverted Pendulum using a PID controller, focusing on control algorithms and tuning with Python using Matplotlib for simulation and analysis.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published