Pendulum simulator

I’d like to make a simple pendulum with one of the motors I got a great deal on via ebay. I’ve made a few solar pendulums and they are fun to have around. I’d like to make a big one with a pretty long arc. Unfortunately when I search for pendulum motor control the results are for an inverted pendulum. I’d like to make a simple non inverted pendulum with very low power consumption and a natural pendulum motion. I imagine I would calculate the natural frequency and use that as a base line while I just try to diminish the torque as it approaches the top of the swing, is the control that simple? The main goals would be a natural motion and high efficiency. Anyone have a link for someone who’s done this simple control scheme?

Are we talking about something similar to a pendulum clock? They should be very simple as the time period of the pendulum is the same regardless of how far it swings.
Maybe you could try to model the escapement mechanism that provides a timed impulse on the pendulum?
Does it need to be closed loop? An old clock (i think) isn’t closed loop. It (i expect) adds a fixed amount of energy at the ?apex? of the swing.

Interesting project!

yes, just like a pendulum clock except it isn’t for keeping time.

ok, so I found someone who just calculated the position and fed it out to a servo.

I may start out with just using a bell crank linkage.

Hey @schoch,
this is an interesting problem.

What you could do is to keep the energy of the system constant. I’ll try to post a more detailed response in the next few days, but I just wanted to let you know that this paper might be interesting to read, I mean not the whole paper just the section IV.C Two-stage bang-bang swing-up controller. Your problem is very similar to the pendulum swing-up. But in your case, you do not want to go all the way up, you just want to compensate for the losses by keeping the kinetic and potential energy sum always at some level. This would give you a very nice controller in my opinion :smiley:


I’ll give that a read.

Here is my naive try which is working ok. The PID’s were way off and it was a bit hard to get them to decent initial settings with all the weight hanging off one end.

Well, I read through that paper and while I don’t know what most of the symbols mean i think I understand the basic idea. Because of my math handicap I tried to use anything that would work to approximate the energy, here’s what I came up with:

// this was inverted and scaled oddly so I multiply by the -0.01, it may be wrong
PE = (mass * grav * effective_length * (1 - cos(encoder.getAngle()))) * -.01;
KE = .5 * mass * sq(vel);

I’m using the velocity from the encoder but I don’t know what the units are… anyway this gives me a plot that looks like this: PE = Potential energy, KE = Kinetic, TE = Total Energy

So it sorta seems right… The velocity (not shown in the plot) isn’t very smooth which effects the other items. You can see the total energy varies quite a bit. I’m not really sure if my calculations are correct or if I just can consider it a pure pendulum or a dampened pendulm due to the motor cogging. If everything is perfect it should uncog itself right?

Being practical and wanting something that worked I simply took a look at voltage.q and just tweaked the pids and pendulum simulation it until the range of voltage was as low as I could get it. I think it is still fighting gravity but it is using less than .01A of current.

Here’s what I didn’t do:

  1. properly calculate the moment of inertia of my pendulum. It will change when I make the real pendulum arm but that should be calculated eventually.
  2. do any Lagrangian or taylor series or matrix stuff or math I barely comprehend.
  3. calculate the actual period of the pendulum (see #1)
  4. do any sort of ramp up.

So it is a fun little thing and I think it will work well. The motor runs cool as does the driver and it ran for a whole day with no problems.


  1. add the larger weight at the end.
  2. implement a training startup
  3. acquire a solar panel to drive it
  4. mount it up high so it doesn’t bonk me in the head
  5. optimize it more

The only interesting thing here is the training setup. I’m going to make it so it will wait for you to set an initial arc. once you move it from it’s 0 position it will take the first max angle and then use that as it’s target energy. it could then calculate the period from the first swing and configure it self for length and center of mass.

here it is in all it’s MDF glory


You could work out the period empirically - i.e. disconnect the motor and push it and measure a period. It looks as if it is going a little faster than my intuition says it should but at 0.01A you must be pretty close - so not too much to gain!

Is this an art piece? I like these fun things and am wondering what you plan for it?

I wouldn’t call it art, just a fun project. It is hard to make beautiful things.

here’s the 2nd prototype


some more literature related to the problem.

This is amazing. I know it’s been some time since you have posted about the project but this closely relates to a project I’ve been working on (SimpleFOC Double Pendulum). Do you have any updates? I’d love to learn more. Thanks for sharing!