Pendulum-cart system

Analysis of Pendulum-cart system and newtonian physics.

In modern Newtonian physics reside two of the most important and widely used mechanical systems; that is, pendulums and springs. Nowadays these systems are ubiquitous in our modern world, appearing in a vast number of mechanical systems such as clocks, car suspensions, metronomes, mattresses, and shock absorbers. The influence these two mechanical systems have had in our everyday life motivates their further study. Thus, B.R.I.T decided to study and model a pendulum-cart mechanism by utilizing equations of motion, free body diagrams, differential equations, and python for a numerical and graphical solution of the system.


Content


1. What is a pendulum-cart system

A pendulum-cart system consists of a cart moving in a horizontal trajectory while being attached to a spring on a wall. Thus, converting the cart’s linear motion into a back-and-forth pattern like that of a simple harmonic oscillator. Additionally, a pendulum is suspended from the cart which will move in response to the cart’s motion.


1.1 Axis and parameter set up

Before we can analyse the system, certain parameters and axis must be chosen. To simplify things, an  < π‘₯, 𝑦, 𝑧 > axis was chosen such that the diagram looks as follows. Here, β€˜π‘§β€™ is an important axis because of the torque’s direction.

  • X = position of the cart (m)
  • L = Length of the pendulum rod (m)
  • Ο΄ = Angle of pendulum (rad)

1.2 Free-body diagram

To further our understanding of the system, we will determine all forces acting on it by creating a free-body diagram to both the pendulum and the cart.

Free-body diagram for the pendulum

m = mass of pendulum (kg)

g = gravitational constant (9.8m/s2)

ΞΌ1 = friction coefficient pendulum

T = tension (N)

⍺ = friction force (N)

mg = force due to gravity (N)

the force that creates the torque β€˜πœβ€™ can be represented as a force β€˜βΊβ€™ acting on both the pendulum and the cart (because of newtons 3rd law). If we take into consideration this new force β€˜βΊβ€™ and the length of the rod β€˜L’ as a vector, then we could find the torque by computing a cross product between them.

Free-body diagram for the cart

M = mass of the cart (kg)

g = gravitational constant (9.8m/s2)

ΞΌ2 = friction coefficient cart

v = velocity (m/s)

k = Spring constant (N/m)

T = tension (N)

⍺ = friction force (N)

mg = force due to gravity (N)

N = normal force (N)


2. Newton’s second law for the pendulum

Applying Newton’s second law will allow us to further examine the mechanics of the system. However, one must first establish certain mathematical relationship between the cart and the pendulum’s position. To do so, we will relate the cart’s position β€˜π‘₯’ with the pendulum’s position in both < π‘₯, 𝑦, 0 > direction which we will call β€˜π‘‹ β€™ and β€˜π‘Œ β€™ respectively. Ultimately, this relationship will allow us to relate their second derivative with Newton’s second law.

π‘₯𝑝 = π‘₯ + 𝐿𝑠𝑖𝑛(πœƒ)

π‘Œp = βˆ’πΏπ‘π‘œπ‘ (πœƒ)


π‘₯′𝑝 = π‘₯β€² + πœƒβ€²πΏπ‘π‘œπ‘ (πœƒ) 

π‘Œβ€²π‘ = πœƒβ€²πΏπ‘ π‘–π‘›(πœƒ)


π‘₯′′𝑝 = π‘₯β€²β€² + 𝐿[πœƒβ€²β€² cos(πœƒ) βˆ’ (πœƒβ€²)2 sin(πœƒ)]

π‘Œβ€²β€²π‘ = πœƒβ€²β€²πΏπ‘ π‘–π‘›(πœƒ) + (πœƒβ€²)2Lcos (πœƒ)


Newton’s second law states that the force is equal to the mass times its acceleration.

Thus, in the < π‘₯, 0,0 > direction we have the following equation.

