Closed Graham-EGI closed 2 years ago
@Graham-EGI To stop the SDI from interfering with the file transfer (e.g. by deleting files after a run is complete), start the target with the following command:
app.tg.start('AutoImportFileLog',false,'ExportToBaseWorkspace',false,'FileLogMaxRuns',100)
@Graham-EGI
This is some example code to retrieve the file and open in SDI:
% post processing script to retrieve data from the target
clearvars; close all; clc;
%% === parameters =========================================================
tgName = 'EGIBaseline';
mdlName = 'sweptCtrlMdl';
dataDir = fullfile('D:','simulink_data');
matFileName = 'simdata.mat';
% =========================================================================
%% === test Speedgoat connection ==========================================
tg = slrealtime(tgName);
try
tg.connect
catch ME
fprintf('\n*** Target %s not connected. Stopping program. Check connection.\n',tgName)
fprintf('\n*** Matlab error \n %s \n\n',ME.getReport)
return
end
if tg.isConnected
fprintf('\n*** Target %s is connected at IP address %s. \n\n',tg.TargetSettings.name,tg.TargetSettings.address)
end
ipAddress = tg.TargetSettings.address;
% =========================================================================
%% === copy data from target ==============================================
newFolder = fullfile(dataDir,mdlName);
mkdir(newFolder);
system(['pscp -r slrt@', ipAddress, ':/home/slrt/applications/', mdlName, '/* ' ,newFolder])
% =========================================================================
%% === Import Logged Data into MATLAB and view in Simulation Data Inspector
importLogData(newFolder)
Simulink.sdi.view;
% =========================================================================
%% === Export to .MAT file from Simulation Data Inspector =================
runIDs = Simulink.sdi.getAllRunIDs; % get run ID
runID = runIDs(end);
rtRun = Simulink.sdi.getRun(runID); % get data for last run
SignalData = rtRun.export;
Simulink.sdi.exportRun(runID,'to','file','filename',matFileName); % export to .mat
% =========================================================================
@Graham-EGI
The importLogData function was something Mathworks provided us early on for beta testing. I believe this is now replaced by
slrealtime.fileLogImport().
Have updated the system to use the logic above.
Seems to work perfectly when running from an interactive MATLAB session (matlab UI), but there are errors when running from the python server.
Python errors:
stoptarget
from host server. Now with the addition of the Simulink.sdi.setRecordData(false);
line being included, the time until the monitoring system catches the speegoat in the "DONE" state is much shorter, but the pTg.stop
line still times out. There is a system in the UI/ middlecode/ host server that catches this timeout error at least.slrealtime.fileLogImport()
and importLogData()
error only when being ran from the python server.Stop error message:
Error using slrealtime.Target/throwError
Cannot stop application on target 'EGIBaseline2': Timed-out waiting for application to stop.
Error in slrealtime.Target/stop
Error in stoptarget (line 3)
pTg.stop
Logging err message:
Error using slrealtime.internal.Application
Enter a valid application name
Error in slrealtime.Application
Error in slrealtime.internal.logging.Importer/checkFileLogDataVersion
Error in slrealtime.internal.logging.Importer/importLocal
Error in importLogData
Error in FOSTWINctrlPost (line 30)
importLogData(loggingDataDir)
@johannes-spinneken Update on the logging without using the data inspector during the simulation:
pTg.stop
in stoptarget.m
still times out. Code lives in private repo.slrealtime.fileLogImport()
seems as though it was working the whole time. Issues came from for some reason this script is the only one that doesn't like the slashes in path names to be /
and needs them to be \\
to escape the back slash when coming from python server. All other paths with forward slashes work so it's a bit odd.Issues resolved, timeouts related to using a constant block for the inport data and using the data inspector. Updates fixed the use of root level inport blocks in non realtime (removing the need for the constant block) and added in system to copy log data from the host machine directly and turn off the data inspector.
Closing
When running the simulation in realtime, there are often issues when running the
pTg.stop
line to stop the simulation on the speedgoat.Symptoms:
pTg.stop
orstoptarget
(when coming from the UI)Cannot stop application on target 'EGIBaseline2' : Timed-out waiting for application to stop
logsout
variable is transferred to the host machineAdding
Simulink.sdi.setRecordData(false);
didn't seem to fix the issue