HIL Implementation of Harmonic Drive Motor (Part II)

Part II: Algorithm Formulation

Previously in Part I: Discretization and Simulation, we discuss the process of obtaining a discrete-time transfer function that represents our HDM plant. At the end, we want an algorithm that can be executed on an embedded computer. Before that, some intermediate step is essential; i.e., the discrete-time transfer function must be put into some structure ready to be formulated to an algorithm. Using digital signal processing terminology, it is called a direct form, abbreviated DF.

Direct Form Conversion

Long time ago, we used to discuss in our dated article Linear Controllers: From Design to Implementation on how to manipulate between direct forms such that the embedded resources are minimized. To focus on that trick, we extract a figure from that material to Figure 1 below, which shows the process of rearranging DFI into DFII. We see that the number of delay (z^{-1}) blocks is reduced in half. One delay means one memory address. The resulting algorithm also appears somewhat simpler.

Figure 1 Direct Form structure manipulation

To apply this process to our HDM model, we note from last time that our plant is in the form shown in Figure 2

Figure 2 block diagram of HDM plant


(1)   \begin{equation*}  P_1(z) = \frac{k_vk_mk(b_{1z5}z^5 + b_{1z4}z^4 + b_{1z3}z^3 + b_{1z2}z^2 + b_{1z1}z + b_{1z0})}{a_{1z5}z^5 + a_{1z4}z^4 + a_{1z3}z^3 + a_{1z2}z^2 + a_{1z1}z + a_{1z0}} \end{equation*}

(2)   \begin{equation*}  P_2(z) = \frac{r(b_{lz2}z^2 + b_{lz1}z + b_{lz0})}{k(a_{lz2}z^2 + a_{lz1}z + a_{lz0})} \end{equation*}

Parameters and coefficients in (1) and (2) are defined as in our previous article.

We need to rearrange (1),(2) in the same form as H(z) in Figure 1. Starting from (1), We multiply both numerator and denominator by z^{-5} and factor out the leading coefficient a_{1z5} from the denominator. This yields

(3)   \begin{equation*}  P_1(z) = k_1\frac{b_{10} + b_{11}z^{-1} + b_{12}z^{-2} + b_{13}z^{-3} + b_{14}z^{-4} + b_{15}z^{-5}}{1+ a_{11}z^{-1} + a_{12}z^{-2} + a_{13}z^{-3} + a_{14}z^{-4} + a_{15}z^{-5}} \end{equation*}

with k_1 = k_vk_mk/a_{1z5}, a_{11} = a_{1z4}/a_{1z5}, a_{12} = a_{1z3}/a_{1z5}, a_{13} = a_{1z2}/a_{1z5}, a_{14} = a_{1z1}/a_{1z5}, a_{15} = a_{1z0}/a_{1z5}, and b_{10} = b_{1z5}, b_{11} = b_{1z4}, b_{12} = b_{1z3}, b_{13} = b_{1z2}, b_{14} = b_{1z1}, b_{15} = b_{1z0}.

Similarly, we can rearrange (2) to

(4)   \begin{equation*}  P_2(z) = k_2\frac{b_{20} + b_{21}z^{-1} + b_{22}z^{-2}}{1+ a_{21}z^{-1} + a_{22}z^{-2}} \end{equation*}

with k_2 = r/ka_{lz2}, a_{21} = a_{lz1}/a_{lz2}, a_{22} = a_{lz0}/a_{lz2},and b_{20} = b_{lz2}, b_{21} = b_{lz1}, b_{22} = b_{lz0}.

With this rearrangement, we can construct the diagram in Figure 2 with (3),(4) in DFII as in Figure 3.

Figure 3 the discrete HDM plant in DFII structure

This superblock could take a while to create. So to make your life easier, we provide the Xcos model hdm_implement.zcos for you to download, together with the initialization script hdmhil.sce. Figure 4 is a screen capture of the simulation. We see that the responses between continuous-time and discrete DFII models match quite well.

Figure 4 simulation with HDM plant in DFII using hdm_implement.zcos

Note that the simulation model in Figure 4 is pretty much the same as the speedtuning.zcos in previous article, except that now the command input is changed to a single pulse with flat magnitude of 100 units, starting at 0.1 sec and ends at 0.7 sec. With this pulse input, we see clearly the oscillatory response of load angle output.

Algorithmic Difference Equation from DFII Structure

From a discrete transfer function described ad DFII, it is straightforward to transform to a difference equation in time-domain, using the fact that z^{-1} represents a unit delay. So for a Z-transform representation x(z) of a sample signal x[n], z^{-1}x(z) is simply x[n-1], or the previous sample of that signal. Continuing in this fashion, z^{-i}x(z) in Z-domain corresponds to x[n-i] in the time-domain. The samples at inputs and outputs of unit delays in Figure 3 are referred to as the states.

As an example on how to develop an algorithm for the discrete subsystem P_1(z), let us define its state as x[n] as in Figure 5.

Figure 5 DFII structure of P_1(z)

With the Z-transform relationship just explained, it is obvious that at time sample n, the difference equation for state update is expressed by

(5)   \begin{equation*}  x[n] = V[n] - a_{11}x[n-1] - a_{12}x[n-2] - a_{13}x[n-3] - a_{14}x[n-4] -  a_{15}x[n-5]  \end{equation*}

and the output q_l is computed from

(6)   \begin{equation*}  q_l[n] = k_1(b_{10}x[n] + b_{11}x[n-1] + b_{12}x[n-2] + b_{13}x[n-3] + b_{14}x[n-4] +  b_{15}x[n-5])  \end{equation*}

Do not forget that in the real-time system this algorithm must be implemented as a timer function with specified period T. Each time the timer interrupt is called, this process must be executed

  • update the states x[n-1], \ldots , x[n-5]
  • compute new state x[n]
  • compute output q_l[n]

For better understanding, we implement this algorithm by writing a Scilab script, dhdmsim.sce, and use it to compute the output from the same input as used in the Xcos simulation model hdm_implement.zcos. Then the computation from the script is compared to the continuous-time simulation data. The result is shown in Figure 6. This makes us confident that the algorithm yields similar output to the DFII simulation.

Figure 6 pulse response from the algorithm compared with continuous-time

So, up to this point we are done with the development and simulation on the host computer. Next time we will test this algorithm on an embedded system. That is where the fun actually begins.

Scilab Script and Model Files

The files used this document are

Note :execute the script file hdmhil.sce first before running simulation

Download all as zip file: hilhdm2.zip



Comments are closed.