Running Real Time Matlab Script Based on Test Point

340 views
Skip to first unread message

Erdem Eskioğlu

unread,
Mar 19, 2021, 4:50:45 AM3/19/21
to IADS
Hello,
 
I would like to run complex functions in matlab real time during the execution of test point to see if the maneuver is acomplished within the tolerances and perform data reductions to reduce reporting time.
What I would like to do basically is running a matlab script from the start of the flight which continously reads the IADS data in real time and when I start a test point via IADS, Matlab needs to identify it and start to record and plot the data in real time until the end of test point then Matlab will calculate some complex functions which I would not like to do in IADS.

Is it possible? If so, how would I do it?

Thanks,
Regards
Erdem

Chant, Adam

unread,
Mar 19, 2021, 11:08:35 AM3/19/21
to IADS

Erdem,
There are a few ways that you can do this, but the simplest would be to use the IADS Test Point System to Launch a MatLab script upon the completion of a test point.
From the Test Point Menu arrow button on the Dashboard: Actions on Stop > Data Export > Export to Matlab
1. Create a “Data Group” with all of the parameters you want to export to MatLab

2. Add the necessary MatLab specific Export Option to the PropertyBag column “\\MatlabExportMethod=DirectlyToMatlab \\MatlabStatementToRun=…”

3. Configure the Test Point System for Actions on Stop

 

The other option would be to use the “iadsread” MatLab function to query the IADS data as you have described and run your matlab scripts as required.

IADSREAD is installed automatically with every IADS installation and a HowTo.m can be found in the C:\Program Files (x86)**\IADS\MatlabExtension\  folder ** Note path for 32 and 64 bit versions.


Variable = iadsread( 'DataDirectory or ServerName$PortId', 'IrigStartTime', 'IrigEndTime' or NumSeconds, 'ParameterNameList (Comma Separated)', [optional arguments..] )


In your case you would use the ServerName$PortId method to query the IADS data server directly and not the data files. It’s not advisable to query the data files directly in real-time as the data isn’t written to the files immediately.

This technique would require a bit more code as it’s basically writing a data interface between IADS and MatLab whereas the Data Export technique does all the work for the user and provides MatLab directly with the data Vector and statement to run.  

Additional details for both techniques can be found in our help system by searching any terms I have listed above in quotes.

 

Thank you,

 

Adam Chant

Project Engineer, IADS

 

Curtiss-Wright

190 Sierra Court A-3 Palmdale, CA 93550

T: 661.273.7003 x210
ach...@curtisswright.com
iads-s...@curtisswright.com

 

From: ia...@googlegroups.com <ia...@googlegroups.com> On Behalf Of Erdem Eskioglu
Sent: Friday, March 19, 2021 1:51 AM
To: IADS <ia...@googlegroups.com>
Subject: [IADS] Running Real Time Matlab Script Based on Test Point [EXTERNAL]

 

WARNING: This message came from an external source. Please exercise caution and proper judgment when opening any attachments, clicking links or responding to this message.


 

--
You received this message because you are subscribed to the Google Groups "IADS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to iads+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/iads/b08ee140-c1fb-4fe1-bd5b-c6e0861d5026n%40googlegroups.com.


This e-mail and any files transmitted with it are proprietary and intended solely for the use of the individual or entity to whom they are addressed. If you have reason to believe that you have received this e-mail in error, please notify the sender and destroy this e-mail and any attached files. Please note that any views or opinions presented in this e-mail are solely those of the author and do not necessarily represent those of the Curtiss-Wright Corporation or any of its subsidiaries. Documents attached hereto may contain technology subject to government export regulations. Recipient is solely responsible for ensuring that any re-export, transfer or disclosure of this information is in accordance with applicable government export regulations. The recipient should check this e-mail and any attachments for the presence of viruses. Curtiss-Wright Corporation and its subsidiaries accept no liability for any damage caused by any virus transmitted by this e-mail.

James Bretz

unread,
Mar 20, 2021, 5:45:44 PM3/20/21
to ia...@googlegroups.com
Hi Erdem,