βˆ‘πΉπ‘œπ‘Ÿπ‘π‘’π‘ π‘₯ π‘π‘’π‘›π‘‘π‘’π‘™π‘’π‘š = π‘šπ‘Žπ‘ π‘ βˆ™π‘Žπ‘π‘π‘’π‘™π‘’π‘Ÿπ‘Žπ‘‘π‘–π‘œπ‘›x

βˆ’π‘‡π‘ π‘–π‘›(πœƒ) βˆ’ 1/L[πœ‡1 πœ”cos (πœƒ)] = π‘š βˆ™ π‘₯β€²β€²

i) βˆ’𝑇𝑠𝑖𝑛(πœƒ) βˆ’ 1/L[πœ‡1 πœƒβ€²cos (πœƒ)] = π‘š βˆ™ [π‘₯β€²β€² + 𝐿(πœƒβ€²β€² cos(πœƒ) βˆ’ (πœƒβ€²)2 sin(πœƒ))]


βˆ‘πΉπ‘œπ‘Ÿπ‘π‘’π‘ π‘¦ π‘π‘’π‘›π‘‘π‘’π‘™π‘’π‘š =π‘šπ‘Žπ‘ π‘ βˆ™π‘Žπ‘π‘π‘’π‘™π‘’π‘Ÿπ‘Žπ‘‘π‘–π‘œπ‘›π‘¦

π‘‘π‘π‘œπ‘ (πœƒ) βˆ’ π‘šπ‘” βˆ’ 1/L[πœ‡1 πœ”𝑠𝑖𝑛 (πœƒ)] = π‘š βˆ™ 𝑦′′

ii) π‘‡π‘π‘œπ‘ (πœƒ) βˆ’ π‘šπ‘” βˆ’ 1/L[(πœ‡1)πœƒβ€² π‘ π‘–𝑛(πœƒ)]  = π‘š βˆ™ [πœƒβ€²β€²πΏπ‘ π‘–π‘›(πœƒ) + 𝐿(πœƒβ€²)2cos (πœƒ)]


2.1 Newton’s second law for the cart

Here, we will follow the same steps as before, but this time will apply them to the cart. This will give us the equations of motion for the cart. Clearly, the cart will have no acceleration on < 0, 𝑦, 0 > direction.

βˆ‘πΉπ‘œπ‘Ÿπ‘π‘’π‘ π‘₯ π‘π‘Žπ‘Ÿπ‘‘ = π‘šπ‘Žπ‘ π‘ βˆ™π‘Žπ‘π‘π‘’π‘™π‘’π‘Ÿπ‘Žπ‘‘π‘–π‘œπ‘›π‘₯

βˆ’π‘˜π‘₯ βˆ’ πœ‡2𝑣 + 𝑇𝑠𝑖𝑛(πœƒ) + 1/L[πœ‡1 πœ”cos (πœƒ)] = M βˆ™ π‘₯β€²β€²

iii) π‘‡π‘ π‘–𝑛(πœƒ) + 1/L[πœ‡1πœƒβ€²cos(πœƒ)] βˆ’ π‘˜π‘₯ βˆ’ πœ‡2π‘₯β€² = π‘€βˆ™π‘₯β€²β€²


βˆ‘πΉπ‘œπ‘Ÿπ‘π‘’π‘ π‘¦ π‘π‘Žπ‘Ÿπ‘‘ =π‘šπ‘Žπ‘ π‘ βˆ™π‘Žπ‘π‘π‘’π‘™π‘’π‘Ÿπ‘Žπ‘‘π‘–π‘œπ‘›π‘¦

𝑁 + (πœ‡1 πœƒβ€²cos (πœƒ))/L βˆ’ 𝑀𝑔 βˆ’ π‘‡π‘π‘œπ‘ (πœƒ) = 0


3. Equations of motion

Clearly, there are three main equations derived from Newton’s second law. There are two equations from the pendulum β€˜i)’ and β€˜ii)’, and only one equation from the cart β€˜iii)’ since the cart has no acceleration in the < 0, 𝑦, 0 > direction.

