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 control law satisfies the stability condition of the sliding mode control which is often referred to as the reachability condition. In the next tutorial, we will provide a deeper theoretical explanation of the 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 depends on the value of the switching function . Due to the sign function, 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 main condition for an ideal sliding motion of the sliding mode controller. 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 the -reachability condition:
(6)