## 1. Introduction

Modern distributed embedded control systems need to be highly distributed, highly integrated and should support operational flexibility (Årzén et al., 2005). The distribution of control systems induces delays in the control loop that degrade the control performance. These delays are usually variable from iteration to iteration of the control loop and depend on several factors as the scheduling of the processes in the network nodes or the scheduling of traffic in the network.

Classic control solutions do not account for the effect of such variable delays. The delay compensator principle was recently proposed in order to deal with the variable sampling to actuation delay effect in real-time distributed control systems.

The delay compensator principle proposes the addition of a compensator to an existing distributed control system to overcome the effect of the variable sampling to actuation delay introduced in the loop, allowing the achievement of a better control performance.

The compensator action is based on the knowledge of the sampling to actuation delay that affects the control loop and it can have any other input needed to generate the correction output that will be added to the output of the existing controller.

This approach can be applied to any distributed control system provided that the sampling to actuation delay is known for each control cycle. The delay compensator principle is generic and can be implemented using different techniques.

In this chapter the delay compensator approach is presented in detail and several implementations are proposed based on non-linear modelling strategies, namely fuzzy logic, neural networks and neuro-fuzzy techniques.

Simulation results are presented for each one of the implementations proposed and the results obtained are compared.

The remainder of this chapter is organized as follows: section 2 presents the problem description, section 3 presents the delay compensator approach, section 4 proposes the fuzzy implementation of the compensator, section 5 presents the neural network implementation of the compensator, section 6 proposes the neuro-fuzzy implementation of the compensator, section 7 describes the test system and the tests, section 8 presents the simulation results obtained and compares the implementations and section 9 concludes this chapter.

## 2. Problem Formulation

Networked control systems are widely used in embedded applications. Figure 1 presents the block diagram of a distributed real-time control system. In this kind of systems the sensor, the controller and the actuator are implemented in separated nodes that are connected through a communication network, usually a fieldbus.

The distribution of the controller and the use of a communication network to connect the nodes of the control loop induce variable delay between the sampling instant and the actuation instant as can be seen in fig. 2.

The sampling to actuation delay (tsa) can be derived from fig. 2 as

where, from fig. 1

andThe delays are introduced due to the Medium Access Control (MAC) and the scheduling mechanism used to schedule the bus time at the network level (t_{mac}) and the processing time and scheduling at the node level (t_{ps}, t_{pc} and t_{pa}). These delays are usually variable from iteration to iteration of the control loop.

In this work the sampling to actuation delay is considered to be less than or equal to the sampling period, since the system is implemented in a real-time framework, where the transmission of the messages is bounded by a hard deadline.

The variable delays introduced in the control loop by the distribution degrade the performance of the control system and can even destabilize the system (Cervin, 2003a), (Tipsuwan and Chow, 2003), (Colom, 2002), (Sanfridson, 2000), (Antunes et al., 2004a) and (Antunes et al., 2004b). Since the destabilization of the control system is not acceptable and the degradation of the control performance is not desirable, it is necessary to search for solutions to overcome this problem.

There are several ways to deal with the variable sampling to actuation delay in distributed control systems including the use of linear and non-linear modeling techniques. In this work we only consider the use of non-linear techniques.

In the framework of non-linear techniques the use of compensators to improve the control performance of the loop is common. Different kinds of compensators have been used to improve the control performance of networked control systems.

(Almutairi et. al., 2001) proposed a fuzzy modulator to use with a PI controller. The modulator produces a multiplying factor that is applied to the control signal coming from the PI controller. The modulator’s output is based on the error and the control signal, making it unclear whether the compensation is related to the delay effect or to the need to improve the PI controller output.

(Lin et al., 2008) proposed a fuzzy-PID controller to work with a neural net-based Smith predictor in order to compensate for the delay effect in a non real-time implementation. This compensation scheme is used in an Ethernet based networked control system with random delays that can be longer than the sampling period with the aim of maintaining the stability of the system.

The delay compensator approach was presented in (Antunes et al., 2006) where a fuzzy implementation of the compensator was proposed. The fuzzy compensator was able to improve the control performance but did not achieve the same performance obtained in the system in the absence of delays.

Since it is well known that the effect of the delays introduced are difficult to model due to its complexity (Cervin, 2003a), (Colom, 2002) the next step was the use of neural network and neuro-fuzzy techniques to implement the compensator.

## 3. The Delay Compensator Approach

The delay compensator approach proposes to add a delay compensator to an existing controller that does not take into account the effect of the variable sampling to actuation delay in the loop.

The compensator proposes a correction to the control action in order to reduce the effect of the sampling to actuation delay.

Figure 3 shows the block diagram of the delay compensator approach.

The compensator action is based on the sampling to actuation delay that affects the system at each control cycle but it can have any other input.

This principle can be applied to any distributed control system provided that the sampling to actuation delay is known for each control cycle.

