Simulink Real-Time 2020b. How do I monitor/log a signal in my application using App Designer?

조회 수: 14 (최근 30일)
Hi,
I am trying to monitor a signal in my real-time application on Speedgoat using App Designer. I am trying to recreate a similar function to the one included in slrtExplorer but so far I have been unsuccessful. I am not able to use the suggested fucntions such as ConnectScalar, getCallbackDataForSignal and so on.
Does anyone know how to do it? Is there an example that is not the invertedPendulum that I can use as a reference?.
Thanks for the help!
  댓글 수: 1
Hamidreza Kolbari
Hamidreza Kolbari 2022년 4월 14일
Hi,
I am working an a project.
I am using below two different functions
function createInstrumentation(app)
% Create a new instrument object that will be linked to the application
app.Instrument = slrealtime.Instrument;
% Connect callback to signal
addSignal(app.Instrument, [app.modelName,'/ControlValue'], 1)
addSignal(app.Instrument, [app.modelName,'/Gain2'], 1)
connectCallback(app.Instrument, @app.instrumentCallback);
end
function instrumentCallback(app, instObj, eventData)
if ~isempty(eventData.AcquireGroupData.Time)
[~, ctrlValue] = instObj.getCallbackDataForSignal(eventData, [app.modelName,'/ControlValue:1']);
[~, valveValue] = instObj.getCallbackDataForSignal(eventData, [app.modelName,'/Gain2:1']);
end
end
pushed button>>>>>>>>>>>\
createInstrumentation(app)
but it is not working. do you know what the problem is?

댓글을 달려면 로그인하십시오.

답변 (1개)

Diego Kuratli
Diego Kuratli 2021년 10월 4일
In R2021b, the code required for binding signals and parameters have been reduced. There is a simple example in the documentation:
If possible, I would recommend to move to R2021b.
For R2020b, this video might help:
  댓글 수: 2
Matteo Pellegri
Matteo Pellegri 2021년 10월 4일
Hi Diego, thanks for the reply.
I am aware of the improvement of 2021b but for now I am not able to move to 2021b.
I watched that video already and the problem is that connectScalar/connectLine are usfeul if you are monitoring a small amount of variables and it seems that I am not able to use the data I am logging with those functions. Furthermore adding programmatically the components and linking them seems way too complex for what I am trying to achieve.
The current workaround I implementes is the following
function setupInstrumentation(app)
% create instrumentation object
hInst = slrealtime.Instrument(mldatx);
%% Add signals and connections
hInst.addSignal({'block/signalName'}, 1);
%add callback
app.hInst.connectCallback(@app.updateCallback);
end
function updateCallback(app,instObj,eventData)
curr_time = eventData.AcquireGroupData.Time;
if ~isempty(curr_time)
aGData = eventData.AcquireGroupData.Data;
[~,cv_data] = instObj.getCallbackDataForSignal(eventData,'block/signalName',1);
app.edit.Value = double(cv_data(end)); %edit field (numeric) is not happy with anything but double
else
%do nothing
end
end
% Button pushed function: LogMessagesButton
function StartLogMessage(app, event)
selectedTargetName = app.getSelectedTargetName();
tg = slrealtime(selectedTargetName);
tg.removeAllInstruments;
app.setupInstrumentation;
% Clear previous data
app.hInst.clearScalarAndLineData;
% Validate and add instrumentation to target
tg.addInstrument(app.hInst);
end
It seems to work. Do you see anything wrong with this?
Thanks again!
Hamidreza Kolbari
Hamidreza Kolbari 2022년 4월 14일
Hi,
I am working an a project.
I am using below two different functions
function createInstrumentation(app)
% Create a new instrument object that will be linked to the application
app.Instrument = slrealtime.Instrument;
% Connect callback to signal
addSignal(app.Instrument, [app.modelName,'/ControlValue'], 1)
addSignal(app.Instrument, [app.modelName,'/Gain2'], 1)
connectCallback(app.Instrument, @app.instrumentCallback);
end
function instrumentCallback(app, instObj, eventData)
if ~isempty(eventData.AcquireGroupData.Time)
[~, ctrlValue] = instObj.getCallbackDataForSignal(eventData, [app.modelName,'/ControlValue:1']);
[~, valveValue] = instObj.getCallbackDataForSignal(eventData, [app.modelName,'/Gain2:1']);
end
end
pushed button>>>>>>>>>>>\
createInstrumentation(app)
but it is not working. do you know what the problem is?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Target Computer Setup에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by