i) βˆ’𝑇𝑠𝑖𝑛(πœƒ) βˆ’ 1/L[πœ‡1 πœƒβ€²cos (πœƒ)] = π‘š βˆ™ [π‘₯β€²β€² + 𝐿(πœƒβ€²β€² cos(πœƒ) βˆ’ (πœƒβ€²)2 sin(πœƒ))]

ii) π‘‡π‘π‘œπ‘ (πœƒ) βˆ’ π‘šπ‘” βˆ’ 1/L[(πœ‡1)πœƒβ€² π‘ π‘–𝑛(πœƒ)]  = π‘š βˆ™ [πœƒβ€²β€²πΏπ‘ π‘–π‘›(πœƒ) + 𝐿(πœƒβ€²)2cos (πœƒ)]

iii) π‘‡π‘ π‘–𝑛(πœƒ) + 1/L[πœ‡1πœƒβ€²cos(πœƒ)] βˆ’ π‘˜π‘₯ βˆ’ πœ‡2π‘₯β€² = π‘€βˆ™π‘₯β€²β€²

If we were to add equation β€˜i)’ and β€˜iii)’ together we would be creating, and simplifying, a new equation which we will call β€˜iv)’ as such.

βˆ’π‘‡π‘ π‘–π‘›(πœƒ) βˆ’ 1/L[πœ‡1 πœƒβ€²cos (πœƒ)] + 𝑇𝑠𝑖𝑛(πœƒ) + 1/L[πœ‡1πœƒβ€²cos(πœƒ)]βˆ’ π‘˜π‘₯ βˆ’ πœ‡2π‘₯β€² = [ π‘š βˆ™ [π‘₯β€²β€² + 𝐿(πœƒβ€²β€² cos(πœƒ) βˆ’ (πœƒβ€²)2 sin(πœƒ))] ] + [π‘€βˆ™π‘₯β€²β€²]

βˆ’ π‘˜π‘₯ βˆ’ πœ‡2π‘₯β€² = π‘₯β€²β€² (m + M) + Lm(πœƒβ€²β€² cos(πœƒ) – (πœƒβ€²)2 sin(πœƒ))

iv) π‘₯β€²β€² (m + M)+ π‘˜π‘₯ + πœ‡2π‘₯β€² = Lm((πœƒβ€²)2 sin(πœƒ) – πœƒβ€²β€² cos(πœƒ))

This new equation β€˜iv)’ is particularly useful because it removes the unknown tension β€˜T’ from one of the equations. Thus, leaving us with the following two formulas.

ii) π‘‡π‘π‘œπ‘ (πœƒ) βˆ’ π‘šπ‘” βˆ’ 1/L[(πœ‡1)πœƒβ€² π‘ π‘–𝑛(πœƒ)]  = π‘š βˆ™ [πœƒβ€²β€²πΏπ‘ π‘–π‘›(πœƒ) + 𝐿(πœƒβ€²)2cos (πœƒ)]

iv) π‘₯β€²β€² (m + M)+ π‘˜π‘₯ + πœ‡2π‘₯β€² = Lm((πœƒβ€²)2 sin(πœƒ) – πœƒβ€²β€² cos(πœƒ))

However, we still have tension β€˜π‘‡β€™ as an unknown variable in equation β€˜π‘–π‘–)’. To get rid of it, one can multiply β€˜i)’ by cos (πœƒ) and β€˜ii)’ by sin (πœƒ) and add them together, we will call this new equation β€˜v)’.

[i)βˆ™cos(ΞΈ)]

βˆ’π‘‡π‘ π‘–π‘›(πœƒ)cos (πœƒ) βˆ’ 1/L[πœ‡1 πœƒβ€²cos2(πœƒ)] = π‘šπ‘₯β€²β€²cos (πœƒ) + πΏπ‘šπœƒβ€²β€² cos2(πœƒ) βˆ’ πΏπ‘š(πœƒβ€²)2 sin(πœƒ) cos (πœƒ)

[ii)βˆ™sin(ΞΈ)]

𝑇𝑠𝑖𝑛(πœƒ)π‘π‘œπ‘ (πœƒ) βˆ’ π‘šπ‘” βˆ™ sin (πœƒ) βˆ’ 1/L[πœ‡1 πœƒβ€² π‘ π‘–𝑛2(πœƒ)]  = πΏπ‘šπœƒβ€²β€²π‘ π‘–π‘›2(πœƒ) + πΏπ‘š(πœƒβ€²)2sin (πœƒ)cos (πœƒ)

[i)βˆ™cos(ΞΈ)]+ [ii)βˆ™ sin(ΞΈ)]

βˆ’ 1/L[πœ‡1]πœƒβ€²(𝑠𝑖𝑛2(πœƒ) + cos2(πœƒ)) βˆ’ π‘šπ‘” βˆ™ sin(πœƒ)  = πΏπ‘šπœƒβ€²β€²[𝑠𝑖𝑛2(πœƒ) + cos2(πœƒ)] + π‘šπ‘₯β€²β€² cos(πœƒ)

v) βˆ’1/Lπœ‡1 πœƒβ€² βˆ’ π‘šπ‘” βˆ™ sin(πœƒ)  = πΏπ‘šπœƒβ€²β€² + π‘šπ‘₯β€²β€² cos(πœƒ)

Finally, we are left with two equations without the tension variable β€˜π‘‡β€™.

iv) π‘₯β€²β€²(π‘š + 𝑀) + π‘˜π‘₯ + πœ‡2π‘₯β€² = πΏπ‘š[(πœƒβ€²)2 sin(πœƒ) βˆ’ πœƒβ€²β€² cos(πœƒ)]

v) βˆ’1/Lπœ‡1 πœƒβ€² βˆ’ π‘šπ‘” βˆ™ sin(πœƒ)  = πΏπ‘šπœƒβ€²β€² + π‘šπ‘₯β€²β€² cos(πœƒ)


3.1 Solving second derivative in terms of lower derivative variables

Clearly, β€˜iv)’ and β€˜v)’ are equations in terms of first and second derivatives of the angle and position. However, before we can transform them as two first order DE’s, we would first need to write πœƒβ€²β€² and π‘₯β€²β€² in terms of lower derivative variables that is πœƒ, πœƒβ€² and π‘₯, π‘₯β€². To do so, we need to multiply equation β€˜v)’ by cos (ΞΈ) and add equation β€˜iv)’ thereby eliminating πœƒβ€²β€² from the equation. Then, solving for π‘₯’’ will input a new equation which we will call β€˜vi)’.

[v)βˆ™cos(ΞΈ)]

βˆ’ 1/L[πœ‡1 πœƒβ€²cos (πœƒ)] βˆ’ π‘šπ‘” βˆ™ sin(πœƒ)cos (πœƒ) = πΏπ‘šπœƒβ€²β€²cos (πœƒ) + π‘šπ‘₯β€²β€² cos2(πœƒ)

[v)βˆ™cos(ΞΈ)]+[iv)]

π‘₯β€²β€²(π‘š + 𝑀) + π‘˜π‘₯ + πœ‡2π‘₯β€² βˆ’ 1/L[πœ‡1 πœƒβ€² cos(πœƒ)] βˆ’ π‘šπ‘” βˆ™ sin(πœƒ) cos(πœƒ) = π‘šπ‘₯β€²β€² cos2(πœƒ) + πΏπ‘š(πœƒβ€²)2 sin(πœƒ)

π‘₯β€²β€²(π‘š + 𝑀) βˆ’ π‘šπ‘₯β€²β€² cos2(πœƒ) = πΏπ‘š(πœƒβ€²)2sin(πœƒ) + π‘šπ‘” βˆ™ sin(πœƒ)cos(πœƒ) + 1/L[πœ‡1 πœƒβ€² cos(πœƒ)] βˆ’ π‘˜π‘₯ βˆ’ πœ‡2π‘₯β€²

π‘₯β€²β€²[(π‘š + 𝑀) βˆ’ π‘š cos2(πœƒ)] = πΏπ‘š(πœƒβ€²)2 sin(πœƒ) + π‘šπ‘” βˆ™ sin(πœƒ) cos(πœƒ) + 1/L[πœ‡1 πœƒβ€² cos(πœƒ)] βˆ’ π‘˜π‘₯ βˆ’ πœ‡2π‘₯β€²

π‘₯β€²β€² = [ πΏπ‘š(πœƒβ€²)2 sin(πœƒ) + π‘šπ‘” βˆ™ sin(πœƒ) cos(πœƒ) + 1/L[πœ‡1 πœƒβ€² cos(πœƒ)] βˆ’ π‘˜π‘₯ βˆ’ πœ‡2π‘₯β€² ] / [ (π‘š + 𝑀) βˆ’ π‘š cos2(πœƒ) ]

π‘₯β€²β€² = [ πΏπ‘š(πœƒβ€²)2 sin(πœƒ) + π‘šπ‘” βˆ™ sin(πœƒ) cos(πœƒ) + 1/L[πœ‡1 πœƒβ€² cos(πœƒ)] βˆ’ π‘˜π‘₯ βˆ’ πœ‡2π‘₯β€² ] / [(π‘š + 𝑀) βˆ’ π‘š (1 + sin2(πœƒ))]

π‘₯β€²β€² = [ πΏπ‘š(πœƒβ€²)2 sin(πœƒ) + π‘šπ‘” βˆ™ sin(πœƒ) cos(πœƒ) + 1/L[ πœ‡1 πœƒβ€² cos(πœƒ)] βˆ’ π‘˜π‘₯ βˆ’ πœ‡2π‘₯β€² ] / [𝑀 + m βˆ™ sin2(πœƒ)]

Now, we can multiply equation β€˜v)’ by (π‘š + 𝑀) and multiply equation β€˜iv)’ by π‘š βˆ™ cos (πœƒ) and add them together thereby allowing the isolation of πœƒβ€²β€² in one single equation which we will call β€˜vii)’.

[v)βˆ™(m+M)]

(π‘š+𝑀)βˆ™1/L[βˆ’πœ‡1πœƒβ€² βˆ’π‘šπ‘”βˆ™sin(πœƒ)] = (π‘š+𝑀)πΏπ‘šπœƒβ€²β€² +π‘šπ‘₯β€²β€²(π‘š+𝑀)cos(πœƒ)

[iv) βˆ™ mcos(ΞΈ)]

π‘šπ‘₯β€²β€²(π‘š + 𝑀)cos (πœƒ) + π‘˜π‘₯π‘šcos (πœƒ) + πœ‡2π‘₯β€²cos (πœƒ) = πΏπ‘š2(πœƒβ€²)2 sin(πœƒ)cos (πœƒ) βˆ’ πΏπ‘š2πœƒβ€²β€² cos2(πœƒ)

[v)βˆ™(m+M)] + [iv)βˆ™mcos(ΞΈ)]

βˆ’(π‘š + 𝑀)1/L( πœ‡1 πœƒβ€²) βˆ’ (π‘š + 𝑀)π‘šπ‘” βˆ™ sin(πœƒ) + π‘˜π‘₯π‘š cos(πœƒ) + πœ‡2π‘₯β€²cos (πœƒ) = (π‘š + 𝑀)πΏπ‘šπœƒβ€²β€² + πΏπ‘š2(πœƒβ€²)2 sin(πœƒ)cos (πœƒ) βˆ’ πΏπ‘š2πœƒβ€²β€² cos2(πœƒ)

βˆ’(π‘š + 𝑀)1/L( πœ‡1 πœƒβ€²) βˆ’ (π‘š + 𝑀)π‘šπ‘” βˆ™ sin(πœƒ) + π‘˜π‘₯π‘š cos(πœƒ) + πœ‡2π‘₯β€²cos (πœƒ) – πΏπ‘š2(πœƒβ€²)2 sin(πœƒ)cos (πœƒ) = (π‘š + 𝑀)πΏπ‘šπœƒβ€²β€²βˆ’ πΏπ‘š2πœƒβ€²β€² cos2(πœƒ)

