Inverted Pendulum Balancer Using Atmel Mega32
The goal of this project was to build and implement an inverted pendulum balancer, in the vertical two dimensional plane, using Proportional-Integral-Derivative (PID) feedback control.
The inverted pendulum balancer is a radio controlled car modified by adding a plexiglass platform and an inverted pendulum with free rotating pivot. The electrical component of the balancer brings together computational hardware (Atmel Mega32 microcontroller), an input angle sensor (US Digital Optical Shaft Encoder), and an output motor driver (National Semiconductor LMD18200 H-Bridge) onto a single board whose sole purpose is to autonomously control the motion of the car in order to keep the pendulum from falling.
Motivated by the School of Mechanical & Aerospace Engineering’s Feedback Control Systems course at Cornell University, our desire was to integrate the knowledge of stabilizing an unstable system using feedback control (MAE478), the fast, flexible computing power of microcontrollers (ECE476), and the use of real-world engineering tools and budgetary constraints imposed on us by project managers. The result was a simple, cheap, and fun device that completed our desired goal.
High Level Design
Our motivation originated from Feedback Control Systems (MAE478), a course that we are both currently enrolled in. We wanted to attempt at a project where we could implement a feedback controller with a microcontroller. The question was what to control. After doing some research, we found a Stanford University EE281 project by Geoffrey Bainbridge. This “Self-Balancing Robot” project attempted to design a one-legged robot which balances itself using a feedback control with Atmel Mega163 microcontroller. Bainbridge attempted to balance a rod directly connected by two wheels. He quickly added a third supporting wheel and pivot after the two wheel design created unwanted rotational motion about the vertical axis. In addition, Bainbridge used a tilt sensor to measure the robot’s angle. However, the tilt sensor proved to be inaccurate due to the combination of the robot’s horizontal acceleration and the arm’s gravitational freefall.
The basic structure of the feedback control system is shown below. The angle sensor reading is subtracted from the reference angle to produce the error. This error is used to calculate the motor control parameters using the PID algorithm (discussed below). The motor control is then sent to the device. We decided to keep our feedback control system SISO (single-input single-output) instead of MIMO (multi-input multi-output) for simplicity to help with our black-box modeling. The reference angle is the only input to the system, and the feedback control uses the error in angle from the reference and calculates a motor output.
Our limited mechanical engineering ability, along with the short timeframe to complete the project, favored the use of a prefabricated car. A four-wheeled vehicle would not experience the rotational motion that Bainbridge encountered in his project. RadioShack’s extensive selection of toy Radio Controlled cars made our selection process very easy. Once a stable vehicle with fast response characteristics was discovered and modified to hold an inverted pendulum, the search turned to finding a reliable, high-resolution angle sensing device. The two most viable choices were a MEMS accelerometer or optical encoder. After initial testing, the analog accelerometer could not perform as well as the digital encoder. Therefore, the 1024 cycles per revolution (CPR) optical shaft encoder from US Digital became our angle sensor. This is a vast improvement over the tilt sensor, as the encoder was not affected by the effects of gravity or the car’s acceleration.
The Atmel Mega32 microcontroller was used instead of the Mega163 due to its superior speed, for external interrupt sampling of the encoder data, and more versatile timer options. Initial black-box testing of the car’s DC motor capabilities gave us a good idea of the car’s performance. Different driving scenarios were observed, including single-direction driving and oscillatory motion. Upon finishing motor control, we moved on to testing the sensor. The optical encoder’s input signals were quickly converted to an error angle referenced from its initial count value.
The final design stage was the Proportional-Integral-Derivative (PID) Controller to relate angle error to motor velocity and direction (see equation below). The proportional term (A) applied a voltage to the motor proportional to the error. This value affected the cart’s response time; higher the proportional term, the faster the car’s response at the expense of system stability. The integral term (B) would correct any steady-state error that would occur due to any sluggish response by the motor. Integral control would give the motor a little extra “push” to ensure correct tracking of the reference angle. However, a higher integral control term would create oscillations that are either unrecoverable or may throw the system to instability. Finally, the derivative term (C) is used to smooth out changes in error over time. This term can usually smooth out the oscillations in the vehicle at the expense of slower response. Fine-tuning of these three variables according to system behavior will allow the car to balance the inverted pendulum.
Program & Hardware Design
Hardware Deisgn – The hardware required for the inverted pendulum balancer can easily be separated into 2 subsystems: Mechanical and Electrical.
Our first priority was to quickly acquire a device capable of forward and reverse motion, with quick transitions and fast acceleration. Lacking the knowledge of mechanical cart design and the ability to gear a motor correctly for sufficient torque to move the cart, we quickly adopted the idea of using a radio controlled car as our base. After testing various RC cars from RadioShack, we found a car that seemed to have the performance we required, along with a sturdy base which would easily allow for a pendulum apparatus to be installed.
The vehicle’s DC motor was located in an easily accessible location at the rear underside of the car. Six AA batteries were the manufacturer’s defined power source; therefore, we knew our power supply would have to supply at least 9 volts. The six AA’s were installed with a break in the last contact of the battery holder and an ammeter (DVM set to measure current) in series to measure the current drawn by the device. With the car not under load (i.e. not on the floor with the wheels in the air), the device drew 300 mA. We estimated that under load, the car would require at least 600-800 mA to run with enough power. After rummaging through many power supplies in the Phillips Hall Digital Lab, we found a 12v 1500mA power supply from RadioShack, which would be more than enough for our needs. It was later discovered that under load and quick transition in motion, the device actually drew approximately 900mA from the supply.
Upon choosing our device, our next task was to build an inverted pendulum on the car. A Plexiglas plate was used to create a platform on which to attach the pendulum (see Image 9 ). This plate was secured to the car with 4 bolts at each corner of the vehicle. At the center of the platform, two brackets were placed with their inside angles touching each other, connected by a ¼” screw, and used to create the pivot of the pendulum (see Figure 3). Finally, a 38” rod (3/8” diameter) was screwed into the center of the top bracket to create our pendulum. It would seem strange to have a 38” rod above a 12” car. The rod’s height, by design, however, acts in our favor, as the larger moment of inertia (and higher center of mass) actually slow down the rod’s initial movement. The added weight to the vehicle would amplify the unwanted effects of the car’s suspension system. Therefore, four elastic bands were placed around the car in order to lock the shocks in a compressed position.
With the pendulum sitting on the top bracket, and the screw acting as a pivot, our next task was to be able to detect the angle and direction of the pendulum’s tilt. Our first option was a MEMS accelerometer from Analog Devices, ADXL202E. However, initial tests proved that the accelerometer’s analog signal would not provide us with the resolution that we required for angle detection. The digital output of the leadless, surface mount ADXL202E was disabled with the PCB that we used to mount it. Therefore, we turned to the MAE department, where we were able to borrow a 1024CPR (cycles per revolution) optical shaft encoder from MAE478’s feedback lab.
(1) Atmel Mega32 Microcontroller [lab]
(1) 16 MHz Crystal [lab]
(1) National Semiconductor LMD18200 H-Bridge [sampled]
(1) Radioshack Grinder Monster RC Truck (Catalog #: 60-4311) [$11.97]
(1) US Digital Optical Shaft Encoder (S1-1024-IB) [borrowed from MAE dept.]
(3) Optoisolators (4N35) [lab]
(1) 110V 60Hz AC to 12V DC transformer (1500mA max) [lab]
(1) 6″x2-1/16″ PC Board [lab]
(1) Mini slide switch [$0.35 from Jameco #204142]
(5) .100″ Straight Male Headers [$0.16 each from Jameco #108337]
(4) Wire with 2 pin female connectors [$1.00 each from lab]
(X) Various resistors, capacitors, and wires [lab]
(1) 7-3/4″x6″x1/4″ Plexi glass [scrap]
(2) L-shaped metal [scrap]
(1) metal rod [scrap]
(4) threaded rod [scrap]
(X) Various screws and nuts [scrap]
TOTAL COST: $17.12 < $25.00 Budget
For more detail: Inverted Pendulum Balancer
About The Author
Leave a Comment
You must be logged in to post a comment.