This example describes the fundamentals of sliding mode control (SMC) and uses SMC to control a mass-spring-damper system.
In SMC, you define a sliding surface that the system state trajectory converges to and remains on. This sliding surface is designed such that it is insensitive to disturbances and uncertainties in the system. Once the system state trajectory is on the sliding surface, the controller uses a feedback control law to drive the system state trajectory to the desired state along the sliding surface. [1]
Consider a dynamic system characterized by the following differential equation.
x ˙ ( t ) = f ( x , t ) + g ( x , t ) u ( x , t ) + d ( t )
This formulation captures the interplay between the system natural evolution, control efforts, and unpredictable external factors, providing a comprehensive model for analysis and design in control engineering.
SMC uses discontinuous control to switch between two distinct system structures, which can be mathematically described as:
u k ( t ) = < u k + ( t ) if S k ( x ) >0 u k - ( t ) if S k ( x ) < 0 , for k = 1 , 2 , ⋯ , n u
Here, u k + ( t ) and u k - ( t ) denote two separate control inputs, n u is the number of inputs, and S k ( x ) is the k th component of the following sliding mode function.
S ( x ) = [ S 1 ( x ) S 2 ( x ) … S n u ( x ) ] T
Proper design of the control input u k ( t ) is crucial for ensuring that the state variables converge to the sliding surface, travel along it, and maintain their trajectory along the surface. Upon reaching the sliding surface, the sliding surface function should satisfy S ( x ) = 0 , indicating the existence of a sliding mode. A necessary and sufficient criterion for guaranteeing this condition is that the product of the sliding surface and its time derivative should be negative, that is, S ( x ) S ˙ ( x ) < 0 . This condition ensures that the system, as described by the initial differential equation, remains in the sliding mode once it has been attained.
As a side effect of the discontinuous control in SMC, the control input can exhibit chattering , which creates rapid oscillations in control input from persistent switching at the sliding surface boundary. Chattering can cause actuator damage and unwanted system dynamics. Therefore, mitigating chattering is essential in SMC design.
In summary, the SMC design includes the following stages:
Consider a mass-spring-damper system with mass, M , attached to a spring with stiffness coefficient, K , and a damper with damping coefficient, D . The dynamics of the system are also subject to an external control force, F , exerted on the mass. This force serves as a mechanism to influence the system dynamic response.
The differential equation for the system is:
M x ¨ + D x ˙ + Kx = F
Define the state variables x 1 = x and x 2 = x ˙ , which produces the following set of first-order differential equations describing the system.
Here, f ( x ) = - D x ˙ + K x M represents the inherent forces of the damper and spring acting on the mass, and g ( x ) = 1 M signifies the influence of the control force F on the mass, normalized by its magnitude.
Define the mass-spring-damper system parameters, where the mass M is 1 kg , the damping coefficient D is 0 . 1 Ns / m , and the spring constant K is 1 N / m .
param.Mass = 1; % Mass (kg) param.Damping = 0.1; % Damping coefficient (Ns/m) param.Stiffness = 1; % Spring constant (N/m)
For this example, the state-space function of the mass-spring-damper system is implemented in the msdStateDer supporting function.
For this example, define the sliding mode function as s ( t ) = ce ( t ) + e ˙ ( t ) , where x d is the desired position and e = x d - x is the tracking error.
Define the SMC control law as follows.
u = 1 g ( η sign ( s ) + ks + c e ˙ + x ¨ d - f )
This choice of control input is based on the Exponential Reaching Law, where you set s ˙ = - η sign ( s ) - ks . You then solve for a control input that satisfies this condition [2]. For positive values for η and k , the necessary and sufficient criterion s ( t ) s ˙ ( t ) < 0 is satisfied.
Set the SMC parameters, specifying the amplitude of the control action η , the proportional gain k , and the sliding surface coefficient c for the controller design. For the initial controller design, the SMC controller assumes that there is no disturbance in the system ( param.smc.d = 0 ).
param.smc.c = 1; param.smc.k = 1.1; param.smc.eta = 0.1; param.smc.d = 0;
For this example, the SMC control input is computed using the smc supporting function.
To view the controller performance, first simulate the system without disturbances.
Set the initial conditions and define the time span for the simulation.
y0 = [1 0]; tspan = 0:1e-3:10;
Create a handle to the control input function.
u = @(x,param) smc(x,param);
Simulate the system response using ode45 .
[T,Y] = ode45(@(t,x) msdStateDer(t,x,u,param),tspan,y0);
Calculate the sliding surface and control input values over the simulation time.
S = param.smc.c*Y(:,1) + Y(:,2); U = smc(Y.',param);
Visualize the system response, phase plane, control input, and sliding surface over time using the plotResponse helper function.
plotResponse(T,U,Y,S,"System Response without Disturbances")
The phase plane provides a visual representation of the system dynamics by plotting position versus velocity. In this plane, the system trajectory converges to the sliding surface, defined by the sliding function s ( t ) = c e ( t ) + e ˙ ( t ) , which represents the desired system behavior. When the trajectory reaches the sliding surface, the system is in sliding mode and the conroller guides it towards the target state.
Plot the phase plane, system trajectory, and sliding surface.
N = 20; x1_values = linspace(-0.5,1.5, N); x2_values = linspace(-1.0,1.0, N); [X1,X2] = meshgrid(x1_values,x2_values); XDOT = msdStateDer([],[X1(:), X2(:)].',u,param); figure hold on quiver(X1(:),X2(:),XDOT(1,:).',XDOT(2,:).', . MaxHeadSize=0.1, . AutoScaleFactor=0.9); plot(Y(:,1),Y(:,2)) plot([-0.5 1.5],-param.smc.c*[-0.5 1.5], ":") xlim([min(X1(:)) max(X1(:))]) ylim([min(X2(:)) max(X2(:))]) xlabel("x1 (position)") ylabel("x2 (velocity)") title("Phase-Plane") legend("df/dt","States","Slide Surface")
This plot shows a visual depiction of the mass-spring-damper system response and the influence of the sliding mode control.
In real-world scenarios, systems are often influenced by external disturbances that can affect their performance. To test the robustness of the SMC strategy, you can introduce a disturbance into the mass-spring-damper system simulation. The bounded disturbance is modeled as a time-varying function d ( t ) that directly affects the dynamics of the system, where | d ( t ) | ≤ D .
For this example, consider a sinusoidal disturbance d ( t ) given by:
d ( t ) = 0 . 5 ⋅ sin ( t )
The SMC control law is designed to counteract the effects of disturbances and drive the system state towards the desired sliding surface. The control law is defined as:
u = 1 g ( η sign ( s ) + ks + c e ˙ + x ¨ d - f + D sign ( s ) )
where the term D sign ( s ) is an additional term that accounts for the upper bound of the disturbance. Define a handle to the disturbance function.
d = @(t) 0.5*sin(t);
Update the SMC controller parameters.
param.smc.c = 5; param.smc.k = 3; param.smc.eta = 0.1; param.smc.d = 0.6;
Create a handle for the control input function and simulate the system response using ode45 .
u = @(x,param) smc(x,param); [T,Y] = ode45(@(t,x) msdStateDer(t,x,u,param,d),tspan,y0);
Calculate sliding surface, S , and control input values, U , over the simulation time.
S = param.smc.c*Y(:,1) + Y(:,2); U = smc(Y.',param);
Generate the plots to visualize the system response, phase plane, control input, and sliding surface over time.
plotResponse(T,U,Y,S,"System Response with Disturbances")
A common issue in SMC is chattering , which is the high-frequency switching of the control input when the system state is close to the sliding surface. To mitigate chattering, you can use a quasi-sliding mode control (QSMC). In QSMC, you replace the discontinuous sign function in the control law with a continuous approximation, such as a saturation function. [3]
For this example, use the following saturation function.
sat ( s , ϕ ) = < 1 if s >ϕ s / ϕ if - ϕ ≤ s ≤ ϕ - 1 if s < - ϕ
Here, ϕ is the boundary layer thickness. This saturation function smoothly interpolates between - 1 and 1 when the sliding variable s is within the boundary layer [ - ϕ ϕ ] , which reduces the high-frequency switching.
The modified control law with the saturation function is given by:
u = 1 g ( η sat ( s , ϕ ) + ks + c e ˙ + x ¨ d - f + D sat ( s , ϕ ) )
The choice of ϕ is critical as it defines the thickness of the boundary layer around the sliding surface. A larger ϕ results in less chattering but can increase the steady-state error. Conversely, a smaller ϕ can reduce steady-state error but increase chattering.
To implement the QSMC, define the saturation function using function handle sat and set the boundary layer thickness, ϕ , to 1e-2.
phi = 1e-2; sat = @(s) min(max(s/phi,-1),1);
Update the control input function to include the saturation function.
u = @(x,param) smc(x,param,sat);
Simulate the system response using the updated control law.
[T,Y] = ode45(@(t,x) msdStateDer(t,x,u,param,d),tspan,y0);
Calculate the sliding surface and control input values over the simulation time.
S = param.smc.c*Y(:,1) + Y(:,2); U = smc(Y.',param,sat);
Visualize the system response, phase plane, control input, and sliding surface over time using QSMC.
plotResponse(T,U,Y,S,"System Response Using QSMC")
The QSMC system achieves similar performance with no chattering in the control input.
[1] Derbel, Nabil, Jawhar Ghommam, and Quanmin Zhu, eds. Applications of Sliding Mode Control . Vol. 79. Springer Singapore, 2017.
[2] Weibing Gao, and J.C. Hung. “Variable Structure Control of Nonlinear Systems: A New Approach.” IEEE Transactions on Industrial Electronics 40, no. 1 (February 1993): 45–55. https://doi.org/10.1109/41.184820.
[3] Richter, Hanz. Advanced control of turbofan engines . Springer Science & Business Media, 2011.
function plotResponse(T,U,Y,S,plotTitle) figure t = tiledlayout(2,2); title(t,plotTitle) % Plot position and velocity over time. nexttile plot(T,Y(:,1),T,Y(:,2)) legend("x_1 (pos)","x_2 (vel)") title("State Response") xlabel("Time (s)") % Plot phase plane (velocity versus position). nexttile plot(Y(:,1),Y(:,2)) title("Phase Plane") xlabel("x_1 (position)") ylabel("x_2 (velocity)") % Plot control input over time. nexttile plot(T,U) title("Control Input") xlabel("Time (s)") ylabel("u(t)") % Plot sliding surface over time. nexttile plot(T,S) title("Slide Mode Function") xlabel("Time (s)") ylabel("s(t)") end