Design and Implementation of Classical Sliding Mode Controller for Ball and Plate System

B all and Plate (B&P) system is a benchmark system in the control engineering field that has been used to verify many control methods. In this paper the design of a sliding mode controller has been investigated and verified in real-time via implementation on a real ball and plate system hardware. The mathematical model has been derived and the necessary parameters have been measured. The sliding mode controller has been designed based on the obtained mathematical model. The resulting controller has been implemented using the Arduino Mega 2560 and a ball and plate system built completely from scratch. The Arduino has been programmed by the Arduino support target for Simulink. Three test signals has been used for verification purposes, namely: single point stabilizing, circular trajectory tracking


INTRODUCTION
The ball and plate (B&P) system shown in Fig. 1 is a promoted version of the traditional ball and beam control problem.The problem consists of a plate which its inclination can be manipulated in two perpendicular directions.The goal is to carry the ball moving on the plate to a desired position, that is to control a freely rolling ball in a specific position or moving it on a trajectory on the plate.The B&P apparatus is a two dimensional electromechanical device which can be further categorized as nonlinear, multivariable (with two inputs and two outputs) and unstable system.Furthermore, the system is under-actuated, as it possesses more degrees of freedom than the number of available actuators.Thus, the fact that the ball"s motion is indirectly controlled by changing the plate inclination in two orthogonal directions is quite an interesting challenge to consider.B&P system has a direct application in robotic manipulation of round objects.When it comes to indirect applications, the system can present many challenges and opportunities as an educational tool to university students studying control systems engineering.
Unlike other educational models, the B&P system has several interesting features for the study of unstable and nonlinear systems.Firstly, models like Magnetic Levitation, Inverted Pendulum and Ball and Beam are all one-dimensional.The degree of freedom (DOF) for Magnetic Levitation is one, for Inverted Pendulum and Ball and Beam is two.The B&P system has four DOF, i.e., with two independent motions of the ball about the plane of the plate and another two motions of the combined ball and plate inclinations (rotations) about the fixed pivot at the center of the plate.Secondly, the B&P system offers an opportunity to study trajectory tracking problems in addition to the stability problems that is the only subject that could be studied in the remaining educational models mentioned.
The ball and plate system has been studied and controlled in several control methods that ranged from linear control technique for optimal, intelligent, and nonlinear control.Some of the recent available researches on the ball and plate system are reviewed in this section.
In Linear controllers field: Jadlovská, et al., 2009 have designed PD, PID and proportional sum derivative (PSD) controllers for trajectory tracking of the ball and plate system.The result showed that the PD controller is much better than the PID controller with a relatively small overshoot.Ghiasi, and Jafari, 2012 have designed an optimal robust (H∞) controller for the ball and the plate system.The (H∞) controller has been designed based on lower fractional transformation structure with multiplication uncertainty.The authors didn"t show the transfer function of the (H∞) controller nor the (ɤ) parameter which is an essential part of determining if the control system is robust or not.Zeeshan, et al., 2012 have focused on the hardware implementation of the ball and plate with a cost effective design.They have used an array of eleven by eleven phototransistors to get ball position.This method gives a direct discrete position of the ball, but with low resolution.This required precise placement of laser sensors and the phototransistors.Two DC motors, one on top of the others was used to move the plate.A standard PID controller is used to implement position tracking.Galvan-colmenares, et al., 2014 have proposed a duel PD controller to solve the ball and plate regulation problem.A novel model for a ball a plate has been developed in the form of robot manipulator equations.The authors used the model for the stability test and to design dual nonlinear compensator for nonlinearities cancellation.According to their results the PD controller with compensator gave better results when compared with PD without compensator.Singh, and Saxena, 2015 have designed a PD controller for trajectory tracking problem of the ball and plate system.The PD controller was used in a cascaded control scheme, where an inner PD controller was used to control the plate dynamics and the outer PD controller was used to control the ball dynamics.The gains of PD controllers have been tuned by PSO.
In Intelligent controllers field: Wang, et al., 2008 have designed a trajectory tracking controller for the ball and plate system.The control system consists of a double loop structure.The inner loop has a servo controller, while the outer loop has a position regulator.The external loop was a single rule fuzzy logic controller with position, velocity and acceleration as inputs and plate angle as output.In Sliding mode field: Park, and Lee, 2003 have used an industrial robot manipulator as an actuator to change the plate"s angle.It has been assumed the motion of the ball and plate is slow enough to neglect the dynamics of industrial robot.A classical sliding mode controller is used for trajectory tracking purpose, it has performed well with tracking and was robust to uncertainty.
Liu, et al., 2009 have designed a sliding mode controller for the ball and plate system.Two scenarios have been used to deal with the uncertainties.In the first scenario, an upper and lower bound has been assumed on the uncertain items and disturbances.In the second scenario, an observer has been used to estimate it.The later scenario gave a better response in terms of tracking and disturbance rejection when compared to the first one.Debono and Bugeja Debono, and Bugeja, 2015 have designed integral sliding mode and state feedback controllers for the ball and plate system.An upper bound on the disturbance and uncertain items has been assumed in simulation.In the practical implementation, the integral sliding mode controller has been able to track a sinusoidal signal with magnitude of ±0.11m and frequency of 3Hz.Negash, and Singh, 2015 have used a sliding mode controller with fuzzy logic to control the ball and plate system.A double loop structure has been used to control the ball position.The sliding mode controller was used in the outer loop to stabilize the ball.A linear compensator based on Diophantine equation was used in the inner loop to control the x and y axis motors.The sliding mode chattering has been reduced by using fuzzy logic.