Yes, this is possible and has been performed by a few customers. You can use the 'iadsread' mex function to read data in realtime directly into a running Matlab script, perform any calculation, then use the 'iadswrite' mex function to send parameter data to the server. To start, I would suggest reading the tutorial in C:\Program Files\IADS\MatlabExtension\HowTo.m. After you become familiar with the iadsread function in post test, you can attempt to connect to a live server. See the tutorial for a simple example. When you are comfortable with that, you can use the HowToIadswrite.m file as a starting example. I don't see this example in the install, so I'll just post it here. The script at the bottom of the page. Look for "% For a working example, start here..."

See below. Let me know if you have any questions,
Jim


% This M-File documents the installation and usage of the IADS 'Mex' data interface
% for Matlab. The library or 'Mex' file that contains the code to interface to
% your existing IADS server is contained within the 'iadswrite.mexw32' for the 32 bit version
% of Matlab and the 'iadswrite.mexw64' file for the 64 bit version of Matlab.
%
% Proper installation of these files will add a function
% to Matlab called 'iadswrite', allowing you to programmatically produce data in realtime
% to an Iads server. In conjunction with the Mex function iadsread, you will then be able
% to write Matlab programs to read, compute, and write derived parameters for complex custom
% operations. In a future version of this interface, you will be able to write Iads data files in
% an offline manner, without the use of the server. That capability is still in development.
%
% If you have already installed Iads on this machine, both the 32 and 64 bit versions of iadswrite
% ('iadswrite.mexw32' and 'iadswrite.mexw64' respectively should be present in your
% C:\Program Files\IADS\MatlabExtension directory. If this is not true, you will have to copy the files
% to this directory.
%
% If Iads is not already installed, simply create a folder on your PC (i.e. C:\Program Files\Iads\MatlabExtension)  
% and copy both the 'iadswrite.mexW32' and 'iadswrite.mexw64' files to this directory;
%
% Once the files are copied you will need to add this directory
% to your Matlab path. To do this, run Matlab. Under the Matlab 'File' dropdown
% choose the option 'Set Path'. A new window will appear titled 'Set Path'.
% Click on the button 'Add Folder'. When the folder browser dialog appears,
% choose the 'MatlabExtension' directory that you created in the first step.
% (i.e. C:\Program Files\Iads\MatlabExtension). Click the 'Save' button to save the
% path, and then 'Close' to close the 'Add Path' window.

% Ok! To test that the 'iadswrite' function is ready to go just type:

iadswrite

% The response is: Error using iadswrite iadswrite: A previoius call to iadsread is required before
% calling iadswrite. Please correct.
% This is correct actually. To use the iadswrite function, you must first call iadsread to get data.
% After the data in acquired from the server, you can use it to calculate the values of output parameter(s).
%
%
% If Matlab returns with  "??? Undefined function or variable 'iadswrite'."
% your path is not set correctly. Make sure your path is set and saved to the directory where you copied iadswrite.mexw32/iadswrite.mexw64 files.

%
% Let's look at each argument in turn.
% Argument 1) ServerName$PortId
%    This string defines the Iads data server for your Flight.
%    This string is used to specify a server name and port id in the format 'ServerName$PortId' to connect iadswrite directly
%    to a real-time data stream. There is example code on this subject below.
%

% Argument 2) IrigStartTime
%    This string defines the Irig time value of the data to be written in the format DDD:HH:MM:SS.MS.
%    In this version of iadswrite, you must set this argument to empty string ''.
%    The value of time for data update is automatically taken from the previous iadsread call to maintain
%    accurate time alignment between inputs and outputs.

% Argument 3) ParameterNameList
%    This string argument is a list of comma seperated parameter names that you want to
%    to write data to. For example, you could import ome aircraft "Wing" parameters by
%    defining a list like: 'AW0001X,AW0002X,AW0003X". Notice the name is the "Parameter"
%    name defined in the config file's "ParameterDefaults Table" (usually the parameter code)
%
%    Note: All filtering and nulling that was set in the ParameterDefaults entry for the
%    specified parameter is applied before the data is returned to Matlab. Spike detection and wild
%    point corrections are *not* applied as of this date. We may consider having this as an option.
%
%    One more option is being considered for next build:
%    * The DataGroupName option will allow you to access a group of parameters defined in
%    your config file under the DataGroup table.

% Argument 4) MatrixOfDataToBeWritten
% This columnwise data matrix contains the data to be written to the Iads server for each parameters defined
%    in argument 3 above. Each column of the matrix corresponds to, in order, the values per parameter being updated.
%    For example, if argument 3 had the value of 'A,B,C', the expected matrix should contain 3 columns, with column 1
%    being the value for parameter A, column 2 the values of B, and column 3, the values of C. A single parameter
% update would be of type vector. The length of the matrix or vector would be defined by the length of the matrix or
%    vector obtained by the iadsread call. In other words, there should be a 1 to 1 correlation from the input data to the
% output data. In essence, each input parameter value should produce an output parameter value.

% Now, let's connect to a running Iads server on a computer named 'IADS-CDS' and get one second of data from the most current
% time for three parameters A, B, and C

abc = iadsread( 'IADS-CDS$58000', '', 1, 'A,B,C' );

% At this point, we can send the data to a Matlab function and have it return the results to be written. For simplicity
% sake, I'll just multiply the input data by 10

abc = abc * 10;

% Now, let's take that result and send it to the Iads server under the parameter names of AMatlab, BMatlab, and CMatlab'
% Before we do this, we need to make sure the server has definitions of the parameters we are about to output.
% You will need to add a parameter in the ParameterDefaults table for each listed in argument 3 below. The parameter
% should be of DataSourceType 'Iap', the ParamType "float", and the equation should call a function named External(). We can accomplish this by
% sending an update query through the iadsread function to the server. In the query below, we'll add 3 new parameters named AMatlab,
% BMatlab, and CMatlab. For the specifics on using an update query through the iadsread function, please contact customer support.
% The statement below is relatively self explanitory and can be modified to incorporate variables for the parameter name.

iadsread( 'IADS-CDS$58000', '', 0, '? update ParameterDefaults set Parameter = ''AMatlab'', ParamType = ''float'', DataSourceType = ''Iap'', DataSourceArguement = ''External()'' where Parameter = ''AMatlab''' );
iadsread( 'IADS-CDS$58000', '', 0, '? update ParameterDefaults set Parameter = ''BMatlab'', ParamType = ''float'', DataSourceType = ''Iap'', DataSourceArguement = ''External()'' where Parameter = ''BMatlab''' );
iadsread( 'IADS-CDS$58000', '', 0, '? update ParameterDefaults set Parameter = ''CMatlab'', ParamType = ''float'', DataSourceType = ''Iap'', DataSourceArguement = ''External()'' where Parameter = ''CMatlab''' );

% Now, very important, we need to 'commit' the update queries to the server. This will send them to the server so they will be
% available on all the other PCs in the room

iadsread( 'IADS-CDS$58000', '', 0, '? commit ParameterDefaults 1' );

% Please ensure that trailing 1 is present in the commit statement. This designates that the commit statment is sent to the server immediately.

% If the call doesn't exception, then we're on to the next parameter

% Likewise, you can use a client to add these parameters to the ParameterDefault table. At this time, the function External() will
% return an error in the Iads client. Ignore this error and save the ParameterDefaults table. Once the parameters are visible
% in the ParameterDefaults table, we can continue.
%
% Finally, let's write some data to the parameters

iadswrite( 'IADS-CDS$58000', '', 'AMatlab,BMatlab,CMatlab', abc )

% That's all there is to it. Now we need to put these concepts all together in an example script

% For a working example, start here...
% The following code will explain things in more detail
% Here's an example script to read data from the Iads server
% in real-time using iadsread, calculate a derived result, and write the
% results back to the server as new parameters using iadswrite.
% With this example, in theory, you could run Matlab in realtime to
% produce derived parameter results.

% First, let's add the parameters to the server that we are about to update and commit.

iadsread( 'IADS-CDS$58000', '', 0, '? update ParameterDefaults set Parameter = ''AMatlab'', ParamType = ''float'', DataSourceType = ''Iap'', DataSourceArguement = ''External()'' where Parameter = ''AMatlab''' );
iadsread( 'IADS-CDS$58000', '', 0, '? update ParameterDefaults set Parameter = ''BMatlab'', ParamType = ''float'', DataSourceType = ''Iap'', DataSourceArguement = ''External()'' where Parameter = ''BMatlab''' );
iadsread( 'IADS-CDS$58000', '', 0, '? update ParameterDefaults set Parameter = ''CMatlab'', ParamType = ''float'', DataSourceType = ''Iap'', DataSourceArguement = ''External()'' where Parameter = ''CMatlab''' );
iadsread( 'IADS-CDS$58000', '', 0, '? commit ParameterDefaults 1' );

% Now let's run in an infinite loop reading data from the Iads server, calculating results, and writing back to the Iads server.
% While this code is running, you should be able to bring up an Iads client display and view the output parameters. For debugging
% purposes, we recommend you watch the parameters in Stripcharts. Compare the input values with the results and see if they are reasonable

while ( 1 )
   
% Request one second of data from parameters A, B, and C from Iads server IADS-CDS on port 58000
    abc = iadsread( 'IADS-CDS$58000', '', 1, 'A,B,C' );
   
    % The iadsread function is gated to the server update cycle so there is absolutely
    % no need to put any 'sleep' calls in your Matlab code. In fact, if you
    % delay your processing too much, you may not be able see the data on the
    % displays until you scroll back. Drop your derived parameters into a StripChart
    % and if you see the value delaying or a RedX on the display, try scrolling back.
    % If the data is latent, you'll need to optimize your code somehow.
   
    % Next, run your calculation on the input data matrix from iadsread
    columnwiseDataToWrite = abc * 10;
   
    % Now, write the results back to the Iads server. For the first
    % argument, we must use the same exact string as the iadsread call.
    % It is important to note that you must only make one call to iadsread
    % followed by a call to iadswrite. Any other combination is likely to misalign data.
    % Notice the third argument is the list of parameter names to be written to the server.
    % There should be one name for each column in the input matrix in argument four.
    % Argument four should contain the columnwise data matrix to write to the server (or file), each column
    % corresponding to a parameter listed in argument 3. The number of rows in columnwiseDataToWrite
    % should correspond exactly to the number of rows in the input data (abc variable above). In
    % other words, every row of the input data should output a corresponding row in your
    % columnwiseDataToWrite data. If not, you will be producing data at the incorrect rate to
    % the server.
   
    iadswrite( 'IADS-CDS$58000', '', 'AMatlab,BMatlab,CMatlab', columnwiseDataToWrite )
   
end


--

James Bretz

unread,
Mar 20, 2021, 6:00:40 PM3/20/21
to ia...@googlegroups.com
Hi Erdem,

I forgot to mention how to detect a test point start/stop. For this, you'll have to add a derived parameter to your configuration (you could name it "testPointIsActive" or similar) with the equation:

GetTestPointActive()

The value of this parameter will go from 0 (zero) to 1 (one) when a test point is started. You can drop this parameter on a StripChart and start/stop a TestPoint to confirm it's behavior. To detect that in Matlab, you would simply watch the value of this parameter for a 0 to 1 transition to mark the start time... and a 1 to 0 transition when the test point is stopped. You would essentially just add this parameter 'testPointIsActive' to the list of parameters in iadsread for your calculation loop and monitor it. If you want to get specific information about which TestPoint is active, you'll have to use the iadsread query capability to query the 'TestPoint' information. See the HowTo.m file for an example on how to perform query. I think the query might be something like '? select  * from TestPointLog' and then retrieve the very last entry in the results matrix.

Jim


/////////////////////////////////////////////////////////////////////
--
Reply all
Reply to author
Forward
0 new messages