Erratum: I have now fixed the errors that were present in the calculations in the previous version of the post.
This term I am teaching a course on modelling dynamical systems. In this post I will present a simple example of modelling a cart-pendulum system (see Fig. 1).
Fig. 1. A cart-pendulum system.
The system consists of a pendulum mounted on a cart sliding horizontally. The pendulum is assumed to be a point mass hanging on a massless wire at an angle of θ The cart is pushed by some external force u=f(t) and its position is defined as z The following parameters define the properties of the system:mass of the cart m1, mass of the pendulum m2 and the length of the pendulum l.
The problem is formulated as follows. Find the equations of motion for the system using Lagrange equations. Linearize the non-linear model obtained. Observe and compare the behaviour of both the linear and the non-linear models.
We will solve it in the following steps:
1) How many degrees of freedom (DoF) do we have here?
2) What form of Lagrange equations should we use?
3) What’s the kinetic energy (K) and the potential energy (U) of the system?
4) Solve Lagrange equations.
5) Define state-space non-linear model.
6) Linearize the model.
7) Simulate the behaviour of the models using Matlab.
1) How many degrees of freedom (DoF) do we have here?
2) What form of Lagrange equations should we use?
3) What’s the kinetic energy (K) and the potential energy (U) of the system?
4) Solve Lagrange equations.
5) Define state-space non-linear model.
6) Linearize the model.
7) Simulate the behaviour of the models using Matlab.
Let’s go!
1) First, it is quite obvious that the system has two degrees of freedom: z and θ.
It ought to be said that there are several ways these generalized coordinates can be chosen, but this is the most convenient choice in this problem.
It ought to be said that there are several ways these generalized coordinates can be chosen, but this is the most convenient choice in this problem.
2) The Lagrange equations for this system are going to be in the following form:
3) Since the Lagrangian of the system is defined as its kinetic energy K minus its potential energy U, we have to find out what K and U are. There are two bodies in the system that have masses (m1 and m2). K will therefore be:
We have to be careful while calculating velocities v1 and v2. The velocity v1 is straightforward, but v2 consists of the carrying linear motion of the cart plus the motion of the pendulum relative to the cart. Moreover, the velocity of the pendulum around the cart can be split into two orthogonal vectors: and .
Since and are calculated as follows:
The will be:
The kinetic energy K will therefore be:
The potential energy U is associated with the mass of the pendulum m2 hanging in the gravitational field. Here, we are going to introduce temporary variable y which describes the vertical displacement of the pendulum:
4) Having calculated both K and U, we can formulate the Lagrangian:
In order to solve the equation, we have to calculate these pesky partial derivatives - first for z, and then for θ. I did this in WolframAlpha.
Now, subsituting the derivatives and the generalized force u into the Lagrange equations, we get a system:
We are not going to calculate this by hand. I have used the following WolframAlpha query (and then substituted the names of variables back):
solve for x, y: (m+n)x+nl(ycos(f)-w^2sin(f))=u, xlcos(f)+yl^2+glsin(f)=0
The equations of motion are:
5) We can now construct the (non-linear) state-space model. This is done by first naming the state-space variables:
and then substituting into the equations above:
This non-linear system is of form:
where, for instance:
6) Linearization of the system is done by replacing the non-linear functions with their first-order approximations at selected “operating point”. Mathematically this is one by assuming the following linear model:
The Δx, Δu and Δy are defined as offsets from the operating point:
Let’s define our operating point as:
The matrices A, B, C and D are calculated as:
It isn’t as scary as it looks. just says that we have to calculate the derivatives of functions , and so on partially over , etc. and put them into the matrix A. The says: after calculating the derivative, substitute and (assumed previously) into the equation.
I have used the following WolframAlpha queries to compute the (non-trivial) derivatives A23, A24 and A43, A44:
d/dx (nsin(x)(gcos(x)+ld^2)+u)/(-ncos(x)^2+m+n)
d/dy (nsin(x)(gcos(x)+ly^2)+u)/(-ncos(x)^2+m+n)
d/dx -(gsin(x)(m+n)+cos(x)(lnd^2sin(x)+u))/(l(-ncos(x)^2+m+n))
d/dy -(gsin(x)(m+n)+cos(x)(lny^2sin(x)+u))/(l(-ncos(x)^2+m+n))
Similarly, B would be:
In order to observe all state variables, define C = I. D has to be filled with zeros, with dimensions that agree with B and C.
7) We can now see how these work!
The scripts for this problem can be found at: https://github.com/dagothar/mos03
The scripts for this problem can be found at: https://github.com/dagothar/mos03
By default, they generate the object response with u=0, but with a starting condition in which the pendulum starts at a positive angle to the vertical. And here are the results:
Fig. 2. Reponse of the non-linear system (to the left) and of the linearized system (to the right).
The responses seem very similar when a small initial angle displacement is given. Things change when the pendulum is placed at a larger starting angle.
Can you guess what happens?
Can you guess what happens?
No comments:
Post a Comment