Control of a Modified Ball and Beam System Using Tracking System in Real Time with a DC Motor as an Actuator

This paper presents amodified ball and beam system, with the intention of realizing a test bed, to study new control techniques in real-time.The ball and beam system consists of a ball over a long beam where the control objective is to stabilizethe position of the ball on the beam by changing the angular position of the beam.In this paper, the ball of the conventional system is replaced by a cart with an embedded microcontroller, enabling the use of a linear encoder as position sensor and allowing to transmit the position via RF (Radio Frequency). The mathematical model of the ball and beam is obtained through the equations of Newton-Euler and the equations were linearized. The system is controlled using the hardware-in-the-loop technique with MATLAB/Simulink.It is applied a tracking control system with entire eigenstructure assignment to control the position of the cart. The actuator used is a DC motor, and a PID(proportional, integral and derivative) control is used to perform the angular position control of beam.The simulation results and the experimental results are compared to validate the mathematical model. The results obtained were satisfactory with adequate accuracy.


I. INTRODUCTION
The ball and beam system is a classic problem in control engineering [1]. The system consists of a ball on a beam, which the purpose is to stabilize the position of the ball by changing the angular position of the beam [2]. The problem has two degrees of freedom, one is the translation of the ball and the other is the angular position of the beam. The ball and beam is an unstable open loop system, so feedback control is required [2]. The ball and beam is a mechanism used mainly in academic's field as a didactic platform.Several authors use these teaching platforms in their work. Some papers present the control study based on the mathematical model of the system, so several techniques are implemented and simulated. In [3] was used a pole placement control in the ball and beam system, in [4]was implemented a fuzzy approach and [5]presented PID (proportional, integral and derivative) and LQR (Linearquadratic regulator) technics. Another important fact about the ball and beam is that due to the simplicity of the plant, several authors present some changes in the model, e.g.in [6] the actuation system is changed,in [7], [8], [9] different types of sensors are used, as well as this work, that presents a change in the plant. This paper presents a continuation of the studies seen in [10] and [11], which the objective is to control a modified ball and beam using atracking control with entire eigenstructure assignment in real time using a DC motor as actuator.

II. BALL AND BEAM SYSTEM
The major change from the modified ball and beam present in this paper to the "traditional" system, is the replacement of the ball by a cart, the first version of this prototype was presented in [10] and [12]. As the project had some problems, those were solved in the plant presented in [11] that was used in this paper, as shown Fig. 1. The use of a cart allowed embedding a microcontroller (dsPIC30F2010), which has the function of decoding the encoder signal, thus determining the position of the cart, and transmitting it through a wireless transmitter/receiver with communication via RS-232 interface. Fig. 2 shows the cart.  The adoption of a linear encoder embedded in the cart, rather than analog sensors, such as resistive, infrared or ultrasonic, which are usually used to determine the position of the ball, in the "tradicional system", is due to the greater accuracy in position measurement and elimination of some commom problems of these sensors, such as presented in [6], in which it is necessary to use a filter to reduce the noise of the resistive sensor that increases the processing time, and [9] presents difficulties in the positioning of the ultrasonic sensor. The location of the encoder sensor coupled to the cart can be seen in Fig. 3, the sensor is pointed by an arrow.The wireless transmitter/receiver is presented in Fig. 4, it transmits the data with the position of the cart through the serial port of the computer. Fig. 5 shows the DC motor with the drive elements, pulleys and belt. The ratio of the transmission system is 3:1. Two pulleys of 20 and 60 teeth and a belt 120 mm of length were used. To perform the feedback on the DC motor, the internal encoder of motor was used, with 334 counts per revolution in with two channels. The motor has a reduction of 1/102, so the transmission ratio between the value measured in the encoder and the angle of the beam is 1/306.

III. MODIFIED BALL AND BEAM DYNAMIC
MODEL Using the free-body diagram shown in Fig. 6, and applying Newton's second law, the equations for the traditional ball and beam are obtained, with (1) referring to the ball and (2) to the beam. Where is the torque of the motor, is the moment of inertia of the beam, is the moment of inertia of the ball, is the radius of the ball, is the position of the ball, is the angle between the beam and the x-coordinate axis and is the gravity acceleration. The model is similar to the equations found in the literature as in [9] and [13]. As seen in [10] and [11], there are no significant changes between the mathematical models of the modified system and the traditional ball and beam.  Additionally, it is considered that the torques produced by the cart weight and moment of inertia of the beam are small compared with the torque of the motor. Therefore, the (4) can be ignoredand the dynamic of the system is summarized to (5). ̈= …………………….……………...……………(5) The system equation can be represented throughstate space (6) and (7). Where A is the state matrix, B is the input matrix, C is output matrix and Dis the direct transmission matrix, x is the input vector, y is the system output and u is the control action vector.

