In this control engineering tutorial, we explain how to simulate a sliding mode controller in MATLAB and Simulink. We will not go too deep into the theory of sliding mode control and we will mainly focus on the implementation in MATLAB and Simulink. We will briefly formulate the system we want to control and the control law. We will also show that the system controlled by using the sliding control law satisfies a stability condition. In the next tutorial, we will provide a deeper theoretical explanation of the sliding mode control.
Model Definition and Sliding Mode Control
The system is described as follows
(1)
where is a scalar variable that we want to control, is the control input, is the model parameter (mass for example), and is the disturbance. We use a single dot above variables to denote the first-time derivative and a double dot to denote the second-time derivative. The system (1) is a double integrator. In reality, this system can be the mass with the control force and under the presence of the disturbance force .
We assume that the disturbance signal is not known, however, we assume that the bound on the uncertainty is known
(2)
That is, we assume that the scalar is known. In fact, we can consider as a control design parameter.
Our control objective is to design a control algorithm that will make sure that follows a time-varying reference trajectory denoted by and that will reject the time-varying disturbance .
In this tutorial, we design a sliding mode control algorithm. To formulate the control problem, we first introduce the control error as follows
(3)
For notation brevity, in the sequel we will omit the time dependence. It is understood that all variables and signals depend on time. First of all, we select the sliding function which is also known as the switching function as follows:
(4)
where is the switching function and is a positive scalar. The parameter is a design parameter. Then, we select the control law as follows
(5)
In the above control law
- is the dynamical system model parameter
- is the parameter defining the switching function (4)
- is the first derivative of the control error that is defined in (3)
- is the second derivative of the reference (desired) trajectory
- is a positive control design parameter (selected by the user)
- is the switching function (sliding function) defined in (4)
- is the disturbance bound defined in (2)
- is the sign function
The type of the control law (5) belongs to the class of the variable structure control laws. Its structure and value depend on the value of the switching function . Due to the sign function, this control law will have three forms. For positive values of the switching function, it will have the first form. Then, for the zero values of the switching function, it will have the second form, and finally, for the negative values of the switching function, it will have the third form.
Next, we will show that the control law (5) satisfies the stability condition. Namely, we will show that this type of control law will guarantee that the sliding mode control will work in practice. The main condition for guaranteeing that the sliding mode controller will work is given by the following equation:
(6)
To show this, let us take the first and second derivatives of the error equation (3)
(7)
Let us take the first derivative of the switching function (4)
(8)
By substituting the second equation from (7) in (8), we obtain
(9)
On the other hand, from (1), we have
(10)
By substituting (10) in (9), we obtain
(11)
On the other hand, by substituting the control law (5) in (11), we obtain
(12)
Next, from the last equation of (12) we have
(13)
Next, we have
(14)
On the other hand, from (2), we have
(15)
By using (14) and (15) in (13), we have
(16)
From the last equation, we have
(17)
Consequently, since , we see that the last equation implies that the following equation
(18)
is satisfied everywhere except at . This shows that the sliding control law is stable.