βˆ’(π‘š + 𝑀)1/L( πœ‡1 πœƒβ€²) βˆ’ (π‘š + 𝑀)π‘šπ‘” βˆ™ sin(πœƒ) + π‘˜π‘₯π‘š cos(πœƒ) + πœ‡2π‘₯β€²cos (πœƒ) – πΏπ‘š2(πœƒβ€²)2 sin(πœƒ)cos (πœƒ) / (π‘š + 𝑀)πΏπ‘šβˆ’ πΏπ‘š2cos2(πœƒ) = πœƒβ€²β€²

βˆ’(π‘š + 𝑀)1/L( πœ‡1 πœƒβ€²) βˆ’ (π‘š + 𝑀)π‘šπ‘” βˆ™ sin(πœƒ) + π‘˜π‘₯π‘š cos(πœƒ) + πœ‡2π‘₯β€²cos (πœƒ) – πΏπ‘š2(πœƒβ€²)2 sin(πœƒ)cos (πœƒ) / (π‘š + 𝑀)πΏπ‘šβˆ’ πΏπ‘š2(1-sin2(πœƒ)) = πœƒβ€²β€²

βˆ’(1 + 𝑀/m)1/L( πœ‡1 πœƒβ€²) βˆ’ (π‘š + 𝑀)𝑔 βˆ™ sin(πœƒ) + π‘˜π‘₯ cos(πœƒ) + πœ‡2π‘₯β€²cos (πœƒ) – πΏπ‘š(πœƒβ€²)2 sin(πœƒ)cos (πœƒ) / L(M+msin2(πœƒ)) = πœƒβ€²β€²

βˆ’ (π‘š + 𝑀)π‘”βˆ™ sin(πœƒ) – πΏπ‘š(πœƒβ€²)2 sin(πœƒ)cos (πœƒ βˆ’ (1 + 𝑀/m)1/L( πœ‡1 πœƒβ€²) + cos(πœƒ)βˆ™[π‘˜π‘₯ + πœ‡2π‘₯β€²] / L(M+msin2(πœƒ)) = πœƒβ€²β€²

Now, we have two single variable-independent equations β€˜vi)’ and β€˜vii)’

vi) π‘₯β€²β€² = [ πΏπ‘š(πœƒβ€²)2 sin(πœƒ) + π‘šπ‘” βˆ™ sin(πœƒ) cos(πœƒ) + 1/L[ πœ‡1 πœƒβ€² cos(πœƒ)] βˆ’ π‘˜π‘₯ βˆ’ πœ‡2π‘₯β€² ] / [𝑀 + m βˆ™ sin2(πœƒ)]

vii) πœƒβ€²β€² = βˆ’ (π‘š + 𝑀)π‘”βˆ™ sin(πœƒ) – πΏπ‘š(πœƒβ€²)2 sin(πœƒ)cos (πœƒ βˆ’ (1 + 𝑀/m)1/L( πœ‡1 πœƒβ€²) + cos(πœƒ)βˆ™[π‘˜π‘₯ + πœ‡2π‘₯β€²] / L(M+msin2(πœƒ))


3.2 First order DE transformation

Now that we have two equations in terms of lower derivative variables, we can re-write them as two first order differential equations which is essential if we want to solve them numerically using π‘…𝑒𝑛𝑔𝑒 πΎπ‘’π‘‘π‘‘π‘Ž methods. Thus, we would need to re-write the variables as such:

π‘₯β€² = 𝑣

πœƒβ€² = πœ”

𝑣′ = [ πΏπ‘šπœ”2sin(πœƒ) + π‘šπ‘”βˆ™sin(πœƒ)cos(πœƒ) + 1/L(πœ‡1πœ”cos(πœƒ))βˆ’π‘˜π‘₯βˆ’πœ‡2𝑣) ] / [ 𝑀 + mβˆ™sin2(πœƒ) ]

