Analog Ball Balancer
July 14, 2011
This page is about my experiments with a ball balancer, a robot that has a single sphere for a wheel. Basically it works like a Segway except it needs to maintain balance in two dimensions instead of one. I've been thinking about building one for several years but couldn't seem to get motivated until I saw the Honda U3X. It's a personal self balancing unicycle. Since the powered omni-wheel design Honda used is beyond my abilities I figured a ball would provide similar results for a lot less work.
A few years ago I built a small two wheel balancer. Please refer to this web page for the basics of how to perform an electronic balancing act. Here I will go into additional details about how to drive a sphere, combining sensor inputs, closed loop motor control, tachometers, speed feedback and radio control. And, it's all done with analog op-amps.
This particular device is a personal research project and has no practical use beyond its educational value. Although, a friend suggested I put a grass skirt on it and program it to dance the hula. I may build a larger human rideable version based on what I learned from this.
Ball Drive
The first step to making a workable ball drive is understanding the placement of the drive rollers. When standard wheels or rollers are used they must be placed on the equator of the driven ball and be placed 90 degrees apart. The top of the ball rest against a ball caster which is free to roll in any directon. This arrangment allows movement in 2 dimensions, X and Y. There is no yaw control (z axis rotation) There are other arrangements using omni-wheels that also deal with yaw but I won't cover them here.
I used four active drive points with four motors for simplicity. Two motors and some sort of belt or chain drive would also work. I tried using only two drive points and passive rollers on the opposite side but there were problems with the ball being ejected due to unbalanced forces. With equal drive on opposite sides we have one side pulling upward and the other pulling downward. The forces cancel and there is no net force to eject the ball.
I used a 5 inch toy basket ball in this project. The sphere needs to be fairly rigid and have good traction. While walking through Walmart I noticed basket balls. They're inflatable and are wrapped in reenforcement cords that limit their expansion when pressurized. When you increase pressure they get stiffer but don't expand. That is until the cords break and it explodes. ( I'm using 20 psi in this one.) They also come in several sizes and are cheap. Basket balls are ideal for light loads but a larger human rideable version might require something more solid like a bowling ball.
Gyro and Accelerometer
Sparkfun sells several small boards with rate gyros and accelerometers on them. They call them IMUs. I used the SEN-09268 model. It has a IDG500 2 axis rate gyro, a 3 axis ADXL335 accelerometer and runs on 3 volts. Data sheet links are at the end of this page.
There are some issues with this device. The X axis accelerometer needs to be paired with the Y axis gyro and likewise the Y accelerometer with the X gyro. The polarity of the Y axis accelerometer needs to be inverted relative to the X gyro it's paired with. Also be aware the accelerometers outputs have a 32K ohm impedance and the gyros have an AZ (auto zero) pin which must be grounded.
Motor Driver
To save time I ordered a Sabertooth 2x5 motor controller from Dimension Engineering. It can control two 5 amp 18 volt motors independently and has several input control options including 0-5V analog voltage. The control is linear and continuous. In analog mode 2.5 volts is zero speed, 5 volts is full speed forward and 0 volts is full speed reverse. This interface is perfect for interface to analog op-amps. It also has several digital input modes that are perfect for either R/C PWM or microcontrollers. It even has a handy regulated 5 volt output that I used to power all of the control electronics in the bot. Here's a link to the datasheet pdf.
Tachometers - why we need them
A tachometer is a small generator coupled to the drive rollers that outputs a voltage proportional to the speed of the drive roller. The voltage output also reverses polarity when the roller reverses.
I used small DC motors for the job because I had several suitable ones in stock. The small 2 wheel balancer I previously built did not have tachometers or "tachs".
There are two problems created when you don't know the speed of your wheels. First of all the motor has a dead zone near zero volts. It will not move at all until the voltage gets high enough to overcome friction. This nonlinear section of the voltage-speed curve confuses the balance correction feedback and causes instability. Since most of the delicate balance corrections are done at very small voltages the effect is pretty pronounced. This can be completely solved with a closed loop proportional plus integral speed regulator. Basically voltage from the tach is fed back and compared to the desired speed. If the tach voltage is too low the motor voltage is raised and if it's too high motor voltage is lowered. Precise speed regulation at very low speeds and with varying loads can be achieved.
The second problem with not knowing speed involves maintaining position while balancing. Without speed feedback the bot will balance and hold position only if it's trimmed to be exactly vertical. If tilted slightly it will rotate the wheels to correct. It will slowly accelerate until it reaches maximum speed then fall on its face. I believe this is caused by the tilt vector being canceled by the acceleration vector. It thinks it's vertical when it's not. Positive speed feedback can be added to the tilt error term to cancel the effects of acceleration. In fact, if taken to the extreme with proportional plus integral feedback will even allow the bot to hold position on an incline.
Below is a video of the bot operating without any tachs or speed feed back of any kind. Note the jerky motions when it trys to correct balance with the motor in the dead zone and suddenly over corrects once the motor starts.
This next video shows the improvements given by tachs and speed feedback. In this case I used proportional plus integral speed feedback which forced the bot the stand still until a substantial weight was added to one side. It even held position on a slight incline. Also when forced to move it tended to try to move back to its former location. Analog memory in action.
P+I motor speed regulator
Here is the basic schematic of the speed regulator. It combines both integral and proportional functions in a single op-amp. To tune it I fed a 1 Hz square wave to into the "set speed" input and adjusted everything so the motor alternated forward and reverse at about 1/3 speed once per second. Then I monitored the "tach input" with a scope. When it's tuned properly the scope will show a clean 1 Hz square wave with minimal ringing or undershoot. R1 and C1 seem to be not to critical. Most of the tuning can be done by adjusting only R2. In the real circuit the op-amp + input is connected to the 2.5 volt bias so the output swings above and below 2.5 volts to be compatible with the sabertooth 2x5 motor controller. Also C1 is 0.33uF in the final version.
Sensor fusion and the complimentary filter
Don't freak out, this isn't too scarry. Sensor fusion is the process of combining two different sensors to get the best features of each. In this case the accelerometers and rate gyros are combined to generate a more accurate estimate of the tilt angle than either one alone.
Rate gyros are not sensitive to acceleration but only provide the rate or derivative of tilt. We could integrate the signal to get a signal proportional to tilt but both the integrator and gyro zero point will drift with time.
Accelerometers will provide the sine of the tilt angle without any drift issues but are also very sensitive to acceleration. Due to the accelerometers sensitivity to acceleration we need to low pass filter its output so only slow long term changes are present . Sadly when filtered this much the response time is way too slow.
Someone came up with a clever solution. We simply add the gyro and accelerometer signals then filter them with a low pass filter. If the amplitudes of the gyro rate of tilt is properly balanced with the accelerometer signal the output will be a pretty clean tilt signal. Basically, the accelerometers high frequency tilt information that is lost due to the filter rolloff is replaced with the rate gyros signal which is rich in the otherwise missing high frequencies. The accelerometer gives us long term tilt and the rate gyro supplies the short term tilt. If the amplitudes are matched properly they will compliment each other and result in a flat frequency response.
Also keep in mind the gyro signal is the derivative (rate of change) of the tilt. As such its amplitude will increase 6 db per octave and it will have a 90 degree phase shift relative to the acceleromters tilt signal. So, when you add the amplitudes of the accelerometer and gyro you are really doing complex math. 1+1 = 1.414, not 2! [ sum = sqrt(Acc^2 + Gyro^2) ]
Above is a schematic of the basic complimentary filter. The 3db cutoff frequency is about 0.33 Hz. R2 and R3 need to be adjusted to balance the two signals for a flat frequency response. There is nothing special about 0.33Hz. The lower it is the more fast acceleration is removed and you need to add more gyro to make up for it. In the real world the op-amp + input should be connected to a pot to adjust the zero tilt bias point.
Here are some scope screen shots of the waveforms resulting from manually tilting the Sparkfun IMU a few degrees for about 3/4 second then returning to the original position. Because the pivot point was not on the accelerometer axis there is some sideways acceleration mixed with the angle change. You can see it on the leading and trailing edges of the green accelerometer traces. Note how it's removed from the filter output in the final screen shot.
In this shot you see the filter output (purple) with only the accelerometer connected. Note the slow sluggish response compared with the green trace (input). It took 3/4 second to fully respond.
Here is the output with only the rate gyro connected. Note the quick response but loss of all DC and low frequency information.
The purple trace is the sum of both accelerometer and rate gyro after passing through the 0.33 Hz low pass filter. It responded in less than 50 ms. This is the tilt informantion we need to maintain balance.
Yes, it's f'in magic.
To tune it for the correct ratio of gyro to accelerometer you adjust R2 and/or R3 until you get an output that looks like the purple trace.
This works well but is still not ideal. The gyro DC offset is still passed through and if it drifts it will shift the zero tilt calibration point. I think I need to experiment with a highpass filter in the gyro path.
Radio Control
A robot that simply balances on a basket ball and doesn't move is pretty useless and not very interesting. So, I added another board with an R/C receiver and PWM to DC converter. The output of the converter is a DC voltage that varies from 2 to 3 volts depending on the transmitter control stick position. I've included the schematic of this circuit with the main schematic. This control voltage is summed with the tilt signal. As a result the bot thinks it's tilted and corrects by moving to correct the false tilt. Unfortunately it's difficult to maintain direction because the bot tends to rotate about the Z axis and change where "front" is relative the the remote driver. A human riding it could correct yaw by dragging a foot.
Here is a video demo of radio control.
Tuning
There are a lot of adjustments required to make this thing balance and remain stable. Here are the basics of what I did.
1. Provide a means of disabling the integrators on the X and Y PID processors. Shorting the caps C3 and C6 will do it. I advise switches or 2 pin shorting jumpers.
2. With the integrators disabled, speed feedback turned off, Radio controlled disconnected, D set to minimum, P and K set midrange and the ball removed adjust the X and Y ZERO pots for zero motor speed. Verify the motors turn in the correct direction when tilted. Reverse the leads if not. Also reverse the tachs.
3. Insert the ball and place on floor. Turn it on. Now it gets tricky. Re-adjust the X and Y zero pots until it wants to stay vertical then if it seems stable enable the integrators and start tweeking P,I,D and K for robust and stable balance. Turning the controls up to high will cause it to suddenly go crazy so be ready at the OFF switch.
4. At this point it's balancing but small weight shifts will send it scooting across the floor. Slowly turn up the speed feedback until it will stop on its own after being shoved.
5. Pre-adjust the radio control PWM to DC converter for 2.5 volts out when the stick is in neutral position then connect it to the main board. Small tweeks to the PWM to DC converter may be required to prevent creep.
Simpilfied System Block Diagram (only one axis shown)
Full schematic diagram pdf file:
Data Sheets.
Sabertooth 2x5 motor controller
Hit Counter 30969
Previous page: Simple Analog Balancing Bot
Next page: Overthruster 30# Combat Robot