# Lagrangian: Inverted telescoping pendulum (robot leg)

1. Sep 6, 2010

### garethpriede

Hi, hopefully someone can check my logic.

I have a lever with a mass on top which is rising towards the vertical on a frictionless pivot. The length of the lever can change. (In reality this is a robot rocking onto a foot and straightening its leg). The intention is to bring the lever to a halt at the vertical by continuously controlling the length.

I've been trying to use the Langrangian, but I'm not sure if I've captured the variables correctly.

x is the length of the leg, theta is the angle from the vertical (so 0 is upright). (I hope my latex paste comes out ok)

L=T-V \\
L=\left[\frac{1}{2}m\omega^{2}+\frac{1}{2}m\dot{x}^{2}\right]-mgxcos(\theta) \\
L=\frac{1}{2}m(x^{2}\dot{\theta}^{2}+\dot{x}^{2})-mgxcos(\theta)\\
\frac{d}{dt}\frac{\partial L}{\partial\dot{\theta}}=\frac{\partial L}{\partial\theta}\\
m\dot{x}^{2}\ddot{\theta}=mgxsin(\theta)\\
\frac{d}{dt}\frac{\partial L}{\partial\dot{x}}=\frac{\partial L}{\partial x}\\
m\ddot{x}=mx\dot{\theta}^{2}+mgsin(\theta)

What worries me is the first partial derivative, something seems to be missing. Do I need to account for the energy involved in extending the leg?

Then if you don't mind a mini part 2, if the pivot has friction, can I still use the Lagrangian (I assume not, but perhaps it's just an extra coefficient somewhere)

2. Sep 6, 2010

### Danger

Welcome to PF, Garethpriede.
If reality is involved, why on Earth would you assume a frictionless pivot?
I have no idea about anything mathematical; I don't even know what a "Lagrangian" is, other than in reference to a Lagrange orbital point.
I can't help wondering, though, why you can't just use a position sensor even as simple as a potentiometer to simply measure the leg position. That's how I'd do it, but I'm no genius. There are a lot of heavy-duty engineers and physicists here who can deal with the question in the way that you are hoping for. Unfortunately, I'm not one of them.

3. Sep 6, 2010

### garethpriede

Hi, thanks for the welcome :)

I have sensors etc so I know what's happening in reality. But I need to design the control system and that requires some maths. Even if I'm making some simplifications, I need a solid base to start on. I saw quite a few other posts on solving Lagrangians, and even for pendulums and pendulums on springs, so I was hoping someone would see the "obvious flaw" in my derivation.

4. Sep 6, 2010

### Danger

Ah, I see. Hmm... Fred Garvin was one of the PF experts in control systems, but I haven't seen anything from him in a long time. I think that Brewnog is very knowledgeable in the field as well, and definitely Astronuc. I'm sure that one or more of them can set you up.

5. Sep 6, 2010

### thrillhouse86

Sorry but the Latex code not coming out was really bugging me!

$$L=T-V$$

then

$$L=\left[\frac{1}{2}m\omega^{2}+\frac{1}{2}m\dot{x}^{2}\right]-mgxcos(\theta)$$

then

$$L=\frac{1}{2}m(x^{2}\dot{\theta}^{2}+\dot{x}^{2})-mgxcos(\theta)\\$$

then

$$\frac{d}{dt}\frac{\partial L}{\partial\dot{\theta}}=\frac{\partial L}{\partial\theta}\\$$

then

$$m\dot{x}^{2}\ddot{\theta}=mgxsin(\theta)\\$$

and

$$\frac{d}{dt}\frac{\partial L}{\partial\dot{x}}=\frac{\partial L}{\partial x}\\$$

then

$$m\ddot{x}=mx\dot{\theta}^{2}+mgsin(\theta)$$

Isn't the energy of a rotating system
$$E_{rot} = \frac{1}{2}I\omega^{2}$$

You can use the parallel-axis theorem to work out the mass-moment of inertia and I'm pretty damn sure that it will be a function of your x variable, that will probably create the missing extending arm term your missing.

I'm interested how your going to control this - are you going to go for a state-space control of the pendulum ?

Last edited: Sep 6, 2010
6. Sep 14, 2010

### Eidos

If you want to add in friction you can model it using Reyleigh dissipation, basically the frictional terms appear as extra forces, so you get:

$$\frac{d}{dt}\frac{\partial L}{\partial\dot{q}_{i}}-\frac{\partial L}{\partial q_{i}}=Q_{i}-D_{i}\dot{q_{i}}$$

Here $$Q_i$$ are the external applied forces for that i'th degree of freedom and $$D_i\dot{q_i}$$ are the friction terms you require.

Sounds like a really fun problem :)