THE MATHMATICAL MODEL
Before any controller design, it is important to obtain a mathematical model for the system to be controlled which is a closest approximation of its true behavior.The system can then be analyzed, and controller can be designed to meet the required performance.The ball and plate system equations is given by Negash, and Singh, 2015: The schematic diagram of the ball and plate system that these equations describe is given in Fig. 2, while, the nomenclature is given in Table 1 and the parameters" values are shown in  Table 2. Eq. ( 1) and Eq. ( 2) describe the ball motion on the plate, and they tell that the acceleration of the ball movement depends on the angles and the angular velocity of the plate inclination.Eq. ( 3) and Eq. ( 4) tell how the plate inclination dynamics is influenced by the external driving forces.The system can be simplified with the following assumptions: 1.If the system inputs are considered as and instead of the torque moments and , where the plate is assumed to move to the specified angles instantaneously, then the equations ( 3) and ( 4) could be dropped out. 2. In the steady state, the plate should be in the horizontal position where both inclination angles are equal to zero.If one assumes that the angle do not change much, say ±30°, the sine function can be replaced by its argument.Based on these basic assumptions and by substituting the moment of inertia of the ball, into Eq.( 1) and Eq. ( 2), two ordinary differential equations are obtained.

CLASSICAL SLIDING MODE CONTROL, Utkin, et al., 2009
Consider a nonlinear dynamical system described by Where is the state vector, is the control vector, , are generally nonlinear functions, and is the uncertainties and disturbances.The task is to design a function of states called sliding function and a state-feedback control law ( ) That will drive the state towards the sliding surface (reaching phase), see Fig. 3, and then slide it to origin [ ] (sliding phase).If the states are considered as the difference between some physical states and desired trajectories, then a tracking behavior can be ensured if the states return to origin.The design of sliding mode controller requires: I.
Selecting a manifold or sliding surface in such a way that makes the system follow a desirable performance when the trajectory subjected to the sliding manifold.II.
Finding a feedback control law that makes the system trajectory hits the sliding surface and stays on it.
The surface function is designed to resemble the distance of the states to the sliding surface.The value of must not equal "0" when that state is away from the sliding surface, and equals "0" when the state is on the sliding surface.The control law of the sliding mode controller will switch its value based on the sign of this distance.So, the sliding mode controller will always try to direct the states towards the sliding surface where s(x) = 0. Since the controller is not a continuous one, the time to reach the surface is finite, and any trajectory hits the surface will slide along it to the origin x = 0. To make the system states satisfy , the following conditions are required: I.
Reaching has to be ensured from any initial condition.II.
Once is reached, the control action has to be able to maintain it.
Based on that lets consider the following Lyapunov function candidate: Where ‖ ‖ is Euclidean norm, i.e., ‖ ‖ is the distance to the manifold where .A sliding mode will exist when the sufficiency condition is satisfied (where; ).This condition is also known as the reachability condition.As an example, when a scalar system is considered (with in Eq. ( 7)), to achieve the feedback control law is designed so that and have opposite signs.That is; 1. makes negative when is positive.
2. makes positive when is is negative.So for the system given in Eq. ( 7) and the Lyapunov function candidate given in Eq. ( 8) we have: according to existence and reachability condition The time derivative of the surface function is given by: Thus, the responsibility of the control action is to keep the states directed toward the surface, hence is given by Where; is the switching gain that usually compensates for the uncertainties and the disturbances in case their upper bounds are known.By substituting Eq. ( 12) in Eq. ( 11): By choosing as Eq. ( 14) states, the condition Eq. ( 10) can be ensured.
Where is a small positive design scalar.The condition in Eq. ( 10) becomes; From mathematical point of view, the differential equation Eq. ( 7) can no longer be solved because the input signal is no longer unique.One method to solve Eq. ( 7) that was suggested by C. Edwards, and S. K. Spurgeon, 1998 is the method of equivalent control.The equivalent control is the required control action to maintain the sliding motion and is derived by equating Eq. ( 11) to zero without considering the uncertainty .
{ } In fact, the equivalent control is the low frequency component of the switching signal, or in other words, low pass filtering the infinitely fast switching control input.In general, Eq. ( 16) would not itself induce a sliding motion and it does often form part of the overall control law, as shown in the first term of Eq. ( 12).However, despite the fact that the Eq. ( 16) and the first term of Eq. ( 12) is identical, their interpretation is different.Where the equivalent control gives a continuous interpretation of the total control signal, the first term of Eq. ( 12) should be seen as an approximation of the required signal to maintain sliding mode.
The classical sliding mode controller design for the ball and plate system is given below: Returning to the Eq. ( 5), the design for x axis is as following: Where: With substituting Eq. ( 21) in Eq. ( 22): Where: is the slope of the sliding surface.The same procedure is repeated to design the controller for the axis by using Eq. ( 6).In both controllers, a saturation function is used instead of "signum" to reduce chattering.

