simple inverted pendulum problem/ optimal control

I have a question. yes it's a homework question. I already gave it in so please no "we won't do your homework for you" replies
this is the problem: a mass (1kg) is attached to a rod (0.5 m) the rod is attached at the base and can rotate in one direction
the control variable "u" is the torque applied at the base of the rod in the clockwise direction
the variable "x" is the angle the rod makes with the vertical axis, in the clockwise direction.
in the beginning the rod is at 90 degrees towards the right, in other words the angle "x" is pi/2 and to bring the rod up we apply negative torque "u"
the equation I have is d/dt (dx/dt) = ( g/L ) sin (x) + u/(m*L*L) where d/dt (dx/dt) is the second derivative of x (angular acceleration) , g is gravitational acceleration, m is mass of object and L is length of rod
we "linearize" this by assuming sin(x) ~ x
so d/dt (dx/dt) = C1* x + C2* u
I chose state variables X1 = x and X2 = dx/dt so X1 prime = X2 X2 prime= C1* X1 + C2* u
is everything correct so far?
I have to minimize a performance criterion J = 0.5* integral from 0 to final time of ( (a*x)^2 + u^2) where the final time is specified (1s or 0.5 s) X1(0) = pi/2 final position of X1 is not specified (free) constant "a" in the performance index is 4 I assumed that we start from a 0 velocity (X2(0)=0) and final velocity is free
applying the optimal contol theory, using lagrange multipliers lambda1 and lambda2, my hamiltonian is H=8*X1^2 + 0.5*u^2 + lambda1*X2 + lambda2*C1*X1+lambda2*C2*u
from this I get that u = -C2*lambda2 and the following differential equations
X1 prime = X2 X2 prime = C1*X1-C2^2 * lambda2 lambda1 prime = -16 *X1 - C1*lambda2 lambda2 prime = -lambda1
with X1(0)=pi/2, X2(0)=0 (my assumption, is it correct?) and lambda1(tf)=lambda2(tf)=0
I used Riccati's equation to find my lambdas at 0
in sumulations with matlab I see that within 1 second the position of the pendulum reaches the vertical however the velocity does not reach 0 and the pendulum swings to the other side and the system is unstable. it oscillates wildly.
I can see from my differential equations that a negative lambda2 will make lambda 1 grow more positive which makes lambda 2 grow more negative. this is clearly unstable
however I have redome my calculations so many times and I don't see the problem. what am I missing?
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
mr sparkle wrote:

At 90 degrees?

...
Without the axis of rotation, the problem is underspecified.
Jerry
--
Engineering is the art of making what you want from things you can get.

  Click to see the full signature.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

the
the
words
"u"
, g

rod
well, around 0 it is valid
my problem is that, while my "controller" brings x to 0, after that it starts to oscillate wildly even if I start with initial position = 0.01 radians or something like that, it still becomes unstable.
it's pissing me off because even though I gave the homework , I have an exam in 2 weeks and I need to understand the problem I'm having
I have 4 inter-connected differential equations and my "feedback" is based on one of the lambdas and it's integrated in the differential equations is this closed-loop or openloop?
because if I integrate Riccati backwards I get a steady state solution very soon so I'm basically always starting with the same lambdas, and if my lambda is S*X where S is the ricatti matrix, and my feedback is based on lambda, then it seems like open loop to me. there's something I'm missing. what is it?

it's a 2D problem. there's the vertical axis y and the pendulum pivots around y in the x-y plane. my variable "x" is the angle between the rod and the y axis
if the y axis points up and the x axis points to the right, the torque u, the angle "x" and velocity, acceleration are defined as being positive in the clockwise direction
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
mr sparkle wrote:
...

So the starting position is horizontal? That doesn't seem to be right. The math I bring to such a problem is what was common practice 50 years ago. I haven't heard of Ricatti until now.
Jerry
--
Engineering is the art of making what you want from things you can get.

  Click to see the full signature.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

and
u,
in
the starting position is horizontal I must minimize the performance J tf 0.5 * integral [ (ax)^2 + u^2] 0
where x (double prime) = g/L sin(x) + u/mL^2
as I said, the starting position doesn't actually matter, even if I start it close to the vertical it's still unstable.

optimal control theory dates from the 60s and 70s this is not new stuff
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
mr sparkle wrote:

