An inverted pendulum (also called a cart and pole) consists of a thin rod attached at the bottom to a mobile cart. Unlike a normal pendulum, an inverted pendulum is inherently unstable. Inverted pendulums must be actively balanced to remain erect.
A self-balancing inverted pendulum is an ideal project for an EE student because it contains multiple useful subcircuits. My inverted pendulum consisted of the following circuits working in tandem:
I designed each of these components seperately, tested them, then incorporated them all into the final design.
The first section I designed was the power regulation. The motors are powered by an unregulated 12-14v DC power brick through the base. The purpose of the power circuit is to supply the rest of the circuit with a clean 5v signal. This is accomplished with an LM7805 IC and filtering capacitors to smooth out any ripples.
The algorithm used to steady the pendulum is very susceptible to high frequency noise from the feedback potentiometer. In order to prevent this, a lowpass filter was placed between this potentiometer and the A/D input port on the microcontroller. This filter was designed with the use of Texas Iinstrument's FILTERPRO software with a cutoff frequency of 60hz. A Bessel filter was used to ensure a smooth response to a step input (sudden movement of the pendulum).
After implementation, it was found that the lowpass filter was not sufficiently removing the high frequency noise so the smoothing capacitor on the second opamp was increased substantially until the filter performed adequately.
Initially, I was concerned that did not have a rail-to-rail opamp to use in the filter. Using a single-supply LM324 limited the output of the filter to 0v to 3.5v. Luckily, the potentiometer can travel more than the maximum recoverable displacement angle of 20 degrees before the opamp saturates.
I designed two versions of the control board. The first used a PIC18F2683 microcontroller. Unfortunately, this PIC didn't have the enhanced PWM module (ECCP) I needed to control the H-bridge. The second used an 18F4685 40-pin PIC. While a 40pin PIC is definately overkill for this project, I wanted to use the ECCP module available on the larger PIC. In the end, I decided the extra size was worth the time I would save by using the enhanced features of the large IC.
The rest of the control board basically speaks for itself. Four A/D pins are used for various inputs to the controller. Full bridge PWM om PORTC controls the H-Bridge. A capacitor is placed on this board to smooth out transients on the ground plane surrounding the control board.
Initally, I attempted to use a H-Bridge based on bipolar junction transistors (BJT's). I attempted to control these using antiphase locked PWM. Unfortunately, after building the circuit I found its performance unsuitable for my needs. Specifically, the transistors produced a significant amount of heat while in use. Instead of masking the problem with large heatsinks, I opted to redesign the h-bridge.
The second h-bridge I designed was based on power mosfets driven with a Microchip TC4424 IC. Using quality mosfets with low on resistance allows the h-bridge to run cool to the touch despite the load on the motor. This means the motor recieves the full power supplied to the circuit.
In the final design I opted to use sign-magnitude PWM control instead of antiphase-locked PWM. This made it easier to utilize the ECCP module of the microcontroller.
An inverted pendulum can easily be stabilized using a PID feedback control system. This means that the response of the device varies according to the current displacement (Proportional), the total displacement over time (Integral), and the rate of change of the displacement (Derivative).
This concept is easily summarized with the following block diagram:
In actual usage of the device, the three constants (K, Ki, Kd) are represented by three potentiometers on the device. This allows the constants to be adjusted so the PID control can be tuned for optimal performance. Although the microcontroller code is beyond the scope of this writeup, the code is available for download for anyone interested.
After testing each component seperately I layed out the circuit board of the final device. Each component of the device was designed with Cadsoft Eagle software. Unfortunately, the student version of Eagle limits the size of the designed PCB. To get around this limitation I combined each sub-circuit using Adobe Photoshop. I used tracks on the top layer of the PCB to connect each sub-circuit.
First, I created the base that the platform sits on. A headphone jack is attached to the center to supply the circuit with power.
Next, I built a platform and attached the motors.
Finally, the circuit was etched at home. Unfortunately, I don't have pictures of etching the final circuit board, but I do have some from an earlier module:
Microchip Ap Note using a PIC16f684 for an Inverted Pendulum
Blueroom Electronics - PIC programming resource