BALL AND PLATE HARDWARE
The ball and plate hardware consists of several components that are working together in harmony to accomplish the central task of ball stabilizing and trajectory tracking.The system can be divided into two parts: mechanical system and electrical system.In mechanical system the physical structure of the ball and plate is presented which consists of the plate, joints, linkage... etc.The electrical components consist of the microcontroller, touch screen, motors...etc.
The mechanical system represents the physical structure of the ball and plate system in which several components are present.A comprehensive view of the system with the components being apart is shown in Fig. 4. The structure consists of a plate made from Acrylic in which the touch screen will be fitted inside.This plate sits on central pillar which goes inside a universal joint this makes the plate able to tilt in two perpendicular directions.Two braces are attached to the plate to deliver the movement of the two servo motors to the plate via linkages.The linkages will transmit the motor movement from the servo arm to the braces, each linkage has a ball joint end to enhance the movement.The whole structure is fitted on a wood made base.The description of each component in Fig. 4 is shown in Table 3.
The electrical system is responsible for ball position sensing and plate moving and controlling.It consists of a touch screen, servo motors, Arduino MEGA, DC-DC converter, and power supply.A resistive touch screen works by applying a voltage across a resistor network, see Fig. 5, and measuring the change in resistance at a given point on the matrix where a screen is touched by an input stylus, pen, or finger.The 5-wire touch screen panel works by applying a voltage at the corners of the bottom resistive layer and measuring the vertical or horizontal resistive network with the wiper, or 5th wire which is embedded in the top sheet.The servo motor is a titanium gear D-940TW, which is part of Hitec"s D-Series with high-resolution and high-speed technology.The response time is 0.07 sec/60° at no load when supplied with 7.5V.The Arduino Mega 2560 is a microcontroller board that is used to implement the sliding mode controller, and it has been programmed in Simulink software.An adjustable step-down module DC-DC converter is used to step down a 12V to 7.5V, which is necessary for the servo motors.The DC-DC converter used is the LM2596.A PC power supply unit is used to power up the motors.This power supply provides 12V which is stepped down to 7.5V and then delivered to the motors.
The electrical schematic diagram is shown in Fig. 6.The touch screen is connected to the C-Port of the Ardunio Mega which is represented by pins A0-A4.The servo Motor X is connected to D7 PWM pin, and the servo Motor Y is connected to D8 PWM pin.
Fig. 7 shows the real construction of the ball and plate system.The Arduino Mega is connected to a laptop PC through the USB port.This connection is necessary to plot various signals such as the ball position, the error, and so on.The software on the PC is Simulink which is used to plot signals only.The control algorithm runs inside Arduino with the help of Simulink support for embedded hardware add-one.This add-one will convert a Simulink file into C-code and write it directly to the Arduino program memory so the code runs independently of the PC.
The rest of this paper is organized as follows.Section 2 introduces the mathematical model of the ball and plate system.Classical Sliding Mode theory and controller design for trajectory tracking is presented in Section 3. The Ball and Plate system hardware is described in section 4. Implementation and results are shown in section 5.

