• No results found

7.2.2 Evasive maneuver

Since this mode uses a heading-based guidance method, then there needs to be a different controller that takes desired heading and velocity as input rather than desired position. The objective is to control the heading towards the desired heading that is computed by the guidance function, in addition to obtaining the desired surge speedud. To do this, the yaw force is computed by a PD-controller similar to Equa-tion 7.22. The difference is that the yaw rateris not controlled to 0, but to a desired raterdsuch that the yaw rate error isr˜=r−rd. Then, the yaw force is

τN =−Kpssa( ˜ψ)−Kdr.˜ (7.25)

The gains are given by Equation 7.24. At the same time, the surge velocity should be controlled by adjusting the surge forceτX. For a starboard-port symmetric vessel like milliAmpere, surge is decoupled from sway and yaw. Then, the surge force can be calculated independently, to achieve the desired speed.

To simulate a speed controller with good performance, the following expression is used to find the desired force based on the desired velocity vectorνd=

ud 0 0>

. This assumes that the model of the vessel Equation 2.1 is known with satisfactory precision.

τ =Mν˙d+ (C+D)νd (7.26)

From this, the desired surge force can be extracted as the first element in the vector, such that τX =

It is worth noting that this is not a method feasible for real control systems as the system matrices, in general, can not be assumed to be known, but for this purpose, it emulates a speed controller with good performance. The total force vector is thenτ =

τX 0 τN

>

.

7.3 Thrust limitation

As stated in Section 4.4, thruster dynamics and -allocation are not considered in this thesis. Therefore, it is not necessary to do thrust allocation in the sense of calculating individual thruster setpoints. However,

7.3 Thrust limitation to maintain realism, the body forces that are applied should respect the maximum limits for thrust.

Combined, the thrusters can produceτf,max1000 Nof force andτN,max = 1800 N m of moment. This can not be achieved at the same time. Therefore, the limitation should consider also what the other forces are. First, the desired force can be related to the maximum available in that DOF throughthrust coefficientsdefined as following:

ct,f = fd τf,max

, ct,N = τd,N τN,max

. (7.28)

Here, τd is desired force from the controller, and fd is the desired linear force computed as fd = q

τd,X2d,Y2 . Then, a relation can be derived to limit the resulting forces, by saying that the sum of the thrust coefficients squared should satisfy

c2t,f +c2t,N = 1. (7.29)

This relation ensures that full surge force and yaw moment can not be applied at the same time, and gives sufficient realism for this purpose. Furthermore, to solve this relation directly, it is necessary to specify one of the thrust coefficients. This is done by making two modes - one where force is prioritized and one where yaw moment is prioritized. This is represented by the variableσpwhich take values 0 and 1 respectively. Then, the maximum allowed thrust coefficients are chosen as:

ct,N =

(0.8 σp= 1

1−0.82 = 0.6 σp= 0, ct,f =

(√1−0.82 = 0.6 σp = 1

0.8 σp = 0, (7.30)

if the thrust coefficient exceeds the allowable limit. This restricts the prioritized force/moment to at most 80% of maximum capacity, while the non-prioritized get the remaining capacity such that Equation 7.29 is respected.

Chapter 8

Simulation setup

8.1 MATLAB simulator

To simulate the behavior of milliAmpere, a MATLAB script that does numerical integration of the model in Equation 2.1 is used. The script was generously supplied by Emil Thyri of the Autoferry project. The hydrodynamic parameters used are the ones identified by Pedersen (2019). These can be viewed in Appendix C. As it was realized that milliAmpere is not directionally stable with the parameters used, the code was modified to simplify the model for this project. Both mass and damping matrices were made diagonal, which meant setting all off-diagonal entries to zero. This made the model easier to work with. The script uses MATLABsode45method to solve the equation of motion for each timestep. The dynamics script can be seen in Appendix A.2.

The simulator is made to emulate the flow presented in Figure 4.1. It consists of a for loop running at a timestep of h = 0.1 s. The input to the solver is the velocity vectorν, the position vectorηand the body forcesτ. The solver then returns new position and velocity vectors, which are used in the next time step. The pseudocode for the simulator where all relevant calls to subfunctions are done can be seen in Algorithm 2, while the actual MATLAB script is presented in Appendix A.3. This script runs the mode simulator first, to determine the mode. Additionally, a function is made to change parameters during the simulation, to emulate new input from the SA system. After this, guidance and control functions are run, before the vessel dynamics script is used to compute the new position and velocity. Lastly, the data from each timestep is saved to be plotted and analyzed later. Then, the loop is repeated as many times as necessary to achieve the specified simulation time.

The implementation of all relevant functions is done in MATLAB. The code is available at GitHub1. The different subsystems interact as shown in Figure 4.1. In the following, the specifics of each simulation are presented. The simulations are run by running the init simX.m script, whereX is the simulation number. This script runs the simulation and plots the results.

1https://github.com/jonmmo/Automatic-control-of-passenger-ferry-with-risk-contingencies

Algorithm 2:Simulator pseudocode initialization;

foreach timestepdo

Determine mode by running mode supervisor;

Change parameters according to simulation specification if needed;

Compute the desired position by using the correct guidance function;

Compute control forces by using correct control function;

Obtain new position and velocity from vessel dynamics;

Save results;

end

Figure 8.1:Simulation environment. Yellow and red circles represent obstacle regions.