Simulation Environment in Python For Ship Encounter Situations
Simulation Environment in Python For Ship Encounter Situations
DOI: 10.12716/1001.17.04.22
ABSTRACT: To assess the risk of collision in radar navigation distance-based safety measures such as Distance
at the Closest Point of Approach and Time to the Closest Point of Approach are most commonly used. Also Bow
Crossing Range and Bow Crossing Time measures are good complement to the picture of the meeting situation.
When ship safety domain is considered then Degree of Domain Violation and Time to Domain Violation can be
applied. This manuscript provides a description of a ship encounter simulation software tool written in Python
accompanied by a case study, implementing all the measures mentioned above. It offers a radar-like Graphical
User Interface (GUI), is able to track AIS-based traffic or encounter scenarios stored in local files. The tool
features several additional functions e.g. Variable Range Marker (VRM) or Electronic Bearing Line (EBL). The
simulator might be a test sandbox for advanced collision avoidance algorithms.
953
of nearby traffic. Section 3 briefly recalls definitions of the message transmitted by them is incomplete or
basic risk-related metrics applicable in ship encounter there is a format distortion or data errors, its
situations. Section 4 introduces the Python simulation transmission is discriminated, i.e. the allocated
tool including details on its initial assumptions, elementary frame will be received and the entire
applied technologies, GUI design and key features. transmission schedule ceases to exist. This frame, if
The section concludes with possible further necessary, is allocated to another AIS having a
development of the tool. A case study with exemplary stronger signal. In order to eliminate the problems
encounter situation analysis with assistance of the tool associated with the reception of weak or distorted
is presented in Section 5. The final section concludes signals from distant devices, messages transmitted by
and summarizes the material presented. AIS at distances greater than 100 nautical miles are
automatically discriminated.
Additionally, the following transmission access
2 AIS AS SOURCE OF INFORMATION ON methods are distinguished:
NEARBY TRAFFIC − ITDMA - extended TDMA (Incremental Time
Division Multiple Access) system,
− RATDMA - access to TDMA (Random Access
Ship situation awareness seems a crucial element of Time Division Multiple Access),
her safety when maritime traffic is considered. The − FATDMA – frequency multiple access (Fixed
situation awareness is especially important for Access Time Division Multiple Access),
autonomous vessels. Typically for such marine units, − SOTDMA - self-organizing time division multiple
they can gather information on the other vessels in the access.
vicinity based on their radar and ARPA displays.
However, due to its analogue roots, radar/ARPA can Depending on the adopted method of access to
suffer e.g. from the shadow effect and are able to transmission, the following AIS work methods are
cover a limited range around a ship. Thus, in practice distinguished:
the most common way of building the situation − autonomous also called continuous - transmitting
awareness for autonomous vessels is by utilization of at time intervals:
Automatic Identification System (AIS). − static - every 6 minutes and on request,
− dynamic - at intervals depending on the
The AIS is a radio device enabling automatic: situation,
− transmission to suitably equipped shore stations, − regarding travel - every 6 minutes, on request
other vessels and aircrafts: data identifying the and after each change of any data,
ship and its type, and specifying its current − safety information - after entering and on
position, course, speed, navigation status and request.
transported dangerous goods, as well as short − assigned mode - the frequency and time moments
safety information, of transmission of position reports are determined
− receipt of such information from similarly automatically by an authorized base device acting
equipped vessels, independently or via a so-called relay device (AIS
− position monitoring and vessel tracking, transponder),
− data exchange with devices ashore. − pooling mode - the ship's AIS transmits the data
The AIS device can be installed: upon receipt of an interrogation signal sent by the
− on ships, AIS of another vessel or aircraft or by the base unit.
− on the shore as a so-called base and relay device, As not all vessels operating at sea are subject to the
− at the centre of the Vessel Traffic Control Service
Downloaded from mostwiedzy.pl
954
Usually, instead of a direct risk estimation, the = Vrx + Vsinψ
VTx
navigator utilizes sets of accompanying distance and
= Vry + Vcosψ
VTy
time metrics. Among them the most popular are
Distance at the Closest Point of Approach (DCPA) V=
rx VTx − Vsinψ
together with Time to the Closest Point of Approach
V= VTx − Vcosψ
(TCPA). When bow distance is taken into account ry
= Vrx + Vx
VTx
= Vry + Vy
VTy
=
VT VTx2 + VTy2
=
Vr Vrx2 + Vry2
Vx = Vsinψ
Vy = Vcosψ
=
V Vx2 + Vy2
where ψ is a course over ground of own ship. Figure 1 Visual representation of BCR & BCT
It follows from the above:
On the basis of the distance criterion, a meeting
situation is recognized as an instance of BCR.
Although the general recommendation is to take into
955
account distances not less than 1 NM, the rigorous therefore
range of values, as in the case of DCPA, is not
imposed. However, there is no strict literature BCRTS perspective
concerning sustained conditions in encounter BCT = .
situations [6] and the scientific literature contains TS SOG
diverse values [7].
It is important to recognize that the crossing is a
specific kind of encounter that occurs when one ship 3.3 DDV & TDV
approaches another from the COLREG visibility
sector (regardless if ahead or astern) of just one When distance-based ship safety domain [8] is
sidelight. Head-on encounters and overtaking are not considered, neither DCPA & TCPA nor BCR & BCT
regarded as instances of the Bow Crossing Range. are able to provide apt and direct information on
Therefore, it becomes clear that BCR might be a useful possible domain violation. Thus, in [2] Szlapczynski
measure when neither of the aforementioned and Szlapczynska proposed a brand new pair of
statements is accurate. The BCR & BCT value (positive domain-based risk metrics, namely Degree of Domain
or negative) informs the navigator of the ship passing Violation (DDV) and Time to Domain Violation
ahead or astern and their respective COLREG Rule 15 (TDV). They provided there analytical formulae for
requirements [6]. DDV & TDV calculation for a standard Coldwell’s
elliptical domain. These metrics have been recently
For BCR & BCT all calculations are made in the applied to near-miss analysis and Collision Alert
two-dimensional space of Cartesian coordinates: System frameworks in [9].
relative bearing to TS is assumed as In order to calculate values of DDV & TDV for
configurable Coldwell’s domain (with a, b, da and db
=
brg rel ( OS ) brgtrue( OS ) − hdgOS ( t ) parameters) it is assumed that the coordinate system
is a two-dimensional Cartesian one with its own ship
in its centre, as presented in Fig 2. Please note that the
where rotation angle α is calculated unlike in sea navigation
i.e. counter clockwise from the X axis.
Y
brgtrue( OS ) wrap _ angle deegres arctan − 180°
X
where
= X OS ( t ) − X TS ( t )
X
= YOS ( t ) − YTS ( t )
Y
aspect is assumed as
where
Figure 2 Assumptions for DDV & TDV: elliptical domain
=
brg brgtrue(TS ) − hdgTS ( t ) presented in Cartesian coordinate system with own ship in
rel (TS ) its centre
where Therefore:
(X, Y) – relative position of a target,
Y (Xe, Ye) – relative position of the centre of an ellipse
brgtrue(TS ) wrap _ angle deegres arctan − 180° being the target's domain,
X Xe = X + h
h= ∆acosα+ ∆bsinα
where Ye = Y + k
k= ∆asinα- ∆bcosα
= X TS ( t ) − X OS ( t )
X (Vx, Vy) – components of the relative velocity of a
target,
= YTS ( t ) − YOS ( t )
Y α – the rotation angle of the target's domain (being
equal to course angle of the target), measured
counter clockwise from X axis to the tip of a target's
According to [6] BCR is understood as true speed vector
BCR = nearest _ points (( X bow( OS ) ,Ybow( OS ) ) , hull (TS )) The elliptic domain moves with the relative speed
of a target:
956
X e ( t ) = X + hf + Vx t cos 2α sin 2α
=A1 +
Ye ( t ) =Y + kf + Vy t b2 a2
1 1
= B1 2 sinα cosα 2 − 2
The parametric equation of a rotated ellipse with a a b
centre in (Xe(t), Ye(t)) as a function of time is:
sin α cos α
2 2
=
C1 +
a2 b2
( e( ) () ) ( e( ) () )
2 2
X t cosα +
Y t sinα X t sinα − Y t cosα
e e
2
+ 2
=
1
a b
To determine TDV it is necessary to solve
following equations:
The parametric equation of the f-scaled ellipse
(with the same centre) as a function of time is:
−B − B32 − 4 A3C3 − B3 + B32 − 4 A3C3
t1 = min
3
,
( X e ( t ) cosα + Ye ( t ) sinα ) ( X e ( t ) sinα − Ye ( t ) cosα )
2 2
2 A3 2 A3
+ =
1
f (t ) a2 f ( t ) b2
2 2
−B − B32 − 4 A3C3 − B3 + B32 − 4 A3C3
t2 = max
3
,
Solving the latter gives a formula for f(t), as 2 A3 2 A3
presented in:
assuming that:
− ( B21 + B22 t )
± D1t 2 + E1t + F1
f1,2 ( t ) =
2 A2 A3 =A1Vx2 + B1VxVy + C1Vy2
where
(
B3= 2 ( A1 X eVe + C1YeVe ) + B1 X eVy + YeVx )
C3 = A1 X e2 + B1 X eYe + C1Ye2 − 1
A2 = A1h + B1hk + C1k − 1
2 2
=
D 2
− A2 C23 where t1<t2,
1 4
B22
t1 – the time remaining to entering the target’s
=E1 2 B21 B22 − 4 A2 C22 domain,
= 2
F1 4
B21 − A2 C21 t2 – the time remaining to leaving the target’s domain.
According to [2] there are three possible cases here:
where t1<0 and t2<0 says that a domain has already been
entered and left,
t1≤0 and t2≥0 says that a domain has already been
B21 = ( 2 A1 X + B1Y ) h + ( 2C1Y + B1 X ) k
entered but not left,
t1>0 and t2>0 says that a domain will be violated in
with time t1 and left in t2.
− E2 ± E22 − 4 D2 F2
,
Downloaded from mostwiedzy.pl
tmin1,2
2 D2 4 PYTHON-BASED SHIP ENCOUNTER
SIMULATION ENVIRONMENT
where
This section describes a simulation tool for ship
encounters implemented using Python language. We
=D2 ( 2
D1 B22 )
− D1 have chosen Python as one of the most popular high
level languages these days, offering a wide range of
=E2 E (B
1
2
22 −D ) 1 built-in functions and easily available open source
modules or packages covering various applications.
=
F2 2
F1 B22 − E12 Moreover, the tool being described here has been a
part of a wider software and hardware solution, built
where in the course of ENDURE project. Thus, a unified
policy towards software implementation was an
(
B22 = 2 A1Vx + B1Vy h + 2C1Vy + B1Vx k) ( ) important factor here.
Obviously, there are numerous tools available, e.g.
[11-17], offering similar ship traffic simulation or ship
whose f(t) minimum over time t is the approach factor
navigational decision support functionality. Some of
fmin. DDV is then obtained by substituting the fmin to
the recent ones are also implemented in Python, the
DDV=max(1-fmin,0). We assume that the following
other are written in C/C++, MatLab or other high level
should be substituted:
languages. Majority of the solutions are not in the
public domain nor have open source licence and even
if they are open sourced, they have got a non-
compatible functional range [11]. Thus, it was
necessary to design and implement our own tool,
957
fully customizable, offering the exact functionality interface was inspired by the interfaces of radar
that was required in the course of the ENDURE devices and ECDIS. The advantage of this solution is a
project. relatively intuitive and easy-to-use interface for
navigators.
The tool described here is able to monitor live
encounter traffic situation AIS data. It is also possible Figure 3 shows an overview of the program’s GUI.
to utilize offline situation data stored in a local file. In the central part, on the azimuth dial, target vessels
Moreover, the tool implements the following risk- visible in a given range are displayed.
related measures: TCPA, DCPA, BCR, BCT, DDV and
TDV, their values can be monitored throughout the
encounter. The following subsections present initial
assumptions of the tool, the applied technologies, GUI
and key features of the tool and finally directions for
further tool development.
958
information contained in the type 4 report.
Additionally, the CADCA (Collision Avoidance
Dynamic Critical Area), presented in the Figure 7, can
be drawn for a fully initialized vessel. CADCA [10] is
a deterministically defined area that geometrically
limits the manoeuvring area of the vessel for which it
is designated. The CADCA shape and size depends
on the movement parameters of the vessel such as
rudder angle, initial forward speed, or planned
alteration of the course. The main assumption of the
CADCA concept is to support navigational decisions
in collision situations. For a detailed description,
please refer to the article [10].
959
circle on a triangle) is shown in the Figure 8. In this 4.4 Possible further development of the tool
case, the calculations of the DDV & TDV safety
Further possible application development includes
indicators are omitted due to the lack of all data. In
this situation, however, it is suggested to rely on implementation of the functionality enabling the
visualization of electronic maps. This would allow the
DCPA & TCPA until report of type 4 is received and
program to be used in difficult navigational areas
consequently the required safety indicators are
without the risk of a collision with a stationary object.
calculated.
Considering the development of the maritime
The tool offers the trial manoeuvre calculations for industry, it is possible to adapt the existing software
planning the collision avoidance manoeuvre. After functionality to the requirements of collision
clicking the TRIAL button, three controls appear to avoidance systems of unmanned ships. However, this
allow the user to change: course, heading and speed. is a topic for the long run.
The word TRIAL appears on the screen, which
indicates that all changes to the parameters of the own An interesting aspect of the software is its open
architecture. It allows the application to be used as a
ship's movements are carried out on a trial basis,
test environment enabling relatively simple
without actually changing them. The functionality of
the trial manoeuvre here consists in presenting the implementation of, for example, experimental safety
indicators. A potential prospect for the development
changes in the relative motion vectors of the target
of the application may also be the use of the current
ship and the change in the value of safety indicators
depending on the planned course, heading or speed operating logic to create a proprietary functionality
consisting in the analysis of the movement of ships
change. The manoeuvre has no time delay, all
using AIS. There are many possibilities, but the issue
planning is done live, the own vessel and target
vessels continue to move during the planning process, of their use in the era of rapid scientific and industrial
development is a topic for a separate discussion. At
according to the received AIS reports. Figure 9 shows
present, the program may turn out to be useful as an
an example of a trial manoeuvre. The own ship as
well as the target ship moves at a given speed and experimental decision support system, which may be
of interest to the scientific community, the maritime
heading. After the planned increase of the own ship's
industry as well as enthusiasts of new technologies.
speed, the appearance of the vector of the relative
speed of the target ship in relation to the own ship, in
the form of a cyan line, symbolizing future positions
in given moments of time, is observed. 5 CASE STUDY – ANALYSIS OF A CROSSING
ENCOUNTER BY THE SIMULATOR TOOL
960
According to the COLREGs, the give-way vessel is
the target ship, while the stand-on vessel is the own
ship. The situation requires that the target ship keeps
clear of the own ship by making a clear course
manoeuvre to starboard. However, no such course
change took place in the first 6 minutes of encounter.
Thereafter, minimal course changes are made, which
contradicts the COLREG recommendation to use
significant course changes. As shown in Figure 12, the
DCPA(t) graph indicates that the vessels have kept a
minimum distance of 0.5 NM from each other during
entire meeting. The upward trend of DCPA indicates
that the target vessel was performing a speed increase
manoeuvre. The effect of this manoeuvre become
clearly visible from about 14 minutes. In comparison
with DCPA as the main predictor of collision risk, the
confidence that the risk decreases was obtained after
about 14 minutes - at this point the distance at the Figure 13. Case study – BCR values during the encounter
closest point of approach (DCPA) grows
exponentially. Considering the graph of the BCR(t),
shown in Figure 13, the target vessel crossed the
course of the own vessel at a distance of 1.6 NM.
Table 1. Case study – parameters of the ships in meeting
________________________________________________
Own ship Target ship
________________________________________________
Name m/t “Bit Power” “Viking Prince”
Length 116.9 m 89.6 m
Beam 18.0 m 21.0 m
Initial coordinates
59° 3' 18'' N 59° 5' 55.0608'' N
004° 10' 44.112'' E 004° 8' 37.1544'' E
Final coordinates 59° 7' 15.6036'' N 59° 5' 7.1736'' N
004° 10' 41.7'' E 004° 16' 36.768'' E
Initial COG 358.0° 101.0°
Initial SOG 9.8 kn 11.5 kn
________________________________________________
the situation, including the type of encounter situation sensitive to changes in the parameters of the ship's
and the effect that will be achieved with the current motion and its position. It is particularly visible in the
movement parameters. time interval 0 - 2.5 minutes, where the shape of the
curve indicates a sudden change in the nature of the
situation and the successive decrease in the risk of
collision (the Degree of Domain Violation decreases).
In this scenario in case of DCPA, the reliable
collision risk assessment was possible after 12
minutes. In the case of BCR – it was possible after
approximately 8 minutes. In this particular scenario
based on DDV one is able to assess the collision risk in
no more than 4.5 minutes. As depicted in Figure 14,
there is an immediate suggestion (at the start of the
recorded situation) of a DDV value of around 0.5,
which shows a severe domain violation, moreover
with upward trend of DDV values during first 2 min.
of the encounter. After reaching the value of 0.9 in
about 3 minutes of observation, the situation
improves until reaching the value of DDV equal to 0,
meaning no domain violation. Thus, one might
Figure 12. Case study – DCPA values during the encounter
conclude that relying on the DDV value alone in the
risk assessment, the situation in this case was safely
cleared up after approximately 4.5 minutes.
961
For the examined crossing case, for which the Eng., vol. 126, pp. 47–56, 2016, doi:
situation allowed the use of DCPA and BCR 10.1016/j.oceaneng.2016.08.030.
indicators for comparison purposes, it is clear that [3] “SOLAS Convention.”
DDV proves its superiority. The DDV answers the https://www.imo.org/en/About/Conventions/Pages/Inter
national-Convention-for-the-Safety-of-Life-at-Sea-
question of whether there is a risk of collision not only
(SOLAS),-1974.aspx
in a binary way, but, when the risk does exist, [4] A. Lenart, “Approach Parameters in Marine Navigation
provides also the risk magnitude. – Graphical Interpretations,” TransNav, Int. J. Mar.
However, the use of the DDV indicator is not Navig. Saf. Sea Transp., vol. 11, no. 3, pp. 521–529, 2017,
doi: 10.12716/1001.11.03.19.
without its drawbacks. Application effectiveness of
[5] Ł. Stolzmann, “Bow Crossing Range Correlation of Small
metrics like DDV or BCR is indirectly limited by the Vessels - Ais Data Analysis With Prospective
use of AIS as its base source of data. One of the Application To Autonomous Ships.,” Sci. J. Gdynia
serious limitation here is the specification of the AIS Maritme Univ., vol. 6988, no. 121, pp. 41–52, 2022, doi:
itself. For example, the user is forced to wait for a 10.26408/121.04.
static data report because the length of the target [6] M. Gil, P. Kozioł, K. Wróbel, and J. Montewka, “Know
vessel is required for the DDV or BCR calculation. It is your safety indicator – A determination of merchant
not uncommon that during a collision avoidance vessels Bow Crossing Range based on big data
manoeuvre every minute saved might be crucial, thus analytics,” Reliab. Eng. Syst. Saf., vol. 220, 2022, doi:
waiting for an AIS report with static data in a critical 10.1016/j.ress.2021.108311.
[7] A Guide to the Collision Avoidance Rules. Elsevier, 2012.
situation may end up at best with a conflict with
doi: 10.1016/C2010-0-68322-2.
COLREG Rule 8. The conclusion is that any ship- [8] R. Szlapczynski and J. Szlapczynska, “Review of ship
length dependant indicator, as e.g. the DDV or BCR safety domains: Models and applications,” Ocean Eng.,
metrics, should be used with caution in real-time vol. 145, no. January, pp. 277–289, 2017, doi:
collision avoidance systems. 10.1016/j.oceaneng.2017.09.020.
[9] R. Szlapczynski and J. Szlapczynska, “A ship domain-
based model of collision risk for near-miss detection and
Collision Alert Systems,” Reliab. Eng. Syst. Saf., vol. 214,
6 SUMMARY no. May, p. 107766, 2021, doi: 10.1016/j.ress.2021.107766.
[10] M. Gil, “A concept of critical safety area applicable for
an obstacle-avoidance process for manned and
The presented here ship encounter simulation and autonomous ships,” Reliab. Eng. Syst. Saf., vol. 214, p.
traffic monitoring tool offers features allowing for 107806, 2021, doi: 10.1016/j.ress.2021.107806.
easy customization and making possible to test [11] S. Blindheim, T. A. Johansen, "Electronic Navigational
various collision avoidance solution within its Charts for Visualization, Simulation, and Autonomous
graphical environment. It is worth noticing that the Ship Control," IEEE Access, vol. 10, pp. 3716-3737, 2022,
tool implements a number of safety indicators, doi: 10.1109/ACCESS.2021.3139767.
namely DCPA, TCPA, BCR, BCT, DDV and TDV and [12] Z. Pietrzykowski, P. Wołejsza, Ł. Nozdrzykowski, P.
is ready for implementation any new metric, if such Borkowski, P. Banaś, J. Magaj, J. Chomski, M. Mąka, S.
necessity arise. As presented in the previous section, Mielniczuk, A. Pańka, P. Hatłas-Sowińska, E. Kulbiej, M.
Nozdrzykowska “The autonomous navigation system of
the tool has been validated on live AIS data stream
a sea-going vessel” Ocean Engineering, Vol. 261, 2022,
and real ship encounter scenario. It is planned to 112104, https://doi.org/10.1016/j.oceaneng.2022.112104.
continue development of the tool towards integration [13] P. Wołejsza, J. Magaj, R. Gralak “Navigation Decision
with the s-57 map and/or with the s-100 map. Also it Supporting System (NAVDEC) — testing on full mission
seems promising to extend the tool in future by simulator” Annual of Navigation 20(1), 2013,
including weather forecast, hydrographic information https://doi.org/10.2478/aon-2013-0010.
Downloaded from mostwiedzy.pl
and ship stability decision support. [14] J. Lisowski, "Dynamic Games Methods in Synthesis of
Safe Ship Control Algorithms", Journal of Advanced
Transportation, vol. 2018, Article ID 7586496, 8 pages,
2018. https://doi.org/10.1155/2018/7586496.
ACKNOWLEDGEMENTS [15] A. Lazarowska,”Evaluation of a deterministic real-time
path planning algorithm for autonomous ships using
radar data” Procedia Computer Science, Vol. 192, 2021,
The study described has been performed as part of the pp. 863-872, https://doi.org/10.1016/j.procs.2021.08.089.
Detection, prediction, and solutions for safe operations of [16] Ł. Kuczkowski, R. Śmierzchalski, (2017). Path planning
MASS (ENDURE) project (number algorithm for ship collisions avoidance in environment
NOR/POLNOR/ENDURE/0019/2019–00), supported by the with changing strategy of dynamic obstacles. In:
Polish National Centre for Research and Development and Mitkowski, W., Kacprzyk, J., Oprzędkiewicz, K., Skruch,
financed by Research Council of Norway. P. (eds) Trends in Advanced Intelligent Control,
Optimization and Automation. KKA 2017. Advances in
Intelligent Systems and Computing, vol 577. Springer,
REFERENCES Cham. https://doi.org/10.1007/978-3-319-60699-6_62.
[17] Y. Huang, L. Chen, R. R. Negenborn, P.H.A.J.M. van
Gelder “A ship collision avoidance system for human-
[1] IMO, “Convention on the International Regulations for machine cooperation during collision avoidance” Ocean
Preventing Collisions at Sea,” COLREG. Engineering, Vol. 217, 2020,
[2] R. Szlapczynski and J. Szlapczynska, “An analysis of https://doi.org/10.1016/j.oceaneng.2020.107913.
domain-based ship collision risk parameters,” Ocean
962