7. Double Pendulum Simulation
This simulation is about the motion of a double pendulum system, which consists of two pendulums connected end-to-end. The simulation demonstrates the chaotic behavior that can arise in classical mechanical systems due to the inherent nonlinearity of the double pendulum’s equations of motion.
7.1. Use cases in engineering
-
Mechatronics: The double pendulum system serves as a useful model for studying the dynamics and control of robotic arms and legged robots. It provides insights into the challenges of controlling complex, multi-joint systems with nonlinear dynamics.
-
Vibration analysis: Double pendulum systems can be used to study the behavior of more complex vibrating structures, such as suspension bridges or building frames during earthquakes.
-
Chaos and nonlinear dynamics: The study of chaotic systems, like the double pendulum, helps engineers develop a deeper understanding of nonlinear dynamics and its impact on the stability and control of engineering systems.
7.2. Possible useful improvements
-
Implementing a more advanced numerical integration method (e.g., Runge-Kutta) to improve the accuracy of the simulation.
-
Adding control mechanisms, such as PID controllers or model predictive control, to study the stabilization of the double pendulum system.
-
Adding a graphical user interface (GUI) for inputting the parameters, initial conditions, and control strategies, making the simulation more interactive and user-friendly.
-
Extending the simulation to a three-dimensional space, allowing for a more realistic representation of real-world engineering systems.
-
Simulating the effects of friction and damping forces, as well as external disturbances, to better understand their impact on the system’s dynamics and stability.
Check this code on GitHub and you are welcome to improve it.
The double pendulum system can be described using the Lagrangian formalism, where the Lagrangian is defined as the difference between the kinetic and potential energies of the system.
The kinetic energy of the system can be expressed as:
where \(m_1\) and \(m_2\) are the masses of the pendulums, \(L_1\) and \(L_2\) are their lengths, and \(\theta_1\) and \(\theta_2\) are the angles that the pendulums make with respect to the vertical axis. The dots represent the time derivative of the variables.
The potential energy of the system can be expressed as:
where \(g\) is the acceleration due to gravity.
The Lagrangian of the double pendulum system can be written as:
Using the Euler-Lagrange equation, the equations of motion for the double pendulum can be derived. These equations can be written as a set of four coupled, first-order ordinary differential equations:
where \(p_1\) and \(p_2\) are the momenta of the pendulums.
The equations of motion can be implemented in Python as follows:
import numpy as np
from scipy.integrate import solve_ivp
#Double pendulum equations
def double_pendulum_equations(t, y, L1, L2, m1, m2,g):
theta1, theta2, p1, p2 = y
cos_diff = np.cos(theta1 - theta2)
sin_diff = np.sin(theta1 - theta2)
# Angular velocities
theta1_dot = (L2 * p1 - L1 * p2 * cos_diff) / (L1 ** 2 * L2 * (m1 + m2 * sin_diff ** 2))
theta2_dot = (-L1 * m1 * p1 - L1 * m2 * p1 * cos_diff + (m1 + m2) * L2 * p2) / (L1 * L2 ** 2 * (m1 + m2 * sin_diff ** 2))
# Time derivatives of momenta
p1_dot = - (m1 + m2) * g * L1 * np.sin(theta1) - m2 * L1 * L2 * theta2_dot * theta1_dot * sin_diff
p2_dot = - m2 * g * L2 * np.sin(theta2) + m2 * L1 * L2 * theta1_dot * theta2_dot * sin_diff
return [theta1_dot, theta2_dot, p1_dot, p2_dot]
where t
is time, y
is an array of the four variables [theta1
, theta2
, p1
, p2
], and the other parameters L1
, L2
, m1
, m2
, and g
are passed as arguments.
The simulation can be performed using the solve_ivp
function from the scipy.integrate
module. This function integrates the equations of motion over a specified time span using a specified numerical method. The resulting solution is stored in the sol object, which contains the values of the variables at each time step.
The animation of the double pendulum system can be created using the Matplotlib library. The animation function plots the positions of the pendulums at each time step using the x and y coordinates of the pendulum endpoints. The endpoints are calculated using the equations:
where (\(x_1\), \(y_1\)) and (\(x_2\), \(y_2\)) are the endpoints of the first and second pendulums, respectively.
The animation also plots the pendulums as circles, with the first pendulum in red and the second in blue. The current time step is indicated by a black circle. The animation function clears the previous frame, sets the limits of the plot, and adds labels and text to the plot.
Add Comment
This policy contains information about your privacy. By posting, you are declaring that you understand this policy:
- Your name, rating, website address, town, country, state and comment will be publicly displayed if entered.
- Aside from the data entered into these form fields, other stored data about your comment will include:
- Your IP address (not displayed)
- The time/date of your submission (displayed)
- Your email address will not be shared. It is collected for only two reasons:
- Administrative purposes, should a need to contact you arise.
- To inform you of new comments, should you subscribe to receive notifications.
- A cookie may be set on your computer. This is used to remember your inputs. It will expire by itself.
This policy is subject to change at any time and without notice.
These terms and conditions contain rules about posting comments. By submitting a comment, you are declaring that you agree with these rules:
- Although the administrator will attempt to moderate comments, it is impossible for every comment to have been moderated at any given time.
- You acknowledge that all comments express the views and opinions of the original author and not those of the administrator.
- You agree not to post any material which is knowingly false, obscene, hateful, threatening, harassing or invasive of a person's privacy.
- The administrator has the right to edit, move or remove any comment for any reason and without notice.
Failure to comply with these rules may result in being banned from submitting further comments.
These terms and conditions are subject to change at any time and without notice.
Comments