# 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 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

with

(1)

(2)

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 in Figure 1. Starting from (1), We multiply both numerator and denominator by and factor out the leading coefficient from the denominator. This yields

(3)

with , , , , , , and , , , , , .

Similarly, we can rearrange (2) to

(4)

with , , ,and , , .

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 represents a unit delay. So for a Z-transform representation of a sample signal , is simply , or the previous sample of that signal. Continuing in this fashion, in Z-domain corresponds to 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 , let us define its state as as in Figure 5.

Figure 5 DFII structure of

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

(5)

and the output is computed from

(6)

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

• update the states
• compute new state
• compute output

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