# Balancing inverted pendulums

The robot above can balance an inverted pendulum. But wait, it gets better. It can balance an inverted pendulum that is articulated in the middle like the one seen above. Wait, wait, wait… it gets even better. It can start with the pendulum hanging below the sliding carriage, flick back and forth to get the two segments swinging, and then come to equilibrium with the pendulum as seen above. Once there, it can recover from a bit of a shove, like some of the big boys. Very impressive, even when compared to two-wheeled balancers. See for yourself after the break.

We don’t have very much information on how this works. We do know that it was a seminar paper from a student at the University of Stuttgart but the rest is pretty much a mystery. Does it use visual processing? What kind of controller is driving this thing? We want to know the details but haven’t yet found a copy of the paper. If you know where we can get our mitts on it please leave a comment below.

[Thanks Ferdinand via Flabber (NSFW)]

## 38 thoughts on “Balancing inverted pendulums”

1. Very interesting, curious if we can put a camera pole atop a base like this? but move in x and y.

2. Frollard says:

according to the end credits its estimated mathematically, so it might only take very simple real-world sampling to get results.

3. nes says:

Ahh, Kalman filters. Is there anything they can’t do?

Now make it work with three links :-)

4. JoshRagem says:

holy moley.

5. James says:

Beautiful. Love it.

6. Amazing! How many lines of code did it take?

7. clever work, but like the rubics cube solver. humans still win.

at 2:42 balancing a stack of three balls.

Can three segments be done? (given they all 3 have a different mass)

9. Laurence says:

It’s not that complicated – the fun comes in calibration (a field with a whole career dedicated to it)

I imagine it uses (like all the other inverted compound pendulum balancers) rotation sensors with a microcontroller/pc using a PID control loop. This is an example of a typical control system with feedback. Search PID pendulum on youtube for more vids!

Does anyone knwow what kind of linear actuator controls the movement of this awesome thing so fast?

11. Charper says:

I haven’t dug up his thesis (if someone finds it, please share), but it looks like a linear motor. Look up LIM – Linear Induction Motor. It’s basically a standard three-phase induction or PM synchronous motor that’s been “unrolled” to produce a linear motion instead of a torque.

12. George says:

“Even when compared to a two-wheel balancer”? This is far more impressive – a double pendulum is a highly nonlinear, chaotic system. While a two-wheel balancer is also nonlinear, you can make a single linear approximation around the point in which you’re interested (upright) and throw linear control theory at it to make it work. You can do the same thing here once you’re mostly upright, but getting there is a lot harder – control theory just isn’t built to deal with chaotic, nonlinear systems.

From his other post, he’s probably using a minor loop state space controller and would therefore have both position and velocity sensing. I doubt he used video processing, since position and velocity sensors would be faster and more precise.

Point is, this is *really* impressive, and the idea behind the ‘swing-up’ phase is brilliant. Wow.

13. Renan says:

The control of inverted pendulums (pendula?) is a classic problem in control theory…

But the double inverted pendulum is a new one for me.

14. Nick says:

Dang. This is great.

15. James says:

Classic control problem. We’ve a similar setup in the Engineering department at Oxford, UK – an undergraduate lab module is to come up with a controller for it (though admittedly, the one above is quite impressive).

16. Oh… constant energy – I get it!

When the pendulums are balanced, the upper one and lower one have a specific amount of potential energy based on their mass and height.

When starting, the system adds that much in the form of kinetic energy to the system, then adjusts to keep that much energy. Vertical balance is one position within that state space.

This means that, at a guess, it should be possible to completely balance the upper pendulum atop the lower one first (with the lower one pointing “down”), then bring both up to vertical.

Thanks for the insight!

17. Mike says:

This is simply amazing. Hats off to the guys that programmed this!

18. basroil says:

I actually have (limited) experience with a very similar setup (double inverted furuta pendulum rather than double inverted linear pendulum). This is very likely a double (technically triple if you include the cart position feedback) rotary encoder fed into a computer using an ADC. A single servo (or dc motor and rotary encoder) drives a a chain to control cart position.

Software can be one of many programs, though Simulink in matlab is a good one to use. The stabilization can be a linearized approximation derived though Hamiltonian or Lagrangian methods. A simple PID will take care of the cart speed once the models are all accounted for.

The main way in which this thing stays up is in the difference between the two rotational inertias, but the way this gets up is beyond me, this energy method is quite interesting though a bit unconventional.

And unlike one of the comments above, I believe the tuning (you tune a PID, not calibrate it) is fairly simple if you just use Zeigler-Nichols approach.

19. Garbz says:

This is almost a textbook classic example of a university level control theory problem. We did an almost identical (but simpler) example for our control theory course. In our case we had a rotating actuation rather than a linear one, so this adds a bit of an extra twist to the problem (in multiple ways).

