0%
0%

# Open-Source inverted pendulum

A inverted pendulum using arduino and Grove-sensor

Similar projects worth following
2.6k views
Inverted pendulum is a device to show the beauty of balance. Showing what control algorithm can do? It‘s a very popular device in the robot-control academic field.
You can find the complete definition here https://en.wikipedia.org/wiki/Inverted_pendulum
I built this open-source inverted pendulum in order to help the peopel who is fascinated with robot control building their own inverted pendulum easily.
All the source code including the inverted pendulum library are accessible on my GitHub repositories.

# About the mechanical structure

I built this inverted pendulum using some standard mechanical structure except the 3D printed parts.

You can find all the standard component in hardware store.

# About the PID control algorithm

You may familiar with the following picture. Yeah, It's a sketch map about PID control algorithm.

The beginners always spent a lot of time to figure out how PID control algorithm work. To make things simpler. I write a inverted pendulum arduino library. You can get the library from my github repository. Using that library you can build your own inverted pendulum without struggling with the code.

Here is the repository

You can config your inverted pendulum by using this single line code.

inverted_pendulum(float A_Kp, float A_Kd, float P_Kp, float P_Kd, long A_st, long P_st, int A_limit, int P_limit)

Then you can get the PID controller's output by using this function.

output = Inverted_pendulum_controller.InvertedPendulumUpdate(Angle_encoder, Position_encoder);

Pretty easy right?

# About the sensor and motor

I use Grove - 12-bit Magnetic Rotary Position Sensor /Encoder (AS5600) and Grove - Ultrasonic Distance Sensor to collect the angle and position data as the feedback of contorl algorithm.

We all know about the potentiometer, quoted from Wikipedia "A potentiometer is a three-terminal resistor with a sliding or rotating contact that forms an adjustable voltage divider." Simply put, the potentiometer converts relative position information into electrical signals. But the traditional potentiometer needs to be in contact with the object being measured. What about scenes that need to be contactless, such as high-speed motor, or high-precision robot arm? Well, the answer to the contactless potentiometer solution is the Grove - 12-bit Magnetic Rotary Position Sensor (AS5600).

The Grove -  AS5600 is a programmable 12-bit high-resolution contactless magnetic rotary position sensor. The Grove -  AS5600 can work as magnetic potentiometer or magnetic encoder with excellent reliability and durability. Compared with the traditional potentiometer/encoder, the Grove -  AS5600 has significant advantages: high precision, non-contact, no rotation angle limitation. All those advantages make it is perfectly suitable for non-contact angle measurement applications, such as the robot arm, tripod head, motor closed-loop control, machine tool axis positioning.

AS5600 is based on the Hall Effect, the build-in Hall sensor can detect changes in the direction of the magnetic field, thus, there is also no rotation angle limit. Then the magnetic field direction information is amplified by the amplifier, with the help of the build-in 12 bit A/D, the AS5600 module can output 4096 positions per round.  The output is selectable, you can either use the I2C interface to output the RAW data or output the PWM wave/Analog wave via the OUT pin. Meanwhile, the maximum angle is also programmable, you can set the maximum angle from 18° to 360°, which means that the measured angular accuracy is up to 18/4096.

AS5600 is excellent for the non-contact rotary position sensor, so seeed made this AS5600 Breakout Board in the Grove form factor. With the Grove I2C connector, you can easily connect this AS5600...

### 电机架_new.STL

Standard Tesselated Geometry - 10.68 MB - 08/25/2019 at 12:37

### 摆杆固定.STL

Standard Tesselated Geometry - 1.69 MB - 08/25/2019 at 12:36

### as5600固定.STL

Standard Tesselated Geometry - 1.09 MB - 08/25/2019 at 12:36

### 惰轮架.STL

Standard Tesselated Geometry - 990.12 kB - 08/25/2019 at 12:36

• 2 × 470mm 2020 Aluminum profile
• 4 × 100mm 2020 Aluminum profile
• 2 × 8mm bearing chock
• 1 × 2GT 16 teeth Idler wheel
• 1 × Grove - 12-bit Magnetic Rotary Position Sensor / Encoder (AS5600)

Share

## Discussions

bomr wrote 08/29/2019 at 13:53 point

You describe the magnetic sensor for the rotation of the pendulum, but never mentioned the type of magnet or how it is mounted. Any further detail to share there?

Are you sure? yes | no

Tony-Lin wrote 09/06/2019 at 06:14 point

Oh, I had forgot to introduce the magnet I used. It will be update in the details.Thank you for pointing out!!!

Are you sure? yes | no

RichardCollins wrote 08/28/2019 at 19:41 point

My eyes are not working very well today, but I could not pass up reading what you have done.

It is a single axis inverted pendulum?

Have you considered a two axis inverted pendulum. The control algorithm needs constraints on energy, angular momentum, and linear momentum in 3D, but it should not be too difficult. Then two axis controls.

My first thought when i saw this, was "I wonder it this could be applied to make a two axis inverted pendulum seismometer?"  Most places have few close earthquakes.  It would need to make corrections at high speed.  But perhaps you could get it stabilized with one set of restraints, then withdraw them and just let it free to make small motions.

My challenge is to try to make it sensitive enough to measure the direct tidal acceleration due to the sun and moon. That is a complex but extremely stable reference signal.   You know you really understand precise null measurement when you can get down to nanometers per second squared (nm/s2) variations.  And hold an inverted pendulum essentially motionless for months or years at a time.

I get more back when I attempt nearly impossible things, even if I fail.  Actually,  I think we are immersed in a world that seeks instant gratification and instant answers, and shys away from attemting things that take thousands or millions of manyears.  An inverted pendulum?  A few tens or hundreds of hours?

If you need anything, ask.  Yours would be a good project to make into a crowdshare.  Or maybe Hackaday,IO needs a crowdshare pool.  Let me think about it.

Richard Collins, The Internet Foundation

Are you sure? yes | no

Tony-Lin wrote 09/06/2019 at 06:11 point

Thank you for your comment. Your idea is very impressive!

Are you sure? yes | no

Andrey V wrote 08/28/2019 at 10:52 point

What control loop freq your are using?

Are you sure? yes | no

Tony-Lin wrote 09/06/2019 at 06:06 point

I set the control loop freq as fast as arduino can. So it is 5~7ms per loop I think.

Are you sure? yes | no

Andrey V wrote 09/09/2019 at 09:56 point

I've impressed with the result. Good work!

Are you sure? yes | no

Mike Szczys wrote 08/27/2019 at 10:09 point

Wow, great performance in the demo videos.

Any future plans for this one? It's a great showpiece and would love to see as a cool installation or increase the difficulty with double-pendulum functionality (do you need sensors in both joints to do that?)

Are you sure? yes | no

Tony-Lin wrote 09/06/2019 at 06:04 point

Thanx! Maybe I will make a two-freedom one in the future. It does need sensors in both joints.

Are you sure? yes | no

## Similar Projects

Project Owner Contributor

### HTC vive lighthouse custom tracking

Simon Trendel

Project Owner Contributor

### Wall Following and Obstacle Avoidance

Sinclair Gurny

Project Owner Contributor

### RC Plane Force-Feedback System

Matt Dombroski

Project Owner Contributor

icstation

# Does this project spark your interest?

Become a member to follow this project and never miss any updates