Seth on Simulink
February 26th, 2009
Modeling Mechanical Systems: The Double Pendulum
Do you ever have to model mechanical systems? Mechanical
systems consist of bodies, joints, and force elements like springs. In this post,
I will show you how to model a double pendulum with base Simulink and using SimMechanics.
Pendulum: Equations of Motion
Most of the models I work with are representations of data
flow and algorithms. If you want a model of a mechanical system, you need the
equations of motion so you can build the system from base Simulink blocks. Of
course, if you don’t know the equations for a pendulum, you must derive them.

If you start with that equation, and follow the process
described in a previous post about how
to draw ODEs, the model of a pendulum looks like this:

This model is a graphical representation of mathematical
operations and algorithm elements. Simulink solves the differential equation
by evaluating the individual blocks according to the sorted order to compute
derivatives for the states. The solver uses numeric integration to compute the
evolution of states through time.
Drawing the Mechanical System
SimMechanics provides an alternative to deriving equations
and implementing them with base blocks. Instead of representing a mathematical
model of the system, we develop a representation that describes the key
components of the mechanical system. The base units in SimMechanics are
physical elements instead of algorithm elements. To build a SimMechanics model,
you must break down the mechanical system into the building blocks that describe
it. When you think about the pendulum, it a body connected to a joint, and
that joint is connected to some kind of base, we will call that the ground.

The base elements in the SimMechanics library have special
names that precisely describe what they are. I didn’t know this until I
started using SimMechanics, but the joint in my pendulum example is called a
Revolute. To build this system, we grab the appropriate blocks and connect
them together (kind of like playing with legos!). The ports on the
SimMechanics blocks are connector ports, and the “signals” running between them
are connector lines. These lines do not represent data flow, they represent
mechanical connections between elements.

These special connection lines and connection ports cannot
connect directly to Simulink signals and ports. Sensors allow you to tap into
a mechanical component and measure its physical properties. In my pendulum
model above, I have measured the angular position (ap) and angular velocity
(av) of the revolute joint.
When you simulate a SimMechanics model, the process is a
little different from regular Simulink data flow. At initialization,
SimMechanics analyzes the mechanical system to determine the topology and
geometry of the machine. At run-time, the external forces and torques are
applied to the machine, integrated, and the machine state is updates. Because
the model may contain constraints, the solver checks for the agreement of all
the elements of the machine within acceptable tolerances. The “blocks” that
make up the machine do not run one at a time in the simulation loop like
regular Simulink blocks.
The Double Pendulum: Equations of Motion
Let’s compare the modeling process for a double pendulum
between base Simulink blocks and using SimMechanics. I don’t know the
equations of motion for a double pendulum off the top of my head, so we can
derive them.

Aside from the cramp in my hand from attempting to make my
writing legible, the implementation in base blocks is a little more difficult.
There are physical connections between the state variables, and if implemented
as written above, you get algebraic loops.

Drawing the Double Pendulum
To make a double pendulum using SimMechanics I just
duplicate the first joint and body to make a second arm connected at the end of
the first.

In literally seconds, I converted the pendulum model to a
double pendulum model.

Now It’s Your Turn
How would you model a three-jointed pendulum? How about N-joints?
Leave a comment
here and let us know if you would derive the equations, or reach for
SimMechanics.
17:35 UTC |
Posted in Modeling, ODEs, Physical Modeling, Simulation |
Permalink |
You can follow any responses to this entry through the RSS 2.0 feed.
You can skip to the end and leave a response. Pinging is currently not allowed.
Leave a Reply
|
I am fascinated with SimMechanics. It must be annoying that all the effort to built a base-simulink model is just a trash!
Anyway, now that you had 2 models, could you please post a comparison of the outputs?
@Arda,
I posted a comparaison of the algorithm in Simulink blocks and in SimMechanics in the same model:
http://www.mathworks.com/matlabcentral/fileexchange/23126
You will see that results from the two implementation are similar.
this is a wonderfull work from you sir i will certainly use simMechanics but knowing how to model the systen by hand is als very important
Dear Mr. Seth Popinchalk.
I could not rest in peace any longer. This blog post trivializes my life’s work! My second method allows us to determine stability of system without solving model’s ODE! SimMechanics gives no insight into stability! Why you use it!? What if, for some obscure initial condition not likely to be simulated, your system is unstable? how will you know? You make mistake to simulate system and not check stability? You must check stability! Checking stability means knowing dynamics! Mr Seth and Mr Guy, your attempt to destroy my work has failed! Read my book: The general problem of the stability of motion.
I agree with mr. Amayreh’s comments. I add this to it: it is important to model system with pencil, paper and simulate using abacus only! No shortcut.
This is good education time, not LEGOS play time!
SimMechanics is Blasphemy!
Good bye.
Aleksandr Mikhailovich Lyapunov
My, my…it seems that our friend Dr. Lyapunov is a bit agitated with the marvellous SimMechanics.
Perhaps I can offer a few words in your favour, Mr Guy, to alleviate my colleagues acerbic, vituperative vitriolic remarks.
The value of your tool seems to lie in exactly the characteristic in question. Namely, that it does not need dynamic analysis of the system being modelled. Perhaps if this tool was available to us in my youth, I would not have been sidetracked by a pesky initial condition in my Lorenz Equation describing the weather for 50 years.
My detailed 12th order model of the weather system failed to produce the results expected-all that modelling for nothing-proving that building mathematical models may not be worth it sometimes.
If I had not been trying to discover the chaotic behavior arising from my equations 50 years ago, perhaps today we could have solved global warming….and that, my friend, would have become known as the REAL butterfly effect!
Former Professor at MIT
Dr. Ed Lorenz
It is a wonderful tool Mr. Seth Popinchalk. I would like to know if I can do the same for Electronic and Electric systems?
Sincerely
Alejandro
@Alejandro - There are a few tools you should look at: SimScape, SimElectronics and SimPowerSystems. Your choice of which tool to use will depending on what you are trying to model. Good luck!
realy nice, but now i have build a mobile robot motion models, can you help me??
I would say “blasphemy” is to use a man’s good name and reputation to rant in such an insulse manner.
News seem to travel slowly in some parts of the world, sadly,
Edward Norton Lorenz passed away on April 16th, 2008.
Aleksandr Mikhailovich Lyapunov passed away on November 3rd 1918.
It’s everybody’s guess what they would have thought of SimMechanics.
X
Hi Hendry,
It is possible to implement a mobile robot using SimMechanics. To begin, you have to assemble the main parts of the robot, like wheels, suspension and main body. After it is done, the most complex part is to define the interaction of the rover with the ground. One simple solution is to represent the ground as a stiff spring-damper system. Many contact dynamics models have been developed in the past and can be implemented in Simulink, for example the “magic formula” for tires. I can also mention that The MathWorks website provide a list of third party products and some of them are specialized in wheel contact dynamics:
http://www.mathworks.com/products/connections/
To give an example of what a rover model can look like, I just submitted a file on the MATLAB Central. Please look for my profile to find it.
I hope it helps
Guy Rouleau
Dr.that is a nice model,but u have to show the equilibrium configuration too.
@tesfaye - The SimMechanics documentation explains how to compute the equilibrium configuration of a model. This section is titled “Trimming Mechanical Model” and can be found online at:
http://www.mathworks.com/access/helpdesk/help/toolbox/physmod/mech/ug/f0-6194.html
This section uses a double pendulum example where the two sections of the pendulum are linked by a rotational spring.
Great tool, for educational and sicentific, simulation.
I would like to know where can i place a motor for controlling position on inverterted pendulum….thanks…