Main Content

Sliding Mode Control Design for a Robotic Manipulator

Since R2024a

This example shows how to design a controller for a robotic manipulator with two actuated joints using sliding mode control (SMC). SMC is useful for systems that require robustness against disturbances and model uncertainties. Using SMC, you can obtain high-precision tracking of desired trajectories even in the presence of external disturbances and parameter variations. For more information on SMC, see Sliding Mode Control Design for Mass-Spring-Damper System.

Dynamics of Robotic Manipulator

Consider the dynamics of a two-jointed robotic manipulator governed by the following dynamic equation.



  • q, q˙, and q¨ are 2-by-1 vectors representing the joint angles, velocities, and accelerations, respectively.

  • The control input τ is 2-by-1 torque vector applied to the joints.

  • The inertia matrix M(q), Coriolis matrix C(q,q˙), gravity vector G(q), and friction vector F(q˙) encapsulate the dynamics of the manipulator

  • τd represents the disturbance torques affecting the system.

To facilitate control design, define the state variables x1=q and x2=q˙, and control input u=τ. Then define the more compact state-space representation of the system.


The state vector x(t) is given by:

x(t)=[qq˙], where q=[θ1θ2]

Here, f(x,t)=M(q)-1[τd-C(q,q˙)q˙-G(q)-F(q˙)] and g(x,t)=M(q)-1

The robot manipulator dynamics are implemented in the robotStateFcn helper function. This function generates the state derivatives with respect to time based on the current state vector x, the control input vector u, and a vector of model parameters. For this example, assume that the friction model, F(q˙) is negligible and not used in calculations.

For this example, define the following parameters of the robot manipulator.

  • M1 and M2 — Masses of the first and second links (kg)

  • L1 and L2 — Lengths of the first and second link (m)

  • J1 and J2 — Moments of inertia of the first and second link (kgm^2)

M1 = 0.5;
M2 = 1.5;
L1 = 1;
L2 = 0.8;
J1 = 5;
J2 = 5;

Reference Trajectory for Robotic Manipulator

In this example, the reference trajectories for the two actuated joints of the robotic manipulator are described by time-varying exponential functions.


The reference trajectory primarily targets the set points a1,2, with additional terms ensuring a smooth transition from the initial position to these set points. The differentiation of these functions is essential for producing consistent velocity and acceleration profiles, contributing to the manipulators stability and precise movement. This characteristic also facilitates the use of control algorithms that require continuous and differentiable set points.

For this example, set the parameters for the reference trajectories of both joints. These parameters define the shape and behavior of the trajectory functions over time.

[a1,b1,c1,d1,e1] = deal(1,-1,0.25,-1,-4);
[a2,b2,c2,d2,e2] = deal(1,1,-0.3,-1,-3);

Plot the reference trajectories for both joints to visualize the target positions over the specified time interval.

qref = @(time,a,b,c,d,e) a + b*exp(d*time) + c*exp(e*time);
time = linspace(0,10);


title("Reference Trajectory for Joint 1")
ylabel("Position (rad)")
xlabel("Time (s)")

title("Reference Trajectory for Joint 2")
ylabel("Position (rad)")
xlabel("Time (s)")

Design Sliding Mode Controller

SMC is a robust control strategy that forces the system state to converge to a predefined sliding surface and maintain this condition thereafter. This objective is achieved through the application of a discontinuous control action that switches depending on the system position relative to the sliding surface.

In this example, the SMC control law used is:


The control depends on the following parameters.

  • e: Tracking error defined e=qd-q.

  • s: Sliding mode function defined as s(t)=ce(t)+e˙(t).

  • η: Amplitude of the discontinuous control action, enhances robustness against disturbances.

  • k: Proportional gain in the continuous part of the control law, reduces steady-state error and improves response time.

  • c: Coefficient in the sliding surface, affects the rate of convergence to the sliding surface.

  • D: Upper bound of the disturbance.

The terms fand g are dependent of the robot manipulator parameters. In real-world scenarios, you might not know these parameters exactly and only have estimated values available.



