I´ve been working on an inverted pendulum built out of an old printer.
I´m balancing it using two PID controllers utilizing Brett Beauregard´s PID Library.
I´m at a point where it´s generally working!
I´m not satisfied with the performance though. The movement is jerky and the system is not responsive at all. Even small outside disturbances lead to cart running into the end of travel before actually catching the pendulum.
I´ve created a Youtube video where you can see the pendulum in action and hear me explain how it´s balanced.
I need some advice on what to do next. I´ve seen other pendulums, supposedly PID controlled, that work much better. I want to reach that level.
The gains are not copied from anywhere. The code is 100% written by myself without any preexisting code from neither me or others.
The gains are tuned about as good as it gets. I´ve been
struggeling to tune these values over weeks now.
I don´t really know what i´m looking for.
My goal is to achieve a better performance, whatever might be necessary.
I´m not really familiar with state domain. As far as I remeber we only ever used s-domain at uni and no frequency domain.
I can derive the equations of motion for the pendulum. With a bit of searching around in my old papers from uni I think I´d be able to laplace transform them into the s-domain. I fear that wouldnt help me much.
First because there´s still the unknow transfer function from the PWM Signal to the Force applied on the cart. The equations of motion are all in terms of Force... well I have no actuators I can tell "please apply -5N"
Second. Suppose I got the formulas. It´s not a single forumla but there are a set of equations that describe the motion. Which one would I transform into the s-domain? And how do practically I implement that formula in my actual system? The little education I had in this field was scarce and purely theoretical. I can´t apply it (thanks uni).
Can you?
I also can't construct controllers from some mechanical formulas, not even describe a given mechanical device by formulas
I've learned about state-space controllers and observers 40 years ago, but that's of no help without the correct formulas at hand. One advantage of state-space controllers is their construction in state space, whereas another transformation from s back into time space is required for the Laplace transformation approach.
The transfer functions from PWM into force are quite complicated (non linear...), dunno which order they really are. Here again state-space is easier to compute, from immediate feedback or an observer, provided that the related formulas and parameters are well known. It would be easier to add a force sensor, to obtain the feedback for an according controller.
I already considered to reactivate what I learned at the Uni, but gave up when I found a set of 3 books, dedicated only to process identification
From my observations of inverse pendulum project demos, and from a demonstration of an adaptive controller for such a pendulum at the Uni, I guess that the projects of better performance use such an (adaptive?) state-space controller, not PID controllers. Adaptive controllers will eliminate the need for finding the right parameters, but this is beyond my capabilities, and also beyond the computation power of an Arduino (matrix inversion...).
Assuming that you have tried all reasonable combinations of Kp,Ki,Kd for two controllers (which is extremely time consuming and difficult to do), and it still doesn't work, then your system model is inadequate.
There are two approaches: construct a reasonable system model and analyze that using control theory, or proceed with trial and error, considering ALL the possible variables.
For example, you want the pendulum to "lean" appropriately to assist in correcting the off-center position of the sled. How did you select the proportionality constant for that correction?
Perhaps just "proportional" is inadequate in this case.
Correct, but for small angles, a force term linearly proportional to the angle is expected. For example, if the pendulum is leaning away from the vertical by an angle A, then the force driving the sled sideways is proportional to sin(A). For small angles, sin(A) ~ A (in radians).
Following this example, refining the system model would include a careful analysis of all the relevant forces and masses involved. There are plenty of examples on line, for example this one.
My system model is inaccurate! Thats what I think. In fact I dont have a "system model",I´m not using any physics knowledge at all at the moment.
I´m literally just taking the error in angle and let a PID controller create a PWM output from it.
This is how my control works atm.
Regarding the gains I went as follows.
First in tuned the inner PID controller, the one controlling the angle.
I started with P only and increased until i got oscillation. I tried to add D but not much changed beside the motion getting more jerky. As far as I know D limits overshoot. In my case I actually want some overshoot to actually stop the pendulum. If therse none (P only) the Motor will stop once angle 0 is reached but the pendulum will then again start to tip over in the same direction again.
I then just added I. The performance got better the more I added so I stopped just when it began to introduce oscillations again.
For the linear controller I added P until the system was responsive enough to actually reverse the cart direction before it´s running into the limit. I increased up to the point where the oscillation started.
I increased I and D until osciallation started but both didnt enhance the performance up to this point, so I set them to 0.
I´d like to create a model, as you said theres plenty information out there. I still dont know how to actually implement that model into the actual code. This step always seems to be missing or I´m not getting it.
Say I derive the Equations of Motion, transform them into s-domain, maybe even find a transfer function for PWM controlled DC Motors.
Whats the next step?
Say I derive the Equations of Motion, transform them into s-domain, maybe even find a transfer function for PWM controlled DC Motors.
Whats the next step
The first step is to carefully study the link in reply #8.
I updated my pendulum in recent weeks and improved it´s performance significantly.
I uploaded a new video showing the progress and explaning the problems I faced and how I solved them.
The last thing to do would be an automated swing up controller. I´m lacking an idea for this though.
If one of you has an idea I´d be glad to hear it, until then i´ll call this project finished.