πœ”’ = [ βˆ’(π‘š+𝑀)π‘”βˆ™sin(πœƒ) βˆ’ πΏπ‘šπœ”2sin(πœƒ)cos(πœƒ) βˆ’ (1+𝑀)(1/L)πœ‡1πœ” + cos(πœƒ)[π‘˜π‘₯ + πœ‡ 𝑣] ] / [𝐿(𝑀 + π‘šπ‘ π‘–π‘›2(πœƒ))]

This method of re-writing is particularly useful when coding in python because we will be able to assign variables π‘₯, πœƒ, 𝑣, 𝑀, 𝑣′, 𝑀′, which are functions, to each component of the mechanical system; that is the cart and the pendulum.


4. Mechanical System in Python

Before we can model the system in python, we will import the necessary libraries which will allows us to use trigonometric functions, lines, etc.

import numpy as np                            # necessary libraries
import matplotlib.pyplot as plt
import scipy.integrate as integrate
import matplotlib.animation as animation      

Similarly, we will need to choose certain parameters for our mechanical system. These will be the default parameters for all scenarios studied below.

M = 5     # Mass of the cart
m = 0.1   # mass of the pendulum
k = 25    # spring constant
L = 0.5   # lenght of string
g = 9.8   # gravitational acceleration 
u1 = 0.1  # friction coefficient pendulum
u2 = 20   # friction coefficient cart

Then, we will need to assign the derivatives of our equations β€˜π‘£π‘–)’ and β€˜π‘£π‘–π‘–)’ certain states. Here, clearly:

π‘‘π‘’π‘Ÿ[0] = π‘₯β€² π‘ π‘‘π‘Žπ‘‘π‘’ [1] = 𝑣 π‘‘π‘’π‘Ÿ[2] = πœƒβ€² π‘ π‘‘π‘Žπ‘‘π‘’[3] = πœ”

As explained above, this is the way we’re writing our four equations in python.

def der_state(t, state):                                          # Here, we are writing first order DE.
        """compute the derivative of the given state"""
        
        der = np.zeros_like(state)
        der[0] = state[1]           #    state[0] = x
        der[2] = state[3]           #    state[2] = theta
        der[1] = ((((L*m)*state[3]**2)*np.sin(state[2])) + m*g*np.sin(state[2])*np.cos(state[2]) + (u1/L)*state[3]*np.cos(state[2]) - k*state[0] - u2*state[1])/(M + m*np.sin(state[2])*np.sin(state[2]))
        der[3] = (-(m + M)*g*np.sin(state[2]) - (L*m)*(state[3]**2)*np.sin(state[2])*np.cos(state[2]) - (1 + (M/m))*(u1/L)*state[3] + np.cos(state[2])*(k*state[0] + u2*state[1]))/(L*M + L*m*np.sin(state[2])*np.sin(state[2]))
        return der

Similarly, we will need to choose an initial condition. Otherwise, neither the cart nor the pendulum will have motion. We will choose an initial condition on the cart and on the angle of the pendulum.

state0 = ([1, 0, 1, 0]) # [x],[x'],[theta],[theta'] initial conditions

The following code was used to solve the differential equations above. Then, the following set of code is used to define the cartesian coordinates so that we can plot on the graph.

sol = integrate.solve_ivp(der_state, (0, tf), state0, t_eval=T)     #this solves both previous DE.
ang_pendulum_pos = sol.y[2]
x_quisite_position_cart = sol.y[0]

# Cartesian coordinates
x2 = x_quisite_position_cart
y2 = 0 # no motion in y direction.

x = x2 + L*np.sin(ang_pendulum_pos)
y = -L*np.cos(ang_pendulum_pos) #the y-axis points down

We will also import another library from matplotlib which will let us display the animation on our screen. We will set up an axis, provide limits, and the type of grid as follows:

from matplotlib import rc
rc('animation', html='html5')

fig = plt.figure()
ax = fig.add_subplot(111, autoscale_on=False, xlim=(-2, 2.1), ylim=(-1, 1))       # setting the graph axis
ax.grid()

