*4.1. Programming Method*

Programming of the RTDT was realized entirely within the MATLAB/Simulink environment using RT-LAB. It generated C code from a Simulink block diagram and sent it to the DRTS for compilation and execution.

## *4.2. Position Tracking Scheme*

The acquired position signal cannot be fed directly to the CFE-CC model after decimal conversion because it is a noisy discrete signal. The model would see speed impulsions that would impact its estimations. In order to filter the position signal, the control loop shown at Figure 4 was programmed in the DRTS.

**Figure 4.** Control loop to filter out position sensor's noise.

The resulting closed loop transfer function is:

$$H(\mathbf{s}) = \frac{\theta}{\theta} = \frac{\mathcal{K}\_{\mathbb{P}}\mathbf{s} + \mathcal{K}\_{i}}{\mathbf{s}^{2} + \mathcal{K}\_{\mathbb{P}}\mathbf{s} + \mathcal{K}\_{i}} \tag{13}$$

where *Kp* and *Ki* are the PI controller's proportional and integral gains. The measured position was transformed beforehand from a sawtooth waveform into a ramp. The difference between measured and estimated position was sent to a PI controller and an integrator. Hence, the error in steady state was theoretically reduced to zero. The controller's gains should be chosen high enough to keep track of the speed variations of the machine.

#### *4.3. CFE-CC Model Implementation for Real-Time Execution*

Resolution of the global system was achieved using the State-Space-Nodal (SSN) solver of OPAL-RT available in the ARTEMIS package [19]. It allowed us to solve power systems equations with a hybrid method between pure state-space and nodal approach [20]. It was built upon the SimPowerSystems (SPS) package, thus the Simulink diagram was designed the same way by using SPS blocks (resistances, sources, inductances, etc.).

A custom block made for SSN resolution was implemented for the CFE-CC model. Figure 5 shows the WRIM bloc containing the CFE-CC model's equations as well as external components connected to it. The stator's terminals were connected to controlled voltage sources, which were the measured stator voltages of the physical machine. The rotor's terminals were connected to external resistors adjustable in real-time from the PC. By placing the machine in a separate nodal group than the external components, it had a decoupling effect with SSN resolution, thus greater stability was achieved even with large external resistances [21].

**Figure 5.** Real-time digital twin (RTDT) implementation overview in Simulink using ARTEMIS package.

In order to implement such a model for SSN resolution, one must first select which circuits are available to the user as external connections, i.e., the Simulink block's terminals of the machine. The WRIM had six circuits, all available for external connection, thus vectors [*vin*] and [*iout*] were each six units large. They were respectively the input voltages and output currents at the Simulink block's terminals. The search coil *ws* was not treated as a circuit because no current could flow through.

$$\begin{bmatrix} \phi \end{bmatrix} = \begin{bmatrix} \phi\_{as} & \phi\_{bs} & \phi\_{cs} & \phi\_{ar} & \phi\_{br} & \phi\_{cr} \end{bmatrix}^{T} \tag{14}$$

$$\begin{bmatrix} \upsilon\_{\rm in} \end{bmatrix} = \begin{bmatrix} \upsilon\_{\rm as} & \upsilon\_{\rm bs} & \upsilon\_{\rm cs} & \upsilon\_{\rm ar} & \upsilon\_{\rm lr} & \upsilon\_{\rm cr} \end{bmatrix}^{T} \tag{15}$$

$$\begin{bmatrix} \begin{bmatrix} i\_{\rm out} \end{bmatrix} \end{bmatrix} = \begin{bmatrix} \begin{bmatrix} i\_{\rm as} & i\_{\rm bs} & i\_{\rm c5} & i\_{\rm ar} & i\_{\rm br} & i\_{\rm cr} \end{bmatrix} \end{bmatrix}^{T} \tag{16}$$

Dynamical system of Equation (5) is rearranged as standard state-space form. To facilitate reading of the following equations, the *θ* dependency is omitted.

$$[\Phi] = [A][\Phi] + [B][v\_{in}] \tag{17}$$

$$[i\_{out}] = [\mathbb{C}][\phi] \tag{18}$$

> With

$$[A] = -[R][L]^{-1} \tag{19}$$

$$\begin{bmatrix} \begin{bmatrix} B \end{bmatrix} \end{bmatrix} = \begin{bmatrix} I \end{bmatrix} \tag{20}$$

$$[\mathbb{C}] = [L]^{-1} \tag{21}$$

Matrices [*B*] and [*C*] depend on the electrical terminals of the model. For the WRIM, [*B*] is equal to the identity matrix [*I*] since every circuit is also a terminal. For the same reason, matrix [*C*] is directly equal to [*L*]−1.

SSN solver discretizes Equation (17) for a fixed time step *Ts* using trapezoidal rule [21]:

$$[\phi]\_{k+1} = [A\_d][\phi]\_k + [B\_d][\upsilon]\_k + [B\_d][\upsilon]\_{k+1} \tag{22}$$

$$\begin{aligned} \left[A\_d\right] = \left( [I] + [A]T\_s/2 \right) / \left( [I] - [A]T\_s/2 \right) \end{aligned} \tag{23}$$

$$
\begin{bmatrix} B\_d \end{bmatrix} = \left( \begin{bmatrix} B \end{bmatrix} T\_s / \mathcal{D} \right) / \left( \begin{bmatrix} I \end{bmatrix} - \begin{bmatrix} A \end{bmatrix} T\_s / \mathcal{D} \right) \tag{24}
$$

SSN solver needs the following two quantities from the CFE-CC model to operate:

$$[\![\mathbf{Y}\_{CDM}] = \![\mathbf{C}]\!][B\_d] \tag{25}$$

$$\left[i\_{hist}\right] = \left[\mathbf{C}\right] \left(\left[A\_d\right]\left[\phi\_k\right] + \left[B\_d\right]\left[\upsilon\_k\right]\right) \tag{26}$$

Matrices [*Ad*(*θ*)], [*Bd*(*θ*)] and [*L*(*θ*)]−<sup>1</sup> were stored in a lookup table. At each time step, the exact matrices were computed as the result of an interpolation between two adjacent matrices of the lookup table by using the angular position measurement. The same type of storage and interpolation was used to retrieve the derivative inductance matrix for torque computation using Equation (6).

Now regarding the search coil, since no current, i.e., no state, was associated with it, it was not included in the dynamical system. Instead, it was computed using Equation (7).

## *4.4. Time Step Selection*

The execution time step of the program was chosen to be as small as possible without any risk of overrun. An overrun occurred if the DRTS did not finish all computations within the specified time step. In that case, a time step was skipped resulting in erroneous estimation. RT-LAB gives information regarding computational requirement of the program. Based on it, a time step of 6 μs was chosen. It was important to have a small time step particularly when a circuit of the CFE-CC model was connected to a large external resistance. A large external resistance created a stiff state-space system, thus requiring a smaller time step to keep the solver stable. The SSN solver increased stability compared to the traditional approach but accuracy decreases when the time step was too large.