IV. CONTROL SYSTEM
The controller used for the ball and beam is a tracking system, its synthesis is presented below. A controllable open-loop system is represented by the th-order state and th-order output (6) and (12): where y is a × 1vector and = is a × 1vector representing the outputs which are required to follow a × 1input vector . According to [14] the design method consists on the addition of a vector comparator and an integrator, which satisfies the (13): ̇= − = − ………………………………… (13) In [14] is presented the state feedback control law to be used here, which is (14): This control law assigns the desired closed loop eigenvalues spectrum if and only if the matrices pair ( ̅ , ̅ ) is controllable [14]. It has been shown that this condition is satisfied if( , ) is a controllable pair and the condition (15)  The feedback matrix must be selected so that the eigenvalues are in the left-half plane for the closed-loop plant matrix of (17). Thus, the outputs ( ) track the piecewise constant command vector ( )in the steady state. The control system is illustrated in Fig. 7. The synthesis of state-feedback control, assumes that all the states are measurable or that they can be generated from output. The ability to reconstruct the plant states from output requires all the states to be observable. The necessary condition for complete observability is given by The reconstructed state vector ̂ may then be used to implement a state-feedback control law =̂. Since, the physical plant may be subjected to unmeasurable disturbances, which cannot be applied to the mathematical model. The difference between the actual plant output, and the simulation output ̂is used as another input in the simulation equation [14]. Thus, the observer state and output equations became, (19) and (20): where is the × observer matrix, the synthesis of can be seen in [14]. The eigenvalues of ( − )are usually selected so that they are to the left of the eigenvalues of .Thus, the observer states rapidly approach the plant states. The physical plant represented by (6) and (12) and the observer by (19) and (20) is shown in Fig. 8.

V. MOTOR CONTROLER
A controller widely used in industry for process control is the PID, each letter represents a different gain, respectively, proportional, integral and derivative. Its transient response is presented in (21) [15]. The popularity of PID in the industry is partly due to its good performance in several different processes and also because of its simplicity that allows the engineers to apply the controldirectly to the plant. It is only nee to tuned the gains, , and [15]. There are several ways to tune the PID gains, the most common is manual tuning through trial and error in simulations or even directly in the experiment itself. The process consists of applying a step in the system and checking its transient response [15]. The PID of the DC motor has been tuned manually in the motor itself.The model of the DC motor was not realized and it is also a stable system of easy tuning. The choice of tuning a PID controller is due to the ease of the application and there is no need of a mathematical model, besides speeding up the final experiments. The tuned PID gains are presented in Table 1.
The controller response is shown in Fig. 9 and Fig. 10. The firstone represents a square wave with a frequency of0.1 Hz and an amplitude of 5º. In the second, is showed a sine input signal with a frequency of0.2 Hz and an amplitude of 5°.  VI. SIMULATION Simulations were performed in MATLAB/Simulink to verify the effectiveness of the control over the proposed mathematical model. The first step is to represent the mathematical plant and control in the MATLAB/Simulink environment. The linearized mathematical model obtained in Section III, is represented here as blocks AP, BP and CP. The complete discrete plant along with the observer is shown in Fig. 11. Where the matrices are presented in (10) and (11).

