I implemented a real-time digital twin, sometime ago, to perform underwater sediment mapping - please see the description in the twins tab.

In this post I will explain the technique used for communicating, in real-time, with the measurement instruments---in this case, a sonar array made up of a towed sound-source and stationary hydrophones forming a vertical antenna under the water surface. The geo-referenced pings were received from the antenna, at regular intervals, and transmitted to the workstation over a local network. The actual determination of the sediment properties, essentially the sediment density, was perfomed by solving a parameter estimation inverse problem for the acoustic wave equation, based on these measurements.

Since the inversion code was written in Matlab, we used the pnet function from the TCP/UDP/IP Toolbox. This toolbox can set up TCP/IP connections or send/receive UDP/IP packets in MATLAB. It can transmit data over an Intranet, either between MATLAB processes or other applications. It can act as server and/or client and can transmit textstrings, arrays of any datatype, files or MATLAB variables. In our case, we used it to transmit both data (in the form of .xml files) and commands for synchronizing the different actions and stages of the acquisition-inversion-ouput cycle.

Here is a code extract that shows how we coded the (infinite) listening loop, the data transmission and the actual call of the inversion routine, run_calcul.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
function [outputs] = run_inv(handles,hObject,port_inv)
% Initialize port, socket
port_inv = 6666;
sock=pnet('tcpsocket',port_inv);
if(sock==-1); error('The TCP port %d is not available',port_inv); end
net(sock,'setreadtimeout',1);
disp(sprintf('\nInversion launched on port %d (waiting for START...)',port_inv));
disp('... to stop: ctrl-C then pnet(''closeall'') ...'); disp(' ');
while (1) %infinite loop of HTTP server    
    % Initialize the connection
    con=pnet(sock,'tcplisten');
    while (con==-1), % no connection
        con=pnet(sock,'tcplisten');
    end
    [ip,port]=pnet(con,'gethost');
    disp(sprintf('Connection from host:%d.%d.%d.%d port:%d\n',ip,port));
    pnet(con,'setreadtimeout', 4);  % do not block server if no request
    pnet(con,'setwritetimeout',1);
    disp('Waiting for request');
    attente = 0;
    while (pnet(con,'status')>0)            % Loop to read requests
        data=pnet(con,'readline',4000000);  % Read the socket
        .
        .
        %-----------------------------------------------------%
        % here we start the treatment of the inversion request
        %-----------------------------------------------------%
        run_calcul(con,obj,test_4S,handles,hObject);                                
        disp(sprintf('*** Exit from inversion\n'));
    end
 end %End of HTTP server loop 
 pnet(sock,'close');

For the actual deployment of the DT, the complete process was piloted by a GUI that controlled all the stages and displayed all the results.

Left: the inversion toolbox GUI. Middle: the 4 components -- GUI, signal processing, sediment cartography, acoustic propagation code. Right: the signal processing. Click on an image to zoom.