Balancing an Inverted Pendulum

One Pendulum Less

We’ve looked at the chaotic dynamics of double pendulums, but let’s take a moment to step back at the double pendulum’s simpler sibling, the single pendulum. This is the first post in a 3-part series looking at balancing an inverted pendulum

  • Balancing an inverted pendulum – Part 1
  • Balancing an inverted pendulum on a cart – Part 2
  • Kaptiza’s pendulum – Part 3

Note: I’m planning on using this series to explore some interesting nonlinear systems, but if you cant wait for them all to come out I recommend exploring Nonlinear Dynamics and Chaos by Storgatz

Dynamics of a Pendulum

Lets begin with drawing the Free body diagram for a pendulum in a constant gravitational field

FBD.png

We have our pendulum of mass, m on an inertia less rod length l, being stretched out an angle of θ. We can derive the equation of motion using forces, torques, or energy methods, but no matter how you do it, we are left with the following equation of motion

\ddot{\theta}-\frac{g}{l}\sin(\theta)=0

Note: the EOM derivation is left as an exercise to the reader.

Equilibrium Points and Stability.

Let’s first find any equilibrium points in the system. This is done by setting both acceleration and velocity to 0.

\frac{g}{l}\sin(\theta)=0=\sin(\theta)

There’s an infinite number of different solutions we could have for sin(θ) = 0. We could have θ=0,π,2π, etc..  an easier way to write out all the solutions would be

\theta = n\pi , n \in Z

Note: Z denotes the set of all integers. In reality, we can make it even simpler. There are only 2 different cases. …,0,2π,4π,… and …,-π,π,3π,… The first case corresponds to when the pendulum is at the bottom of it’s swing, and the second case corresponds to when the pendulum is at the top of it’s swing.

Now that we have all the equilibrium points, let’s rewrite this in state-space form and then linearize it about the equilibrium points

x_1 = \theta

x_2=\dot{x_1}=\dot{\theta}

$latex  \boldsymbol{\dot{x}}=A(x^*)\boldsymbol{x}$

Note the * referring to the fact that A was linearized about a specific point

\begin{bmatrix} \dot{x}_1 \\ \dot{x}_2 \end{bmatrix} = \begin{bmatrix} 0 & 1 \\ \frac{g}{l}\cos(\theta^*) & 0 \end{bmatrix} \begin{bmatrix} {x}_1 \\ {x}_2 \end{bmatrix}

Case 1 – Bottom of the Swing

Let’s explore case 1, when the pendulum s at the bottom of its swing and θ=0. This makes the A matrix

\begin{bmatrix} 0 & 1 \\ \frac{g}{l}& 0 \end{bmatrix}

where

\frac{g}{l}<1

which gives us two imaginary eigenvalues corresponding to sinusoidal motion

Case 2 – Top of the Swing

Let’s explore case 1, when the pendulum is at the top of its swing and θ=π. This makes the A matrix

\begin{bmatrix} 0 & 1 \\ -\frac{g}{l}& 0 \end{bmatrix}

where

\frac{g}{l}<1

Which gives us two real eigenvalues. One stable, and the other unstable. The unstable one will dominate the stable eigenvalue making the vertical position unstable. This makes intuitive sense We know that if we try to stand a pendulum up it will always fall and end up at the bottom of it’s swing.

Adding a Torque

So how can we, as the title of this post implies, balance this inverted pendulum? The simplest way, and how we’ll do it in this post is simply by adding a motor that can provide a torque at the pivot point of the pendulum. This changes the equation of motion of the pendulum to

\ddot{\theta}-\frac{g}{l}\sin(\theta)=T.

What should our control torque T be? We want the pendulum to go to a specific place so lets define our error as the difference between where the pendulum is,θ, and where the pendulum wants to be,θ_d,

E = (\theta_D - \theta).

If we just had this error term as our torque, we would just overshoot the target like in the gif below

overSwing.gif

We would continue overshooting the target forever. Let’s now also say we want to end on our desired angle and stay there. We can do this by making our torque also a function of the time derivative of the error.

\dot{E}=-\dot{\theta}

This makes our new equations of motion

\ddot{\theta}-\frac{g}{l}\sin(\theta)=-\beta\dot{\theta}+\alpha(\theta_D-\theta).

As an exercise to the reader, take some time to determine what the new equilibrium points are as well as what makes the inverted location stable.

Here’s a gif of the simulation with the new dynamics thanks to our applied control.

damped.gif

Note: If this post was interesting to you, you’d probably enjoy Nonlinear Dynamics and Chaos by Storgatz.

Want more Gereshes

If you want to receive the weekly Gereshes blog post directly to your email every Monday morning, you can sign up for the newsletter here! Don’t want another email? That’s ok, Gereshes also has a twitter account and subreddit!