VII. EXPERIMENTAL PLANT
The chosen position sensor is a linear encoder of 150 pulses per inch. To control the plant it is necessary to transmit the position to the control system, for that was used a wireless transmission via RF, which works as follows: the control system sends an interrupt request to the microcontroller, the cart position is read and sent in the interrupt routine. In this way the discretization time is determined only by MATLAB/Simulink and not by the microcontroller. It is not necessary to reprogram the microcontroller when the discretization rate of the control system is changed. The position of the cart is an integer of 16 bits, when using a transmitter/receiver with RS-232 interface, it is only possible to transmit 8 bits at a time, so it is necessary to transmit the position of the cart in 2 bytes. The convertion of the integer into the position of the floatingpoint cart is performed on MATLAB/Simulink. The baud rate used in serial communication is 9600 bps. Fig. 12 illustrates data transmission. The discretization of the mathematical model was performed using the ZOH (zero order hold) technique, the time used was 0.02 seconds. Fig.12: Wireless Communication.
The acquisition and request of the wireless signal performed in MATLAB/Simulink is shown in Fig.13. MATLAB/Simulink converts the cart position from binary to a decimal number and then converts counts to millimeters. In the output,MATLAB/Simulink sends an ASCII character, in the case, an open key ({).

Fig.13: Serial Communication in MATLAB.
The proposed tracking system for the experiments is shown in Fig. 14, as it can be seen, there is an observer to estimate the speed of the cart.Because using a time derivative would generate noise, since the encoder is a digital sensor.

Fig.14: Ball and Beam Experimental Control Plant.
With the DC motor the process is illustrated in Fig. 15, the ball and beam controller calculates an angle. The DC motor has an output feedback controller that will control the angular position of the motor, which follows the path pre-defined by the balland beam controller. And finally the angle acts on the ball and beam plant closing the cycle. In the expanded PID block, in addition to the controller, there is a block that adds noise to the controller output, as show inFig. 16. Two digital ports are required to operate the motor, which will control the direction of rotation of the motor and a frequency output that generates the PWM.

VIII. RESULTS
The control of the ball and beam plant is performed by the tracking system, and the motor is controlled by the PID, in the first test a step input was used. It is noteworthy that, the simulation does not contain the mathematical model of the motor, neither the PID, only the mathematical model of the ball and beam system.
The set of pulleys plus the reduction of the motor has a transmission ratio of 1:306, this is in agreement that was established as hypothesis in the mathematical model, where it is assumed that the inertia and the mass of the beam are negligible in relation to the torque of the motor. The purpose of using a relatively high gear ratio for the system is to cause an "inertial uncoupling" of the system, so that the open-loop motor has the same behavior as when coupled to the system. In the tests the following eigenvalues were used [2.811474014; 2.973049064; 2.97386922] rad/s, a genetic algorithm was used to find the eigenvalues [11]. As seen in Fig. 17, the real system is close to the mathematical model. The system converges to the given reference value. Fig. 18 shows the output of the ball and beam controller and the output of the PID controller, it is verified that both responses are close.  A square wave was used as an input signal in the system, the results are shown in Fig.19. The response presents a stationary error due the friction and because of the nonlinearity of the plant it occurs oscillation. Fig.20 shows the PID response when the system input is a square wave.

Fig.18:Response of the PID Control for a Step Input.
A sinusoidal input was also tested as shown in Fig. 21, the frequency of the sine used was 0.2 Hz, it is worth noting that the cart does not stop during sine input, which reduces the influence of friction. The main differences between the mathematical model and the real system are given at the inflection points of the curve, since the cart tends to stop and take some time to start moving again. Fig. 22shows the control action of the system when there is a sinusoid as input, it is possible to perceive the proximity between the output of the tracking system and the output of the PID, another interesting fact that is visualized in Fig. 22, is that the control action is around the 1° (One Degree) position, this is due to inaccuracy in the zeroing of the equipment. One solution to this is to use a Z-channel encoder that indicates the zero position or use an absolute encoder that has all the preset positions.   The main problems encountered in the system are the oscillation, which occurs because of the nonlinearities not contemplated in the model and the regime error that is due to the friction, a solution found to prevent the cart to stop is to add a noise to the PID control action, the system response is seen in Fig. 23. The stationary system error has been reduced, as has the system oscillation. A white noise of 0.001 ° of intensity was added. Fig. 24 shows a noisy control action, it is evident that the control action it's closer to the control action calculated by the tracking system, an oscillation added to the system prevents the cart from stopping thereby, avoiding the static friction. IX. CONCLUSION The model proposed through mathematical modeling has proved to be efficient. The eigenvalues found were fast enough to control the plant without saturating the actuation system. The differences between the simulations and the experimental tests are probably due to the cart friction and other non-modeled nonlinearities. Controlling both the motor and the ball and beam simultaneously, proved to be a challenge. It is fundamental to be familiar with the system, to know the reference axes and directions of rotation, since the tracking control wasused as a reference to the PID control, so any reference error will result in divergence of the system. Another difficulty is work with two controllers simultaneously, sometimes it is simply not clear, each gain changes in the system as a whole, or in which controller it is necessary to make some change. Despite the difficulties, the experiment presented satisfactory results, the controller presented oscillation and delay in the reversal of direction. An efficient way to reduce stationary error and the oscillation was to add a noise to the output of the PID, the results have improved considerably. In future works, it will be interesting to model the DC motor used, and to perform a control technique in the motor based on the model. Probably the motor will tend to have a better performance, a control technique that can be used is the cascade control for position. One technique to be studied for the ball and beam is the robust control, as it is possible to choose a range of eigenvalues that improves performance.