Introduction: Ball Balancer and PID Fiddler
This project is presented for people who have experience with using an Arduino. Prior knowledge of using servos, OLED displays, pots, buttons, soldering, will be helpful. This project uses 3D printed parts.
Ball Balancer is a PID test rig for experimenting with PID tuning. PID Fiddler is a remote for adjusting PID tuning.
A PID is used when you need more control of movement. A good example is a balancing robot. The robot needs to make small adjustments to maintain balance, and quick response to catch itself if it encounters a bump or push. A PID can be used to tune the wheel motors response to maintain balance.
A PID requires feedback from a sensor. A balancing robot uses gyros and accelerometers to measure the absolute angle of the robot. The output of the sensor is used by the PID to control the motors to maintain balance.
So why did I make a boring ball balancer? Sure it's cool, but balancing robots tip over when they are not tuned correctly. Balancing robots are not the best device for experimenting with PID tuning. The ball balancer is much more stable and is a good visual tool to see the effects of PID tuning. The knowledge gained from tuning the ball balancer can be applied to tuning a balancing robot.
The Ball Balancer is a rail on a pivot point. On the rail is a ball the moves back and forth on the rail when the rail is tipped. The rail is tipped with a servo. On the end of the rail is a sensor that measures the distance of the ball from the sensor. The input to the PID is the distance of the ball from the sensor, and the output of the PID is the servo that tips the rail and moves the ball.
I am using the Arduino PID library. https://playground.arduino.cc/Code/PIDLibrary
The PID Fiddler is what I use to tune the PID values. You don't need one, but it helps. The PID Fiddler is remote from the Ball Balancer, it connects with only two wires, and it can be connected and disconnected while the Ball Balancer is running. Once you find the best values, the values can be hard coded in your project sketch.
The extra effort of making the PID Fiddler pays off in time it takes to make tuning changes to the PID. You can quickly see the results of your changes. And it can be reused on future projects that use PIDs. Not to mention it's fun to build, and looks cool!
Step 1: Ball Balancer - Parts
3D Printed parts found here: https://www.thingiverse.com/thing:2798979
(Assembly instruction are found in the Post-Printing instructions in the link above)
1 - 1" x 1/8" aluminum angle, cut to 500mm length.
1 - Adafruit VL53L0X Time of Flight Distance Sensor: https://www.adafruit.com/product/3317
1 - Hobby Servo with control horn
1 - Stiff wire for linkage (about 7mm)
- Misc. Mounting screws
1- Arduino Uno
2 - LEDs (red, green)
3 - 330 Ohm resistors
- Misc. Jumper wires and Breadboard
- Flat Black Spray Paint
1 - White Ping Pong ball
Step 2: Ball Balancer - Assembly
Assembly instruction for the Ball Balancer are found here: https://www.thingiverse.com/thing:2798979
Some additional tips:
Spray paint the inside of the rail flat black to reduce error from the sensor.
Linkage (Shown in picture above):
- Use a stiff wire about 7mm in length for linkage between the servo control horn and the sensor bracket.
- Level the rail, place the control horn horizontal at the mid point of the servo movement (servo value 90).
- Bend a small loop in the top of the wire, and a z shaped bend at the bottom of the wire.
- Put the z end into the control horn, mark the point at the center of the loop on the sensor bracket.
- Drill a small hole and use a small screw to attach the wire to the sensor bracket.
Step 3: Ball Balancer Wiring & Arduino Sketch
Refer to the picture above for wiring.
Use a separate power supply for the servo. This could be a bench power supply, or battery pack. I am using a bench power supply set at 5V.
The PID Fiddler will be attached by two wires, one to Pin 1 (Serial RX), and one to ground.
The sketch is provided.
Sketch Notes: The set point value will change from 200mm to 300mm every 15 seconds. It is helpful to use the Serial Monitor on the Arduino IDE to see the sensor output.
Step 4: PID Fiddler 2 - Parts
3D printed shield and knobs are found here: https://www.thingiverse.com/thing:2805654
4 - 10 Kohm pots
1- Momentary Contact Buttons: https://www.adafruit.com/product/1010
1- Adafruit Monochrome 128x32 I2C OLED Graphic Display: https://www.adafruit.com/product/931
1- Arduino Uno
- misc. header ping (.1 in), terminal blocks, hook up wire
Step 5: Pid Fiddler 2 - Wiring, Assembly and Arduino Sketch
Use wiring diagram for wiring the shield.
- For tips on making custom circuit boards, see my instructable: https://www.instructables.com/id/Custom-Circuit-Boards/
- Super glue headers on the 3D printed shield.
- I use wire wrap wire.
- Use square bottom pots and cut off mounting tabs, hot glue them in place.
- Components are soldered. Use female header for the OLED, and the OLED can be easily unplugged and removed for use in other projects.
- Connect a wire from the terminal block (wired to pin 2, TX) to pin 1 (serial RX) of the Ball Balancer Arduino. Connect a wire between the terminal block (ground) to the ground of the Ball Balancer Arduino.
- Hold down the button, adjust knobs to adjust PID settings, release button to send the values to the Ball Balancer.
Step 6: Using Ball Balancer and PID Fiddler
The only thing left is to start playing with it!
- Place the ball on the rail.
- Hold the button down on the PID Fiddler, set P, I, and D to zero, ST to 200 to start.
- The servo will stop responding.
- Now start experimenting with different P, I, and D values to see how it affects the response and movement of the ball.
- Try changing values for Sample Time (ST). The sample time is the time in milliseconds the input is collected. The values are averaged over the sample time. The sensor output of a still target will vary by a small amount. If the sample time is too small, the output of the PID will "jitter". The PID is trying to correct for the noise in the sensor readings. Using longer Sample Times will smooth out the noise, but the output of the PID will become jerky.