Skip to content

LukaszSzarecki/inverted_pendulum

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Inverted pendulum

Simple inverted pendulum simulation using Python

Table of contents

General info

An exercise in visualization of the equations of motion. The ultimate goal is to simulate an inverted pendulum using a nonlinear system of equations. Additionally, the object can be stimulated by three signals (sine, triangle and square).

System Parameters:

  • initial angle (Φ)
  • pendulum mass (m)
  • pendulum length (L)
  • coefficient of friction (b)
  • input signal (Ƭ)

Fixed data:

  • acceleration of gravity (g ≈ 9.81 ms/s^2)

inverted-pendulum-scheme

Equations:

  • moment of inertia (rod about end) image
  • moment due to gravity image
  • moment due to friction image

Model:

  • ω angular velocity
  • φ angular displacement

image

A non-linear differential equation - solved with Fourth Order RK-Method

image

Technologies

Project is created with:

  • Python 3.9
  • PyQt5
  • Numpy 1.21.4
  • Matplotlib 3.5.0

Code Examples

Running file named main.py

length and mass must by int values

Angle and friction could be float values

  1. Example
  • frition = 1
  • initial angle = 0.001 [°]
  • length = 3 [m]
  • mass = 1 [kg]
  • input signal = zero

image

For these data we can observe that the pendulum from the vertical position (at the top) rotated (down) by 180° and due to the high value of friction it completely decelerated and remained in this position.

2. Example

  • frition = 1
  • initial angle = 0.001 [°]
  • length = 3 [m]
  • mass = 1 [kg]
  • input signal = triangular

image

The pendulum has rotated 180° and oscillates about this value according to the triangular excitation slowly decaying.

3. Example

  • frition = 0
  • initial angle = 1 [°]
  • length = 1 [m]
  • mass = 1 [kg]
  • input signal = zero

image

We see a non-decaying oscillation, the pendulum is moving on an angle interval (0, 360). Obviously, does not cross the vertical. These are harmonic vibrations.

4. Example

  • frition = 0.1
  • initial angle = 0.1 [°]
  • length = 1 [m]
  • mass = 1 [kg]
  • input signal = rectangular

image

This is the first time that the pendulum has swung in the opposite direction from the previous examples. This was due to the rectungular input signal, which caused the pendulum to moved opposite to the action of gravity at first.

Setup (in-built)

To run this project...

About

Simple inverted pendulum simulation using Python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages