**5. Nomoto model of ship-steering process**

To analyze a ship's dynamics as a Nomoto model it is convenient to define a coordinate system as indicate in figure 4.

**Figure 4.** Coordinates and notation used to described the equations

Let 'V' be the total velocity, 'u' and 'v' the x and y components of the velocity, and 'r' the angular velocity of the ship. In normal steering the ship makes small deviations from straight-line course. The natural state variables are the sway velocity 'v', the turning rate 'r', and the heading '*ψ*'. The equations 2 are obtained, where 'u' is the constant forward velocity, 'l' the length of the ship and 'a' and 'b' are parameters of the model ship.

$$\begin{array}{l}\frac{dv}{dt} = \frac{u}{l}a\_{11} + \mu a\_{12}r + \frac{\mu^2}{l}b\_1\delta\\\frac{dr}{dt} = \frac{u}{l^2}a\_{21}v + \frac{\mu}{l}a\_{22}r + \frac{\mu^2}{l^2}b\_2\delta\\\frac{d\psi}{dt} = r\end{array} \tag{2}$$

From equation 2 is determinated the transfer function from rudder angle to heading in the equation 3.

$$G(s) = \frac{K(1+sT\_3)}{s(1+sT\_1)(1+sT\_2)}\tag{3}$$

where,

4

PID Controller with Gain Schedulling

Knowledge Based Tuning Rules


**Figure 2.** Gain Scheduling control schematic

**tuning rules**

one shown in Figure 3.

System

**Figure 3.** Neuronal network structure

parameter in each case.

Conditions

INPUT ERROR OUTPUT

Conditioning sensor

**4. Implementation with neural networks instead of the knowledge base**

The replacement of the rules that define the gains of PID controller based on the working point system is raised by a neural network whose inputs are the operation conditions of the plant, and as outputs it will have the parameters of PID controller (*K*, *Ti* and *Td*). The neural network used is a network type MLP (Multi Layer Perceptron) with a similar topology to the

It is possible to raise several simple neural networks for each parameter instead of one, in which all of them have as input, the system conditions but the output is the controller

Non Linear System

K

Ti

Td

Operating Points

$$\begin{array}{l} \text{K} = \text{K}\_0 \text{u}/\text{l} \\ T\_{\text{i}} = T\_{\text{i}0} \text{l}/\text{u} \\ \end{array} \qquad \begin{array}{l} \text{i} \\ \text{i} = \text{1,2,3} \\ \end{array} \tag{4}$$

The parameters *K*<sup>0</sup> and *Ti*<sup>0</sup> are parameters of ship model. In many cases the model can be simplified to equation 5.

$$G(\mathbf{s}) = \frac{\mathbf{b}}{\mathbf{s}(\mathbf{s} + \mathbf{a})} \tag{5}$$

where,

$$\begin{array}{l} b = b\_0 \left(\frac{\mu}{\mathcal{T}}\right)^2 = b\_2 \left(\frac{\mu}{\mathcal{T}}\right)^2\\ a = a\_0 \left(\frac{\mu}{\mathcal{T}}\right) \end{array} \tag{6}$$

It will be replaced the fixed values commented, where it should be pointed out for the case of the freighter, that the parameter *a*<sup>0</sup> has a value of 0.19 and the variable will be replaced in

To carry out the simulations and to achieve the desired data for implementing the proposed model, it is used Matlab/Simulink. For which it is edited in the first place the following

> In1 Out1 Servo-Rudder

The PID block houses, the scheme shown in Figure 7, whose structure is as the one explained at the beginning of the document, in which it should be noted for a better approximation to

> 1 s Inte

du/dt Derivative

The servo-rudder block has inside, the diagram of figure 8, which is neither more nor less

The operation conditions of the system are infinite therefore certain values have to be chosen. It makes no sense to obtain parameters for multiple cases so it is necessary to make a coherent estimate to achieve good results. One approach is to choose a reasonable amount of equidistant values and observe the changes of the parameters for each case. If there are substantial changes from one value to another then an opportunity of taking new

There are own terms of the ship that will not vary as can be the area of the rudder. In this case, the only term that will define the operation conditions or gains adjustment rules of the

(1/2)\*((v/l)^2)\*A\*l/D s +a0\*(v/l).s 2 Ship

Neuro-Knowledge Model Based on a PID Controller to Automatic Steering of Ships

simout To Workspace

Scope

http://dx.doi.org/10.5772/50316

107

1 Out1

Saturation

control scheme based on descriptions made previously, shown in Figure 6.

each case as necessary.

Step

In1 Out1

Harmonic\_Balance\_Relay

Kp Gain

**Figure 6.** Control scheme in Simulink format

1 In1

**Figure 7.** PID block in Simulink format

**6.1. System operation conditions**

PID MS

the real system, the congestion at the output of the block adder.

than the diagram of the Servo of Figure 5 in Simulink format.

intermediate values between them will be provided.

Td Gain2

1/Ti Gain1

This model is called the first order Nomoto model of a ship. Its gain 'b' can be expressed approximately as expression 7.

$$b = c \left(\frac{u}{l}\right)^2 \left(\frac{Al}{D}\right) \tag{7}$$

where ′ *<sup>D</sup>*′ is the displacement (in *<sup>m</sup>*3), ′ *<sup>A</sup>*′ is the rudder area (in *<sup>m</sup>*2) and ′ *<sup>c</sup>*′ is a parameter whose empirical value is approximately 0.5. The parameter ′ *<sup>a</sup>*′ will depend on trim, speed and loading and its sing may change with the operating conditions.

#### **6. System used to verify the proposed method**

To illustrate the method proposed in this document for the automatic steering of ships, it is going to be applied to a freighter with 161 meters of length, which displacement will range from 8,000 *m*<sup>3</sup> in the vacuum until the 20,000 *m*<sup>3</sup> full load. The velocity at which will be able to navigate will be more than 2 meters per second, for which is perfectly valid the model used, to 8 meters per second maximum velocity. It is necessary to specify that the Servo-rudder operates at a speed of 4 meters per second limited to ±30 degrees, according to this description the model shown in Figure 5.

**Figure 5.** Servo-rudder blocks diagram

The transfer function of the freighter remains as it is indicated in the expression 8, in which was only given the value to ′ *<sup>c</sup>*′ that is 0.5.

$$G(s) = \frac{0.5\left(\frac{\mu}{\bar{l}}\right)^2 \frac{Al}{D}}{s\left(s + a\_0 \frac{\mu}{\bar{l}}\right)}\tag{8}$$

It will be replaced the fixed values commented, where it should be pointed out for the case of the freighter, that the parameter *a*<sup>0</sup> has a value of 0.19 and the variable will be replaced in each case as necessary.

To carry out the simulations and to achieve the desired data for implementing the proposed model, it is used Matlab/Simulink. For which it is edited in the first place the following control scheme based on descriptions made previously, shown in Figure 6.

**Figure 6.** Control scheme in Simulink format

6

where,

where ′

approximately as expression 7.

*<sup>D</sup>*′ is the displacement (in *<sup>m</sup>*3), ′

to this description the model shown in Figure 5.

**Figure 5.** Servo-rudder blocks diagram

was only given the value to ′

whose empirical value is approximately 0.5. The parameter ′

**6. System used to verify the proposed method**

and loading and its sing may change with the operating conditions.

sp 4

*<sup>c</sup>*′ that is 0.5.

*b* = *b*<sup>0</sup>

*a* = *a*<sup>0</sup>

*b* = *c u l*

 *u l* <sup>2</sup> <sup>=</sup> *<sup>b</sup>*<sup>2</sup>

 *u l*

This model is called the first order Nomoto model of a ship. Its gain 'b' can be expressed