Here, the manipulator inertia matrix Mˆ(q), Coriolis matrix Cˆ(q,q˙), friction vector Fˆ(q˙) and gravity vector Gˆ(q) are estimated values.

To reduce chattering in the control signal, you can replace the sign with the following saturation function.


This approximation of the signum function requires the boundary layer thickness, ϕ, to be positive.

For this example, define the following SMC controller parameters.

eta = [1; 3];  % Amplitude of discontinuous control action
K = [2; 1];    % Proportional gain
C = [5; 5];    % Sliding surface coefficient
D = 0;         % Disturbance estimate
Phi = 0.01;    % Boundary layer thickness
delta = 0.01;

Closed-Loop Simulation Using SMC Controller

To evaluate the performance of the designed SMC controller, simulate the robotic manipulator in Simulink®. The simulation tests the controller reference tracking under conditions of both known and uncertain parameters.

Open the model.

mdl = "robotManipulatorModel";

Simulate the system starting from any initial position with zero velocity using the signum function.

Define the initial state of the robotic manipulator.

x0 = [0;0;0;0];

Choose the variant of the control strategy. In this case, use the sign function variant for the SMC controller.

variantPath = "robotManipulatorModel/SMC Controller/Variant Subsystem";

Set the robot dynamics parameters for the simulation within the Estimator subsystem, assuming that the robot parameters are known and unaffected by any external disturbances.

[Md1,Md2,Ld1,Ld2,Jd1,Jd2] = deal(M1,M2,L1,L2,J1,J2);

Simulate the model.

simout = sim(mdl);

Post process the simulation results for plotting.

[sim1, ref] = postProcessSimResults(simout,C);

Simulate the system with the same initial conditions but with a parameter mismatch between the robot and the Estimator subsystem. Doing so tests the robustness of the SMC controller against model uncertainties.

Md1 = 0.1;
Md2 = 1.0;
Ld1 = 1;
Ld2 = 0.8;
Jd1 = 4;
Jd2 = 6;

simout = sim(mdl);
sim2 = postProcessSimResults(simout,C);

Plot the simulation results.

stackedplot(ref,sim1,sim2, ...
    ["q1","q2","qdot1","qdot2"], ...
    Title="State Trajectories");

The SMC controller is still capable of tracking the reference trajectory even after adjusting the parameters.

Visualize the controller performance by plotting the control inputs and the sliding mode function.

stackedplot(sim1,sim2, ...
    {"Tau1","S1","Tau2","S2"}, ...
    Title="Control Inputs and Slide Mode Function Plots");

Reduce Control Input Chattering

Due to the use of the signum function in the SMC controller, the control input exhibits chattering. One common practice to reduce chattering is to use the saturation function instead of the sign function.

% switch the controller to use saturation function
variantPath = "robotManipulatorModel/SMC Controller/Variant Subsystem";

Assign known dynamic parameters to the controller for the first simulation run.

[Md1,Md2,Ld1,Ld2,Jd1,Jd2] = deal(M1,M2,L1,L2,J1,J2);

Execute the simulation with the saturation function in place.

simout = sim(mdl);
[sim3, ref] = postProcessSimResults(simout,C);

Specify the mismatched parameter values and simulate the robot.

Md1 = 0.1;
Md2 = 1.0;
Ld1 = 1;
Ld2 = 0.8;
Jd1 = 4;
Jd2 = 6;

simout = sim(mdl);
sim4 = postProcessSimResults(simout,C);

Plot the state trajectories to compare the performance of the controller with the saturation function against the reference trajectories and previous results.

stackedplot(ref,sim1,sim2,sim3,sim4, ...
    ["q1","q2","qdot1","qdot2"], ...
    Title="State Trajectories")

Plot the control inputs and sliding mode function.

stackedplot(sim3,sim4, ...
    {"Tau1","S1","Tau2","S2"}, ...
    Title="Control Inputs and Slide Mode Function Plots");

When you use the saturation function in the control law, chattering is significantly reduced in the control input.

Another way to reduce chattering is to use the relay function instead of the sign function. You can try it out by selecting "relay" in the variant subsystem in the Simulink model.

Related Topics