December 4, 2024

Tutorial on How to Simulate Sliding Mode Control Algorithm in MATLAB and Simulink


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)   \begin{align*}m\ddot{x}=u(t)+d(t)\end{align*}

where x\in \mathbb{R} is a scalar variable that we want to control, u(t)\in \mathbb{R} is the control input, m is the model parameter (mass for example), and d(t)\in \mathbb{R} 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 m with the control force u and under the presence of the disturbance force d.

We assume that the disturbance signal d(t) is not known, however, we assume that the bound on the uncertainty is known

(2)   \begin{align*}|d(t)|\le \alpha\end{align*}

That is, we assume that the scalar \alpha\in \mathbb{R} is known. In fact, we can consider \alpha as a control design parameter.

Our control objective is to design a control algorithm that will make sure that x(t) follows a time-varying reference trajectory denoted by x_{D}(t) and that will reject the time-varying disturbance d(t).

In this tutorial, we design a sliding mode control algorithm. To formulate the control problem, we first introduce the control error as follows

(3)   \begin{align*}\varepsilon (t) =x_{D}(t)-x(t)\end{align*}

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)   \begin{align*}\sigma =c \varepsilon + \dot{\varepsilon}\end{align*}

where \sigma is the switching function and c>0 is a positive scalar. The parameter c is a design parameter. Then, we select the control law as follows

(5)   \begin{align*}u=m\Big( c\dot{\varepsilon}+\ddot{x}_{D}+\frac{1}{m}\big(k \sigma+\alpha \text{sgn}(\sigma) \big) \Big)\end{align*}

In the above control law

  • m is the dynamical system model parameter
  • c is the parameter defining the switching function (4)
  • \dot{\varepsilon} is the first derivative of the control error that is defined in (3)
  • \ddot{x}_{D} is the second derivative of the reference (desired) trajectory
  • k>0 is a positive control design parameter (selected by the user)
  • \sigma is the switching function (sliding function) defined in (4)
  • \alpha is the disturbance bound defined in (2)
  • \text{sgn} 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 \sigma. 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 \eta-reachability condition:

(6)   \begin{align*}\sigma \cdot \dot{\sigma} \le -\eta |\sigma|\end{align*}