Inverted Pendulum robot not working properly

Thread Starter

Paul_Alexa

Joined Jul 16, 2022
22
Hello everybody,

Thank you for taking the time to read this. I am building an inverted pendulum robot and I am unsatisfied with the performance I'm getting. My purpose was to build something with a PID regulator that can be tuned "on the fly" to study the effects of various changes, seeing how it oscillates as the Kp is increased, for example. Well, to say the least, I find the performance of the robot underwhelming, it did not manage to stay up by itself at all. Since this is my first time ever building a robot I am not surprised. After scouring the internet for information I was bewildered by how many different implementations I have found and do not know in which direction to start. I was given this as part of a course for university. My main focus isn't robotics, I'm focused on HV systems and it's a bit tricky for me, to say the least.

System details:
The electrical part: Arduino Nano ESP32, using an Arduino Cloud remote, MPU6050, CNC Shield, A4998 stepper drivers in full step mode, Nema17 steppers. Power comes from a battery pack capable of delivering 12V at 2A.
The mechanical part: 2x 250x150 4mm thick perspex panels, held together by 4x 8mm threaded rods,panels are spaced 50mm apart. Battery pack is on the top platform, the electronics are on the bottom. Please note that I have removed the third platform that you can see in the sketch. I still have it around.
Steppers are controlled by AccelStepper library.


My questions:

Is the code suboptimal and causing the issue? Right now I am using the angle i get from the MPU6050, feeding it into the PID regulator, then using it to determine the speed(in steps) with which the steppers should spin in order for the robot to balance itself. I have decided to not try to calculate the number of steps it would take for the bot to balance itself as I figured it would have been too complex.
Is the mechanical part lacking? Should I strive to achieve a center of gravity as low as possible?

I am looking for a broadstroke picture as to which direction I should head in,
Thank you very much for you consideration.

What else I can tell you: during testing I powered the robot from a lab bench PSU. The PSU never went into current limiting mode. I also calibrated the drivers to ensure that no more than 400mA of current goes into each motor, as per datasheet. I was in the process of tuning the PID controller when I asked myself if it was all ok, I got up to a KP of 50. The oscillations are high and the robot can almost balance itself, it does require assistance and I feel that it reacts slowly to angle changes.

Alternative code link:
https://codefile.io/f/es26MNjhmY
 

Attachments

crutschow

Joined Mar 14, 2008
34,680
Have you considered using Fuzzy Logic for the feedback control, instead of PID.
Fuzzy Logic can be easier to tune to get the desired result as compared to PID.
Here's a tutorial.
Also search for articles about using Fuzzy Logic to control an inverted pendulum.
 

Thread Starter

Paul_Alexa

Joined Jul 16, 2022
22
Have you considered using Fuzzy Logic for the feedback control, instead of PID.
Fuzzy Logic can be easier to tune to get the desired result as compared to PID.
Here's a tutorial.
Also search for articles about using Fuzzy Logic to control an inverted pendulum.
I have not considered Fuzzy Logic for my application. Thank you very much for the documentation you have provided.
 

Sensacell

Joined Jun 19, 2012
3,475
So much simpler to build an analog PID controller- all the same ideas, just done with opamps.
Once you have done this... digital ones make actual sense, you will really understand what is going on.

Stepper motors would be my last choice- they introduce many layers of complexity that cloud the story.
If you must go digital, try a DAC that drives a servo amp and a DC brushed motor.
 
Last edited:
Top