Are you sure that is the right way to model the problem? Is the robot leg bending to change length?

Can you please submit a diagram so that we can see the degrees of freedom?

Lastly, if all that you can control is the length of the leg you're going to have a tough time to stabilise the system in the upright condition. Some work was done on stabilising an inverted pendulum using only movements that are parrallel to the length of the pendulum but that requires really high frequency pulsing.

Last edited: Sep 14, 2010
7. Sep 20, 2010

### garethpriede

to provide some more input, I want a robot to rock sideways from leg to leg. So at t=0, the robot is balanced on the left leg with the right leg in the air and the legs are splayed by about 10degrees. It then starts to fall to the right until it lands on the right leg. Its momentum keeps it moving and it rises up on the right leg until it runs out of energy. It then falls back to the left again and repeats. There are losses in the ankle joint and the landing collision, so eventually the rocking comes to a halt.

In order to overcome the losses and also to control the rocking frequency, i control the length of the landing leg (or you could call it the pivot leg) while the robot is rising and slowing down.

i'm not interested in the dynamics while the robot is falling or with the collision, i only want to model what happens as the robot is rising on the pivot leg with a continuously changing leg length. so I can model this as an inverted pendulum with all the mass at the tip, having some initial angular velocity and some initial angle with the vertical.

my first practical attempt is quite simple, I shorten the landing leg by a fixed amount to ensure there's enough angular velocity to keep the robot moving, then shortly afterwards, as soon as I have enough data to calculate the resulting angular velocity, I lengthen the leg once by some amount to stop it rocking too far (which I calculate using conservation of angular momentum, but that isn't the focus of this post)

This results in a very rough controller which does work at keeping the robot rocking indefinitely, but without any insight into the frequency etc, and without the mathematical model to continuously control the leg length.

So I've been trying to get a full non-linear model of the system, but my maths isn't up to it. It looks like a similar problem to the classical inverted-pendulum-on-a-cart problem, but without the cart and with a variable pendulum length. I'm happy to ignore the friction in the joint for now, I can determine it experimentally later, as a first go I just need to model the effect of leg length.

Any help is greatly appreciated.

8. Sep 20, 2010

### Eidos

Im assuming a point mass at the tip of an extendable rod, angle is zero when the rod is upright, the x direction is along the horizontal and y direction is along the vertical.

Let the position vector be $$r(t)=[x,y]$$

$$r(t)=[x(t)-l(t)sin\theta(t),\, l(t)cos\theta(t)]$$

Therefore
$$T=1/2m\dot{r(t)}\bullet\dot{r(t)}$$

Note: this is the vector dot product of $$\dot{r(t)}$$ with itself.

$$V=mgl(t)cos(\theta(t))$$

Now the Lagragian is
$$L=T-V$$
and you do exactly what we did before with the Lagrangian for each of the variables
$$x(t),\theta(t), l(t)$$
but only $$l(t)$$ is actuated.

Hence you'll get

$$\frac{d}{dt}\frac{\partial L}{\partial \dot{x}}-\frac{\partial L}{\partial x}=0$$

$$\frac{d}{dt}\frac{\partial L}{\partial \dot{l}}-\frac{\partial L}{\partial l}=F_l$$

$$\frac{d}{dt}\frac{\partial L}{\partial \dot{\theta}}-\frac{\partial L}{\partial \theta}=0$$

where $$F_l$$ is the force you apply to lengthen or shorten the leg.

I hope thats the sort of thing you were looking for

Last edited: Sep 20, 2010
9. Sep 20, 2010

### Eidos

As an aside, the other leg (i.e. the one not being balanced on) will enter the model as a stray (constant) torque in the $$\theta$$ co-ordinate, so you'll probably need to include it to model the dynamics correctly.

Lastly, you are probably only interested in the dynamics in the $$\theta$$ co-ordinate only so you can neglect the other two equations if you assume that $$l(t)$$ moves to its controlled value much much faster than $$\theta(t)$$ changes.

Hence you have

$$\frac{d}{dt}\frac{\partial L}{\partial \dot{\theta}}-\frac{\partial L}{\partial \theta}=\tau_s$$

where $$\tau_s$$ is the stray torque I mentioned earlier

Last edited: Sep 20, 2010
10. Sep 22, 2010

### garethpriede

Thankyou very much, that makes much better sense now. That's exactly what I was hoping to find out.

11. Sep 22, 2010

### Eidos

My pleasure

I've thought about some further refinements where you make the stray torque depend on the angle of the leg if you want to.

$$\frac{d}{dt}\frac{\partial L}{\partial \dot{\theta}}-\frac{\partial L}{\partial \theta}=\tau_s(\theta)$$

Good luck!
Let us know how it goes ^^