IMPLEMENTATION AND RESULTS
The implementation Simulink file consist of three parts.The first part is shown in Fig. 8 which contains the touch screen block and the range converter block that converts the position signal from integer to meter.The discrete derivative is used to get the ball velocity from the position.The obtained signals enter to Kalman filter to reduce noise.The second part is given in Fig. 9, the first block represents the reference signals.The equations of the circular path case or the square path case, or the point case, are represented inside this block.The sliding mode controller block, Fig. 10, contains the classical sliding mode controller equations.The 180/pi block will convert the signal from radian to degree.The saturation block will limit the angle to +/-10 °.The range converter will convert the range from (-45 ° to +45 °) to (0 ° to 180 °) because the servo motor range is 0 ° to 180 °.The third part is shown in Fig. 11, this part is responsible for sending signals via serial port.The signals are multiplied by 10000 or 1000 to convert them into integers.
The classical PD controller is used to compare the results with the Sliding Mode (SM) controller.The PD parameters are Kp=0.5 and Kd=0.2.A low pass filter with a cutoff frequency of 1.5 Hz is used in the derivative action of the PD controller to reduce the noise amplification by the differentiation.
Fig. 12 to Fig. 16 are the results for tracking a circular trajectory.The ball follows the desired trajectory with high amount of error when PD controller is used.It can be notice form Fig. 14 the ball is rotating on an oval shape lies outside of the desired trajectory.The SM was able to make the ball follow the desired trajectory with low error.The control action of PD controller is smoother than that of SM because SM suffers from the chattering effect.
Fig. 17 to Fig. 21 are the results for tracking a square trajectory.In this case, the PD controller was faster than the SM as the rising time in PD is smaller than that in SM as shown in Fig. 18 and Fig. 19.Although PD is faster, but it suffers from high error, especially at the square corners where the response has high overshoot.In Fig. 19 it can be noticed the SM trajectory is closer to the desired and the corners are mores stable.The control action in PD reached the saturation limit at the corners, while in SM, the control action is kept less than .Fig. 22 to Fig. 26 are the results for stabilizing the ball at a fixed position on the plate.In the single point stabilizing, the PD had the advantage of starting at a point closer to the origin as shown in Fig. 22 to Fig. 24.Despite that, the SM still has a better stabilization.It can be noticed from Fig. 22 that the ball has a high overshoot in x axis while in SM there is no overshoot.The steady state error in PD is higher than that in SM.The PD is faster in terms of reaching a point near the origin, but it will move around that point rather than heads towards the origin.The control action in SM has a lot of oscillation, again this is due to the chattering phenomenal.A chattering reduction was used with the three cases (circular, square, and single point), the chattering reduction method will reduce the chattering but will not eliminate it.
In overall, the SM controller was able to follow a circular trajectory, square trajectory and a single point stabilizing with a low amount of error and overshoot.The PD controller seems to have a faster rising time, but with a high overshoot and steady state error which is not acceptable in control engineering point of view.

CONCLUSTIONS
In this work, the ball and plate system has been studied and explained.In the experimental work of the ball and plate system, one of the problems was how to connect the mechanical linkage to the plate in a way to make it free to rotate.3D parts has been designed and 3D printed to act as a hinge attached to the plate from one side and the linkage is free to rotate form the other side.A high speed servo motors have been used to execute the controller commands as fast as possible.The controller commands are the plate angles.It has been noticed that the servo motors suffers from chattering when it move to an angle.To reduce this chattering, a ferromagnetic ring has been used to reduce noise in the servo cable which causes the chattering.The used touch screen provides the ball position, but it does not provide its velocity.The ball velocity is important since it is an essential part of the controller algorithm.By differentiating the ball position, the velocity is obtained, but the problem is that it is contaminated with a high amount of noise.To solve this issue, Kalman filter has been used to filter out the position and velocity signals.
The classical sliding mode controller was able to stabilize the ball and also make it follow desired trajectories.The sliding mode controller showed a significant improvement in response over the classical PD controller.To reduce chattering effect, a boundary layer chattering reduction method has been used.Without this chattering reduction, the implementation would be impossible because the servo motors will damage.
 Galvan-colmenares, S., Galvan-colmenares, S., Moreno-armendáriz, M.,Rubio, J., Ortízrodriguez, F.,Yu, W., and Aguilar-ibáñez, C. 2014 Dong, et al., 2009 have designed a GA Fuzzy Neural Network Controller (GA-FNNC) for the stabilization problem of ball and plate system.The controller consists of 5 layers.The first layer is the input linguistic layer which is the error and change of error.The second layer represents the membership functions.The third layer are the rules.The fourth layer is to make rules unitary.The fifth layer is the output layer.GA is used to find the optimal weights of the Neural Network.Han, et al., 2012 have designed aneural network PID controller (PIDNN) to solve trajectory tracking problem of ball and plate system.Two PIDNN were used, one for each axis.A differential evaluation PSO (DEPSO) has been used to train PIDNN weight online.Pattanapong, and Deelertpaiboon, 2013 have designed a Fuzzy PD controller with with an adaptive integral action for stabilization and trajectory tracking of the ball and plate system.

