Introduction: PID Controlled Ball Balancing Stewart Platform
Motivation and Overall Concept:
As a physicist in training, I am naturally
attracted to, and seek to understand physical systems. I have been trained to solve complex problems by breaking them down into their most basic and essential ingredients, then building the problem back up from there. Though I have been learning mechanics and electromagnetism from first principles, I have yet to use them in some physical application. I will finally be getting this opportunity by creating a robot that uses automatic controls theory to autonomously balance a ball on a flat, fully controlled platform, all on its own!
In this how-to; which is meant for the technically savvy hacker, programmer, or engineer, we will use an Arduino Uno as our microcontroller platform. The closed feedback loop first starts when it senses the position of a solid metal ball bearing lying on a flat touch resistive screen, which feeds back the balls immediate position. This position is then fed into a proportional-integral-derivative (PID) controller, which we have programmed into the Arduino Uno. I have made this code open source and linked in the project. The controller is tasked with restoring the ball to any user chosen position on the table, even when significantly perturbed. The structural supporting platform we will be using is known as a “Stewart platform,” and is supported by six independent connecting rods driven by servo motors which will provide up to six degrees of freedom; X, Y and Z translations, roll, pitch and yaw (rotations about the X, Y, and Z axes respectively). Constructing and programming such a highly mobile platform present’s its own challenges, so for this project, we will only call upon the pitch and roll degrees of freedom, leaving the others as optional upgrades of functionality, if the user so desires. Along with the platform moving the ball to any of a set of static user defined positions, advanced programmers will find it easy to enhance the program and add some panache by replacing our static, user defined position, with a semi-continuous trace of a user defined path, such as a figure eight, circular trajectory, your name in cursive, or my favorite a live stream of someone’s stylus or finger on their own mobile device! Happy hacking!
Step 1: Get Materials
1. A few sheets of 1/4" and 1/8" Acrylic
2. 6 - Servo Motors (We used HS5485HB Servo’s)
3. 6 - Threaded (Adjustable) Connecting Rods
4. 6 - CNC Machined Servo Arm’s with multiple holes for adjustability
5. 12 - Heim Joint Rod Ends
6. 6 - Rods (Adjustable)
7. 1- 17” Five Wire Resistive Touch Screen Panel USB kit (sense position of ball bearing)
Step 2: Prepare Materials
The best way to get the acrylic cut is by using a laser cam. Access to one can be difficult, so the acrylic can also be easily cut using whatever cutting tools you are familiar with, properly trained on, and can operate safely. If I were doing this at home for instance, I would use a hand coping saw. The overall shape of the Stewart platform need not match exactly to the model I built. However, I do want to point out a few simplifying opportunities. First, it is much easier to map the pitch and roll degrees of freedom by using three basis, instead of the standard two. this is done by making the attachment of the connecting rods to the actual platform an equilateral triangle. This allows you to neglect all the complications of finding the pitch and roll degrees of freedom (DOF) from scratch, instead we use 3 non-linearly independent "basis" that are simply the map of that corner of the triangle going up. This would be challenging for you or I to write out coordinates in this basis, but the interdependence of these basis is easily handled by the code. This simplifying assumption is key to neglecting all the intricacies of the geometry. See the picture MS Paint graphic and whiteboard picture for details.
Once the pieces are cut, you will need to drill out all the holes, that are where your connecting rods and ball joints connect to. Be careful to match the hole size to the proper hardware you are using. This is vital to have your chosen fasteners working. The hole sizes are based on what size tap you will need for your fastener. To do this, find an online reference for the specific tap size, pitch and thread type (fine vs course). I recommend course threads for acrylic, but if you must use fine thread, it should work out, since that what we used anyway. Now its time to move on to assembly.
Step 3: Assemble Materials
Carefully assemble the materials to spec. Be especially careful not to strip any screws. Once this is done, you will have to either change hardware by sizing up and drilling bigger holes and tapping them, or you will need to cut a whole new piece of acrylic. Note to also be careful with the touch resistive screen. It is fragile!!! It is a thin layer of glass after all. Note that we had an accident ourselves.
Step 4: Programming
The programming can take some time. This is where your programming skills can really pay off. You need not be able to write the code from scratch, but if you can find a well commented and organized source code to modify, then that makes life that much easier. Here is the link to our source code: https://github.com/a6guerre/Ball-balanced-on-Stew..., help yourself! It is certainly not optimized, but got the job done! Remember that we are using three separate non-orthoganal, non-linearly independent basis for the controls map. We are simply reading everything in x,y and mapping to A, B, and C. This response is then tuned globally to adjust how much more or less we want the system to respond.
Step 5: Testing!
Here we test the degrees of freedom. Note now how our three basis pay off! For example, to get the roll DOF, we simply go down one unit on the left, while going up one unit on the right, and vice a versa for the other direction. It is also important to have done a sufficiently good job filtering noise from your touch screen. This is vital to having good data to feed into your PID.
Step 6: Fine Tune and Enjoy!
The testing phase was really just to get the bugs out. Here, we focus on fine tuning the controls system. this is done best with a preset algorithm. My favorite is to approach it like a critical dampening problem, Ahem! I'm a physicist! So you turn off the dampening term! Ie the derivative term, which acts like a drag term. Now the ball will oscillate wildly! However, the goal is to get the oscillations to be as close to harmonic as possible, not growing or decaying, as best you can. Once that's done, you turn on the derivative term, and adjust until it gets back to equilibrium as quickly as possible. This is when critical dampening is achieved. However, if this doesn't work there are many other well proven tuning schemes for PID controlled systems. I found this on wikipedia, under PID controller. Thanks so much for taking a look at my project, and please reach out with any questions, I'll be glad to answer any questions you have. Special note: I want to point out that this project from start to finish was done by the Miracle Max Guerrro, and myself in just under four weeks, including waiting for two weeks for a new screen that was stuck in customs, after our first one broke. So please excuse it's far from perfect performance. Happy hacking!
We have a be nice policy.
Please be positive and constructive.