# Apply Extended State Observer for Reference Tracking of DC Motor

Since R2024a

This example shows how to use the Extended State Observer block to perform reference tracking for a DC motor model.

### DC Motor Model

In armature-controlled DC motors, the applied voltage ${\mathit{V}}_{\mathit{a}}$ controls the angular velocity $\omega$ of the shaft. A simplified model of the DC motor is shown in this figure.

For this example, the physical constants for the motor are:

• $\mathit{R}$ = 2.0 Ohms

• $\mathit{L}$ = 0.5 Henrys

• ${\mathit{K}}_{\mathit{m}}$ (Torque constant) = 0.1

• ${\mathit{K}}_{\mathit{b}}$ (Back emf constant) = 0.1

• ${\mathit{K}}_{\mathit{f}}$ = 0.2 Nms

• $\mathit{J}$ = 0.02 kg m^2

In this model, a pulse disturbance signal is injected to the system at 10 seconds.

### Design PID Controller

The goal of the controller is to provide tracking to step changes in reference angular velocity. Before applying the extended state observer (ESO), design PID controller for tracking the reference trajectory. The model contains one PID controller with gains tuned using the PID Tuner app. For more information on tuning PID controllers in Simulink® models, see Introduction to Model-Based PID Tuning in Simulink.

Open the Simulink model for the DC motor. When the variant of `ESO` subsystem is set to `Disabled`, the control input is feed through such that $\mathit{u}={\mathit{u}}_{0}$.

```mdl = 'scdDCMotorESO'; open_system(mdl) enableESO = 0;```

Simulate the model and view the results.

```sim(mdl) y1 = logsout.getElement('y'); y1data = y1.Values.Data(:,:)'; plot(y1.Values.Time,y1data); grid on; hold on;```

The plot shows that the PID controller can track the Step reference trajectory closely.

### Design Extended State Observer

In this section, design an extended state observer to improve the disturbance rejection performance of the PID controller.

To create an LTI system for the Extended State Observer block, linearize the DC motor plant. To do so, specify a linearization input point at the input of `DC Motor` block and a linearization output point with a loop opening at the output of `DC Motor` block as shown in the model.

Get the linearization analysis points specified in the model.

`io = getlinio(mdl);`

Linearize the model.

`sys = linearize(mdl,io);`

When the variant of the `ESO` subsystem is set to `Enabled`, the control input is $\mathit{u}={\mathit{u}}_{0}-\stackrel{ˆ}{\mathit{d}}$, where $\stackrel{ˆ}{\mathit{d}}$ is an estimate of the disturbance in the system.

`enableESO = 1;`

Specify the LTI system for the Extended State Observer block. The disturbance comes into the model from the same channel of the control input, specify $\mathit{k}=1$ for the relationship ${\mathit{B}}_{\mathit{d}}={\mathit{k}×\mathit{B}}_{\mathit{u}}$. Select the observer bandwidth 5~7 times of the controller bandwidth. In this example, the observer bandwidth is set to be 30 rad/s.

Simulate the model and view the results.

```sim(mdl) y2 = logsout.getElement('y'); y2data = y2.Values.Data(:,:)'; plot(y2.Values.Time,y2data); legend('withoutESO','withESO','Location','southeast')```

The plot shows that PID controller tracks the step reference trajectory closely before 10 seconds. When there is disturbance in the system after 10 seconds, ESO rejects disturbance better than the PID controller alone.

Close the model.

`bdclose(mdl)`