Finally, we will define all our objects (cart, pendulum, lines, table, wall, spring), we will assign them colors, width, size, type of lines (using matplotlib libraries). All of these are explained in the full code provided. Thus, giving us something that looks like this:


4.1 Evaluating certain scenarios

Now, we have a working mechanical system in python.

https://colab.research.google.com/

Thus, we will start the evaluation of certain scenarios. In total we will study three main scenarios plus two interesting cases, these being:

  • Over damped system
  • Underdamped system
  • Critically damped system
  • System under Moon’s gravity
  • System with heavy pendulum

Scenario #1

The system is overdamped. For this scenario, we will continue using the initial conditions and parameters of above, but we will only change the value of the cart’s friction coefficient β€˜πœ‡2’ to 20 thereby giving it a significant opposing force.

Clearly our code’s graphical representation of the system demonstrates that, with a high friction coefficient, the cart stops all motion in 1/4 of its period. The pendulum, however, can achieve some oscillation but immediately decays when the cart ultimately stops.

Scenario #2

The system is underdamped. Similarly, this scenario will continue using the initial conditions and parameters of above. However, this time we will change the value of the cart’s friction coefficient β€˜πœ‡2’ to 0.1 thereby giving it a non-significant opposing force.

This time, the system will experience some simple harmonic behaviour. We see the cart and pendulum oscillate back and forth with almost no varying amplitude. This is anticipated since there is almost no resistance on neither of the components of the mechanical system.

Scenario #3

The system is critically damped. Likewise, this scenario will continue using the initial conditions and parameters of above. However, this time we will change the value of the cart’s friction coefficient β€˜πœ‡2’ to 15 thereby giving it a significant but critical opposing force.

This is an interesting case because it demonstrates how the system returns to its equilibrium position faster than the overdamped scenario. With our chosen value of the cart’s friction coefficient, we see some overshooting thereby implying that this is a fraction of the actual of the critically damped value.

Scenario #4

The system under Moon’s gravity. This scenario will continue using the initial conditions and parameters of above. However, this time we will change the value of gravitational acceleration to one sixth of earths which corresponds to 1.62 π‘š/s2 , the Moon’s surface gravity.

This is, particularly, an interesting case. It is possible to see the pendulum oscillate much more than it did with Earth’s gravity. Similarly, the cart’s motion is affected much more by the pendulum and thus its horizontal velocity is much faster.

Scenario #5

The system with heavy pendulum. This scenario will use the same initial conditions and parameters of above. However, this time only the mass of the pendulum β€˜m’ will be changed to 4Kg instead of 0.1Kg.

Clearly, this is another simple harmonic oscillator case. The heavy pendulum, in combination with the low friction coefficients, results in a system that oscillates much faster than the previous cases. Similarly, this scenario possesses lots of momentum. Thus, resulting in a bigger amplitude. Lastly, the initial condition chosen plus the big mass of the pendulum, provide a significant initial conservative force which is immediately converted into kinetic energy thereby increasing the speed of oscillation.


5. Conclusion

Ultimately, this project has analyzed and modeled a pendulum-cart mechanism. B.R.I.T applied equations of motion and Newton’s second law to derive four new equations. These four were mathematically manipulated leading to two known single-variable second order differential equations. Then, these two new equations were re-written as two first order differential equations allowing python, our program of choice, to solve them numerically thereby allowing us to represent the mechanical system graphically.


5.1. Resources

B.R.I.T made use of the following resources.

Neumann, E. (2021, June 25). Cart + Pendulum, retrieved from myPhysicsL⍺b.com

https://www.myphysicslab.com/

n/a (2002). Runge-Kutta Method, retrived from ScienceDirect.com

https://www.sciencedirect.com/

Hunter J. (2012). Matplotlib.axes.Axes.plot, retrieved from matplotlib.org

https://matplotlib.org/

B.R.I.T would also like to thank professor Ivan T. Ivanov for its guidance and mentorship.

Recommended Articles