You can't use a small-angle approximation at 90 degrees. The error is 1% at 6 degrees. Deriving the parameters with false assumptions isn't likely to lead to anything useful. That said, have you checked your pole locations? If it blows up starting at small angles, there must be at least one in the right half of the s plane.
Jerry
--
Engineering is the art of making what you want from things you can get.

  Click to see the full signature.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

of course it's unstable, it's an inverted pendulum. it falls down by itself.
the linearization is not the problem. I made a model in simulink with actual sine and cosine functions and it made no difference.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
mr sparkle wrote:

Presumably, your task is to apply torques (or lateral forces to the fulcrum) that will stabilize it. It's the poles of the closed loop that must be in the left half plane.
Jerry
--
Engineering is the art of making what you want from things you can get.

  Click to see the full signature.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

let's say I have a linear system in a matrix form, how can I find the poles of the closed loop?
I know the poles of the open loop, they are on the real axis a + and - 4.4 approximately.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
OK, I found my answer. I was dumb
I was doing a sort-of open loop control the controller that brings a pendulum from 90 degrees (horizontal) to 0 degrees (vertical) can be open loop but after of course the system becomes unstable the regulator has to be closed loop, obviously I left the control U as open loop and didn't get why it functioned correctly in the beginning, bringing my pendulum vertical, then started to oscillate violently
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
mr sparkle wrote:

I still don't get what you're doing. Most open-loop gizmos don't oscillate, or if they do, it's because something applies a "force" in a direction to oppose a "displacement". (The quotes leave open the possibility of analog quantities, like voltage and charge.)
Jerry
--
Engineering is the art of making what you want from things you can get.

  Click to see the full signature.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

becomes
correctly
oscillate
there's something called a "terminal controller" which is interested in bringing the state of a system from X0 to Xf at a time tf, and after tf, doesn't care what happens. there's something called a regulator which tries to keep the state around X1, and tf goes to infinity.
and please disregard the "open loop" comment. I'm too new at this. I still don't know how to connect optimal control theory and the classical control theory
I basically made a terminal controller and wondered why it didn't act as a regulator. the two structures are very similar. the terminal controller's control u = M*S(t)*x(t) where x is the state vector, M is a combination of the linear system's matrices and S(t) is a time varying gain matrix solved by integrating backwards a riccati equation. in the case of a terminal controller the matrix S(t) is precomputed and stored, and so I thought it looked more like an open loop controller. the regulator's controller is u = M*S(0)*x(t) where S(0) is the steady state solution of the riccati equation as tf goes to infinity, therefore the gain matrix in the regulator is constant.
what I did was make a terminal controller u = M*S(t)*x(t) and instead of stopping the simulation at tf I kept going. the problem is that the matrix S(t) becomes zero at tf, since it's defined as a backward integration from tf. it makes no sense to keep using it after tf. so what I was doing was dumb. the system became uncontrolled after tf.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
mr sparkle wrote:

With a linear system in matrix form dx/dt = Ax + Bu, y = Cx, the poles of the system are the eigenvalues of A. In your case you should have a 4-dimensional system (two x and two lambda).
--

Tim Wescott
Wescott Design Services
  Click to see the full signature.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

poles
4.4
are those the open loop poles or the closed loop poles? I guess I can always put everything in the laplace domain and find the transfer function.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
mr sparkle wrote:

It depends on whether your description is in open or closed loop -- you've shown some confusion in another post, which I will try to address tomorrow when I have time. Tonight I need to clean up after a party _and_ put two boys to bed.
--

Tim Wescott
Wescott Design Services
  Click to see the full signature.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
mr sparkle wrote:

Yes, but I date from the early 60s, which put me into grad school too early to get this stuff. If it was being discovered in the 60s and 70s then it wouldn't have hit normal instruction until the mid to late 80s. Don't be hard on us -- we're trying to help.
It may lend some insight if you could check your answers with some more direct and possibly more traditional methods. Finding the transfer function from control input to position output would give you a polynomial to find the roots of, or you could just find the eigenvalues of the final system matrix if you prefer.
--

Tim Wescott
Wescott Design Services
  Click to see the full signature.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

Polytechforum.com is a website by engineers for engineers. It is not affiliated with any of manufacturers or vendors discussed here. All logos and trade names are the property of their respective owners.