In [1]:
from IPython.core.display import HTML
def css_styling():
    styles = open("styles/example.css", "r").read()
    return HTML(styles)
css_styling()


Out[1]:

In [1]:
#from pylab import *
from ivisual import *
from numpy import pi,sin,cos

from IPython.html.widgets import interact, interactive, fixed
from IPython.html import widgets
from IPython.display import clear_output, display, HTML, display_html, Javascript
from __future__ import division



In [2]:
from __future__ import division, print_function
from IPython.core import page
page.page = print

Inverted Pendulum

An inverted pendulum is a pendulum which has its center of mass above its pivot point as follows:

Pendulum with oscillatory base

Do you even see the show about how to keep the disk not falling down from top of a banboo rode?

The equation of motion for a pendulum connected to a massless, oscillating base is derived the same way as with the pendulum on the cart. The position of the point mass is now given by: $$ \left( -\ell \sin \theta , y + \ell \cos \theta \right) $$ and the velocity is found by taking the first derivative of the position: $$ v^2=\dot y^2-2 \ell \dot y \dot \theta \sin \theta + \ell^2\dot \theta ^2. $$

The Lagrangian for this system can be written as: \begin{eqnarray} L &=& \text{Kinetic Energy}-\text{Potential Energy} \\ &=&\frac{1 }{2} m \left ( \dot y^2-2 \ell \dot y \dot \theta \sin \theta + \ell^2\dot \theta ^2 \right) - m g \left( y + \ell \cos \theta \right ) \end{eqnarray} and the equation of motion follows from: $$ {\mathrm{d} \over \mathrm{d}t}{\partial{L}\over \partial{\dot \theta}} - {\partial{L}\over \partial \theta} = 0 $$ resulting in: $$ \ell \ddot \theta - \ddot y \sin \theta = g \sin \theta. $$

If $y$ represents a simple harmonic motion, $y = A \sin \omega t$, the following differential equation is: $$ \ddot \theta - {g \over \ell} \sin \theta = -{A \over \ell} \omega^2 \sin \omega t \sin \theta. $$


In [ ]:
scene = idisplay('Inverted Pendulum')

scene.autoscale = 0     # disable function of auto-zooming
scene.title = 'Inverted pendulum'
scene.range = (2.05,2.05,2.05)
scene.background=color.white

theta = 0.1*pi           # angle of 1st pendulum to vertical (initial value)

theta_dot = 0.0	# rate of change of theta1 - initial value

g = 9.8	# acceleration of gravity
l = 1.0	# pendulum arm length 
m = 0.3	# mass of pendulum ball
omega=30.
A=0.1

time = 0.0       # initial value of time
dt = 0.0001      # time step

# Create balls
pivot=vector(-l*sin(theta),A*sin(omega*time)+l*cos(theta),0)
ball = sphere(color=color.blue, pos=pivot, radius=0.08, make_trail=True, interval=10, retain=50)

arm = cylinder(pos=(0,0,0), axis=pivot, radius=.03, color=color.cyan)

nub = sphere(pos=(0,0,0), radius=0.1, color=color.white)      # little white nub

wall1=mybox = box(pos=(-0.1,0,0), axis=(-0.,0.3,0.), length=0.3, height=0.1, width=0.1,color=color.green,opacity=0.3) 
wall2=mybox = box(pos=(0.1,0,0), axis=(-0.,0.3,0.), length=0.3, height=0.1, width=0.1,color=color.green,opacity=0.3) 


while (True):
    rate(5000);
    yp=A*sin(omega*time);
    
    theta_dot_dot=g*sin(theta)/l-A*omega*omega*sin(omega*time)*sin(theta)/l;
    theta_dot = theta_dot + theta_dot_dot*dt
    theta = theta + theta_dot*dt

    ball.pos = (-l*sin(theta),yp+l*cos(theta),0)
    arm.pos=(0,yp,0)
    nub.pos=(nub.x,yp,0)
    
    arm.axis = (ball.pos.x, ball.pos.y-yp, 0)
    time += dt



In [3]:
scene = idisplay('Inverted Pendulum')
scene.autoscale = 0
scene.title = 'Inverted pendulum'
scene.range = (2.05,2.05,2.05)
scene.background=color.white



In [4]:
omega=30.
def anim(b):
    theta = 0.1*pi           # angle of 1st pendulum to vertical (initial value)

    theta_dot = 0.0	# rate of change of theta1 - initial value

    g = 9.8	# acceleration of gravity
    l = 1.0	# pendulum arm length 
    m = 0.3	# mass of pendulum ball
    A=0.1

    time = 0.0       # initial value of time
    dt = 0.0001      # time step

    pivot=vector(-l*sin(theta),A*sin(omega*time)+l*cos(theta),0)
    ball = sphere(color=color.blue, pos=pivot, radius=0.08, make_trail=True, interval=10, retain=50)

    arm = cylinder(pos=(0,0,0), axis=pivot, radius=.03, color=color.cyan)

    nub = sphere(pos=(0,0,0), radius=0.1, color=color.white)      # little white nub

    wall1=mybox = box(pos=(-0.1,0,0), axis=(-0.,0.3,0.), length=0.3, height=0.1, width=0.1,color=color.green,opacity=0.3) 
    wall2=mybox = box(pos=(0.1,0,0), axis=(-0.,0.3,0.), length=0.3, height=0.1, width=0.1,color=color.green,opacity=0.3) 


    while (True):
       rate(5000);
       yp=A*sin(omega*time);
    
       theta_dot_dot=g*sin(theta)/l-A*omega*omega*sin(omega*time)*sin(theta)/l;
       theta_dot = theta_dot + theta_dot_dot*dt
       theta = theta + theta_dot*dt

       ball.pos = (-l*sin(theta),yp+l*cos(theta),0)
       arm.pos=(0,yp,0)
       nub.pos=(nub.x,yp,0)
    
       arm.axis = (ball.pos.x, ball.pos.y-yp, 0)
       time += dt

In [5]:
omega_range = widgets.FloatSliderWidget(min=1.,max=100.,step=1,value=30.,description="Frequency $\omega$")
button = widgets.ButtonWidget(description="Start")
display(omega_range, button, scene)   
button.on_click(anim)

def on_value_change(name, value):
    global omega
    omega = value

omega_range.on_trait_change(on_value_change, 'value')


Myth of Indian Rope Trick

Sometimes described as "the world’s greatest illusion", the Indian rope trick,

was once studied by

D. J. Acheson & T. Mullin, Nature, Upside-down pendulums p. 215-216, Nov. 1993.

The theory of popular rope trick is explained by the dynamics system of a sequence of connected inverted pendulums if the frequencies of one and last rods is very fast!


In [ ]: