Development of Microcontroller-Based Ball and Beam Trainer Kit

A ball and beam trainer kit based on microcontroller was developed for teaching control system course for the sophomore students. This specially-purposed kit consists of a ball located on a beam with a fixed axle at one of its end. At the other end, a servomotor was employed to control the position of the ball by adjusting the rotation angle of the servomotor. Seven predetermined positions were set to 10, 20, 30, 40, 50, 60, and 70 cm relative to the fixed axle of the beam. The Proportional-Integral-Derivative (PID) scheme was then used to compensate the error. This kit is equipped with a user interface to configure controller coefficients, select the set points, plot the actual ball position, and display parameter values. The user interface program runs on PC or notebook connected to microcontroller via serial communications. A questionnaire-based assessment about the use of this kit was conducted by 17 students taking the course, giving a rating value of 94.12%.


Introduction
Traditionally, control systems courses are offered by Electrical and Mechanical Engineering Departments all over the world.As in many other university-level technical courses, interactive tools have been very helpful for the students in order to better comprehend the substances along with formal lectures and exercises.Mostly, an interactive tool in control education provides graphical windows which employ active, dynamic, and clickable components.An interactive tool using Easy Java Simulations was implemented in the field of Control Engineering education [1].A simulator was developed using user friendly virtual interface software to control the speed of a small size DC motor.The user is able to select and adjust the parameters of any desired controller that is defined and represented virtually [2].Educative tools, Linear System Analysis and Design (LSAD) [3] and Interactive Learning Modules for Proportional-Integral-Derivative (ILM-PID) [4], were built to make students more active and involved in their own control engineering learning process.Excel spreadsheets for basic control education was developed to help students understand how feedback works [5].The Ch-Control System Toolkit, a software package for the design and analysis of control system, was utilized to develop Web-based Control System Design and Analysis System (WSCDAS) and Web-based Controller/Compensator Design Module (WCCDM).These software tools were used for teaching automatic control of linear time-invariant system [6].A control simulation for nonlinear system was applied using JAVA-enabled open source software, therefore, students have all necessary elements to practice using nonlinear system which in this case an inverted pendulum [7].
However, all of the above mentioned works were merely implemented by the use computer-based virtual tools.An actual system needs to be constructed in companion with such virtual counterpart.Microcontroller is a compact microcomputer containing a processor core, memory, input/output peripheral, timer/counter, which is able to govern the operation of any plants.Microcontrollers have also been used in learning control system with laboratory scale practical models.Low-cost digital temperature control kit was designed to implement various control strategies using microcontroller [8].A microcontroller-based control application was designed to distribute supervisory and control tasks within a plant in industry [9].Low-cost educational microcontroller-based tool for fuzzy logic-controlled line-following mobile robot was put into practice for teaching second-year students [10].
Ball and Beam is a widespread example of application of feedback control system and has been theoretically taught in most universities.In this paper, an ATMega 8535 microcontroller-based ball and beam simulator was built to encompass both virtual and actual tools for learning control system course.This kit consists of a long beam which can be tilted to control the displacement of a ball on it using Proportional-Integral-Derivative (PID) controller.Hardware details and the user interface implementing the controller are given in the paper.

System Modeling
A set of mathematical equations was addressed to represent the ball and beam employing appropriate physical laws.All variables contained in the ball and beam system are shown in Figure 1.The exerted force due to translational motion, F tx , is: While the torque of the ball due to rotational motion, T r , is: where, F rx = exerted force due to ball rotation J = moment of inertia of solid ball ω b = angular velocity of the ball v b = translational velocity of the ball From (1), (2), and (3) we obtain: It is obviously known that W x is the force due to mass of the ball (m) and gravitational acceleration (g) along the x-axis while neglecting frictions between the ball and the beam, and can be formulated by: By dividing both sides by m, we have: For α small, sin α is approximated by α, giving: Meanwhile, the relationship between the angle servomotor axle and the beam is given by: By substituting Equation ( 8) to ( 7), we get: Therefore, the transfer function of the ball and beam in s-domain is given by: Constants g, d, and L are 9.8 m/s 2 , 5 cm , and 69 cm, consecutively.It is very clear from the above transfer function that this system is of second order with double roots on s=0 at the denominator.It also means that this open-loop system has double pole which lie right on the imaginary axis of s-plane, implying an unstable nature.It makes sense since the ball always keeps rolling down due to the gravity and never rolls back up to reach set points whenever the beam is steadily tilted up.MatLab simulation shows that the step response blows up as the time goes on, as shown in Figure 2. The design of the Ball and Beam consists of the closed-loop control system modeling, mechanical and electronic hardware, and microcontroller software.The overview of the system is shown in Figure 3.

Mechanical Design
The designed ball and beam system has a dimension of 90 cm, 15 cm, and 26 cm in length, width, and height, respectively.A billiard ball, having diameter of 5.65 cm and weighing about 180 gram, rolls back and forth by the use of servo-mechanism to reach any desired set points.The mechanical hardware is shown in Figure 4. Two infrared ranging sensors GP2D12 are placed at both ends of the beam and 5-voltpowered to measure the displacement of the ball.These sensors apply triangulation principle with infrared LED as the emitting element and Position Sensitive Detector as the receiver.An integrated signal processing was pre-embedded in the sensors to produce analog voltages as the output.These sensors are able to detect any objects 10 to 80 cm away.The output voltage of GP2D12 when detecting 10 cm and 80 cm-away objects are 2.6 and 0.4 volts, respectively.The object must be 6 cm in diameter to be properly detected from the distance of 80 cm [11].In order to acquire valid ball displacement data, the microcontroller sample left and right GP2D12 sensor values with interval of 1 cm.The acquired data are then put into a look-up table, which in turn, build a linear interpolation to determine all possible positions of the ball.The left GP2D12 measures the ball displacement starting from 0 cm to 35 cm, whereas the right GP2D12 measures the ball displacement starting from 35 cm to 60 cm.
The actuator activating the Ball and Beam is a servomotor Turnigy 620MG which is equipped with internal closed feedback inside [12].A servomotor consists of DC motor, gearbox, variable resistor, and control circuit.The rotational angle of servomotor is determined 49 by the duty cycle of pulses with period of 20 ms.Horn and extender were assembled at the servomotor axle to adjust its angle and thus tilt the beam up and down.A 5 cm horn was meant to increase the angular velocity of the beam.An R-C (resistor-capacitor) low pass filter which has cut-off frequency f c =1.608 Hz was implemented by the means of software to stabilize data acquisition of both left and right GP2D12.Suppose sampling period = ∆t, then input voltage Vin(t) was sequentially represented as x i , x i+1 , ..., x n and output voltage Vout(t) was sequentially represented as y i , y i+1 , ..., y n , then the discrete low pass filter is given by: Where a=RC/(RC+∆t) In order to monitor the status of the system, a set of debugger was added into system.A red Blue LED indicated the beam status whether "Run" or "Stop".A Red LED and buzzer indicated whether or not a ball was already on the beam.A 16x2 character LCD displayed information regarding to the serial connection status with user interface program as well as the beam status.The heart of the system is the AVR ATMega 8535 manufactured by ATMEL Corporation [13].This handy chip facilitates internal Analog-Digital Converter, large program and data memory, internal comparator circuit, internal Pulse-Width Modulation, and internal timer.Subroutines of the controller handle time sampling tasks, data acquisition from GP2D12 sensor, data-filtering using low pass filter, data conversion to displacement, PID calculation, servomotor angle adjustment, and connectivity to user interface program via serial communication on PC or laptop for both sending data to be plotted by user interface program and receiving commands from user interface program, as shown in Figure 5. the open-loop poles, which originally lie on the imaginary axis, to the left-half s-plane.PID calculation was initialized with error calculation, i.e. difference between set points and process variables.The obtained error was the used to calculate manipulated variable (MV), which is formulated by: Then, the value of MV was used to control servomotor pulse duty cycle through pulse width modulation (PWM).During calculating PID, the integral and derivative sampling period was 50 ms.The transfer function of closed-loop system is now of fourth order and given by: Figure 6.Block diagram of closed-loop system The realized Ball and Beam system is depicted in Figure 7.

User Interface
The user interface program was used to adjust PID configuration within closed-loop control system, select the desired set points, display the plot of ball displacement and set points, and calculate the rise time, peak time, maximum overshoot, and settling time, as shown in Figure 8.The application design was accomplished in Visual Studio 2010 with Visual Basic programming language (VB.Net).On the user interface main page, there are three major displays, which are: control panel, plotter display, and info display.While communicating with the microcontroller, an updater program handles datasending task to user interface program as well as data-receiving from user interface program via serial communication with baud rate of 115200 bps.Along the communication, character string packets were transmitted and then translated into instructions or commands.The format of the character string packets received by microcontroller was defined as #[instruction]X.The character "#" was used as the initial mark while the character "X" was used to end the data packet.The instruction itself lies between character "#" and X".Meanwhile, the microcontroller sent character string packet which no longer needs initial marks but only end marks "/n".

Results
A set of tests was carried know to assess the overall performance of the Ball and Beam training kit.

User Interface
Such tests were done to obtain the optimum K p , K i , and K d constants with respect to the rise time, maximum overshoot, peak time, and settling time [14][15], as well as to evaluate the performance of the closed-loop system.Testing mechanisms were carried by adjusting set points from 20 cm to 10 cm, as indicated in Figure 10.The overall performance of the system needs to be evaluated by calculating rise time, maximum overshoot, peak time, and settling time at all set points using specified K p , K i , and K d configurations.Evaluations were carried by adjusting set points every 15 seconds starting from 0 cm, 10 cm, 20 cm, 30 cm, 40 cm, 50 cm, 60 cm, 50 cm, 40 cm, 30 cm, 20 cm, 10 cm, and finally back to 0 cm.All test configurations were conducted four times and then evaluate the average of rise time, average of maximum peak (Mp), average of peak time, average of settling time, and percentage of successful settling.

Feedbacks from Students
Seventeen students taking the Control System course were required to fill out a questionnaire as a basic assessment about the use of the microcontroller-based Ball and Beam.The statement in the questionnaire had to be answered on a five-point Likert scale with points 1, 2, 3, 4, and 5 representing "strongly disagree", "disagree", "neutral", "agree", and "strongly agree", respectively.After exploring and practicing the Ball and Beam system, they gave their opinion on the following statements: The Ball and Beam helps students to understand closedloop control system concepts and is easy to perform. Figure 11 shows the questionnaire result of the statement asked to the students.The result indicates that the microcontroller-based Ball and Beam system is an advantageous tool in achieving better understanding of closed-loop control system concepts and very easy to perform.The result of questionnaire was then converted to Rating Value of 94.12% indicating that the students were very satisfied.

Conclusion
We have developed an ATMega 8535 microcontroller-based Ball and Beam system which consists of infrared ranging sensors, servomotor, PID controller, ball and beam.A virtual user interface, which runs on PC or notebook connected to microcontroller via serial communications, was used to bridge out the system and students.Such user interface was aimed to configure controller coefficients Kp, Ki, and Kd, to select the set points, to plot the actual ball position, and to display parameter values, namely, actual error, rise time, maximum overshoot, peak time and settling time of the system.The PID constants Kp=5, Ki=0.2, Kd=45 was chosen to be the default configuration since it has the largest percentage of successful settling, i.e. 93.75%.This Ball and Beam training tool shows conformities with control system theory, in terms of physical modeling, system stability, and closed-loop PID-controlled system.Feedback from the students indicates that the Ball and Beam system is a helpful tool in achieving better understanding of closed-loop control system concepts and very easy to perform.

Figure 1 .
Figure 1.Ball and Beam physical model Development of Microcontroller-Based Ball and Beam Trainer Kit (Gunawan Dewantoro) 47

Figure 2 . 3 .
Figure 2. Step response of the open-loop system

Figure 4 .
Figure 4. Front view of the mechanical design Development of Microcontroller-Based Ball and Beam Trainer Kit (Gunawan Dewantoro)

Figure 5 .
Figure 5. Flow chart of controller subroutines Figure 6 shows the closed-loop control system consisting of a PID controller, plant (Ball and Beam), and low pass filter.C(s) is the transfer function of PID controller in s-domain, G(s) is the transfer function of the plant, i.e.Ball and Beam system, and H(s) is the transfer function of GP2D12 low pass filter.The PID controller was supposed to make the plant stable by shifting

Figure 7 .
Figure 7.The realized Ball and Beam a) Control panel consists of four panels: Beam Status, Plot Data, PID Configuration, and Ball Position.At ball position option, users are allowed to select the desired set points, as shown in Figure 9. b) Plot display has a grid area to plot the current ball position.The vertical axis represents the displacement (cm) ranging from -10 to 70 cm, while the horizontal axis IJEEI ISSN: 2089-3272  Development of Microcontroller-Based Ball and Beam Trainer Kit (Gunawan Dewantoro) 51 represents the time (s).The yellow line indicates the midpoint of the beam.The purple line indicates the ball displacement, while red line represents a marker on which the response starts settling.c) Info display shows time response characteristics, including: current position, set point, current error, rise time, maximum overshoot, peak time, and settling time.

Figure 11 .
Figure 11.Pie chart of the questionnaire