The determination of the sampling to actuation delay can be done either by an online measurement or by off-line computations depending on the a priori knowledge of the overall system operation conditions. The online measurement of the sampling to actuation delay provides a more generic and flexible solution that does not require the knowledge of the details of the operation conditions of the global system in which the distributed controller is inserted.

In order for the compensator to operate with the correct value of the delay affecting the network, the controller and the actuator must be implemented in the same network node.

The delay compensator principle is generic and can be implemented using different techniques.

Since the compensator output is added to the output signal from the existing controller, the compensator can easily be turned on or off and the control loop will be closed by the existing controller.

4 Fuzzy Implementation of the Delay Compensator ApproachIn (Antunes et al., 2006) a fuzzy (FZ) implementation of the delay compensator was proposed based in the empirical knowledge about the delay effect on the distributed control system. A linear approximation was used to model the delay effect. The linear approximation is based on the simple fact that when there is sampling to actuation delay there is less time for the control signal to act on the controlled system. This can be compensated by increasing or decreasing the control action depending on the previous values of the control action and on the amount of the sampling to actuation delay. It is also known that small amounts of delay do not need to be accounted because they do not affect significantly the control performance (Cervin, 2003a).

The fuzzy (FZ) compensator is based on this linear approximation of the sampling to actuation delay effect. The compensator action is achieved by increasing or decreasing the control output according to the delay amount and the previous value of the control output in order to compensate for the delays introduced in the loop.

The fuzzy compensator block is presented in figure 4.

The fuzzy module uses a Mamdani type function (Mamdani and Assilian, 1975) with two inputs (the sampling to actuation delay and the previous value of the control signal from the existing controller), one output (the compensation value) and six rules.

The rules state that if the difference between the previous two samples of the control signal is “null” then the contribution of the compensator is “null”. If the delay is “low” then the contribution is “null”. Otherwise if the delay is medium or high, the contribution of the compensator will also be medium or high, with a sign given by the difference between the previous two samples of the control signal: if the control signal is decreasing then the contribution of the compensator is negative and if the control signal is increasing then the contribution is positive. This corresponds to a linear approach of the effect of the sampling to actuation delay. The membership functions for the inputs and the output are bell shaped. As described in (Antunes et al., 2006) the fuzzy delay compensator allowed the improvement of the control performance of the loop but was not able to overcome all the performance degradation induced by the delays.

## 5. Neural Network Implementation of the Delay Compensator

This section describes the neural network (NN) implementation of the delay compensator to further improve the control performance. This implementation was first proposed in (Antunes et al., 2008a).

The model for the NN delay compensator is not a regular model. The information available to train the model is the output of a certain system with (y_{d}(k)) and without (y(k)) the effect of sampling to actuation delay. The objective is to produce a model that can compensate the effect of this delay (knowing the delay for the iteration) in order to correct the control signal to avoid the degradation of the performance. It is necessary to find a way to produce a model that can perform the requested task.

The authors considered two possibilities:

- calculating the error between the two outputs: e

_{y}(k)=y(k)-y_{d}(k) and reporting this error to the input through an inverse model or,- calculating the equivalent input of a system without sampling to actuation delay that would have resulted in the output y

_{d}(k). This is also obtained through an inverse model. The second approach is illustrated in figure 5.

The first alternative would only be valid in the case of a linear system, since for non-linear systems there is no guarantee that the output error could be reported to the corresponding input, since the error range (y- y_{d}) is very different from the output signal range. Using the difference between y and y_{d} and applying it to the inverse model could result in a distortion due to the non-linearity.

The study of the lag space and the use of the method proposed in fig. 5 resulted in the model represented in fig. 6.

This model has, as inputs, a past sample of the output of the compensator, two past samples of the control signal and two past samples of the delay information. The model is composed of ten neurons with hyperbolic tangents in the hidden layer and one neuron in the output layer with linear activation function and was trained for 15000 iterations with the Levenberg-Marquardt algorithm (Levenberg, 1944), (Marquardt, 1963).

## 6. Neuro-fuzzy Implementation of the Delay Compensator

The use of neuro-fuzzy techniques to implement the delay compensator was first proposed in (Antunes et al., 2008b).

The model needed to implement the neuro-fuzzy delay compensator approach is similar to the one describded in the previous section. Using the method from fig. 5 and studying the lag space results in the model represented in figure 7.

This model inputs’ are: a past sample of the output, two past samples of the control signal and two past samples of the delay information.

The ANFIS structure used to obtain the model contains five layers and 243 rules. It has five inputs with three membership functions each (bell shaped with three non-linear parameters) and one output. The total number of fitting parameters is 774, including 45 premise parameters (3*3*5 non-linear) and 729 consequent parameters (3*243 linear). The neuro-fuzzy (NF) model was trained for 100 iterations with the ANFIS function of MATLAB toolbox (MATLAB, 1996).

## 7. The Test System

The architecture of the test system, the tests and the existing controller will be presented in the following subsections.

### 7.1. Architecture of the distributed system