To illustrate the method proposed in this document for the automatic steering of ships, it is going to be applied to a freighter with 161 meters of length, which displacement will range from 8,000 *m*<sup>3</sup> in the vacuum until the 20,000 *m*<sup>3</sup> full load. The velocity at which will be able to navigate will be more than 2 meters per second, for which is perfectly valid the model used, to 8 meters per second maximum velocity. It is necessary to specify that the Servo-rudder operates at a speed of 4 meters per second limited to ±30 degrees, according

The transfer function of the freighter remains as it is indicated in the expression 8, in which

*l* <sup>2</sup> *Al D*

*<sup>G</sup>*(*s*) = 0.5 *<sup>u</sup>*

*s <sup>s</sup>* <sup>+</sup> *<sup>a</sup>*<sup>0</sup> *<sup>u</sup> l*

<sup>2</sup> *Al D* 

 *u l* 2

*<sup>A</sup>*′ is the rudder area (in *<sup>m</sup>*2) and ′

s

(6)

(7)

*<sup>c</sup>*′ is a parameter

*<sup>a</sup>*′ will depend on trim, speed

(8)

The PID block houses, the scheme shown in Figure 7, whose structure is as the one explained at the beginning of the document, in which it should be noted for a better approximation to the real system, the congestion at the output of the block adder.

**Figure 7.** PID block in Simulink format

The servo-rudder block has inside, the diagram of figure 8, which is neither more nor less than the diagram of the Servo of Figure 5 in Simulink format.

#### **6.1. System operation conditions**

The operation conditions of the system are infinite therefore certain values have to be chosen. It makes no sense to obtain parameters for multiple cases so it is necessary to make a coherent estimate to achieve good results. One approach is to choose a reasonable amount of equidistant values and observe the changes of the parameters for each case. If there are substantial changes from one value to another then an opportunity of taking new intermediate values between them will be provided.

There are own terms of the ship that will not vary as can be the area of the rudder. In this case, the only term that will define the operation conditions or gains adjustment rules of the

*6.2.1. Relay-feedback method*

as it is shown in Figure 9.


**Figure 9.** Application scheme of Relay-Feedback

oscillation period.

amplitude d and a width of the hysteresis window h.

This is an alternative way to the chain closed method of Ziegler-Nichols [24–28], for the empirical location of the critical gain (*Kc*) and the period of sustained oscillation (*Tc*) of the system. It uses of the method of relay (Relay Feedback) developed by Aström and Hägglud [13, 29], which consists in leading the system to the oscillation state by the addition of a relay

PID SYSTEM ERROR

This oscillation taken from the system has a period with approximately the same value as the period of sustained oscillation Tc (critical period). In the experiment it is recommended to use a relay with hysteresis which characteristics like the one shown in Figure 10 with an

1. Leading the process to put the process in steady state, with the system regulated by the PID controller, with any parameters that let us achieve that status. It will be taken note of

2. Then the control is finished with the relay, instead of the PID controller. As a set point it is given the value read in the output of the process in the previous step. It is introduced in the input shown in Figure 7 as the Offset, the control signal value taken in the previous

3. The process is situated into operation with the indications made in the previous paragraph, and it is expected to become regular in the output (in practice it can be considered to have reached this state when the maximum value of the output repeats

4. It will be noted down the two parameters shown in Figure 11, where *Tc* is the sustained

*Kc* <sup>=</sup> <sup>4</sup>*<sup>d</sup> π* √

*<sup>a</sup>*<sup>2</sup> <sup>−</sup> *<sup>h</sup>*<sup>2</sup> (9)

After the assembly is done, it will proceed as follows to get the parameters mentioned:

the control signal values and the output of the process in those conditions.

paragraph which is necessary to put the process in steady state.

the same value for at least two consecutive periods).

5. The critical gain of the process is determined by expression 9.

CONTROL SIGNAL

+

Neuro-Knowledge Model Based on a PID Controller to Automatic Steering of Ships

http://dx.doi.org/10.5772/50316

109

+ +

**Figure 8.** Servo-rudder in Simulink format

controller, are the displacement and the velocity of the ship. It is necessary to highlight that the displacement is not going to be obviously a property that is constantly changing as can do the velocity, even if it is in a slow way. Taking into account the above and the ranges of values that can take each of the two parameters from which the model depends on, it is established the Table 1 of possible conditions.


**Table 1.** Working points selected

#### **6.2. Obtaining the controller parameters for each operation status**

In the stage of obtaining the parameters of different working points, in the control implementation by the scheduling of the virtual controller instead of PID controller in parallel could be selected a hysteresis block. This is an attempt to obtain the controller parameters using the Relay Feedback method and it will be discussed in a summarized form.

#### *6.2.1. Relay-feedback method*

1 Out1

4

s TF0

controller, are the displacement and the velocity of the ship. It is necessary to highlight that the displacement is not going to be obviously a property that is constantly changing as can do the velocity, even if it is in a slow way. Taking into account the above and the ranges of values that can take each of the two parameters from which the model depends on, it is

D u

8000

12000

16000

20000

In the stage of obtaining the parameters of different working points, in the control implementation by the scheduling of the virtual controller instead of PID controller in parallel could be selected a hysteresis block. This is an attempt to obtain the controller parameters

**6.2. Obtaining the controller parameters for each operation status**

using the Relay Feedback method and it will be discussed in a summarized form.

+/-30

1 In1

**Figure 8.** Servo-rudder in Simulink format

**Table 1.** Working points selected

established the Table 1 of possible conditions.

8

This is an alternative way to the chain closed method of Ziegler-Nichols [24–28], for the empirical location of the critical gain (*Kc*) and the period of sustained oscillation (*Tc*) of the system. It uses of the method of relay (Relay Feedback) developed by Aström and Hägglud [13, 29], which consists in leading the system to the oscillation state by the addition of a relay as it is shown in Figure 9.

This oscillation taken from the system has a period with approximately the same value as the period of sustained oscillation Tc (critical period). In the experiment it is recommended to use a relay with hysteresis which characteristics like the one shown in Figure 10 with an amplitude d and a width of the hysteresis window h.

After the assembly is done, it will proceed as follows to get the parameters mentioned:


$$K\_c = \frac{4d}{\pi\sqrt{a^2 - h^2}}\tag{9}$$

the set point on several occasions and there could be cases in which this is inadvisable

In the particular case shown in this paper, there is no need to implement the hysteresis mentioned in the explanation of Relay Feedback with a window, because works with a relatively slow system. Instead, a simple comparator as the one shown in Figure 12 will

Logically the value of h is zero and the value of d is 0.5. It is established as set point a value of 0.5, and the offset for this case is not necessary because it would be zero. Under these conditions the system becomes operational, and the result obtained is shown in figure 13. It is necessary to pay attention to the final zone, where the oscillation is now stabilized and periodic, and with the expressions commented above for the Relay Feedback method, the

With the parameters that have been obtained in the previous paragraph, it is possible to get the controller parameters applying direct formulas, achieving the three terms of the regulator.

d

Neuro-Knowledge Model Based on a PID Controller to Automatic Steering of Ships

http://dx.doi.org/10.5772/50316

111

because of the damage they can cause during the process.


**Figure 12.** Hysteresis for the plant tested

extracted parameters are *Tc* and *Kc*.

*6.2.3. Obtaining the PID controller initial parameters*

*6.2.2. Obtaining the parameters Tc and Kc*

be sufficient.

**Figure 10.** Hysteresis for Relay-Feedback

**Figure 11.** Parameters to read in the sustained oscillation (critic period)

The Relay Feedback has the advantage that adjustment can be made on the set point and it can be carried out at any time. However, a problem is that to tune, the process must exceed the set point on several occasions and there could be cases in which this is inadvisable because of the damage they can cause during the process.

### *6.2.2. Obtaining the parameters Tc and Kc*

d

a

h h

The Relay Feedback has the advantage that adjustment can be made on the set point and it can be carried out at any time. However, a problem is that to tune, the process must exceed

10


Tc

**Figure 11.** Parameters to read in the sustained oscillation (critic period)

**Figure 10.** Hysteresis for Relay-Feedback

In the particular case shown in this paper, there is no need to implement the hysteresis mentioned in the explanation of Relay Feedback with a window, because works with a relatively slow system. Instead, a simple comparator as the one shown in Figure 12 will be sufficient.

**Figure 12.** Hysteresis for the plant tested

Logically the value of h is zero and the value of d is 0.5. It is established as set point a value of 0.5, and the offset for this case is not necessary because it would be zero. Under these conditions the system becomes operational, and the result obtained is shown in figure 13.

It is necessary to pay attention to the final zone, where the oscillation is now stabilized and periodic, and with the expressions commented above for the Relay Feedback method, the extracted parameters are *Tc* and *Kc*.

#### *6.2.3. Obtaining the PID controller initial parameters*

With the parameters that have been obtained in the previous paragraph, it is possible to get the controller parameters applying direct formulas, achieving the three terms of the regulator.

In this most delicate task of adjustment it is necessary to indicate that it should not saturate the output controller at any time. It is necessary to reach a compromise, since an excess of proportional gain causes a fast response in the output and with little overshoot, which apparently is ideal, but under these conditions the servo is constantly fluctuating, which will cause it to deteriorate in a short period of time. As conclusion, it is going to search gradual

Neuro-Knowledge Model Based on a PID Controller to Automatic Steering of Ships

http://dx.doi.org/10.5772/50316

113

<sup>0</sup> <sup>500</sup> <sup>1000</sup> <sup>1500</sup> <sup>2000</sup> <sup>2500</sup> <sup>3000</sup> <sup>3500</sup> -10

It is necessary to indicate that for this model the method of adjusting parameters Ziegler-Nichols is not the ideal, since the initial values of the parameters do not give good

Taking all the comments above into account all the comments above we obtain the controller parameters fine-tuned for each of the cases discussed above, which seeks a criterion of minimum overshoot and maximum speed for the restrictions presented in the preceding


**Figure 14.** Example of steering and control signal to the rudder

*6.2.5. Parameters obtained for each case*

results, differing greatly from those achieved after fine-tuning.

paragraphs. In this way we reach the parameters of the table 3.

0

5

10

15

outputs, without saturation or sudden changes such as the case shown in Figure 14.

**Figure 13.** Result of application of Relay-Feedback in a working point


**Table 2.** Ziegler-Nichols formulas for closed chain

In this case it will be necessary to obtain them for a criterion of changes in the load (for load disturbances rejection).

Taking this into account the expressions to tune controllers in closed chain of Ziegler-Nichols will be applied. They are the pioneer formulas for obtaining controller parameters, and they are good at changes in the load. The specification that it is trying to obtain is a list of overshoot of a quarter decay ratio, which means that in the face of the input of a disturbance, the successive overtopping of reference, are four times lower than the previous one (damping factor of 1/4) . Such expressions are shown in Table 2.

#### *6.2.4. Fine tuning of the controller*

The parameters obtained in the preceding paragraph would be necessary subject to a fine-tuning, because the results reached are not suitable.

In this most delicate task of adjustment it is necessary to indicate that it should not saturate the output controller at any time. It is necessary to reach a compromise, since an excess of proportional gain causes a fast response in the output and with little overshoot, which apparently is ideal, but under these conditions the servo is constantly fluctuating, which will cause it to deteriorate in a short period of time. As conclusion, it is going to search gradual outputs, without saturation or sudden changes such as the case shown in Figure 14.

**Figure 14.** Example of steering and control signal to the rudder

It is necessary to indicate that for this model the method of adjusting parameters Ziegler-Nichols is not the ideal, since the initial values of the parameters do not give good results, differing greatly from those achieved after fine-tuning.

#### *6.2.5. Parameters obtained for each case*

12

0

**Figure 13.** Result of application of Relay-Feedback in a working point

factor of 1/4) . Such expressions are shown in Table 2.

fine-tuning, because the results reached are not suitable.

**Table 2.** Ziegler-Nichols formulas for closed chain

*6.2.4. Fine tuning of the controller*

disturbances rejection).

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

0 500 1000 1500 2000 2500 3000

K =0.6 x *Kc Ti* =0.5 x *Tc Td* =0.125 x *kc*

In this case it will be necessary to obtain them for a criterion of changes in the load (for load

Taking this into account the expressions to tune controllers in closed chain of Ziegler-Nichols will be applied. They are the pioneer formulas for obtaining controller parameters, and they are good at changes in the load. The specification that it is trying to obtain is a list of overshoot of a quarter decay ratio, which means that in the face of the input of a disturbance, the successive overtopping of reference, are four times lower than the previous one (damping

The parameters obtained in the preceding paragraph would be necessary subject to a

Taking all the comments above into account all the comments above we obtain the controller parameters fine-tuned for each of the cases discussed above, which seeks a criterion of minimum overshoot and maximum speed for the restrictions presented in the preceding paragraphs. In this way we reach the parameters of the table 3.


simout To Workspace

http://dx.doi.org/10.5772/50316

115

1 Out1

Subtract

Product1

velocity of the ship. The pins In1 and Out1 are the Neuro\_PID block pins of the figure 15,

By this way, the implemented controller will choose the most appropriate parameters for the area in which it is working. It should be noted that more points could be obtained to train neural networks, but it would be more expensive. Furthermore, the neural network itself follows the tendency of data, already interpolates properly between them, showing one of

To validate the model created it is resorted to its simulation with different values of the

It has been made different tests at multiple points of work, and in Figure 17 is shown four representative examples in which in all cases is made a steering to -5ž and once stabilized to +10ž.The answer is satisfactory and similar in all cases with the only difference in velocity due to the different velocities. It should be noted that at small velocities to get an adequate response of the steering, similar to the one of the entire range, it is necessary to saturate the

Saturation

Scope

(1/2)\*((v/l)^2)\*A\*l/D s +a0\*(v/l).s 2 Ship

Neuro-Knowledge Model Based on a PID Controller to Automatic Steering of Ships

1 s Divide Integrator

> du/dt Derivative

In1 Out1 Servo-Rudder

Product

In1 Out1 Neuro\_PID

> p{1} y{1} Ti Neural Network1 p{1} y{1} Td Neural Network2

which control signal is joined directly to the servo-rudder.

parameters, on which depend the velocity model and displacement.

p{1} y{1} K Neural Network

1 In1

Step

**Figure 15.** System on Simulink format

v Constant1

**Figure 16.** Neuro-PID Block

the advantages of its use.

D Constant

**Table 3.** Controller parameters obtained for each rule

#### **6.3. Implementation of the neural network**

It has been designed a neural network type MLP (Multi Layer Perceptron) for scheduling of each one of the controller constants *K*, *Ti* and *Td*. They all have two inputs, which are the displacement and the velocity of the ship, and one output that is the corresponding constant. The neuronal network has an intermediate layer with 5 neurons for *K* and 6 for *Ti* and *Td*. This structure has been adopted after many tests with different numbers of neurons in the middle layer (tests were made from 4 to 9 neurons in the middle layer) for each of the neural networks. The activation functions of neurons in the middle layer are a kind of hyperbolic tangent, except in the output layer, where one neuron is with a linear function.

Once this configuration is selected it is shown the different characteristics of the training carried out with backpropagation learning. It has been made the training of *K*, *Ti* and *Td* at 531, 705 and 686 respectively epochs, with an average error at the end of the training less than 1%. The artificial neural networks have been trained off-line, although the checking of its proper operation has been performed on line.