Figure 1 .
Figure 1.The Ball and Plate system.

Figure 2 .Figure 3 .
Figure 2. A schematic diagram of the ball and plate system.

Figure 4 .
Figure 4.The Ball and Plate system Structure.

Figure 5 .
Figure 5.The five wire touch screen resistor network.

Figure 7 .
Figure 7.The real construction of the ball and plate system.

Figure 8 .
Figure 8.The first part of the Simulink file.

Figure 9 .
Figure 9.The second part of the Simulink file.

Figure 13 .
Figure 13.The Y axis signal (for circular path).

Figure 11 .Figure 14 .
Figure 11.The third part of the Simulink file.

Figure 16 .
Figure 16.The control action for Y axis (for circular path).

Figure 17 .
Figure 17.The X axis signal (for square path).

Figure 18 .
Figure 18.The Y axis signal (for square path).

Figure 21 .
Figure 21.The control action for Y axis (for square path).

Figure 22 .
Figure 22.The X axis signal (for single point).

Figure 23 .
Figure 23.The Y axis signal (for single point).

Figure 24 .Figure 25 .
Figure 24.The point position about x-axis ̇ rad/sec Plate deflection angular velocity about x-axis rad Plate deflection angular about y-axis ̇ rad/sec Plate deflection angular velocity about y-axis Nm Torque exerted on the plate in x-axis direction Nm Torque exerted on the plate in y-axis direction

‫تصوين‬ ‫وتنفيذ‬ ‫هتحكن‬ ‫الكزة‬ ‫لنظام‬ ‫كالسيكي‬ ‫هنزلك‬ ‫ولوحة‬ ‫الخالصة‬
. Dual PD Control Regulation with Nonlinear Compensation for a Ball and Plate System.Mathematical Problems in Engineering, Vol.2014, No. 1, PP.1-10. Ghiasi, A.R. and Jafari, H., 2012.Optimal Robust Controller Design for the Ball and Plate System.In The 9th International Conference on Electronics Computer and Computation ICECCO-2012, At Ankara, Turkey.PP. 1-4. Han, K., Tian, Y., Kong, Y., Li, J., and Zhang, Y., 2012.Tracking control of ball and plate system using a improved PSO on-line training PID neural network.2012 IEEE International Conference on Mechatronics and Automation, ICMA 2012, PP.2297-2302. Jadlovská, A., Jajčišin, Š., and Lonščák R., 2009.Modelling and PID Control Design of Nonlinear Educationl Model Ball & Plate.In 17th International Conference on Process Control.PP. 475-483. Liu, D., Tian, Y., and Duan, H., 2009.Ball and Plate Control System based on sliding mode control with uncertain items observe compensation.In Proceedings of 2009 IEEE International Conference on Intelligent Computing and Intelligent Systems, ICIS 2009.PP. 216-221.In 2013 IEEE International Conference on Mechatronics and Automation, IEEE ICMA 2013, PP.1513-1517. Singh, D. and Saxena, P., 2015.Trajectory Control of a Ball in a Ball and Plate System Using Cascaded PD Controllers Tuned by PSO.In Proceedings of Fourth International Conference on Soft Computing for Problem Solving, Advances in Intelligent Systems and Computing.PP. 53-65.In Proceedings of 2012 9th International Bhurban Conference on Applied Sciences & Technology (IBCAST) Islamabad-Pakistan, PP. 22-26.
 Negash, A. and Singh, N.P., 2015.Position Control and Tracking of Ball and Plate System Using Fuzzy Sliding Mode Controller.In Afro-European Conf.for Advances in Intelligent Systems and Computing.PP. 147-161. Park, J.H. and Lee, Y.J., 2003.Robust visual servoing for motion control of the ball on a plate.Mechatronics, Vol. 13 No. 7, PP.723-738. Pattanapong, Y. and Deelertpaiboon, C., 2013.Ball and plate position control based on fuzzy logic with adaptive integral control action. Zeeshan, A., Nauman, N., and Khan, M.J., 2012.Design Control and Implementation of a Ball on Plate Balancing System.

Table 2 .
The parameters" values.Figure 26.The control action for Y axis (for single point).