The test system is composed of 2 nodes: the sensor node and the controller and actuator node connected through the Controller Area Network (CAN) bus (Bosch, 1991). The controller and the actuator have to share the same node in order to be possible to measure accurately the value of the sampling to actuation delay that affects the control loop at each control cycle. The block diagram of the distributed system is presented in figure 8.

Message M1 is used to transport the sampled value from the sensor node to the controller and actuator node.

The transfer function of the plant is presented in (4).

The system was simulated using TrueTime, a MATLAB/Simulink based simulator for real-time distributed control systems (Cervin et al., 2003b).

### 7.2. Description of the tests

Three different situations were simulated.

Test 1 is the reference test, where the sampling to actuation delay is constant and equal to 4 ms. It corresponds to the minimum value of the MAC and processing delays obtained when the bus is used only by message M1.

In tests 2 and 3 additional delay was introduced to simulate a loaded network. The sampling to actuation delay introduced follows a random distribution over the interval [0,h] for test 2 and a sequence based in the gamma distribution that concentrates the values in the interval [h/2, h] for test 3.

The sampling to actuation delay obtained for tests 2 and 3 is depicted in figure 9 and 10.

The delay compensator was implemented in the controller and actuator node according with the block diagram from fig. 11.

The tests were made for the system with and without the delay compensator.

### 7.3. Existing controller

The existing controller is a pole-placement (PP) controller (Ǻström and Wittenmark, 1997). It does not take into account the sampling to actuation delay. The controller parameters are constant and computed based on the discrete-time model given by equation (5).

The pole-placement technique allows the complete specification of the closed-loop response of the system by the appropriate choice of the poles of the closed-loop transfer function. In this case the closed-loop pole is placed at _{m}=2 Hz. An observer was also used with _{0}=4 Hz.

The sampling period (h) is equal to 280 ms and was chosen according to the rule of thumb proposed by (Ǻström and Wittenmark, 1997).

The identification of the system was based in the discrete model in (5) and the parameters were computed off-line.

The parameters of the control function were obtained by directly solving the Diophantine equation for the system. The resulting control function is given by (6).

where t_{0}=3.2832, a_{o}= 0.3263, s_{0}=7.4419 and s_{1}= -5.2299.

## 8. The Simulation Results

The results obtained for test 1 (reference test) with only the existing pole-placement (PP) controller are presented in figure 12.

The tests were performed for the system with only the PP controller (reference test) and for the system with the fuzzy (FZDC), the neural network (NNDC) and neuro-fuzzy (NFDC) implementations of the delay compensator.

The control performance was assessed by the computation of the Integral of the Squared Error (ISE) between t= 5 s and 29 s. The results obtained for ISE are presented in Table 1.

The percentage of improvement obtained compared to the reference test (test 1) for ISE is presented in Table 2.

The improvement is calculated as the amount of error induced by the sampling to actuation delay that the FZDC, NNDC or NFDC compensators were able to reduce. The formula used for the computation of the improvement is presented in (7).

where ISE_{DC} represents the ISE value obtained with the delay compensator and ISE_{PP} represents the ISE value obtained with only the PP controller.

The control results for tests 2 and 3 with and without the delay compensator are presented in figures 13 to 20.

The results show the effectiveness of the delay compensator. For tests 2 and 3 the control performance obtained using the delay compensator is better than the ones obtained without compensation.

The NN implementation of the delay compenator achieved the best results. For test 2 the NN compensator was able to reduced by 80% the effect of the variable sampling to actuation delay and for test 3 the reduction is equal to 73%. The FZ compensator was able to improve the control performance in 40% for test 2 and 47% for test 3. The results obtained for the NF compensator (40% for test 2, 53% for test 3) are similar to the ones obtained with the FZ compensator.

Against our expectations the NF compensator is not able to improve the control performance as much as the NN compensator.

The control signals show that the fuzzy and the neuro-fuzzy compensators are not able to prevent the oscillations of the output of the plant, while the neural network compensator is.

Nevertheless the other techniques are also able to improve the control performance and are easier and faster to implement because they do not need the expertise required to train the neural network model.

In conclusion, neural network seem to be better suited for modelling the effect of the variable sampling to actuation delays in distributed control systems.

## 9. Conclusion

This chapter presents several implementations of the delay compensator approach using non-linear techniques. The delay compensator can be added to any existing distributed control system provided that the sampling to actuation delay can be determined for each control cycle. The delay compensator is implemented through a model that describes the effect of the sampling to actuation delay in terms of the control signal. This model is then used to compensate the control signal according to the delay at the actuation moment.

All the implementations proposed were able to improve the control performance in the distributed control system.

The fuzzy implementation is based in a linear approximation of the delay effect. It is simple to design and implement but is not able to prevent oscillations on the output of the plant.

The neuro-fuzzy implementation is easier to train than the neural network approach and achieves results similar to the ones obtained with fuzzy logic.

The neural network compensator was able to model effectively the effect of the sampling to actuation delay on the distributed control system and it achieved the best results. This approach requires the use of some expertise in produce the model needed to implement the compensator.

Future work includes the test of these implementations of the delay compensator approach using real prototypes and different plants.