If this is anything like what we did at university the feedback for balancing will be two rotary encoders showing the angle of each arm of the pendulum. The actuator will then be the linear stepper controlling the left and right motion.

Most likely since this is a university level project it will be run by something like the Matlab using the Simulink toolbox and an xPC rapid prototyping system to drive the pendulum directly from a Matlab control model (ours was made of several PD controllers hooked end to end and a statemachine to control the initial swingup)

20. Gert says:

Usefull application?

21. elektronisk says:

I think the following method of acheiving balance is more elegant (first balances lowest leg, then the top):

22. Brian says:

Thats the bestest thing anyones ever made ever :D

but just to be annoying, at 2:00 it should be opposite not opposit :D

23. Bluechip says:

As others have said, this is based on a classic problem in control theory; I’ve done something almost identical before as part of an undergraduate thesis.

I don’t know how he implements things, but I used a pretty standard reinforcement learning algorithm and let the controller learn how to balance the double pendulum itself. Modified TD-lambda algorithms are capable of learning how to balance a single pendulum in about thirty iterations; they’ll do a double pendulum in less than two hundred if you get the discounting right.

24. Tom says:

We had a rotary encoder giving us the position of the arm, and another rotary encoder giving us the number of turns of the cart’s belt drive. We then used a lab pc with Matlab to make a PID controller. Hopefully I’ll get to mess with something even more fun later in my course.

25. Ash says:

The parts and BOM for these types of projects isn’t actually that hard to reproduce

We had to build inverted pendulums (single pendulum) for our project course, a number of groups had different concepts, but most of us used:

-DC motors, some teams used steppers
-Magnetic rotary encoders, some used optical encoders
-H-bridges and power circuits for the motors
-control was done via a microcontroller, either PIC or even on an arduino

The toughest part was definitely tuning of the PID algorithm

I dont remember exactly which sensor we used, but its on this list here:

http://www.austriamicrosystems.com/eng/Products/Magnetic-Encoders/Rotary-Encoders

26. Kenn Sebesta says:

As everyone else has said, this is a classical controls problem, and a quite simple one at that. The fun is getting the sensors to give reliable feedback, to get the motors to behave nicely, and either correctly model the friction or eliminate it.

To see a much, much better one, look here: http://www.youtube.com/watch?v=8HDDzKxNMEY

Lastly, the kinematics of the situation show that an infinite number of pendulums can be balanced. The devils in the details, though.

27. bob says:

Awesome. Great project.

28. JMS says:

I may be repeating a lot of your comments, but I did this as an undergrad in ’99 in a couple of weeks and it’s fun to reminisce. It’s usually a state-space controller that’s used if you want to be able to tell the pendulum to move to a specific position on the track and stay there, even with perturbations. PIDs are not great for this kind of thing, as they have difficulty with “snappy” recovery from a push, especially if you want the pendulum to stay in or move to one position–though they will work. To get it to work properly, you have to do something you don’t see in the “hack space” often… that is actually model the real world physics of what is going on. The system is robust with the right controller, however, in that you can change the linkage distances and weights and still get it to work well. When I put one together, It was balanced on a rotating arm connected to a motor shaft… which meant that I had to model Coriolis forces (effects), but I never ran out of “track” to play with. The way the angles are measured are often by optical encoders–good resolution and no drift/noise. The coolest thing about these setups is that if you push on the inverted pendulum, it will feel like it is attached to a spring that wants to keep the pieces upright. I like to think of the control system as “virtual springs.” As for flipping the pendulum up to vertical from hanging… no big deal there either. Actually, that’s the easiest part. You just pump the system with a sine wave at the natural frequency of the pendulum and it will eventually go vertical, at which point you switch control to the state space controller. In ’99 I did this with a break out board and a motor controller connected to a 286 running DOS. The 286 was overpowered compared to the processing needs. These projects are great for the classroom and for demonstration purposes. Also, you can code the system in such a way as to have students “plug in” their control matrices and see how they work. If you build one, don’t forget the kill switch!

29. JMS says:

I’m surprised no one mentioned the segway.

30. Ren says:

I think it needs another servo,
to whack the hand that keeps trying to upset the pendulum.

31. pascal says:

The ghetto version of this uses a loudspeaker with the double pendulum fixed to the surface. By selecting the right frequency to output over the speaker, the pendulums will be stable (a friend of mine did this as a high-school degree project)

Also most AI toolkits seem to include an example to “evolve” the feedback loop they used (the evolved function outputs if the wagon should move left or right when given the current angles, its reinforced when the pendulums stay upright longer)

32. Andrew Meyer says:

@JMS: They did–“two-wheeled balancers” is a class that includes instance Segway.